mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-10 19:09:06 +07:00
Settler search optimization
This commit is contained in:
parent
a0f5e190fc
commit
3cd21c4b8e
@ -133,16 +133,19 @@ class UnitAutomation{
|
|||||||
// This is to improve performance - instead of ranking each tile in the area up to 19 times, do it once.
|
// This is to improve performance - instead of ranking each tile in the area up to 19 times, do it once.
|
||||||
val nearbyTileRankings = unit.getTile().getTilesInDistance(7)
|
val nearbyTileRankings = unit.getTile().getTilesInDistance(7)
|
||||||
.associateBy ( {it},{ Automation().rankTile(it,unit.civInfo) })
|
.associateBy ( {it},{ Automation().rankTile(it,unit.civInfo) })
|
||||||
var bestCityLocation = unit.getTile().getTilesInDistance(5)
|
|
||||||
.minus(tilesNearCities)
|
|
||||||
.maxBy { rankTileAsCityCenter(it, nearbyTileRankings) }
|
|
||||||
|
|
||||||
if(bestCityLocation==null) { // We got a badass over here, all tiles within 5 are taken? SEARCH EVERYWHERE
|
var possibleTiles = unit.getTile().getTilesInDistance(5)
|
||||||
bestCityLocation = unit.civInfo.getViewableTiles()
|
.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)
|
.minus(tilesNearCities)
|
||||||
.maxBy { rankTileAsCityCenter(it, nearbyTileRankings) }
|
|
||||||
}
|
if(possibleTiles.isEmpty())// STILL? Practically impossibru but this may prevent a crash
|
||||||
bestCityLocation!!
|
return // todo: add random walk?
|
||||||
|
|
||||||
|
val bestCityLocation = possibleTiles
|
||||||
|
.maxBy { rankTileAsCityCenter(it, nearbyTileRankings) }!!
|
||||||
|
|
||||||
if (unit.getTile() == bestCityLocation)
|
if (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