From 4adbd2e6348db5ebc186416c7b860ecfa7516718 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 21 Nov 2023 01:47:17 +0500 Subject: [PATCH] Add a TriggerUponDiscoveringTile unique type (#10523) * Add a TriggerUponDiscoveringTile unique type * Add a check for trigger presence --- .../com/unciv/logic/map/mapunit/MapUnit.kt | 24 ++++++++++++++++++- .../unciv/models/ruleset/unique/UniqueType.kt | 1 + docs/Modders/uniques.md | 6 +++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt index 6bdfac3402..766525fbb2 100644 --- a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt +++ b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt @@ -21,6 +21,7 @@ import com.unciv.models.ruleset.unique.StateForConditionals import com.unciv.models.ruleset.unique.Unique import com.unciv.models.ruleset.unique.UniqueMap import com.unciv.models.ruleset.unique.UniqueType +import com.unciv.models.ruleset.unique.UniqueTriggerActivation import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.ruleset.unit.UnitType import com.unciv.models.stats.Stats @@ -344,8 +345,29 @@ class MapUnit : IsPartOfGameInfoSerialization { if (updateCivViewableTiles && oldViewableTiles != viewableTiles // Don't bother updating if all previous and current viewable tiles are within our borders && (oldViewableTiles.any { it !in civ.cache.ourTilesAndNeighboringTiles } - || viewableTiles.any { it !in civ.cache.ourTilesAndNeighboringTiles })) + || viewableTiles.any { it !in civ.cache.ourTilesAndNeighboringTiles })) { + + val unfilteredTriggeredUniques = getTriggeredUniques(UniqueType.TriggerUponDiscoveringTile, StateForConditionals.IgnoreConditionals).toList() + if (unfilteredTriggeredUniques.isNotEmpty()) { + val newlyExploredTiles = viewableTiles.filter { + !it.isExplored(civ) + } + for (tile in newlyExploredTiles) { + // Include tile in the state for correct RNG seeding + val state = StateForConditionals(civInfo=civ, unit=this, tile=tile); + for (unique in unfilteredTriggeredUniques) { + if (unique.conditionals.any { + it.type == UniqueType.TriggerUponDiscoveringTile + && tile.matchesFilter(it.params[0], civ) + } && unique.conditionalsApply(state) + ) + UniqueTriggerActivation.triggerUnitwideUnique(unique, this) + } + } + } + civ.cache.updateViewableTiles(explorerPosition) + } } fun isActionUntilHealed() = action?.endsWith("until healed") == true diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 6850f3e179..a0749f01b4 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -766,6 +766,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: TriggerUponPromotion("upon being promoted", UniqueTarget.UnitTriggerCondition), TriggerUponLosingHealth("upon losing at least [amount] HP in a single attack", UniqueTarget.UnitTriggerCondition), TriggerUponEndingTurnInTile("upon ending a turn in a [tileFilter] tile", UniqueTarget.UnitTriggerCondition), + TriggerUponDiscoveringTile("upon discovering a [tileFilter] tile", UniqueTarget.UnitTriggerCondition), //endregion diff --git a/docs/Modders/uniques.md b/docs/Modders/uniques.md index 4e76fd8919..e86a63ea98 100644 --- a/docs/Modders/uniques.md +++ b/docs/Modders/uniques.md @@ -2133,6 +2133,12 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl Applicable to: UnitTriggerCondition +??? example "<upon discovering a [tileFilter] tile>" + Triggers for each tile discovered (unfogged) by the unit. + Example: "<upon discovering a [Farm] tile>" + + Applicable to: UnitTriggerCondition + ## UnitActionModifier uniques !!! note ""