diff --git a/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt b/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt index 2796f05d98..10de611b77 100644 --- a/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt +++ b/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt @@ -170,7 +170,7 @@ class UnitTurnManager(val unit: MapUnit) { UncivGame.Current.settings.addCompletedTutorialTask("Construct an improvement") val improvementInProgress = tile.improvementInProgress ?: return - tile.changeImprovement(improvementInProgress, unit.civ) + tile.changeImprovement(improvementInProgress, unit.civ, unit) tile.improvementInProgress = null tile.getCity()?.updateCitizens = true diff --git a/core/src/com/unciv/logic/map/tile/Tile.kt b/core/src/com/unciv/logic/map/tile/Tile.kt index 3e96ff8d87..0cbd5d3f60 100644 --- a/core/src/com/unciv/logic/map/tile/Tile.kt +++ b/core/src/com/unciv/logic/map/tile/Tile.kt @@ -306,8 +306,8 @@ open class Tile : IsPartOfGameInfoSerialization { fun removeImprovement() = improvementFunctions.changeImprovement(null) - fun changeImprovement(improvementStr: String, civToHandleCompletion:Civilization? = null) = - improvementFunctions.changeImprovement(improvementStr, civToHandleCompletion) + fun changeImprovement(improvementStr: String, civToHandleCompletion: Civilization? = null, unit: MapUnit? = null) = + improvementFunctions.changeImprovement(improvementStr, civToHandleCompletion, unit) // function handling when adding a road to the tile fun addRoad(roadType: RoadStatus, creatingCivInfo: Civilization?) { diff --git a/core/src/com/unciv/logic/map/tile/TileInfoImprovementFunctions.kt b/core/src/com/unciv/logic/map/tile/TileInfoImprovementFunctions.kt index 594ecd8a82..ecfd949a44 100644 --- a/core/src/com/unciv/logic/map/tile/TileInfoImprovementFunctions.kt +++ b/core/src/com/unciv/logic/map/tile/TileInfoImprovementFunctions.kt @@ -6,8 +6,10 @@ import com.unciv.logic.civilization.LocationAction import com.unciv.logic.civilization.NotificationCategory import com.unciv.logic.civilization.NotificationIcon import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers +import com.unciv.logic.map.mapunit.MapUnit import com.unciv.models.ruleset.tile.TileImprovement import com.unciv.models.ruleset.unique.StateForConditionals +import com.unciv.models.ruleset.unique.UniqueTriggerActivation import com.unciv.models.ruleset.unique.UniqueType @@ -187,7 +189,7 @@ class TileInfoImprovementFunctions(val tile: Tile) { fun changeImprovement(improvementName: String?, /** For road assignment and taking over tiles - DO NOT pass when simulating improvement effects! */ - civToActivateBroaderEffects:Civilization? = null) { + civToActivateBroaderEffects: Civilization? = null, unit: MapUnit? = null) { val improvementObject = tile.ruleset.tileImprovements[improvementName] when { @@ -223,6 +225,9 @@ class TileInfoImprovementFunctions(val tile: Tile) { ) takeOverTilesAround(civToActivateBroaderEffects, tile) + if (civToActivateBroaderEffects != null && improvementObject != null) + triggerImprovementUniques(improvementObject, civToActivateBroaderEffects, unit) + val city = tile.owningCity if (city != null) { city.cityStats.update() @@ -233,6 +238,29 @@ class TileInfoImprovementFunctions(val tile: Tile) { } } + private fun triggerImprovementUniques( + improvement: TileImprovement, + civ: Civilization, + unit: MapUnit? = null + ) { + for (unique in improvement.uniqueObjects.filter { !it.hasTriggerConditional() }) + if (unit != null) { + UniqueTriggerActivation.triggerUnitwideUnique(unique, unit) + } + else UniqueTriggerActivation.triggerCivwideUnique(unique, civ, tile = tile) + + if (unit != null){ + for (unique in unit.getTriggeredUniques(UniqueType.TriggerUponBuildingImprovement) + .filter { improvement.matchesFilter(it.params[0]) }) + UniqueTriggerActivation.triggerUnitwideUnique(unique, unit) + } + + for (unique in civ.getMatchingUniques( + UniqueType.TriggerUponBuildingImprovement, StateForConditionals(civInfo = civ, unit = unit)) + .filter { improvement.matchesFilter(it.params[0]) }) + UniqueTriggerActivation.triggerCivwideUnique(unique, civ, tile = tile) + } + private fun adtivateRemovalImprovement( improvementName: String, civToActivateBroaderEffects: Civilization? diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueTarget.kt b/core/src/com/unciv/models/ruleset/unique/UniqueTarget.kt index 2c8602e334..8ddb74a03b 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueTarget.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueTarget.kt @@ -48,7 +48,7 @@ enum class UniqueTarget( // Tile-specific Terrain, - Improvement, + Improvement(inheritsFrom = Triggerable), Resource(inheritsFrom = Global), Ruins(inheritsFrom = UnitTriggerable), diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 9f988b0b40..9682b343fe 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -756,6 +756,7 @@ enum class UniqueType( /** Can be placed upon both units and as global */ TriggerUponConqueringCity("upon conquering a city", UniqueTarget.TriggerCondition, UniqueTarget.UnitTriggerCondition), TriggerUponFoundingCity("upon founding a city", UniqueTarget.TriggerCondition), + TriggerUponBuildingImprovement("upon building a [improvementFilter] improvement", UniqueTarget.TriggerCondition, UniqueTarget.UnitTriggerCondition), TriggerUponDiscoveringNaturalWonder("upon discovering a Natural Wonder", UniqueTarget.TriggerCondition), TriggerUponConstructingBuilding("upon constructing [buildingFilter]", UniqueTarget.TriggerCondition), // We have a separate trigger to include the cityFilter, since '[in all cities]' can be read '*only* if it's in all cities' diff --git a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt index fab7e1c010..42290a6eff 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt @@ -40,7 +40,7 @@ object UnitActionsFromUniques { return UnitAction(UnitActionType.Create, "Create [$improvementName]", action = { - tile.changeImprovement(improvementName, unit.civ) + tile.changeImprovement(improvementName, unit.civ, unit) unit.destroy() // Modders may wish for a nondestructive way, but that should be another Unique }.takeIf { unit.currentMovement > 0 }) } @@ -255,7 +255,7 @@ object UnitActionsFromUniques { ), action = { val unitTile = unit.getTile() - unitTile.changeImprovement(improvementName, unit.civ) + unitTile.changeImprovement(improvementName, unit.civ, unit) // without this the world screen won't show the improvement because it isn't the 'last seen improvement' unit.civ.cache.updateViewableTiles()