From bc1b1e7672e4642a35447cb3c18cad6e1088f8da Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 4 Dec 2018 11:45:16 +0200 Subject: [PATCH] Solved a super-rare bug where the game would get stuck if you expanded the city onto a tile with an enemy that couldn't be teleported anywhere else - kudos Groundless Name! --- android/build.gradle | 6 +++--- .../com/unciv/logic/map/UnitMovementAlgorithms.kt | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 655c9de09a..b961fc4475 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -20,9 +20,9 @@ android { defaultConfig { applicationId "com.unciv.game" minSdkVersion 14 - targetSdkVersion 27 - versionCode 172 - versionName "2.10.9" + targetSdkVersion 28 + versionCode 173 + versionName "2.10.10" } // Had to add this crap for Travis to build, it wanted to sign the app diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index bee0867858..6884854293 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -183,13 +183,24 @@ class UnitMovementAlgorithms(val unit:MapUnit) { fun teleportToClosestMoveableTile(){ var allowedTile:TileInfo? = null var distance=0 - while(allowedTile==null){ + while(allowedTile==null && distance<5){ distance++ allowedTile = unit.getTile().getTilesAtDistance(distance) .firstOrNull{unit.canMoveTo(it)} } + + // 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) + .firstOrNull { unit.canMoveTo(it) } + if(allowedTile!=null) break + } + } unit.removeFromTile() // we "teleport" them away - unit.putInTile(allowedTile) + if(allowedTile!=null) // it's possible that there is no close tile, and all the guy's cities are full. Screw him then. + unit.putInTile(allowedTile) } } \ No newline at end of file