/// <summary> /// Enters the village. /// </summary> /// <param name="discoveringUnit"></param> /// <returns>The <see cref="VillageGoody"/> awarded to the discovering country.</returns> public VillageGoody Discover(Unit discoveringUnit) { if (discoveringUnit == null) { throw new ArgumentNullException("discoveringUnit"); } VillageGoody goody = GoodyFactory.GetGoody(this, discoveringUnit); goody.ApplyGoody(discoveringUnit.ParentCountry); return(goody); }
/// <summary> /// Moves the unit to the desired cell. Takes the appropriate /// number of turns. /// </summary> /// <param name="destination">The coordinates on the <see cref="Grid"/> /// the <see cref="Unit"/> is trying to move to.</param> /// <returns></returns> public virtual MoveResult MoveTo(Point destination) { GameRoot root = GameRoot.Instance; Grid grid = root.Grid; //create a journey to the destination Journey journey = CreateJourney(destination); ReadOnlyCollection <Point> path = journey.CalculateExistingPath(); if (journey == null) { return(MoveResult.UnreachableTerrain); } GridCell currentCell = grid.GetCell(this.Coordinates); GridCell nextCell = grid.GetCell(this.Journey.PeekNextPoint()); int roadBonus = root.Ruleset.RoadMovementBonus; if (roadBonus == 0) { throw new InvalidOperationException(ServerResources.RulesetHasInvalidRoadBonus); } if (this.MovesLeft == 0) { OnTurnFinished(); return(MoveResult.NoMovesLeft); } //fight any enemies at the destination MoveResult result = CombatUnits(nextCell); if (result == MoveResult.MoveSuccess) { //we're still alive, so we must have taken the new cell. int moveCost = nextCell.Terrain.MovementCost; if (currentCell.HasRoad && nextCell.HasRoad) { if (currentCell.HasRailroad && nextCell.HasRailroad) { moveCost = 0; } else { moveCost = moveCost / roadBonus; } } //we can now actually move to the new cell. this.Journey = journey; ContinueJourney(); if (this.MovesLeft >= moveCost) { this.MovesLeft -= moveCost; } else { this.MovesLeft = 0; } //check for villages if (nextCell.Village != null) { VillageGoody goody = nextCell.Village.Discover(this); VillageEventArgs e = new VillageEventArgs(nextCell.Village, goody); OnVillageEncountered(e); nextCell.Village = null; } // Check to see if we just invaded a foreign city. if (nextCell.City != null && nextCell.City.ParentCountry != ParentCountry) { nextCell.City.Capture(this); } OnMoved(); if (this.MovesLeft <= 0) { OnTurnFinished(); } } return(result); }
/// <summary> /// Initializes a new instance of the <c>VillageEventArgs</c> class. /// </summary> /// <param name="villageEncountered"></param> /// <param name="goody"></param> public VillageEventArgs(Village villageEncountered, VillageGoody goody) { _village = villageEncountered; _goody = goody; }