Allow policy removal unique to remove multiple policies (#11427)

* Allow policy removal unique to remove multiple policies

* Fix typo and filter

* More accurate translation line. Not sure if the engine cares
This commit is contained in:
SeventhM 2024-04-11 13:32:59 -07:00 committed by GitHub
parent 31cc884323
commit a072f452b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 59 additions and 11 deletions

View File

@ -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]? =

View File

@ -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 "") +

View File

@ -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(

View File

@ -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
}
}

View File

@ -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: