mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-10 15:27:27 +07:00
Better performance for 'best tile to found city' (minimized canReach calls) @tuvus
This commit is contained in:
parent
10cb51795c
commit
052df9c064
@ -35,14 +35,22 @@ object CityLocationTileRanker {
|
||||
val uniqueCache = LocalUniqueCache()
|
||||
val bestTilesToFoundCity = BestTilesToFoundCity()
|
||||
val baseTileMap = HashMap<Tile, Float>()
|
||||
for (tile in possibleCityLocations) {
|
||||
val tileValue = rankTileToSettle(tile, unit.civ, nearbyCities, baseTileMap, uniqueCache)
|
||||
if (tileValue > bestTilesToFoundCity.bestTileRank && unit.movement.canReach(tile)) {
|
||||
bestTilesToFoundCity.bestTile = tile
|
||||
bestTilesToFoundCity.bestTileRank = tileValue
|
||||
|
||||
val possibleTileLocationsWithRank = possibleCityLocations
|
||||
.map {
|
||||
val tileValue = rankTileToSettle(it, unit.civ, nearbyCities, baseTileMap, uniqueCache)
|
||||
bestTilesToFoundCity.tileRankMap[it] = tileValue
|
||||
|
||||
Pair(it, tileValue)
|
||||
}
|
||||
bestTilesToFoundCity.tileRankMap[tile] = tileValue
|
||||
.sortedByDescending { it.second }
|
||||
|
||||
val bestReachableTile = possibleTileLocationsWithRank.firstOrNull { unit.movement.canReach(it.first) }
|
||||
if (bestReachableTile != null){
|
||||
bestTilesToFoundCity.bestTile = bestReachableTile.first
|
||||
bestTilesToFoundCity.bestTileRank = bestReachableTile.second
|
||||
}
|
||||
|
||||
return bestTilesToFoundCity
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user