mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-07 05:51:12 +07:00
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:
parent
31cc884323
commit
a072f452b6
@ -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]? =
|
||||
|
||||
|
@ -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 "") +
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user