From 731aec0e65a60f34871624f97661f7ecd97956d4 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Tue, 3 Aug 2021 08:24:31 +0200 Subject: [PATCH] Use stat characters in Civilopedia Unit/Building costs (#4736) --- .../assets/jsons/Civ V - Vanilla/Units.json | 2 +- core/src/com/unciv/models/ruleset/Building.kt | 8 ++++++-- .../com/unciv/models/ruleset/unit/BaseUnit.kt | 18 ++++++++++++------ .../unciv/ui/civilopedia/CivilopediaScreen.kt | 4 +++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/android/assets/jsons/Civ V - Vanilla/Units.json b/android/assets/jsons/Civ V - Vanilla/Units.json index 67fc11b817..8cc2e33877 100644 --- a/android/assets/jsons/Civ V - Vanilla/Units.json +++ b/android/assets/jsons/Civ V - Vanilla/Units.json @@ -1509,7 +1509,7 @@ "name": "Great Prophet", "unitType": "Civilian", "uniques": ["Can construct [Holy site] if it hasn't spread religion yet", "Can spread religion [4] times", - "May found a religion", "Great Person - [Faith]", "Unbuildable"], + "May found a religion", "Great Person - [Faith]", "Unbuildable", "Hidden when religion is disabled"], "movement": 2 }, { diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index cf56fafd2d..0ce5b1086f 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -13,6 +13,7 @@ import com.unciv.models.translations.fillPlaceholders import com.unciv.models.translations.tr import com.unciv.ui.civilopedia.FormattedLine import com.unciv.ui.civilopedia.ICivilopediaText +import com.unciv.ui.utils.Fonts import java.util.* import kotlin.collections.ArrayList import kotlin.collections.HashMap @@ -221,8 +222,9 @@ class Building : NamedStats(), IConstruction, ICivilopediaText { } if (cost > 0) { - textList += FormattedLine() - textList += FormattedLine("{Cost}: $cost") + val stats = mutableListOf("$cost${Fonts.production}") + if (canBePurchased()) stats += "${(getBaseGoldCost()*0.1).toInt()*10}${Fonts.gold}" + textList += FormattedLine(stats.joinToString(", ", "{Cost}: ")) } if (requiredTech != null || requiredBuilding != null || requiredBuildingInAllCities != null) @@ -349,6 +351,8 @@ class Building : NamedStats(), IConstruction, ICivilopediaText { return productionCost.toInt() } + private fun getBaseGoldCost() = (30.0 * cost).pow(0.75) * (1 + hurryCostModifier / 100.0) + override fun getGoldCost(civInfo: CivilizationInfo): Int { // https://forums.civfanatics.com/threads/rush-buying-formula.393892/ var cost = (30 * getProductionCost(civInfo)).toDouble().pow(0.75) * (1 + hurryCostModifier / 100f) diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index e9e83dfb93..a10a586956 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -97,10 +97,16 @@ class BaseUnit : INamed, IConstruction, ICivilopediaText { stats += "$range${Fonts.range}" } if (movement != 0 && !movesLikeAirUnits()) stats += "$movement${Fonts.movement}" - if (cost != 0) stats += "{Cost}: $cost" if (stats.isNotEmpty()) textList += FormattedLine(stats.joinToString(", ")) + if (cost > 0) { + stats.clear() + stats += "$cost${Fonts.production}" + if (canBePurchased()) stats += "${(getBaseGoldCost()*0.1).toInt()*10}${Fonts.gold}" + textList += FormattedLine(stats.joinToString(", ", "{Cost}: ")) + } + if (replacementTextForUniques != "") { textList += FormattedLine() textList += FormattedLine(replacementTextForUniques) @@ -185,12 +191,12 @@ class BaseUnit : INamed, IConstruction, ICivilopediaText { return productionCost.toInt() } - fun getBaseGoldCost(civInfo: CivilizationInfo): Double { - return (30.0 * cost).pow(0.75) * (1 + hurryCostModifier / 100f) * civInfo.gameInfo.gameParameters.gameSpeed.modifier - } + private fun getBaseGoldCost() = (30.0 * cost).pow(0.75) * (1 + hurryCostModifier / 100.0) + private fun getGoldCostWithGameSpeed(civInfo: CivilizationInfo) = + getBaseGoldCost() * civInfo.gameInfo.gameParameters.gameSpeed.modifier override fun getGoldCost(civInfo: CivilizationInfo): Int { - var cost = getBaseGoldCost(civInfo) + var cost = getGoldCostWithGameSpeed(civInfo) for (unique in civInfo.getMatchingUniques("Gold cost of purchasing [] units -[]%")) { if (matchesFilter(unique.params[0])) cost *= 1f - unique.params[1].toFloat() / 100f @@ -205,7 +211,7 @@ class BaseUnit : INamed, IConstruction, ICivilopediaText { return (cost / 10).toInt() * 10 // rounded down to nearest ten } - fun getDisbandGold(civInfo: CivilizationInfo) = getBaseGoldCost(civInfo).toInt() / 20 + fun getDisbandGold(civInfo: CivilizationInfo) = getGoldCostWithGameSpeed(civInfo).toInt() / 20 override fun shouldBeDisplayed(construction: CityConstructions): Boolean { val rejectionReason = getRejectionReason(construction) diff --git a/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt b/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt index 0c7ebc46d4..529c9eee39 100644 --- a/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt +++ b/core/src/com/unciv/ui/civilopedia/CivilopediaScreen.kt @@ -228,7 +228,9 @@ class CivilopediaScreen( ) } categoryToEntries[CivilopediaCategories.Unit] = ruleset.units.values - .filter { "Will not be displayed in Civilopedia" !in it.uniques } + .filter { "Will not be displayed in Civilopedia" !in it.uniques + && !(hideReligionItems && "Hidden when religion is disabled" in it.uniques) + } .map { CivilopediaEntry( it.name,