Fixed bug where unit would try to randomwalk but there wasn't anywhere to go
This commit is contained in:
parent
389c489faf
commit
1a2d3d4421
1 changed files with 6 additions and 3 deletions
|
@ -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<TileInfo, Float>): Float {
|
||||
|
|
Loading…
Reference in a new issue