Add unit name and building name countables

This commit is contained in:
yairm210 2024-05-27 16:15:08 +03:00
parent 7474dcaddc
commit d7018de5c5
3 changed files with 40 additions and 13 deletions

View File

@ -10,21 +10,32 @@ object Countables {
val relevantStat = Stat.safeValueOf(countable)
if (relevantStat != null) {
return if (stateForConditionals.relevantCity != null) {
stateForConditionals.relevantCity!!.getStatReserve(relevantStat)
} else if (relevantStat in Stat.statsWithCivWideField && stateForConditionals.relevantCiv != null) {
stateForConditionals.relevantCiv!!.getStatReserve(relevantStat)
} else {
null
return when {
stateForConditionals.relevantCity != null ->
stateForConditionals.relevantCity!!.getStatReserve(relevantStat)
relevantStat in Stat.statsWithCivWideField && stateForConditionals.relevantCiv != null ->
stateForConditionals.relevantCiv!!.getStatReserve(relevantStat)
else -> null
}
}
if (stateForConditionals.gameInfo == null) return null
val gameInfo = stateForConditionals.gameInfo ?: return null
if (countable == "year") return stateForConditionals.gameInfo!!.getYear(stateForConditionals.gameInfo!!.turns)
if (stateForConditionals.gameInfo!!.ruleset.tileResources.containsKey(countable))
if (countable == "year") return stateForConditionals.gameInfo!!.getYear(gameInfo.turns)
val civInfo = stateForConditionals.relevantCiv ?: return null
if (gameInfo.ruleset.tileResources.containsKey(countable))
return stateForConditionals.getResourceAmount(countable)
if (countable in gameInfo.ruleset.units){
return civInfo.units.getCivUnits().count { it.name == countable }
}
if (countable in gameInfo.ruleset.buildings){
return civInfo.cities.count { it.cityConstructions.containsBuildingOrEquivalent(countable) }
}
return null
}
}

View File

@ -84,9 +84,10 @@ enum class UniqueParameterType(
override fun isKnownValue(parameterText: String, ruleset: Ruleset): Boolean {
if (parameterText in knownValues) return true
if (parameterText.toIntOrNull() != null) return true
if (parameterText.toFloatOrNull() != null) return true
if (Stat.isStat(parameterText)) return true
if (parameterText in ruleset.tileResources) return true
if (parameterText in ruleset.units) return true
if (parameterText in ruleset.buildings) return true
return false
}

View File

@ -278,6 +278,21 @@ Used to indicate for what use the terrain should be viewed when dividing the wor
Allowed values are:
- improvement name (Note that "Road" and "Railroad" _do_ work as improvementFilters, but not as tileFilters at the moment.)
- "All"
- "Great Improvements", "Great"
- "All Road" - for Roads & Railroads
- `All`
- `Great Improvements`, `Great`
- `All Road` - for Roads & Railroads
## countable
Indicates *something that can be counted*, used both for comparisons and for multiplying uniques
Allowed values:
- `year`
- Unit name (counts your existing units)
- Building name (counts your existing buildings)
- Stat name - gets the stat *reserve*, not the amount per turn (can be city stats or civilization stats, depending on where the unique is used)
- Resource name (can be city stats or civilization stats, depending on where the unique is used)
For example: If a unique is placed on a building, then the retrieved resources will be of the city. If placed on a policy, they will be of the civilization.
This can make a difference for e.g. local resources, which are counted per city.