CORRECT handling for mods that changed their buildings or units

This commit is contained in:
Yair Morgenstern 2020-12-04 14:12:47 +02:00
parent 81a38be5f4
commit 5cf3e7764a

View File

@ -5,6 +5,7 @@ import com.unciv.Constants
import com.unciv.UncivGame import com.unciv.UncivGame
import com.unciv.logic.automation.NextTurnAutomation import com.unciv.logic.automation.NextTurnAutomation
import com.unciv.logic.city.CityConstructions import com.unciv.logic.city.CityConstructions
import com.unciv.logic.city.PerpetualConstruction
import com.unciv.logic.civilization.* import com.unciv.logic.civilization.*
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
@ -271,9 +272,13 @@ class GameInfo {
for (building in city.cityConstructions.builtBuildings.toHashSet()) for (building in city.cityConstructions.builtBuildings.toHashSet())
if (!ruleSet.buildings.containsKey(building)) if (!ruleSet.buildings.containsKey(building))
city.cityConstructions.builtBuildings.remove(building) city.cityConstructions.builtBuildings.remove(building)
for (building in city.cityConstructions.constructionQueue.toList())
if (!ruleSet.buildings.containsKey(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
city.cityConstructions.constructionQueue.remove(building) 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) cityInfo.cityStats.updateCityHappiness()
for (cityInfo in civInfo.cities) { for (cityInfo in civInfo.cities) {
// As of 3.10.14, specialists are saved by name not by stat // 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( cityInfo.population.specialistAllocations.add(
Specialist.specialistNameByStat(key), value.toInt()) Specialist.specialistNameByStat(key), value.toInt())
cityInfo.population.specialists.clear() 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() cityInfo.cityStats.update()
} }
} }