Resolved #12180 - only trigger population reassignment on new buildings when it really changes something

This commit is contained in:
yairm210 2024-09-02 18:13:33 +03:00
parent 2ed5fb9d05
commit 396bf60e25

View File

@ -543,13 +543,16 @@ class CityConstructions : IsPartOfGameInfoSerialization {
&& city.isCapital())
civ.tech.addScience(civ.tech.scienceOfLast8Turns.sum() / 8)
// Happiness is global, so it could affect all cities
if (building.isStatRelated(Stat.Happiness, city)) {
for (city in civ.cities) {
city.reassignPopulationDeferred()
}
}
else city.reassignPopulationDeferred()
val previousHappiness = civ.getHappiness()
// can cause civ happiness update: reassignPopulationDeferred -> reassignPopulation -> cityStats.update -> civ.updateHappiness
city.reassignPopulationDeferred()
val newHappiness = civ.getHappiness()
/** Same check as [com.unciv.logic.civilization.Civilization.updateStatsForNextTurn] -
* but that triggers *stat calculation* whereas this is for *population assignment* */
if (previousHappiness != newHappiness && city.civ.gameInfo.ruleset.allHappinessLevelsThatAffectUniques
.any { newHappiness < it != previousHappiness < it})
city.civ.cities.filter { it != city }.forEach { it.reassignPopulationDeferred() }
if (tryAddFreeBuildings)
city.civ.civConstructions.tryAddFreeBuildings()