mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-31 15:19:29 +07:00
Unify "get stat for conditional state" logic
This commit is contained in:
@ -61,7 +61,7 @@ object Conditionals {
|
||||
return compare(state.getResourceAmount(resourceOrStatName), lowerLimit * gameSpeedModifier, upperLimit * gameSpeedModifier)
|
||||
val stat = Stat.safeValueOf(resourceOrStatName)
|
||||
?: return false
|
||||
val statReserve = if (state.relevantCity != null) state.relevantCity!!.getStatReserve(stat) else state.relevantCiv!!.getStatReserve(stat)
|
||||
val statReserve = state.getStatAmount(stat)
|
||||
|
||||
gameSpeedModifier = if (modifyByGameSpeed) state.gameInfo!!.speed.statCostModifiers[stat]!! else 1f
|
||||
return compare(statReserve, lowerLimit * gameSpeedModifier, upperLimit * gameSpeedModifier)
|
||||
|
@ -8,16 +8,7 @@ object Countables {
|
||||
if (countable.toIntOrNull() != null) return countable.toInt()
|
||||
|
||||
val relevantStat = Stat.safeValueOf(countable)
|
||||
|
||||
if (relevantStat != null) {
|
||||
return when {
|
||||
stateForConditionals.relevantCity != null ->
|
||||
stateForConditionals.relevantCity!!.getStatReserve(relevantStat)
|
||||
relevantStat in Stat.statsWithCivWideField && stateForConditionals.relevantCiv != null ->
|
||||
stateForConditionals.relevantCiv!!.getStatReserve(relevantStat)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
if (relevantStat != null) return stateForConditionals.getStatAmount(relevantStat)
|
||||
|
||||
val gameInfo = stateForConditionals.gameInfo ?: return null
|
||||
|
||||
|
@ -9,6 +9,7 @@ import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.map.mapgenerator.mapregions.Region
|
||||
import com.unciv.logic.map.mapunit.MapUnit
|
||||
import com.unciv.logic.map.tile.Tile
|
||||
import com.unciv.models.stats.Stat
|
||||
|
||||
data class StateForConditionals(
|
||||
val civInfo: Civilization? = null,
|
||||
@ -66,9 +67,19 @@ data class StateForConditionals(
|
||||
val gameInfo by lazy { relevantCiv?.gameInfo }
|
||||
|
||||
fun getResourceAmount(resourceName: String): Int {
|
||||
if (relevantCity != null) return relevantCity!!.getAvailableResourceAmount(resourceName)
|
||||
if (relevantCiv != null) return relevantCiv!!.getResourceAmount(resourceName)
|
||||
return 0
|
||||
return when {
|
||||
relevantCity != null -> relevantCity!!.getAvailableResourceAmount(resourceName)
|
||||
relevantCiv != null -> relevantCiv!!.getResourceAmount(resourceName)
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
fun getStatAmount(stat: Stat) : Int {
|
||||
return when {
|
||||
relevantCity != null -> relevantCity!!.getStatReserve(stat)
|
||||
relevantCiv != null && stat in Stat.statsWithCivWideField -> relevantCiv!!.getStatReserve(stat)
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
Reference in New Issue
Block a user