/// <summary> /// Invokes the AI strategy on the Similization item /// </summary> internal virtual void Invoke(AICity foreignCity) { if (foreignCity == null) { throw new ArgumentNullException("foreignCity"); } if (!this.managedCities.Contains(foreignCity)) { this.managedCities.Add(foreignCity); foreignCity.ImprovementBuilt += new EventHandler <ImprovementBuiltEventArgs>(OnImprovementBuilt); } }
/// <summary> /// Gets a new city from the village for the exploring units' country. /// </summary> /// <param name="v"></param> /// <param name="explorer"></param> /// <returns></returns> private static City GetCity(Village v, Unit explorer) { City newCity = null; if (explorer.GetType() == typeof(AIUnit) || explorer.GetType() == typeof(AISettler) || explorer.GetType() == typeof(AIWorker)) { newCity = new AICity(explorer.Coordinates, explorer.ParentCountry); } else { newCity = new City(explorer.Coordinates, explorer.ParentCountry); } return(newCity); }
/// <summary> /// Settles a new city. This will create a new city (with the /// given name), and remove the settler from the map. /// </summary> /// <param name="cityName">The name of the city to create.</param> /// <returns>A <c>City</c> object for the city just created.</returns> public override City Settle(string cityName) { GameRoot root = GameRoot.Instance; GridCell cell = root.Grid.GetCell(this.Coordinates); if (cell.City == null) { AICity newCity = new AICity(this.Coordinates, this.ParentCountry); newCity.Name = cityName; ParentCountry.Cities.Add(newCity); //have to move to the next unit, since this unit no longer exists. root.ActivateNextUnit(); return(newCity); } else { throw new InvalidOperationException(ServerResources.GridCellHasCity); } }
/// <summary> /// Event handler for the <i>ImprovementBuilt</i> event of a city using this strategy. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected override void OnImprovementBuilt(object sender, ImprovementBuiltEventArgs e) { AICity city = e.City as AICity; BuildableItem nextImprovement = null; GameRoot root = GameRoot.Instance; //what to do with what we just built? if (e.Improvement.GetType() == typeof(AIUnit)) { AIUnit unit = e.Improvement as AIUnit; switch (city.PrimaryNeed) { case AICityNeed.Commerce: break; case AICityNeed.Culture: break; case AICityNeed.Food: break; case AICityNeed.UnitDefense: unit.Fortified = true; break; } } else if (e.Improvement.GetType() == typeof(AISettler)) { } else if (e.Improvement.GetType() == typeof(AIWorker)) { AIWorker worker = e.Improvement as AIWorker; worker.ParentCity = e.City; worker.Automated = true; } //next item to build switch (city.PrimaryNeed) { case AICityNeed.Commerce: if (!city.HasWorkerInFields()) { nextImprovement = UnitFactory.CreateWorker(city); } else { nextImprovement = city.GetBuildableItemForNeed(city.PrimaryNeed, typeof(Improvement)); } break; case AICityNeed.Culture: nextImprovement = city.GetBuildableItemForNeed(city.PrimaryNeed, typeof(Improvement)); break; case AICityNeed.Food: if (!city.HasWorkerInFields()) { nextImprovement = UnitFactory.CreateWorker(city); } else { nextImprovement = city.GetBuildableItemForNeed(city.PrimaryNeed, typeof(Improvement)); } break; case AICityNeed.UnitDefense: nextImprovement = city.GetBuildableItemForNeed(city.PrimaryNeed, typeof(Unit)); break; } city.NextImprovement = nextImprovement; }
/// <summary> /// Starts using this strategy for the city. /// </summary> /// <param name="foreignCity"></param> internal override void Invoke(AICity foreignCity) { base.Invoke(foreignCity); }