From 3e3ada8f788fd2314e21563aae9ca86126312188 Mon Sep 17 00:00:00 2001 From: Arthur van der Staaij Date: Wed, 11 Aug 2021 22:54:46 +0200 Subject: [PATCH] Fixed bug where units would not enter a city upon capture As listed in #4697. --- core/src/com/unciv/logic/battle/Battle.kt | 7 +++---- .../src/com/unciv/logic/map/UnitMovementAlgorithms.kt | 11 +++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index 32008f48fd91e..7a77826711eaa 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -69,11 +69,11 @@ object Battle { // check if unit is captured by the attacker (prize ships unique) // As ravignir clarified in issue #4374, this only works for aggressor - val captureSuccess = defender is MapUnitCombatant && attacker is MapUnitCombatant + val captureMilitaryUnitSuccess = defender is MapUnitCombatant && attacker is MapUnitCombatant && defender.isDefeated() && !defender.unit.isCivilian() && tryCaptureUnit(attacker, defender) - if (!captureSuccess) // capture creates a new unit, but `defender` still is the original, so this function would still show a kill message + if (!captureMilitaryUnitSuccess) // capture creates a new unit, but `defender` still is the original, so this function would still show a kill message postBattleNotifications(attacker, defender, attackedTile, attacker.getTile()) postBattleNationUniques(defender, attackedTile, attacker) @@ -104,9 +104,8 @@ object Battle { attacker.unit.action = null } - // we're a melee unit and we destroyed\captured an enemy unit // Should be called after tryCaptureUnit(), as that might spawn a unit on the tile we go to - if (!captureSuccess) + if (!captureMilitaryUnitSuccess) postBattleMoveToAttackedTile(attacker, defender, attackedTile) reduceAttackerMovementPointsAndAttacks(attacker, defender) diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 246a14afc245b..4a2dda3447573 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -431,11 +431,14 @@ class UnitMovementAlgorithms(val unit:MapUnit) { if (!canPassThrough(tile)) return false - if (tile.isCityCenter() && tile.getOwner() != unit.civInfo) return false // even if they'll let us pass through, we can't enter their city + // even if they'll let us pass through, we can't enter their city - unless we just captured it + if (tile.isCityCenter() && tile.getOwner() != unit.civInfo && !tile.getCity()!!.hasJustBeenConquered) + return false - if (unit.isCivilian()) - return tile.civilianUnit == null && (tile.militaryUnit == null || tile.militaryUnit!!.owner == unit.owner) - else return tile.militaryUnit == null && (tile.civilianUnit == null || tile.civilianUnit!!.owner == unit.owner) + return if (unit.isCivilian()) + tile.civilianUnit == null && (tile.militaryUnit == null || tile.militaryUnit!!.owner == unit.owner) + else + tile.militaryUnit == null && (tile.civilianUnit == null || tile.civilianUnit!!.owner == unit.owner) } private fun canAirUnitMoveTo(tile: TileInfo, unit: MapUnit): Boolean {