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()
This commit is contained in:
OptimizedForDensity
2022-06-07 01:27:25 -04:00
committed by GitHub
parent f5317eb53b
commit c40b25a73b
3 changed files with 3 additions and 2 deletions

View File

@ -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()

View File

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

View File

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