Fixed captured units not tp-ing out of illegal tiles (#4701)

In particular, this fixes the bug where embarked units captured by a
civilization without optics would stay embarked. This therefore fixes
case 4 of #4237.

In principle, it should not even be possible that captured units can no
longer stand on the tile they were on, since the capturing unit has to
be able to move to it. However, in Unciv, it is possible to capture
units without moving to their tile. This is a different problem that
needs to be addressed some time in the future.
This commit is contained in:
Arthur van der Staaij 2021-08-01 10:31:53 +02:00 committed by GitHub
parent ff1a75bb13
commit 0c7dd9ada9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -421,18 +421,24 @@ object Battle {
capturedUnit.civInfo.addNotification("An enemy [" + attacker.getName() + "] has captured our [" + defender.getName() + "]",
defender.getTile().position, attacker.getName(), NotificationIcon.War, defender.getName())
val capturedUnitTile = capturedUnit.getTile()
// Apparently in Civ V, captured settlers are converted to workers.
if (capturedUnit.name == Constants.settler) {
val tile = capturedUnit.getTile()
capturedUnit.destroy()
// This is so that future checks which check if a unit has been captured are caught give the right answer
// For example, in postBattleMoveToAttackedTile
capturedUnit.civInfo = attacker.getCivInfo()
attacker.getCivInfo().placeUnitNearTile(tile.position, Constants.worker)
attacker.getCivInfo().placeUnitNearTile(capturedUnitTile.position, Constants.worker)
} else {
capturedUnit.civInfo.removeUnit(capturedUnit)
capturedUnit.assignOwner(attacker.getCivInfo())
capturedUnit.currentMovement = 0f
// It's possible that the unit can no longer stand on the tile it was captured on.
// For example, because it's embarked and the capturing civ cannot embark units yet.
if (!capturedUnit.movement.canPassThrough(capturedUnitTile)) {
capturedUnit.movement.teleportToClosestMoveableTile()
}
}
destroyIfDefeated(defenderCiv, attacker.getCivInfo())