// Update stats of all cities private void CitiesTurn(IPlayer player) { var currentScienceCost = AdvanceFunctions.CalculateScienceCost(this, _activeCiv); var foodRows = Rules.Cosmic.RowsFoodBox; var shieldRows = Rules.Cosmic.RowsShieldBox; foreach (var city in _activeCiv.Cities) { city.ImprovementSold = false; // Change food in storage city.FoodInStorage += city.SurplusHunger; var shields = city.Production; var tax = city.Tax; var science = city.Science; // Change city size if (city.FoodInStorage < 0) { city.FoodInStorage = 0; city.Size -= 1; AutoRemoveWorkersDistribution(city); city.CalculateOutput(city.Owner.Government, this); } else { var maxFood = (city.Size + 1) * foodRows; if (city.FoodInStorage > maxFood) { city.FoodInStorage = 0; city.Size += 1; var storageBuildings = city.Improvements .Where(i => i.Effects.ContainsKey(ImprovementEffect.FoodStorage)).Select(b => b.Effects[ImprovementEffect.FoodStorage]).ToList(); if (storageBuildings.Count > 0) { var totalStorage = storageBuildings.Sum(); if (totalStorage is > 100 or < 0) { totalStorage = storageBuildings.Where(v => v is >= 0 and <= 100).Max(); } if (totalStorage != 0) { city.FoodInStorage += maxFood * totalStorage / 100; } } AutoAddDistributionWorkers(city); // Automatically add a workers on a tile city.CalculateOutput(city.Owner.Government, this); } } if (city.UnhappyCitizens > 0) { if (city.WeLoveKingDay) { player.WeLoveTheKingCanceled(city); city.WeLoveKingDay = false; } if (city.UnhappyCitizens > city.HappyCitizens) { player.CivilDisorder(city); city.CivilDisorder = true; continue; } if (city.CivilDisorder) { city.CivilDisorder = false; player.OrderRestored(city); } } else { if (city.CivilDisorder) { city.CivilDisorder = false; player.OrderRestored(city); } if (city.HappyCitizens >= city.Size - city.UnhappyCitizens - city.HappyCitizens) { if (!city.WeLoveKingDay) { player.WeLoveTheKingStarted(city); } city.WeLoveKingDay = true; } } if (!ProductionPossibilities.ProductionValid(city)) { var newItem = ProductionPossibilities.AutoNext(city); player.CantProduce(city, newItem); if (newItem != null) { city.ItemInProduction = newItem; } } city.ShieldsProgress += shields; if (city.ShieldsProgress >= city.ItemInProduction.Cost * shieldRows) { if (city.ItemInProduction.CompleteProduction(city, Rules)) { city.ShieldsProgress = 0; player.CityProductionComplete(city); } } _activeCiv.Money += tax; foreach (var cityImprovement in city.Improvements) { if (cityImprovement.Upkeep > 0) { if (_activeCiv.Money >= cityImprovement.Upkeep) { _activeCiv.Money -= cityImprovement.Upkeep; } else { //Sell it !! city.SellImprovement(cityImprovement); player.CantMaintain(city, cityImprovement); } } } if (science > 0) { _activeCiv.Science += science; if (_activeCiv.ReseachingAdvance < 0) { var researchPossibilities = AdvanceFunctions.CalculateAvailableResearch(this, _activeCiv); player.SelectNewAdvance(this, researchPossibilities); currentScienceCost = AdvanceFunctions.CalculateScienceCost(this, _activeCiv); } else if (currentScienceCost <= _activeCiv.Science) { this.GiveAdvance(_activeCiv.ReseachingAdvance, _activeCiv); _activeCiv.Science -= currentScienceCost; } } } }
// Update stats of all cities private void CitiesTurn(IPlayer player) { var currentScienceCost = AdvanceFunctions.CalculateScienceCost(this, _activeCiv); var foodRows = Rules.Cosmic.RowsFoodBox; var shieldRows = Rules.Cosmic.RowsShieldBox; foreach (var city in _activeCiv.Cities) { city.ImprovementSold = false; // Change food in storage city.FoodInStorage += city.SurplusHunger; var shields = city.Production; var tax = city.Tax; var science = city.Science; // Change city size if (city.FoodInStorage < 0) { city.FoodInStorage = 0; city.ShrinkCity(this); } else { var maxFood = (city.Size + 1) * foodRows; if (city.FoodInStorage > maxFood) { city.GrowCity(this); city.ResetFoodStorage(foodRows); } } if (city.UnhappyCitizens > 0) { if (city.WeLoveKingDay) { player.WeLoveTheKingCanceled(city); city.WeLoveKingDay = false; } if (city.UnhappyCitizens > city.HappyCitizens) { player.CivilDisorder(city); city.CivilDisorder = true; continue; } if (city.CivilDisorder) { city.CivilDisorder = false; player.OrderRestored(city); } } else { if (city.CivilDisorder) { city.CivilDisorder = false; player.OrderRestored(city); } if (city.HappyCitizens >= city.Size - city.UnhappyCitizens - city.HappyCitizens) { if (!city.WeLoveKingDay) { player.WeLoveTheKingStarted(city); } city.WeLoveKingDay = true; } } if (!ProductionPossibilities.ProductionValid(city)) { var newItem = ProductionPossibilities.AutoNext(city); player.CantProduce(city, newItem); if (newItem != null) { city.ItemInProduction = newItem; } } city.ShieldsProgress += shields; if (city.ShieldsProgress >= city.ItemInProduction.Cost * shieldRows) { if (city.ItemInProduction.CompleteProduction(city, Rules)) { city.ShieldsProgress = 0; player.CityProductionComplete(city); } } _activeCiv.Money += tax; foreach (var cityImprovement in city.Improvements) { if (cityImprovement.Upkeep > 0) { if (_activeCiv.Money >= cityImprovement.Upkeep) { _activeCiv.Money -= cityImprovement.Upkeep; } else { //Sell it !! city.SellImprovement(cityImprovement); player.CantMaintain(city, cityImprovement); } } } if (science > 0) { _activeCiv.Science += science; if (_activeCiv.ReseachingAdvance < 0) { var researchPossibilities = AdvanceFunctions.CalculateAvailableResearch(this, _activeCiv); player.SelectNewAdvance(this, researchPossibilities); currentScienceCost = AdvanceFunctions.CalculateScienceCost(this, _activeCiv); } else if (currentScienceCost <= _activeCiv.Science) { this.GiveAdvance(_activeCiv.ReseachingAdvance, _activeCiv); _activeCiv.Science -= currentScienceCost; } } } }