Add resource support to stat gamespeed conditional (#10677)

* Tweaked the stat gamespeed conditional

Tweaked the stat gamespeed conditional to accept the resources

* Changed some names

* Fixed a double limit bug
This commit is contained in:
PLynx 2023-12-10 21:59:22 +01:00 committed by GitHub
parent 4282cdb626
commit 87b02e49cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 12 deletions

View File

@ -195,12 +195,19 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s
}
/** Helper for ConditionalWhenAboveAmountStatSpeed and its below counterpart */
fun checkStatAmountWithSpeed(compare: (current: Int, limit: Float) -> Boolean): Boolean {
fun checkResourceOrStatAmountWithSpeed(compare: (current: Int, limit: Float) -> Boolean): Boolean {
if (state.civInfo == null) return false
val stat = Stat.safeValueOf(condition.params[1])
val limit = condition.params[0].toInt()
val resourceOrStatName = condition.params[1]
var gameSpeedModifier = state.civInfo.gameInfo.speed.modifier
if (state.civInfo.gameInfo.ruleset.tileResources.containsKey(resourceOrStatName))
return compare(getResourceAmount(resourceOrStatName), limit * gameSpeedModifier)
val stat = Stat.safeValueOf(resourceOrStatName)
?: return false
val limit = condition.params[0].toFloat() * state.civInfo.gameInfo.speed.statCostModifiers[stat]!!
return compare(state.civInfo.getStatReserve(stat), limit)
gameSpeedModifier = state.civInfo.gameInfo.speed.statCostModifiers[stat]!!
return compare(state.civInfo.getStatReserve(stat), limit * gameSpeedModifier)
}
return when (condition.type) {
@ -222,10 +229,10 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s
checkResourceOrStatAmount { current, limit -> current > limit }
UniqueType.ConditionalWhenBelowAmountStatResource ->
checkResourceOrStatAmount { current, limit -> current < limit }
UniqueType.ConditionalWhenAboveAmountStatSpeed ->
checkStatAmountWithSpeed { current, limit -> current > limit } // Note: Int.compareTo(Float)!
UniqueType.ConditionalWhenBelowAmountStatSpeed ->
checkStatAmountWithSpeed { current, limit -> current < limit } // Note: Int.compareTo(Float)!
UniqueType.ConditionalWhenAboveAmountStatResourceSpeed ->
checkResourceOrStatAmountWithSpeed { current, limit -> current > limit } // Note: Int.compareTo(Float)!
UniqueType.ConditionalWhenBelowAmountStatResourceSpeed ->
checkResourceOrStatAmountWithSpeed { current, limit -> current < limit } // Note: Int.compareTo(Float)!
UniqueType.ConditionalHappy -> checkOnCiv { stats.happiness >= 0 }
UniqueType.ConditionalBetweenHappiness ->

View File

@ -649,8 +649,8 @@ enum class UniqueType(
ConditionalWhenBelowAmountStatResource("when below [amount] [stat/resource]", UniqueTarget.Conditional),
// The game speed-adjusted versions of above
ConditionalWhenAboveAmountStatSpeed("when above [amount] [stat] (modified by game speed)", UniqueTarget.Conditional),
ConditionalWhenBelowAmountStatSpeed("when below [amount] [stat] (modified by game speed)", UniqueTarget.Conditional),
ConditionalWhenAboveAmountStatResourceSpeed("when above [amount] [stat/resource] (modified by game speed)", UniqueTarget.Conditional),
ConditionalWhenBelowAmountStatResourceSpeed("when below [amount] [stat/resource] (modified by game speed)", UniqueTarget.Conditional),
/////// city conditionals
ConditionalInThisCity("in this city", UniqueTarget.Conditional),

View File

@ -1926,12 +1926,12 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: Conditional
??? example "&lt;when above [amount] [stat] (modified by game speed)&gt;"
??? example "&lt;when above [amount] [stat/resource] (modified by game speed)&gt;"
Example: "&lt;when above [3] [Culture] (modified by game speed)&gt;"
Applicable to: Conditional
??? example "&lt;when below [amount] [stat] (modified by game speed)&gt;"
??? example "&lt;when below [amount] [stat/resource] (modified by game speed)&gt;"
Example: "&lt;when below [3] [Culture] (modified by game speed)&gt;"
Applicable to: Conditional