From 6a713deeea28fa5919f73f2cf6aeb1bce96653f9 Mon Sep 17 00:00:00 2001 From: Arthur van der Staaij <32672293+avdstaaij@users.noreply.github.com> Date: Wed, 16 Jun 2021 10:12:52 +0200 Subject: [PATCH] Fixed units not teleporting out of sold city tiles (#4161) Fixed a bug where units were not immediately teleported out of the territory of a city when the owner of the city accepted a trade to sell it in their turn. This bug also used to crash the game if one of the units that were not teleported out was selected and they were able to reach a tile with a same-type unit of their own civ that could also reach them, since the unit swapping eligibility checking code would try to remove the unit and then place them back on an illegal tile. --- core/src/com/unciv/logic/trade/TradeLogic.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/logic/trade/TradeLogic.kt b/core/src/com/unciv/logic/trade/TradeLogic.kt index 91ffb1e9fa..2327eb7559 100644 --- a/core/src/com/unciv/logic/trade/TradeLogic.kt +++ b/core/src/com/unciv/logic/trade/TradeLogic.kt @@ -88,7 +88,14 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci if (offer.type == TradeType.City) { val city = from.cities.first { it.id == offer.name } city.moveToCiv(to) - city.getCenterTile().getUnits().toList().forEach { it.movement.teleportToClosestMoveableTile() } + city.getCenterTile().getUnits().forEach { it.movement.teleportToClosestMoveableTile() } + city.getTiles().forEach{ tile -> + tile.getUnits().forEach{ unit -> + if (!unit.civInfo.canEnterTiles(to)) { + unit.movement.teleportToClosestMoveableTile() + } + } + } to.updateViewableTiles() from.updateViewableTiles() }