From 48bf588b486789377d90f95c79e5a7ecc006c502 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 18 Jan 2023 10:40:47 +0200 Subject: [PATCH] Conditioned trigger uniques do not 'go off' without the trigger (e.g. when tech researched, building built) --- .../com/unciv/logic/city/CityConstructions.kt | 13 ------------ .../unciv/logic/civilization/PolicyManager.kt | 5 +++-- .../unciv/logic/civilization/TechManager.kt | 20 +++++++++++-------- core/src/com/unciv/models/ruleset/Building.kt | 16 +++++++++++++-- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index c9c8fcd2e3..57ef27c85e 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -16,7 +16,6 @@ import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.unique.LocalUniqueCache import com.unciv.models.ruleset.unique.StateForConditionals import com.unciv.models.ruleset.unique.UniqueMap -import com.unciv.models.ruleset.unique.UniqueTriggerActivation import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.stats.Stat @@ -441,18 +440,6 @@ class CityConstructions : IsPartOfGameInfoSerialization { NotificationCategory.General, NotificationIcon.Construction, buildingIcon) } } - - if (construction is Building) { - for (unique in cityInfo.civInfo.getTriggeredUniques(UniqueType.TriggerUponConstructingBuilding, StateForConditionals(cityInfo.civInfo, cityInfo))) - if (unique.conditionals.any {it.type == UniqueType.TriggerUponConstructingBuilding && construction.matchesFilter(it.params[0])}) - UniqueTriggerActivation.triggerCivwideUnique(unique, cityInfo.civInfo, cityInfo) - - for (unique in cityInfo.civInfo.getTriggeredUniques(UniqueType.TriggerUponConstructingBuildingCityFilter, StateForConditionals(cityInfo.civInfo, cityInfo))) - if (unique.conditionals.any {it.type == UniqueType.TriggerUponConstructingBuildingCityFilter - && construction.matchesFilter(it.params[0]) - && cityInfo.matchesFilter(it.params[1])}) - UniqueTriggerActivation.triggerCivwideUnique(unique, cityInfo.civInfo, cityInfo) - } } fun addBuilding(buildingName: String) { diff --git a/core/src/com/unciv/logic/civilization/PolicyManager.kt b/core/src/com/unciv/logic/civilization/PolicyManager.kt index 11fd9c7767..ecc4bbdb19 100644 --- a/core/src/com/unciv/logic/civilization/PolicyManager.kt +++ b/core/src/com/unciv/logic/civilization/PolicyManager.kt @@ -6,6 +6,7 @@ import com.unciv.models.ruleset.Policy import com.unciv.models.ruleset.Policy.PolicyBranchType import com.unciv.models.ruleset.PolicyBranch import com.unciv.models.ruleset.unique.UniqueMap +import com.unciv.models.ruleset.unique.UniqueTarget import com.unciv.models.ruleset.unique.UniqueTriggerActivation import com.unciv.models.ruleset.unique.UniqueType import com.unciv.ui.utils.extensions.toPercent @@ -199,8 +200,8 @@ class PolicyManager : IsPartOfGameInfoSerialization { } for (unique in policy.uniqueObjects) - UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) - + if (unique.conditionals.none { it.type!!.targetTypes.contains(UniqueTarget.TriggerCondition) }) + UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponAdoptingPolicy)) if (unique.conditionals.any {it.type == UniqueType.TriggerUponAdoptingPolicy && it.params[0] == policy.name}) diff --git a/core/src/com/unciv/logic/civilization/TechManager.kt b/core/src/com/unciv/logic/civilization/TechManager.kt index 82612f400b..b5d550c296 100644 --- a/core/src/com/unciv/logic/civilization/TechManager.kt +++ b/core/src/com/unciv/logic/civilization/TechManager.kt @@ -7,6 +7,7 @@ import com.unciv.logic.map.RoadStatus import com.unciv.models.ruleset.Era import com.unciv.models.ruleset.tech.Technology import com.unciv.models.ruleset.unique.UniqueMap +import com.unciv.models.ruleset.unique.UniqueTarget import com.unciv.models.ruleset.unique.UniqueTriggerActivation import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.ruleset.unit.BaseUnit @@ -248,9 +249,15 @@ class TechManager : IsPartOfGameInfoSerialization { repeatingTechsResearched++ researchedTechnologies = researchedTechnologies.withItem(newTech) addTechToTransients(newTech) - for (unique in newTech.uniqueObjects) { - UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) - } + for (unique in newTech.uniqueObjects) + if (unique.conditionals.none { it.type!!.targetTypes.contains(UniqueTarget.TriggerCondition) }) + UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) + + for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponResearch)) + if (unique.conditionals.any {it.type == UniqueType.TriggerUponResearch && it.params[0] == techName}) + UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) + + updateTransientBooleans() for (city in civInfo.cities) { city.updateCitizens = true @@ -340,17 +347,14 @@ class TechManager : IsPartOfGameInfoSerialization { .sortedBy { it.eraNumber } for (era in erasPassed) for (unique in era.uniqueObjects) - UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) + if (unique.conditionals.none { it.type!!.targetTypes.contains(UniqueTarget.TriggerCondition) }) + UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) val eraNames = erasPassed.map { it.name }.toHashSet() for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponEnteringEra)) if (unique.conditionals.any {it.type == UniqueType.TriggerUponEnteringEra && it.params[0] in eraNames}) UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) } - - for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponResearch)) - if (unique.conditionals.any {it.type == UniqueType.TriggerUponResearch && it.params[0] == techName}) - UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) } fun updateEra() { diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index e9598851a7..010a3c1634 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -644,7 +644,8 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction { getRejectionReasons(cityConstructions).isEmpty() override fun postBuildEvent(cityConstructions: CityConstructions, boughtWith: Stat?): Boolean { - val civInfo = cityConstructions.cityInfo.civInfo + val cityInfo = cityConstructions.cityInfo + val civInfo = cityInfo.civInfo if (civInfo.gameInfo.spaceResources.contains(name)) { civInfo.victoryManager.currentsSpaceshipParts.add(name, 1) @@ -666,7 +667,18 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction { cityConstructions.addFreeBuildings() for (unique in uniqueObjects) - UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo, cityConstructions.cityInfo) + if (unique.conditionals.none { it.type!!.targetTypes.contains(UniqueTarget.TriggerCondition) }) + UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo, cityConstructions.cityInfo) + + for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponConstructingBuilding, StateForConditionals(civInfo, cityInfo))) + if (unique.conditionals.any {it.type == UniqueType.TriggerUponConstructingBuilding && matchesFilter(it.params[0])}) + UniqueTriggerActivation.triggerCivwideUnique(unique, cityInfo.civInfo, cityInfo) + + for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponConstructingBuildingCityFilter, StateForConditionals(cityInfo.civInfo, cityInfo))) + if (unique.conditionals.any {it.type == UniqueType.TriggerUponConstructingBuildingCityFilter + && matchesFilter(it.params[0]) + && cityInfo.matchesFilter(it.params[1])}) + UniqueTriggerActivation.triggerCivwideUnique(unique, cityInfo.civInfo, cityInfo) if (hasUnique(UniqueType.EnemyLandUnitsSpendExtraMovement)) civInfo.updateHasActiveEnemyMovementPenalty()