From 06691d429e2cc1e5b6db378f0964501a50ff57d7 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 4 Sep 2023 14:58:48 +0300 Subject: [PATCH] Resolved #10011 - Teleport units away from city center when liberating --- core/src/com/unciv/logic/map/mapunit/UnitMovement.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt b/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt index bc9adca295..28dba13979 100644 --- a/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt +++ b/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt @@ -488,7 +488,9 @@ class UnitMovement(val unit: MapUnit) { var distance = 0 // When we didn't limit the allowed distance the game would sometimes spend a whole minute looking for a suitable tile. - if (canPassThrough(unit.getTile())) return // This unit can stay here - e.g. it has "May enter foreign tiles without open borders" + if (canPassThrough(unit.getTile()) + && !isCityCenterCannotEnter(unit.getTile())) + return // This unit can stay here - e.g. it has "May enter foreign tiles without open borders" while (allowedTile == null && distance < 5) { distance++ allowedTile = unit.getTile().getTilesAtDistance(distance) @@ -698,6 +700,10 @@ class UnitMovement(val unit: MapUnit) { unit.mostRecentMoveType = UnitMovementMemoryType.UnitMoved } + private fun isCityCenterCannotEnter(tile: Tile) = tile.isCityCenter() + && tile.getOwner() != unit.civ + && !tile.getCity()!!.hasJustBeenConquered + /** * Designates whether we can enter the tile - without attacking * DOES NOT designate whether we can reach that tile in the current turn @@ -710,7 +716,7 @@ class UnitMovement(val unit: MapUnit) { return false // 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.civ && !tile.getCity()!!.hasJustBeenConquered) + if (isCityCenterCannotEnter(tile)) return false return if (unit.isCivilian())