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
This commit is contained in:
Jack Rainy 2022-04-27 09:16:11 +03:00 committed by GitHub
parent 8891883998
commit 6e88828240
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 14 deletions

View File

@ -64,8 +64,6 @@ class CityStats(val cityInfo: CityInfo) {
var baseStatTree = StatTreeNode()
var statPercentBonusList = LinkedHashMap<String, Stats>()
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

View File

@ -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})"