From 3792dc04a8ca60bb92b1de301b0caeddd1f934f7 Mon Sep 17 00:00:00 2001 From: itanasi <44038014+itanasi@users.noreply.github.com> Date: Mon, 16 Dec 2024 04:55:55 -0800 Subject: [PATCH] Rebase and commit (#12662) --- .../com/unciv/logic/automation/Automation.kt | 39 ++++++++++++++----- core/src/com/unciv/logic/city/CityFocus.kt | 6 ++- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/core/src/com/unciv/logic/automation/Automation.kt b/core/src/com/unciv/logic/automation/Automation.kt index a4aef7bb6f..0fbe243378 100644 --- a/core/src/com/unciv/logic/automation/Automation.kt +++ b/core/src/com/unciv/logic/automation/Automation.kt @@ -46,7 +46,34 @@ object Automation { return rank } + // More complicated logic to properly weigh Food vs other Stats (esp Production) + private fun getFoodModWeight(city: City, surplusFood: Float): Float { + val speed = city.civ.gameInfo.speed.modifier + // Zero out Growth if close to Unhappiness limit + if (city.civ.getHappiness() < -8) + return 0f + if (city.civ.isAI()) { + // When Happy, 2 production is better than 1 growth, + // but setting such by default worsens AI civ citizen assignment, + // probably due to badly configured personalities not properly weighing food vs non-food yields + if (city.population.population < 5) + return 2f + if (surplusFood > city.population.getFoodToNextPopulation() / (10 * speed)) + return 0.75f // get Growth just under Production + return 1.5f + } + // Human weights. May be different since AI Happiness is always "easier" + // Only apply these for Default to not interfere with Focus weights + if (city.getCityFocus() == CityFocus.NoFocus) { + if (city.population.population < 5) + return 2f + if (surplusFood > city.population.getFoodToNextPopulation() / (10 * speed)) + return 0.75f // get Growth just under Production + } + return 1f + } + fun rankStatsForCityWork(stats: Stats, city: City, areWeRankingSpecialist: Boolean, localUniqueCache: LocalUniqueCache): Float { val cityAIFocus = city.getCityFocus() val yieldStats = stats.clone() @@ -116,16 +143,8 @@ object Automation { newGrowthFood += growthFood / 4 } newGrowthFood = newGrowthFood.coerceAtLeast(0f) // floor to 0 for safety - - // When Happy, 2 production is better than 1 growth, - // but setting such by default worsens AI civ citizen assignment, - // probably due to badly configured personalities not properly weighing food vs non-food yields - - // Zero out Growth if close to Unhappiness limit as well - val baseFocusWeight = if (city.civ.getHappiness() < -8) 0 else { - if (cityAIFocus in CityFocus.zeroFoodFocuses) 1 else 2 - } - yieldStats.food += newGrowthFood * foodBaseWeight * baseFocusWeight + + yieldStats.food += newGrowthFood * foodBaseWeight * getFoodModWeight(city, surplusFood) } if (city.population.population < 10) { diff --git a/core/src/com/unciv/logic/city/CityFocus.kt b/core/src/com/unciv/logic/city/CityFocus.kt index 110c81254b..3a844cd2f7 100644 --- a/core/src/com/unciv/logic/city/CityFocus.kt +++ b/core/src/com/unciv/logic/city/CityFocus.kt @@ -41,13 +41,15 @@ enum class CityFocus( FaithFocus("${Stat.Faith.character}", true, Stat.Faith), GoldGrowthFocus("${Stat.Gold.character} ${Stat.Food.character}", true) { override fun getStatMultiplier(stat: Stat) = when (stat) { - Stat.Gold, Stat.Food -> 2f + Stat.Gold -> 2f + Stat.Food -> 1.5f else -> 1f } }, ProductionGrowthFocus("${Stat.Production.character} ${Stat.Food.character}", true) { override fun getStatMultiplier(stat: Stat) = when (stat) { - Stat.Production, Stat.Food -> 2f + Stat.Production -> 2f + Stat.Food -> 1.5f else -> 1f } },