diff --git a/core/src/com/unciv/logic/civilization/NotificationActions.kt b/core/src/com/unciv/logic/civilization/NotificationActions.kt index 6eea7f60c5..b89a61c986 100644 --- a/core/src/com/unciv/logic/civilization/NotificationActions.kt +++ b/core/src/com/unciv/logic/civilization/NotificationActions.kt @@ -5,6 +5,7 @@ import com.badlogic.gdx.utils.Json import com.badlogic.gdx.utils.JsonValue import com.unciv.logic.IsPartOfGameInfoSerialization import com.unciv.logic.city.City +import com.unciv.logic.map.mapunit.MapUnit import com.unciv.ui.components.MayaCalendar import com.unciv.ui.screens.cityscreen.CityScreen import com.unciv.ui.screens.civilopediascreen.CivilopediaScreen @@ -93,8 +94,17 @@ class MayaLongCountAction : NotificationAction { } } -/** A notification action that shows and selects units on the map. */ +/** A notification action that shows and selects units on the map. + * + * Saves and serializes only the location. Activation will select the tile which will select any unit + * on it or cycle through selections if this NotificationAction is the only one on the Notification. + * When the unit has been moved away, activation still shows the tile and not the unit. + * + * As MapUnits do not have any persistent ID differentiating them from other units of same Civ and BaseUnit, + * this cannot be done significantly better. Should someone add a persisted UUID to MapUnit, please change this too. + */ class MapUnitAction(private val location: Vector2 = Vector2.Zero) : NotificationAction { + constructor(unit: MapUnit) : this(unit.currentTile.position) override fun execute(worldScreen: WorldScreen) { worldScreen.mapHolder.setCenterPosition(location, selectUnit = true) } diff --git a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt index 4085bc8a80..dc32408554 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt @@ -117,7 +117,7 @@ class CityStateFunctions(val civInfo: Civilization) { } // Point to the gifted unit, then to the other places mentioned in the message - val unitAction = sequenceOf(MapUnitAction(placedUnit.getTile().position)) + val unitAction = sequenceOf(MapUnitAction(placedUnit)) val notificationActions = unitAction + LocationAction(cities.city2.location, city.location) receivingCiv.addNotification( "[${civInfo.civName}] gave us a [${militaryUnit.name}] as gift near [${city.name}]!", diff --git a/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt b/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt index 0c61f7afba..2796f05d98 100644 --- a/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt +++ b/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt @@ -3,6 +3,7 @@ package com.unciv.logic.map.mapunit import com.unciv.UncivGame import com.unciv.logic.battle.MapUnitCombatant import com.unciv.logic.civilization.LocationAction +import com.unciv.logic.civilization.MapUnitAction import com.unciv.logic.civilization.NotificationCategory import com.unciv.logic.civilization.NotificationIcon import com.unciv.models.ruleset.unique.UniqueTriggerActivation @@ -127,7 +128,7 @@ class UnitTurnManager(val unit: MapUnit) { ) } else unit.civ.addNotification( "Our [${unit.name}] took [$tileDamage] tile damage", - unit.currentTile.position, + MapUnitAction(unit), NotificationCategory.Units, unit.name ) diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt index 671f314285..9a423befee 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt @@ -74,7 +74,7 @@ object UniqueTriggerActivation { civInfo.addNotification( notificationText, - MapUnitAction(placedUnit.getTile().position), + MapUnitAction(placedUnit), NotificationCategory.Units, placedUnit.name ) @@ -142,7 +142,7 @@ object UniqueTriggerActivation { civInfo.addNotification( notificationText, sequence { - yield(MapUnitAction(placedUnit.getTile().position)) + yield(MapUnitAction(placedUnit)) yieldAll(LocationAction(tile?.position)) }, NotificationCategory.Units,