mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-20 09:17:47 +07:00
Settlers no longer try to go towards unreachable tiles in order to found cities
Settler random walk is now like the rest of the units
This commit is contained in:
parent
79971b05b8
commit
fe0c6e07a2
@ -137,14 +137,18 @@ class UnitAutomation{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// else, go to a random space
|
// else, go to a random space
|
||||||
val reachableTiles = unit.getDistanceToTiles()
|
randomWalk(unit)
|
||||||
.filter { unit.canMoveTo(it.key)}
|
|
||||||
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.
|
// if both failed, then... there aren't any reachable tiles. Which is possible.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun randomWalk(unit: MapUnit) {
|
||||||
|
val reachableTiles = unit.getDistanceToTiles()
|
||||||
|
.filter { unit.canMoveTo(it.key) }
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
fun rankTileAsCityCenter(tileInfo: TileInfo, nearbyTileRankings: Map<TileInfo, Float>): Float {
|
fun rankTileAsCityCenter(tileInfo: TileInfo, nearbyTileRankings: Map<TileInfo, Float>): Float {
|
||||||
val bestTilesFromOuterLayer = tileInfo.tileMap.getTilesAtDistance(tileInfo.position,2)
|
val bestTilesFromOuterLayer = tileInfo.tileMap.getTilesAtDistance(tileInfo.position,2)
|
||||||
.sortedByDescending { nearbyTileRankings[it] }.take(2)
|
.sortedByDescending { nearbyTileRankings[it] }.take(2)
|
||||||
@ -166,25 +170,23 @@ class UnitAutomation{
|
|||||||
val possibleTiles = unit.getTile().getTilesInDistance(5)
|
val possibleTiles = unit.getTile().getTilesInDistance(5)
|
||||||
.minus(tilesNearCities)
|
.minus(tilesNearCities)
|
||||||
|
|
||||||
if(possibleTiles.isEmpty()) // We got a badass over here, all tiles within 5 are taken? Screw it, random walk.
|
val bestCityLocation: TileInfo? = possibleTiles
|
||||||
|
.sortedByDescending { rankTileAsCityCenter(it, nearbyTileRankings) }
|
||||||
|
.firstOrNull { unit.movementAlgs().canReach(it) }
|
||||||
|
|
||||||
|
if(bestCityLocation==null) // We got a badass over here, all tiles within 5 are taken? Screw it, random walk.
|
||||||
{
|
{
|
||||||
unit.moveToTile(unit.getDistanceToTiles()
|
randomWalk(unit)
|
||||||
.filter { unit.canMoveTo(it.key) && it.value==unit.currentMovement } // at edge of walking distance
|
|
||||||
.toList().getRandom().first)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val bestCityLocation = possibleTiles
|
if (unit.getTile() == bestCityLocation) // already there!
|
||||||
.maxBy { rankTileAsCityCenter(it, nearbyTileRankings) }!!
|
UnitActions().getUnitActions(unit, UnCivGame.Current.worldScreen).first { it.name == "Found city" }.action()
|
||||||
|
|
||||||
if (unit.getTile() == bestCityLocation)
|
|
||||||
UnitActions().getUnitActions(unit, UnCivGame.Current.worldScreen!!).first { it.name == "Found city" }.action()
|
|
||||||
else {
|
else {
|
||||||
unit.movementAlgs().headTowards(bestCityLocation)
|
unit.movementAlgs().headTowards(bestCityLocation)
|
||||||
if (unit.currentMovement > 0 && unit.getTile() == bestCityLocation)
|
if (unit.currentMovement > 0 && unit.getTile() == bestCityLocation)
|
||||||
UnitActions().getUnitActions(unit, UnCivGame.Current.worldScreen!!).first { it.name == "Found city" }.action()
|
UnitActions().getUnitActions(unit, UnCivGame.Current.worldScreen).first { it.name == "Found city" }.action()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user