Rebase and commit (#12662)

This commit is contained in:
itanasi 2024-12-16 04:55:55 -08:00 committed by GitHub
parent c68b19470f
commit 3792dc04a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 12 deletions

View File

@ -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) {

View File

@ -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
}
},