From 7af63dd8b1dbf666106943722fa0b494c90e3d77 Mon Sep 17 00:00:00 2001 From: nacro711072 Date: Wed, 14 Dec 2022 23:30:10 +0800 Subject: [PATCH] Avoid destroying all onboard units after player upgrade Air Carrier unit. (#8129) --- core/src/com/unciv/logic/map/MapUnit.kt | 12 +++++++----- .../src/com/unciv/ui/worldscreen/unit/UnitActions.kt | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 731ea01355..18264d11fa 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -916,17 +916,19 @@ class MapUnit : IsPartOfGameInfoSerialization { attacksSinceTurnStart.clear() } - fun destroy() { + fun destroy(destroyTransportedUnit: Boolean = true) { val currentPosition = Vector2(getTile().position) civInfo.attacksSinceTurnStart.addAll(attacksSinceTurnStart.asSequence().map { CivilizationInfo.HistoricalAttackMemory(this.name, currentPosition, it) }) currentMovement = 0f removeFromTile() civInfo.removeUnit(this) civInfo.updateViewableTiles() - // all transported units should be destroyed as well - currentTile.getUnits().filter { it.isTransported && isTransportTypeOf(it) } - .toList() // because we're changing the list - .forEach { unit -> unit.destroy() } + if (destroyTransportedUnit) { + // all transported units should be destroyed as well + currentTile.getUnits().filter { it.isTransported && isTransportTypeOf(it) } + .toList() // because we're changing the list + .forEach { unit -> unit.destroy() } + } isDestroyed = true } diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index ee7e451260..d75c608be9 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -446,7 +446,7 @@ object UnitActions { return UnitAction(UnitActionType.Upgrade, title = title, action = { - unit.destroy() + unit.destroy(destroyTransportedUnit = false) val newUnit = civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name) /** We were UNABLE to place the new unit, which means that the unit failed to upgrade!