mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-07 14:02:48 +07:00
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:
parent
4282cdb626
commit
87b02e49cd
@ -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 ->
|
||||
|
@ -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),
|
||||
|
@ -1926,12 +1926,12 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
|
||||
|
||||
Applicable to: Conditional
|
||||
|
||||
??? example "<when above [amount] [stat] (modified by game speed)>"
|
||||
??? example "<when above [amount] [stat/resource] (modified by game speed)>"
|
||||
Example: "<when above [3] [Culture] (modified by game speed)>"
|
||||
|
||||
Applicable to: Conditional
|
||||
|
||||
??? example "<when below [amount] [stat] (modified by game speed)>"
|
||||
??? example "<when below [amount] [stat/resource] (modified by game speed)>"
|
||||
Example: "<when below [3] [Culture] (modified by game speed)>"
|
||||
|
||||
Applicable to: Conditional
|
||||
|
Loading…
Reference in New Issue
Block a user