Happiness change from bought buildings can reapply citizen focus (#9395)

* Happiness change from bought buildings can reapply citizen focus

* Fix compilation error
This commit is contained in:
SomeTroglodyte 2023-05-17 23:37:38 +02:00 committed by GitHub
parent 1de866c7ed
commit d31a2d83ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -314,8 +314,7 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){
private fun addHappinessBuildingChoice() {
val happinessBuilding = nonWonders
.filter { (it.isStatRelated(Stat.Happiness)
|| it.hasUnique(UniqueType.RemoveAnnexUnhappiness))
.filter { it.isStatRelated(Stat.Happiness)
&& Automation.allowAutomatedConstruction(civInfo, cityInfo, it) }
.filterBuildable()
.minByOrNull { it.cost }

View File

@ -689,6 +689,13 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
if (isStatRelated(Stat.Science) && civInfo.hasUnique(UniqueType.TechBoostWhenScientificBuildingsBuiltInCapital))
civInfo.tech.addScience(civInfo.tech.scienceOfLast8Turns.sum() / 8)
// Happiness change _may_ invalidate best worked tiles (#9238), but if the building
// isn't bought then reassignPopulation will run later in startTurn anyway
if (boughtWith != null && isStatRelated(Stat.Happiness)) {
cityConstructions.city.reassignPopulation()
cityConstructions.city.updateCitizens = false
}
cityConstructions.city.cityStats.update() // new building, new stats
civInfo.cache.updateCivResources() // this building/unit could be a resource-requiring one
civInfo.cache.updateCitiesConnectedToCapital(false) // could be a connecting building, like a harbor
@ -721,6 +728,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
if (getMatchingUniques(UniqueType.Stats).any { it.stats[stat] > 0 }) return true
if (getMatchingUniques(UniqueType.StatsFromTiles).any { it.stats[stat] > 0 }) return true
if (getMatchingUniques(UniqueType.StatsPerPopulation).any { it.stats[stat] > 0 }) return true
if (stat == Stat.Happiness && hasUnique(UniqueType.RemoveAnnexUnhappiness)) return true
return false
}