From c40b25a73b5fa1d17cc73f7e67eb8658a4081c25 Mon Sep 17 00:00:00 2001 From: OptimizedForDensity <105244635+OptimizedForDensity@users.noreply.github.com> Date: Tue, 7 Jun 2022 01:27:25 -0400 Subject: [PATCH] Fix rare case where ruins would delete an AI unit while trying to upgrade it (#7084) * Fix rare case where ruins could delete AI units when upgrading the unit * Don't moveToTile if the unit is destroyed * Update comment * Forgot to uncomment line * Move currentMovement = 0f to destroy() --- core/src/com/unciv/logic/map/MapUnit.kt | 1 + core/src/com/unciv/logic/map/TileInfo.kt | 2 +- core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index dc1c1c90f3..022e0a59d6 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -924,6 +924,7 @@ class MapUnit { fun destroy() { 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() diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index a2dcd585fd..f08bb88ed8 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -1104,7 +1104,7 @@ open class TileInfo { when { airUnits.contains(mapUnit) -> airUnits.remove(mapUnit) civilianUnit == mapUnit -> civilianUnit = null - else -> militaryUnit = null + militaryUnit == mapUnit -> militaryUnit = null } } diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 0561069cf1..04e0ce5bf8 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -417,7 +417,7 @@ class UnitMovementAlgorithms(val unit: MapUnit) { } fun moveToTile(destination: TileInfo, considerZoneOfControl: Boolean = true) { - if (destination == unit.getTile()) return // already here! + if (destination == unit.getTile() || unit.isDestroyed) return // already here (or dead)! if (unit.baseUnit.movesLikeAirUnits()) { // air units move differently from all other units