From 0c7dd9ada975cdeb7bb558d4e240b6a26fc18d49 Mon Sep 17 00:00:00 2001 From: Arthur van der Staaij <32672293+avdstaaij@users.noreply.github.com> Date: Sun, 1 Aug 2021 10:31:53 +0200 Subject: [PATCH] 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. --- core/src/com/unciv/logic/battle/Battle.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index f775f33daf..4c4d9389e0 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -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())