Avoid destroying all onboard units after player upgrade Air Carrier unit. (#8129)

This commit is contained in:
nacro711072
2022-12-14 23:30:10 +08:00
committed by GitHub
parent ed83cc9954
commit 7af63dd8b1
2 changed files with 8 additions and 6 deletions

View File

@ -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
}

View File

@ -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!