From e406533ef00bae94efc413d7bf7b190f1c380cc7 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 10 Aug 2023 16:05:38 +0300 Subject: [PATCH] AI: Finer-tuned Food ranking vs other stats for cities --- .../com/unciv/logic/automation/Automation.kt | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/core/src/com/unciv/logic/automation/Automation.kt b/core/src/com/unciv/logic/automation/Automation.kt index 67361a7613..f2a10c1c43 100644 --- a/core/src/com/unciv/logic/automation/Automation.kt +++ b/core/src/com/unciv/logic/automation/Automation.kt @@ -40,6 +40,8 @@ object Automation { return rank } + val zeroFoodFocuses = setOf(CityFocus.CultureFocus, CityFocus.FaithFocus, CityFocus.GoldFocus, + CityFocus.HappinessFocus, CityFocus.ProductionFocus, CityFocus.ScienceFocus) private fun rankStatsForCityWork(stats: Stats, city: City, cityStats: Stats, specialist: Boolean, localUniqueCache: LocalUniqueCache): Float { val cityAIFocus = city.cityAIFocus val yieldStats = stats.clone() @@ -62,23 +64,20 @@ object Automation { if (surplusFood > 0 && city.avoidGrowth) { yieldStats.food = 0f // don't need more food! - } else { - if (cityAIFocus != CityFocus.NoFocus && cityAIFocus != CityFocus.FoodFocus && cityAIFocus != CityFocus.ProductionGrowthFocus && cityAIFocus != CityFocus.GoldGrowthFocus) { - // Focus on non-food/growth - if (surplusFood < 0) - yieldStats.food *= 8 // Starving, need Food, get to 0 - else - yieldStats.food /= 2 - } else if (!city.avoidGrowth) { - // NoFocus or Food/Growth Focus. Target +2 Food Surplus - if (surplusFood < 2) - yieldStats.food *= 8 - else if (cityAIFocus != CityFocus.FoodFocus) - yieldStats.food /= 2 - if (city.population.population < 5 && cityAIFocus != CityFocus.FoodFocus) - // NoFocus or GoldGrow or ProdGrow, not Avoid Growth, pop < 5. FoodFocus already does this up - yieldStats.food *= 3 - } + } else if (cityAIFocus in zeroFoodFocuses) { + // Focus on non-food/growth + if (surplusFood < 0) + yieldStats.food *= 8 // Starving, need Food, get to 0 + else + yieldStats.food /= 2 + } else if (!city.avoidGrowth) { + // NoFocus or Food/Growth Focus. Target +2 Food Surplus + if (surplusFood < 2) + yieldStats.food *= 8 + else if (city.population.population < 5) + yieldStats.food *= 3 + else if (cityAIFocus == CityFocus.FoodFocus) + yieldStats.food *= 2 } if (city.population.population < 5) {