diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index d67cc0b568..7a0765221f 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -1675,6 +1675,7 @@ Adopt free policy = Unlocked at = Gain 2 free technologies = All policies adopted = +[branchName] branch = Policy branch: [branchName] = Are you sure you want to adopt [branchName]? = diff --git a/core/src/com/unciv/models/ruleset/Policy.kt b/core/src/com/unciv/models/ruleset/Policy.kt index c7fe0ca224..596ad3c3c1 100644 --- a/core/src/com/unciv/models/ruleset/Policy.kt +++ b/core/src/com/unciv/models/ruleset/Policy.kt @@ -1,5 +1,7 @@ package com.unciv.models.ruleset +import com.unciv.Constants +import com.unciv.logic.MultiFilter import com.unciv.models.ruleset.unique.StateForConditionals import com.unciv.models.ruleset.unique.UniqueTarget import com.unciv.models.ruleset.unique.UniqueType @@ -33,6 +35,19 @@ open class Policy : RulesetObject() { fun isBranchCompleteByName(name: String) = name.endsWith(branchCompleteSuffix) } + fun matchesFilter(filter: String): Boolean { + return MultiFilter.multiFilter(filter, ::matchesSingleFilter) + } + fun matchesSingleFilter(filter: String): Boolean { + return when(filter) { + in Constants.all -> true + name -> true + "[${branch.name}] branch" -> true + in uniques -> true + else -> false + } + } + /** Used in PolicyPickerScreen to display Policy properties */ fun getDescription(): String { return (if (policyBranchType == PolicyBranchType.Member) name.tr() + "\n" else "") + diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt index ebfb85feb9..b8ab693722 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt @@ -607,6 +607,25 @@ enum class UniqueParameterType( } }, + /** Implemtented by [com.unciv.models.ruleset.Policy.matchesFilter] */ + PolicyFilter("policyFilter", "Oligarchy", "The name of any policy") { + private val knownValues = Constants.all + + override fun isKnownValue(parameterText: String, ruleset: Ruleset): Boolean { + if (parameterText in knownValues) return true + if (parameterText in ruleset.policies) return true + if (ruleset.policies.values.any { it.hasUnique(parameterText) }) return true + return false + } + + override fun getErrorSeverity( + parameterText: String, + ruleset: Ruleset + ): UniqueType.UniqueParameterErrorSeverity? { + return getErrorSeverityForFilter(parameterText, ruleset) + } + }, + /** Used by [UniqueType.HiddenWithoutVictoryType], implementation in Civilopedia and OverviewScreen */ VictoryT("victoryType", "Domination", "The name of any victory type: 'Neutral', 'Cultural', 'Diplomatic', 'Domination', 'Scientific', 'Time'") { override fun getErrorSeverity( diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt index 212447405a..3d0ccabc28 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt @@ -296,19 +296,23 @@ object UniqueTriggerActivation { } } UniqueType.OneTimeRemovePolicy -> { - val policyName = unique.params[0] - if (!civInfo.policies.isAdopted(policyName)) return null - val policy = civInfo.gameInfo.ruleset.policies[policyName] ?: return null - + val policyFilter = unique.params[0] + val policiesToRemove = civInfo.policies.adoptedPolicies + .mapNotNull { civInfo.gameInfo.ruleset.policies[it] } + .filter { it.matchesFilter(policyFilter) } + if (policiesToRemove.isEmpty()) return null + return { - civInfo.policies.removePolicy(policy) + for (policy in policiesToRemove){ + civInfo.policies.removePolicy(policy) - val notificationText = getNotificationText( - notification, triggerNotificationText, - "You lose the [$policyName] Policy" - ) - if (notificationText != null) - civInfo.addNotification(notificationText, PolicyAction(policyName), NotificationCategory.General, NotificationIcon.Culture) + val notificationText = getNotificationText( + notification, triggerNotificationText, + "You lose the [${policy.name}] Policy" + ) + if (notificationText != null) + civInfo.addNotification(notificationText, PolicyAction(policy.name), NotificationCategory.General, NotificationIcon.Culture) + } true } } diff --git a/docs/Modders/Unique-parameters.md b/docs/Modders/Unique-parameters.md index 47c31a43c2..d9c89f04cb 100644 --- a/docs/Modders/Unique-parameters.md +++ b/docs/Modders/Unique-parameters.md @@ -153,6 +153,15 @@ A filter determining a part of the population of a city. It can be any of the fo - `Unemployed` - `Followers of the Majority Religion` or `Followers of this Religion`, both of which only apply when this religion is the majority religion in that city +## policyFilter + +Can be any of: + +- `All` or `all` +- `[policyBranchName] branch` +- The name of the policy +- A unique the Policy has (verbatim, no placeholders) + ## combatantFilter Can be any of: