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.
This commit is contained in:
Arthur van der Staaij 2021-06-16 10:12:52 +02:00 committed by GitHub
parent b3f5820cb4
commit 6a713deeea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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