From 1a2d3d442120a8afab0f5d17e11ab43537908878 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 25 May 2018 12:08:06 +0300 Subject: [PATCH] Fixed bug where unit would try to randomwalk but there wasn't anywhere to go --- core/src/com/unciv/logic/automation/UnitAutomation.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index 079ab169..78e6dfc0 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -151,9 +151,12 @@ class UnitAutomation{ } // else, go to a random space - unit.moveToTile(unit.getDistanceToTiles() - .filter { it.key.unit == null && it.value==unit.currentMovement } // at edge of walking distance - .toList().getRandom().first) + val reachableTiles = unit.getDistanceToTiles() + .filter { it.key.unit == null} // at edge of walking distance + val reachableTilesMaxWalkingDistance = reachableTiles.filter { it.value==unit.currentMovement} + if(reachableTilesMaxWalkingDistance.any()) unit.moveToTile(reachableTilesMaxWalkingDistance.toList().getRandom().first) + else if(reachableTiles.any()) unit.moveToTile(reachableTiles.toList().getRandom().first) + // if both failed, then... there aren't any reachable tiles. Which is possible. } fun rankTileAsCityCenter(tileInfo: TileInfo, nearbyTileRankings: Map): Float {