Use stat characters in Civilopedia Unit/Building costs (#4736)

This commit is contained in:
SomeTroglodyte 2021-08-03 08:24:31 +02:00 committed by GitHub
parent e8876e90bf
commit 731aec0e65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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