diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 88149fd6fb..6a8d07a213 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -479,7 +479,7 @@ class CityInfo { // Edge case! What if a water unit is in a city, and you raze the city? // Well, the water unit has to return to the water! - for (unit in getCenterTile().getUnits()) { + for (unit in getCenterTile().getUnits().toList()) { if (!unit.movement.canPassThrough(getCenterTile())) unit.movement.teleportToClosestMoveableTile() } diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index 924e9665d8..ebecb9cc6f 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -340,7 +340,8 @@ class DiplomacyManager() { hasOpenBorders = newHasOpenBorders if (bordersWereClosed) { // borders were closed, get out! - for (unit in civInfo.getCivUnits().filter { it.currentTile.getOwner()?.civName == otherCivName }) { + for (unit in civInfo.getCivUnits() + .filter { it.currentTile.getOwner()?.civName == otherCivName }.toList()) { unit.movement.teleportToClosestMoveableTile() } } @@ -597,7 +598,7 @@ class DiplomacyManager() { diplomaticStatus = DiplomaticStatus.Peace val otherCiv = otherCiv() // Get out of others' territory - for (unit in civInfo.getCivUnits().filter { it.getTile().getOwner() == otherCiv }) + for (unit in civInfo.getCivUnits().filter { it.getTile().getOwner() == otherCiv }.toList()) unit.movement.teleportToClosestMoveableTile() for (thirdCiv in civInfo.getKnownCivs()) { diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index f4e294b550..34672f01ef 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -291,6 +291,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) { * This will not use movement points or check for a possible route. * It is used e.g. if an enemy city expands its borders, or trades or diplomacy change a unit's * allowed position. + * CAN DESTROY THE UNIT. */ fun teleportToClosestMoveableTile() { var allowedTile: TileInfo? = null @@ -310,13 +311,16 @@ class UnitMovementAlgorithms(val unit:MapUnit) { if (allowedTile != null) break } } - unit.removeFromTile() // we "teleport" them away - if (allowedTile != null) { // it's possible that there is no close tile, and all the guy's cities are full. Screw him then. + if (allowedTile != null) { + unit.removeFromTile() // we "teleport" them away unit.putInTile(allowedTile) // Cancel sleep or fortification if forcibly displaced - for now, leave movement / auto / explore orders if (unit.isSleeping() || unit.isFortified()) unit.action = null } + // it's possible that there is no close tile, and all the guy's cities are full. + // Nothing we can do. + else unit.destroy() } fun moveToTile(destination: TileInfo) {