From 8263d972ff21108a59b93f82a1fec18b3015dff9 Mon Sep 17 00:00:00 2001 From: Skekdog <47750815+Skekdog@users.noreply.github.com> Date: Mon, 3 Jul 2023 21:52:47 +0100 Subject: [PATCH] Fix civilopedia gold cost (#9729) * Fix exponent being applied wrong * Format more consistent with rest of project * Fix building gold cost in civilopedia and use slash instead of a comma * Add INonPerpetualConstruction.getCivilopediaGoldCost() --- core/src/com/unciv/models/ruleset/Building.kt | 6 ++---- core/src/com/unciv/models/ruleset/IConstruction.kt | 5 +++++ .../com/unciv/ui/objectdescriptions/BaseUnitDescriptions.kt | 4 +--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index 00e235ee1e..644ffafa6e 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -240,11 +240,9 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction { if (cost > 0) { val stats = mutableListOf("$cost${Fonts.production}") if (canBePurchasedWithStat(null, Stat.Gold)) { - // We need what INonPerpetualConstruction.getBaseGoldCost calculates but without any game- or civ-specific modifiers - val buyCost = (30.0 * cost.toFloat().pow(0.75f) * hurryCostModifier.toPercent()).toInt() / 10 * 10 - stats += "$buyCost${Fonts.gold}" + stats += "${getCivilopediaGoldCost()}${Fonts.gold}" } - textList += FormattedLine(stats.joinToString(", ", "{Cost}: ")) + textList += FormattedLine(stats.joinToString("/", "{Cost}: ")) } if (requiredTech != null) diff --git a/core/src/com/unciv/models/ruleset/IConstruction.kt b/core/src/com/unciv/models/ruleset/IConstruction.kt index c3c30e04b4..b82f1bb7e1 100644 --- a/core/src/com/unciv/models/ruleset/IConstruction.kt +++ b/core/src/com/unciv/models/ruleset/IConstruction.kt @@ -63,6 +63,11 @@ interface INonPerpetualConstruction : IConstruction, INamed, IHasUniques { return Stat.values().any { canBePurchasedWithStat(city, it) } } + fun getCivilopediaGoldCost(): Int { + // Same as getBaseGoldCost, but without game-specific modifiers + return ((30.0 * cost.toFloat()).pow(0.75) * hurryCostModifier.toPercent() / 10).toInt() * 10 + } + fun getBaseGoldCost(civInfo: Civilization): Double { // https://forums.civfanatics.com/threads/rush-buying-formula.393892/ return (30.0 * getProductionCost(civInfo)).pow(0.75) * hurryCostModifier.toPercent() diff --git a/core/src/com/unciv/ui/objectdescriptions/BaseUnitDescriptions.kt b/core/src/com/unciv/ui/objectdescriptions/BaseUnitDescriptions.kt index 68c004c754..12aaedb267 100644 --- a/core/src/com/unciv/ui/objectdescriptions/BaseUnitDescriptions.kt +++ b/core/src/com/unciv/ui/objectdescriptions/BaseUnitDescriptions.kt @@ -93,9 +93,7 @@ object BaseUnitDescriptions { stats.clear() stats += "${baseUnit.cost}${Fonts.production}" if (baseUnit.canBePurchasedWithStat(null, Stat.Gold)) { - // We need what INonPerpetualConstruction.getBaseGoldCost calculates but without any game- or civ-specific modifiers - val buyCost = (30.0 * baseUnit.cost.toFloat().pow(0.75f) * baseUnit.hurryCostModifier.toPercent()).toInt() / 10 * 10 - stats += "$buyCost${Fonts.gold}" + stats += "${baseUnit.getCivilopediaGoldCost()}${Fonts.gold}" } textList += FormattedLine(stats.joinToString("/", "{Cost}: ")) }