From 08a280c29dc63bcb8b2d5867963b426d569c5e9d Mon Sep 17 00:00:00 2001 From: SeventhM <127357473+SeventhM@users.noreply.github.com> Date: Tue, 4 Jul 2023 10:16:48 -0700 Subject: [PATCH] Scaling purchase costs for faith/culture/science/etc. with speed (#9721) * Scaling with speed * Changing to float, and allowing a unique to set a gold price --- core/src/com/unciv/models/ruleset/Building.kt | 11 +++++------ core/src/com/unciv/models/ruleset/IConstruction.kt | 10 +++++----- core/src/com/unciv/models/ruleset/Speed.kt | 1 + core/src/com/unciv/models/ruleset/unit/BaseUnit.kt | 4 +--- .../src/com/unciv/models/ruleset/unit/BaseUnitCost.kt | 10 +++++----- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index 644ffafa6e..b2b71bb3cb 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -384,8 +384,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction { ) } - override fun getBaseBuyCost(city: City, stat: Stat): Int? { - if (stat == Stat.Gold) return getBaseGoldCost(city.civ).toInt() + override fun getBaseBuyCost(city: City, stat: Stat): Float? { val conditionalState = StateForConditionals(civInfo = city.civ, city = city) return sequence { @@ -402,12 +401,12 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction { it.params[1].toInt(), it.params[4].toInt(), city.civ.civConstructions.boughtItemsWithIncreasingPrice[name] - ) + ) * city.civ.gameInfo.speed.statCostModifiers[stat]!! } ) yieldAll(city.getMatchingUniques(UniqueType.BuyBuildingsByProductionCost, conditionalState) .filter { it.params[1] == stat.name && matchesFilter(it.params[0]) } - .map { getProductionCost(city.civ) * it.params[2].toInt() } + .map { (getProductionCost(city.civ) * it.params[2].toInt()).toFloat() } ) if (city.getMatchingUniques(UniqueType.BuyBuildingsWithStat, conditionalState) .any { @@ -416,14 +415,14 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction { && city.matchesFilter(it.params[2]) } ) { - yield(city.civ.getEra().baseUnitBuyCost) + yield(city.civ.getEra().baseUnitBuyCost * city.civ.gameInfo.speed.statCostModifiers[stat]!!) } yieldAll(city.getMatchingUniques(UniqueType.BuyBuildingsForAmountStat, conditionalState) .filter { it.params[2] == stat.name && matchesFilter(it.params[0]) && city.matchesFilter(it.params[3]) - }.map { it.params[1].toInt() } + }.map { it.params[1].toInt() * city.civ.gameInfo.speed.statCostModifiers[stat]!! } ) }.minOrNull() } diff --git a/core/src/com/unciv/models/ruleset/IConstruction.kt b/core/src/com/unciv/models/ruleset/IConstruction.kt index b82f1bb7e1..c8c97af38e 100644 --- a/core/src/com/unciv/models/ruleset/IConstruction.kt +++ b/core/src/com/unciv/models/ruleset/IConstruction.kt @@ -73,21 +73,21 @@ interface INonPerpetualConstruction : IConstruction, INamed, IHasUniques { return (30.0 * getProductionCost(civInfo)).pow(0.75) * hurryCostModifier.toPercent() } - fun getBaseBuyCost(city: City, stat: Stat): Int? { - if (stat == Stat.Gold) return getBaseGoldCost(city.civ).toInt() - + fun getBaseBuyCost(city: City, stat: Stat): Float? { val conditionalState = StateForConditionals(civInfo = city.civ, city = city) // Can be purchased for [amount] [Stat] [cityFilter] val lowestCostUnique = getMatchingUniques(UniqueType.CanBePurchasedForAmountStat, conditionalState) .filter { it.params[1] == stat.name && city.matchesFilter(it.params[2]) } .minByOrNull { it.params[0].toInt() } - if (lowestCostUnique != null) return lowestCostUnique.params[0].toInt() + if (lowestCostUnique != null) return lowestCostUnique.params[0].toInt() * city.civ.gameInfo.speed.statCostModifiers[stat]!! + + if (stat == Stat.Gold) return getBaseGoldCost(city.civ).toFloat() // Can be purchased with [Stat] [cityFilter] if (getMatchingUniques(UniqueType.CanBePurchasedWithStat, conditionalState) .any { it.params[0] == stat.name && city.matchesFilter(it.params[1]) } - ) return city.civ.getEra().baseUnitBuyCost + ) return city.civ.getEra().baseUnitBuyCost * city.civ.gameInfo.speed.statCostModifiers[stat]!! return null } diff --git a/core/src/com/unciv/models/ruleset/Speed.kt b/core/src/com/unciv/models/ruleset/Speed.kt index 3ff231b4b0..412d83a385 100644 --- a/core/src/com/unciv/models/ruleset/Speed.kt +++ b/core/src/com/unciv/models/ruleset/Speed.kt @@ -40,6 +40,7 @@ class Speed : RulesetObject(), IsPartOfGameInfoSerialization { Stat.Gold -> goldCostModifier Stat.Science -> scienceCostModifier Stat.Faith -> faithCostModifier + Stat.Culture -> cultureCostModifier else -> 1f } map[stat] = modifier diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index 7e81cde9cd..3589de70a0 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -95,9 +95,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction { return super.canBePurchasedWithStat(city, stat) } - override fun getBaseBuyCost(city: City, stat: Stat): Int? { - if (stat == Stat.Gold) return getBaseGoldCost(city.civ).toInt() - + override fun getBaseBuyCost(city: City, stat: Stat): Float? { return sequence { val baseCost = super.getBaseBuyCost(city, stat) if (baseCost != null) diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnitCost.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnitCost.kt index 845fb68b2b..843f9527b7 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnitCost.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnitCost.kt @@ -76,7 +76,7 @@ class BaseUnitCost(val baseUnit: BaseUnit) { } - fun getBaseBuyCosts(city: City, stat: Stat): Sequence { + fun getBaseBuyCosts(city: City, stat: Stat): Sequence { val conditionalState = StateForConditionals(civInfo = city.civ, city = city) return sequence { yieldAll(city.getMatchingUniques(UniqueType.BuyUnitsIncreasingCost, conditionalState) @@ -89,12 +89,12 @@ class BaseUnitCost(val baseUnit: BaseUnit) { it.params[1].toInt(), it.params[4].toInt(), city.civ.civConstructions.boughtItemsWithIncreasingPrice[baseUnit.name] - ) + ) * city.civ.gameInfo.speed.statCostModifiers[stat]!! } ) yieldAll(city.getMatchingUniques(UniqueType.BuyUnitsByProductionCost, conditionalState) .filter { it.params[1] == stat.name && baseUnit.matchesFilter(it.params[0]) } - .map { getProductionCost(city.civ) * it.params[2].toInt() } + .map { (getProductionCost(city.civ) * it.params[2].toInt()).toFloat() } ) if (city.getMatchingUniques(UniqueType.BuyUnitsWithStat, conditionalState) @@ -103,14 +103,14 @@ class BaseUnitCost(val baseUnit: BaseUnit) { && baseUnit.matchesFilter(it.params[0]) && city.matchesFilter(it.params[2]) } - ) yield(city.civ.getEra().baseUnitBuyCost) + ) yield(city.civ.getEra().baseUnitBuyCost * city.civ.gameInfo.speed.statCostModifiers[stat]!!) yieldAll(city.getMatchingUniques(UniqueType.BuyUnitsForAmountStat, conditionalState) .filter { it.params[2] == stat.name && baseUnit.matchesFilter(it.params[0]) && city.matchesFilter(it.params[3]) - }.map { it.params[1].toInt() } + }.map { it.params[1].toInt() * city.civ.gameInfo.speed.statCostModifiers[stat]!! } ) } }