When settlers have no viable spots within 5 tiles, they random walk to edges of walking ability

This commit is contained in:
Yair Morgenstern 2018-05-16 23:45:25 +03:00
parent 75b6a59ef4
commit d3799a0c64
2 changed files with 10 additions and 9 deletions

View File

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.game"
minSdkVersion 14
targetSdkVersion 26
versionCode 57
versionName "2.1.7"
versionCode 58
versionName "2.1.8"
}
buildTypes {
release {

View File

@ -133,15 +133,16 @@ class UnitAutomation{
val nearbyTileRankings = unit.getTile().getTilesInDistance(7)
.associateBy ( {it},{ Automation().rankTile(it,unit.civInfo) })
var possibleTiles = unit.getTile().getTilesInDistance(5)
val possibleTiles = unit.getTile().getTilesInDistance(5)
.minus(tilesNearCities)
if(possibleTiles.isEmpty()) // We got a badass over here, all tiles within 5 are taken? SEARCH EVERYWHERE
possibleTiles = unit.civInfo.getViewableTiles()
.minus(tilesNearCities)
if(possibleTiles.isEmpty())// STILL? Practically impossibru but this may prevent a crash
return // todo: add random walk?
if(possibleTiles.isEmpty()) // We got a badass over here, all tiles within 5 are taken? Screw it, random walk.
{
unit.moveToTile(unit.getDistanceToTiles()
.filter { it.key.unit == null && it.value==unit.currentMovement } // at edge of walking distance
.toList().getRandom().first)
return
}
val bestCityLocation = possibleTiles
.maxBy { rankTileAsCityCenter(it, nearbyTileRankings) }!!