mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 03:53:12 -04:00
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:
parent
cc45cefb99
commit
d1606cdcb9
@ -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.
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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())
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user