From 5cf3e7764ab6d9f0a39b1178bb23e5fddac260aa Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 4 Dec 2020 14:12:47 +0200 Subject: [PATCH] CORRECT handling for mods that changed their buildings or units --- core/src/com/unciv/logic/GameInfo.kt | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index 813c3cd44e..99ae9a22ae 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -5,6 +5,7 @@ import com.unciv.Constants import com.unciv.UncivGame import com.unciv.logic.automation.NextTurnAutomation import com.unciv.logic.city.CityConstructions +import com.unciv.logic.city.PerpetualConstruction import com.unciv.logic.civilization.* import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileMap @@ -271,9 +272,13 @@ class GameInfo { for (building in city.cityConstructions.builtBuildings.toHashSet()) if (!ruleSet.buildings.containsKey(building)) city.cityConstructions.builtBuildings.remove(building) - for (building in city.cityConstructions.constructionQueue.toList()) - if (!ruleSet.buildings.containsKey(building)) - city.cityConstructions.constructionQueue.remove(building) + + // Remove invalid buildings or units from the queue - don't just check buildings and units because it might be a special construction as well + for (construction in city.cityConstructions.constructionQueue.toList()) { + if (!ruleSet.buildings.containsKey(construction) && !ruleSet.units.containsKey(construction) + && !PerpetualConstruction.perpetualConstructionsMap.containsKey(construction)) + city.cityConstructions.constructionQueue.remove(construction) + } } @@ -322,13 +327,19 @@ class GameInfo { for (cityInfo in civInfo.cities) cityInfo.cityStats.updateCityHappiness() for (cityInfo in civInfo.cities) { - // As of 3.10.14, specialists are saved by name not by stat - for((key, value) in cityInfo.population.specialists.toHashMap().filter { it.value>0 }) + for ((key, value) in cityInfo.population.specialists.toHashMap().filter { it.value > 0 }) cityInfo.population.specialistAllocations.add( Specialist.specialistNameByStat(key), value.toInt()) cityInfo.population.specialists.clear() + /** We remove constructions from the queue that aren't defined in the ruleset. + * This can lead to situations where the city is puppeted and had its construction removed, and there's no way to user-set it + * So for cities like those, we'll auto-set the construction + */ + if (cityInfo.isPuppet && cityInfo.cityConstructions.constructionQueue.isEmpty()) + cityInfo.cityConstructions.chooseNextConstruction() + cityInfo.cityStats.update() } }