Added triggerable unique to remove policy (#11405)

* Added triggerable unique to remove policy

* Revert a completed branch to incomplete state

* Fixed grammatical error
This commit is contained in:
Jeremy Woo 2024-04-07 16:28:25 +08:00 committed by GitHub
parent cc45cefb99
commit d1606cdcb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 58 additions and 0 deletions

View File

@ -117,6 +117,12 @@ class PolicyManager : IsPartOfGameInfoSerialization {
}
}
private fun removePolicyFromTransients(policy: Policy) {
for (unique in policy.uniqueObjects) {
policyUniques.removeUnique(unique)
}
}
fun addCulture(culture: Int) {
val couldAdoptPolicyBefore = canAdoptPolicy()
storedCulture += culture
@ -232,6 +238,30 @@ class PolicyManager : IsPartOfGameInfoSerialization {
if (!canAdoptPolicy()) shouldOpenPolicyPicker = false
}
fun removePolicy(policy: Policy, branchCompletion: Boolean = false) {
if (!branchCompletion)
numberOfAdoptedPolicies--
adoptedPolicies.remove(policy.name)
removePolicyFromTransients(policy)
// if a branch is already marked as complete, revert it to incomplete
if (!branchCompletion) {
val branch = policy.branch
if (branch.policies.count { isAdopted(it.name) } == branch.policies.size - 1) {
removePolicy(branch.policies.last(), true)
}
}
civInfo.cache.updateCivResources()
// This ALSO has the side-effect of updating the CivInfo statForNextTurn so we don't need to call it explicitly
for (city in civInfo.cities) {
city.cityStats.update()
city.reassignPopulationDeferred()
}
}
/**
* Return the highest priority ([Int]) among the given [Set] of [PolicyBranch]es.
* Would return null if the given [Set] is empty.

View File

@ -225,6 +225,11 @@ class UniqueMap() : HashMap<String, ArrayList<Unique>>() {
for (unique in uniques) addUnique(unique)
}
fun removeUnique(unique: Unique) {
val existingArrayList = get(unique.placeholderText)
existingArrayList?.remove(unique)
}
fun getUniques(uniqueType: UniqueType) =
this[uniqueType.placeholderText]?.asSequence() ?: emptySequence()

View File

@ -295,6 +295,23 @@ object UniqueTriggerActivation {
true
}
}
UniqueType.OneTimeRemovePolicy -> {
val policyName = unique.params[0]
if (!civInfo.policies.isAdopted(policyName)) return null
val policy = civInfo.gameInfo.ruleset.policies[policyName] ?: return null
return {
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)
true
}
}
UniqueType.OneTimeEnterGoldenAge, UniqueType.OneTimeEnterGoldenAgeTurns -> {
return {
if (unique.type == UniqueType.OneTimeEnterGoldenAgeTurns) civInfo.goldenAges.enterGoldenAge(unique.params[0].toInt())

View File

@ -765,6 +765,7 @@ enum class UniqueType(
OneTimeGainPopulationRandomCity("[amount] population in a random city", UniqueTarget.Triggerable),
OneTimeDiscoverTech("Discover [tech]", UniqueTarget.Triggerable),
OneTimeAdoptPolicy("Adopt [policy]", UniqueTarget.Triggerable),
OneTimeRemovePolicy("Remove [policy]", UniqueTarget.Triggerable),
OneTimeFreeTech("Free Technology", UniqueTarget.Triggerable), // used in Buildings
OneTimeAmountFreeTechs("[positiveAmount] Free Technologies", UniqueTarget.Triggerable), // used in Policy
OneTimeFreeTechRuins("[positiveAmount] free random researchable Tech(s) from the [era]", UniqueTarget.Triggerable),

View File

@ -72,6 +72,11 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: Triggerable
??? example "Remove [policy]"
Example: "Remove [Oligarchy]"
Applicable to: Triggerable
??? example "Free Technology"
Applicable to: Triggerable