From 6e88828240d68345204eccf241709dd3ced13347 Mon Sep 17 00:00:00 2001 From: Jack Rainy Date: Wed, 27 Apr 2022 09:16:11 +0300 Subject: [PATCH] Correct calculation of the production for the Settlers (#6590) * Correct contribution to the Settler production * Correct indicator of the food usage during Settler production * More precise calculation of the food to production conversion * Revert of starvation avoidance during Settler production * Minor tweaks --- core/src/com/unciv/logic/city/CityStats.kt | 31 ++++++++++++------- .../com/unciv/ui/cityscreen/CityStatsTable.kt | 4 +-- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/core/src/com/unciv/logic/city/CityStats.kt b/core/src/com/unciv/logic/city/CityStats.kt index a79c3ca29f..a725e5f90b 100644 --- a/core/src/com/unciv/logic/city/CityStats.kt +++ b/core/src/com/unciv/logic/city/CityStats.kt @@ -64,8 +64,6 @@ class CityStats(val cityInfo: CityInfo) { var baseStatTree = StatTreeNode() - var statPercentBonusList = LinkedHashMap() - var statPercentBonusTree = StatTreeNode() // Computed from baseStatList and statPercentBonusList - this is so the players can see a breakdown @@ -75,8 +73,6 @@ class CityStats(val cityInfo: CityInfo) { var statsFromTiles = Stats() - var foodEaten = 0f - var currentCityStats: Stats = Stats() // This is so we won't have to calculate this multiple times - takes a lot of time, especially on phones //endregion @@ -96,7 +92,7 @@ class CityStats(val cityInfo: CityInfo) { // Deprecated as of 3.19.19 if (civInfo.hasUnique(UniqueType.GoldBonusFromTradeRoutesDeprecated)) percentageStats[Stat.Gold] += 25f // Machu Picchu speciality // - for ((stat, value) in stats) { + for ((stat) in stats) { stats[stat] *= percentageStats[stat].toPercent() } } @@ -344,7 +340,7 @@ class CityStats(val cityInfo: CityInfo) { } fun isConnectedToCapital(roadType: RoadStatus): Boolean { - if (cityInfo.civInfo.cities.count() < 2) return false// first city! + if (cityInfo.civInfo.cities.size < 2) return false// first city! // Railroad, or harbor from railroad return if (roadType == RoadStatus.Railroad) @@ -573,7 +569,7 @@ class CityStats(val cityInfo: CityInfo) { Now we have the excess food, to which "growth" modifiers apply Some policies have bonuses for growth only, not general food production. */ - updateFoodEaten() + val foodEaten = calcFoodEaten() newFinalStatList["Population"]!!.food -= foodEaten var totalFood = newFinalStatList.values.map { it.food }.sum() @@ -599,11 +595,12 @@ class CityStats(val cityInfo: CityInfo) { val buildingsMaintenance = getBuildingMaintenanceCosts() // this is AFTER the bonus calculation! newFinalStatList["Maintenance"] = Stats(gold = -buildingsMaintenance.toInt().toFloat()) - if (totalFood > 0 - && currentConstruction is INonPerpetualConstruction + if (totalFood > 0 + && currentConstruction is INonPerpetualConstruction && currentConstruction.hasUnique(UniqueType.ConvertFoodToProductionWhenConstructed) ) { - newFinalStatList["Excess food to production"] = Stats(production = totalFood, food = -totalFood) + newFinalStatList["Excess food to production"] = + Stats(production = getProductionFromExcessiveFood(totalFood), food = -totalFood) } val growthNullifyingUnique = cityInfo.getMatchingUniques(UniqueType.NullifiesGrowth).firstOrNull() @@ -621,8 +618,17 @@ class CityStats(val cityInfo: CityInfo) { finalStatList = newFinalStatList } - private fun updateFoodEaten() { - foodEaten = cityInfo.population.population.toFloat() * 2 + // calculate the conversion of the excessive food to the production + // See for details: https://civilization.fandom.com/wiki/Settler_(Civ5) + private fun getProductionFromExcessiveFood(food : Float): Float { + return if (food >= 4.0f ) 2.0f + (food / 4.0f).toInt() + else if (food >= 2.0f ) 2.0f + else if (food >= 1.0f ) 1.0f + else 0.0f + } + + private fun calcFoodEaten(): Float { + var foodEaten = cityInfo.population.population.toFloat() * 2 var foodEatenBySpecialists = 2f * cityInfo.population.getNumberOfSpecialists() for (unique in cityInfo.getMatchingUniques(UniqueType.FoodConsumptionBySpecialists)) @@ -630,6 +636,7 @@ class CityStats(val cityInfo: CityInfo) { foodEatenBySpecialists *= unique.params[0].toPercent() foodEaten -= 2f * cityInfo.population.getNumberOfSpecialists() - foodEatenBySpecialists + return foodEaten } //endregion diff --git a/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt b/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt index d0e1f5ba54..23e023a95b 100644 --- a/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityStatsTable.kt @@ -71,11 +71,11 @@ class CityStatsTable(val cityScreen: CityScreen): Table() { var turnsToPopString = when { - cityInfo.isGrowing() -> "[${cityInfo.getNumTurnsToNewPopulation()}] turns to new population" cityInfo.isStarving() -> "[${cityInfo.getNumTurnsToStarvation()}] turns to lose population" cityInfo.getRuleset().units[cityInfo.cityConstructions.currentConstructionFromQueue] - .let { it != null && it.hasUnique(UniqueType.ConvertFoodToProductionWhenConstructed) } + .let { it != null && it.hasUnique(UniqueType.ConvertFoodToProductionWhenConstructed) } -> "Food converts to production" + cityInfo.isGrowing() -> "[${cityInfo.getNumTurnsToNewPopulation()}] turns to new population" else -> "Stopped population growth" }.tr() turnsToPopString += " (${cityInfo.population.foodStored}${Fonts.food}/${cityInfo.population.getFoodToNextPopulation()}${Fonts.food})"