Fixed bug where workers would try to head towards tiles they couldn't reach to construct roads

This commit is contained in:
Yair Morgenstern 2018-07-06 16:47:51 +03:00
parent 0c17e19ea2
commit 1c304da9d1

View File

@ -60,8 +60,10 @@ class WorkerAutomation(val unit: MapUnit) {
return true
}
val closestTileInPathWithNoRoad = pathToClosestCity.filter { unit.canMoveTo(it)}
.minBy { HexMath().getDistance(unit.getTile().position, it.position) }
val closestTileInPathWithNoRoad = pathToClosestCity
.filter { unit.canMoveTo(it)}
.sortedByDescending { HexMath().getDistance(unit.getTile().position, it.position) }
.firstOrNull { unit.movementAlgs().canReach(it) }
if(closestTileInPathWithNoRoad==null) return false
unit.movementAlgs().headTowards(closestTileInPathWithNoRoad)