private bool TroopObjectCreateFromCity(ICity city, ISimpleStub stub, uint x, uint y, out ITroopObject troopObject) { if (stub.TotalCount == 0 || !city.DefaultTroop.RemoveFromFormation(FormationType.Normal, stub)) { troopObject = null; return(false); } var troopStub = city.CreateTroopStub(); troopStub.BeginUpdate(); troopStub.Add(stub); troopStub.EndUpdate(); troopObject = city.CreateTroopObject(troopStub, x, y + 1); troopObject.BeginUpdate(); troopObject.Stats = new TroopStats(formula.GetTroopRadius(troopStub, null), formula.GetTroopSpeed(troopStub)); world.Regions.Add(troopObject); troopObject.EndUpdate(); return(true); }
/// <summary> /// Creates a city under the specified player with initial troop and main building /// </summary> public virtual void CreateCity(ICityFactory cityFactory, IPlayer player, string cityName, byte level, Position cityPosition, IBarbarianTribeManager barbarianTribeManager, out ICity city) { city = cityFactory.CreateCity(world.Cities.GetNextCityId(), player, cityName, cityPosition, formula.GetInitialCityResources(), formula.GetInitialCityRadius(), formula.GetInitialAp(), Theme.DEFAULT_THEME_ID, Theme.DEFAULT_THEME_ID, Theme.DEFAULT_THEME_ID, Theme.DEFAULT_THEME_ID); var mainBuildingPosition = cityPosition.Left(); IStructure mainBuilding = city.CreateStructure(2000, level, mainBuildingPosition.X, mainBuildingPosition.Y); player.Add(city); world.Cities.Add(city); city.BeginUpdate(); mainBuilding.BeginUpdate(); world.Regions.Add(mainBuilding); mainBuilding.EndUpdate(); var defaultTroop = city.CreateTroopStub(); defaultTroop.BeginUpdate(); defaultTroop.AddFormation(FormationType.Normal); defaultTroop.AddFormation(FormationType.Garrison); defaultTroop.AddFormation(FormationType.InBattle); defaultTroop.EndUpdate(); RecalculateCityResourceRates(city); SetResourceCap(city); city.EndUpdate(); if (player.GetCityCount() == 1) { barbarianTribeManager.CreateBarbarianTribeNear(1, 10, city.PrimaryPosition.X, city.PrimaryPosition.Y, 10); } }
public virtual bool TroopStubCreate(out ITroopStub troopStub, ICity city, ISimpleStub stub, TroopState initialState = TroopState.Idle) { if (!city.DefaultTroop.RemoveFromFormation(FormationType.Normal, stub)) { troopStub = null; return(false); } troopStub = city.CreateTroopStub(); troopStub.BeginUpdate(); troopStub.Add(stub); troopStub.State = initialState; troopStub.EndUpdate(); return(true); }