From 7805f90dab33a80d73b6758ad6fccb4853905d97 Mon Sep 17 00:00:00 2001 From: lyrjie Date: Sat, 18 Jan 2020 23:14:29 +0300 Subject: [PATCH] Fix: ships being teleported into landlocked cities (#1718) * Fix: ships being teleported into landlocked cities * Proposal: extend the city teleport to all owned tiles * Utilizing the existing method Co-authored-by: dumichno <57294813+dumichno@users.noreply.github.com> --- core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 1d86918d64..a66a8c58d2 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -188,6 +188,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) { fun teleportToClosestMoveableTile(){ var allowedTile:TileInfo? = null var distance=0 + // When we didn't limit the allowed distance the game would sometimes spend a whole minute looking for a suitable tile. while(allowedTile==null && distance<5){ distance++ allowedTile = unit.getTile().getTilesAtDistance(distance) @@ -195,10 +196,9 @@ class UnitMovementAlgorithms(val unit:MapUnit) { } // No tile within 4 spaces? move him to a city. - // When we didn't limit the allowed distance the game would sometimes spend a whole minute looking for a suitable tile. if(allowedTile==null){ for(city in unit.civInfo.cities){ - allowedTile = city.getCenterTile().getTilesInDistance(1) + allowedTile = city.getTiles() .firstOrNull { canMoveTo(it) } if(allowedTile!=null) break } @@ -276,7 +276,10 @@ class UnitMovementAlgorithms(val unit:MapUnit) { // because optimization on this function results in massive benefits! fun canPassThrough(tile: TileInfo):Boolean{ if(tile.getBaseTerrain().impassable) return false - if(tile.isLand && unit.type.isWaterUnit() && !tile.isCityCenter()) + if (tile.isLand + && unit.type.isWaterUnit() + // Check that the tile is not a coastal city's center + && !(tile.isCityCenter() && tile.isCoastalTile())) return false if(tile.isWater && unit.type.isLandUnit()){