From 50de8e65c660e61f1555b6a444f691f35bbe7d1c Mon Sep 17 00:00:00 2001 From: EmperorPinguin <99119424+EmperorPinguin@users.noreply.github.com> Date: Mon, 23 Jun 2025 22:18:15 +0200 Subject: [PATCH] AI: update getStatDifferenceFromBuilding (#13492) * Update * Update ConstructionAutomation.kt --- .../logic/automation/city/ConstructionAutomation.kt | 7 +++++-- core/src/com/unciv/logic/city/CityStats.kt | 9 +++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/logic/automation/city/ConstructionAutomation.kt b/core/src/com/unciv/logic/automation/city/ConstructionAutomation.kt index 9fdce85cdd..d153b846bd 100644 --- a/core/src/com/unciv/logic/automation/city/ConstructionAutomation.kt +++ b/core/src/com/unciv/logic/automation/city/ConstructionAutomation.kt @@ -370,11 +370,14 @@ class ConstructionAutomation(val cityConstructions: CityConstructions) { private fun getStatDifferenceFromBuilding(building: String, localUniqueCache: LocalUniqueCache): Stats { val newCity = city.clone() newCity.setTransients(city.civ) // Will break the owned tiles. Needs to be reverted before leaving this function + //todo: breaks city connection; trade route gold is currently not considered for markets etc. + newCity.cityStats.update(updateCivStats = false, localUniqueCache = localUniqueCache, calculateGrowthModifiers = false) // Don't consider growth penalties for food values (we can work more mines/specialists instead of farms) + val oldStats = newCity.cityStats.currentCityStats newCity.cityConstructions.builtBuildings.add(building) newCity.cityConstructions.setTransients() - newCity.cityStats.update(updateCivStats = false, localUniqueCache = localUniqueCache) + newCity.cityStats.update(updateCivStats = false, localUniqueCache = LocalUniqueCache(), calculateGrowthModifiers = false) // Establish new localUniqueCache (for tile yield uniques) city.expansion.setTransients() // Revert owned tiles to original city - return newCity.cityStats.currentCityStats - city.cityStats.currentCityStats + return newCity.cityStats.currentCityStats - oldStats } private fun getBuildingStatsFromUniques(building: Building, buildingStats: Stats) { diff --git a/core/src/com/unciv/logic/city/CityStats.kt b/core/src/com/unciv/logic/city/CityStats.kt index 1e6b262552..4afdb800a6 100644 --- a/core/src/com/unciv/logic/city/CityStats.kt +++ b/core/src/com/unciv/logic/city/CityStats.kt @@ -488,7 +488,8 @@ class CityStats(val city: City) { fun update(currentConstruction: IConstruction = city.cityConstructions.getCurrentConstruction(), updateTileStats:Boolean = true, updateCivStats:Boolean = true, - localUniqueCache:LocalUniqueCache = LocalUniqueCache()) { + localUniqueCache:LocalUniqueCache = LocalUniqueCache(), + calculateGrowthModifiers:Boolean = true) { if (updateTileStats) updateTileStats(localUniqueCache) @@ -499,7 +500,7 @@ class CityStats(val city: City) { updateCityHappiness(statsFromBuildings) updateStatPercentBonusList(currentConstruction) - updateFinalStatList(currentConstruction) // again, we don't edit the existing currentCityStats directly, in order to avoid concurrency exceptions + updateFinalStatList(currentConstruction, calculateGrowthModifiers) // again, we don't edit the existing currentCityStats directly, in order to avoid concurrency exceptions val newCurrentCityStats = Stats() for (stat in finalStatList.values) newCurrentCityStats.add(stat) @@ -508,7 +509,7 @@ class CityStats(val city: City) { if (updateCivStats) city.civ.updateStatsForNextTurn() } - private fun updateFinalStatList(currentConstruction: IConstruction) { + private fun updateFinalStatList(currentConstruction: IConstruction, calculateGrowthModifiers: Boolean = true) { val newFinalStatList = StatMap() // again, we don't edit the existing currentCityStats directly, in order to avoid concurrency exceptions for ((key, value) in baseStatTree.children) @@ -572,7 +573,7 @@ class CityStats(val city: City) { var totalFood = newFinalStatList.values.map { it.food }.sum() // Apply growth modifier only when positive food - if (totalFood > 0) { + if (totalFood > 0 && calculateGrowthModifiers) { // Since growth bonuses are special, (applied afterwards) they will be displayed separately in the user interface as well. // All bonuses except We Love The King do apply even when unhappy val growthBonuses = getGrowthBonus(totalFood)