Add Adoped Policies by Civilizations

This commit is contained in:
Rob Loach 2025-09-20 14:58:14 -04:00
parent d51ef24c20
commit 1d0c94d2c5
No known key found for this signature in database
GPG Key ID: 627C60834A74A21A
3 changed files with 31 additions and 0 deletions

View File

@ -164,6 +164,23 @@ enum class Countables(
.map { text.fillPlaceholders(it) }.toSet()
},
FilteredPoliciesByCivs("Adopted [policyFilter] Policies by [civFilter] Civilizations") {
override fun eval(parameterText: String, gameContext: GameContext): Int? {
val (policyFilter, civFilter) = parameterText.getPlaceholderParameters().takeIf { it.size >= 2 } ?: return null
val civilizations = gameContext.gameInfo?.civilizations ?: return null
return civilizations
.filter { it.isAlive() && it.matchesFilter(civFilter, gameContext) }
.sumOf { it.policies.getAdoptedPoliciesMatching(policyFilter, gameContext).size }
}
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): UniqueType.UniqueParameterErrorSeverity? {
val params = parameterText.getPlaceholderParameters()
if (params.size < 2) return UniqueType.UniqueParameterErrorSeverity.RulesetInvariant
return UniqueParameterType.PolicyFilter.getErrorSeverity(params[0], ruleset) ?:
UniqueParameterType.CivFilter.getErrorSeverity(params[1], ruleset)
}
override fun getKnownValuesForAutocomplete(ruleset: Ruleset) = setOf<String>()
},
RemainingCivs("Remaining [civFilter] Civilizations") {
override fun eval(parameterText: String, gameContext: GameContext): Int? {
val filter = parameterText.getPlaceholderParameters()[0]

View File

@ -379,6 +379,8 @@ Allowed values:
- Example: `Only available <when number of [[Culture] Buildings] is more than [0]>`
- `Adopted [policyFilter] Policies`
- Example: `Only available <when number of [Adopted [Oligarchy] Policies] is more than [0]>`
- `Adopted [policyFilter] Policies by [civFilter] Civilizations`
- Example: `Only available <when number of [Adopted [Oligarchy] Policies by [City-States] Civilizations] is more than [0]>`
- `Remaining [civFilter] Civilizations`
- Example: `Only available <when number of [Remaining [City-States] Civilizations] is more than [0]>`
- `Owned [tileFilter] Tiles`

View File

@ -244,6 +244,16 @@ class CountableTests {
freePolicies++
adopt(taggedPolicyBranch) // Will be completed as it has no member policies
}
// Add a second Civilization
val civ2 = game.addCiv()
val city2 = game.addCity(civ2, game.tileMap[2,2])
civ2.policies.run {
freePolicies += 2
adopt(getPolicyByName("Tradition"))
adopt(getPolicyByName("Oligarchy"))
}
val tests = listOf(
"Completed Policy branches" to 2, // Tradition and taggedPolicyBranch
"Adopted [Tradition Complete] Policies" to 1,
@ -251,6 +261,8 @@ class CountableTests {
"Adopted [Liberty Complete] Policies" to 0,
"Adopted [[Liberty] branch] Policies" to 2, // Liberty has only 1 member adopted
"Adopted [Some marker] Policies" to 1,
"Adopted [Some marker] Policies by [All] Civilizations" to 1,
"Adopted [Oligarchy] Policies by [All] Civilizations" to 2,
)
for ((test, expected) in tests) {
val actual = Countables.getCountableAmount(test, GameContext(civ))