diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index 079ab169d8..78e6dfc0fd 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 {