mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-21 18:36:17 -04:00
AI: update getStatDifferenceFromBuilding (#13492)
* Update * Update ConstructionAutomation.kt
This commit is contained in:
parent
9cce7b21bd
commit
50de8e65c6
@ -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) {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user