mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 11:34:54 -04:00
perf(memory): Don't store city distances intermediately
This commit is contained in:
parent
a7ccbde718
commit
cbbec40e00
@ -647,13 +647,17 @@ object NextTurnAutomation {
|
|||||||
fun getClosestCities(civ1: Civilization, civ2: Civilization): CityDistance? {
|
fun getClosestCities(civ1: Civilization, civ2: Civilization): CityDistance? {
|
||||||
if (civ1.cities.isEmpty() || civ2.cities.isEmpty())
|
if (civ1.cities.isEmpty() || civ2.cities.isEmpty())
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
var minDistance: CityDistance? = null
|
||||||
|
|
||||||
val cityDistances = arrayListOf<CityDistance>()
|
|
||||||
for (civ1city in civ1.cities)
|
for (civ1city in civ1.cities)
|
||||||
for (civ2city in civ2.cities)
|
for (civ2city in civ2.cities){
|
||||||
cityDistances += CityDistance(civ1city, civ2city,
|
val currentDistance = CityDistance(civ1city, civ2city,
|
||||||
civ1city.getCenterTile().aerialDistanceTo(civ2city.getCenterTile()))
|
civ1city.getCenterTile().aerialDistanceTo(civ2city.getCenterTile()))
|
||||||
|
if (minDistance == null || currentDistance.aerialDistance < minDistance.aerialDistance)
|
||||||
|
minDistance = currentDistance
|
||||||
|
}
|
||||||
|
|
||||||
return cityDistances.minByOrNull { it.aerialDistance }!!
|
return minDistance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -531,7 +531,7 @@ class WorkerAutomation(
|
|||||||
if (tile.hasViewableResource(civInfo)) valueOfFort -= 1
|
if (tile.hasViewableResource(civInfo)) valueOfFort -= 1
|
||||||
|
|
||||||
// if this place is not perfect, let's see if there is a better one
|
// if this place is not perfect, let's see if there is a better one
|
||||||
val nearestTiles = tile.getTilesInDistance(1).filter { it.owningCity?.civ == civInfo }.toList()
|
val nearestTiles = tile.getTilesInDistance(1).filter { it.owningCity?.civ == civInfo }
|
||||||
for (closeTile in nearestTiles) {
|
for (closeTile in nearestTiles) {
|
||||||
// don't build forts too close to the cities
|
// don't build forts too close to the cities
|
||||||
if (closeTile.isCityCenter()) {
|
if (closeTile.isCityCenter()) {
|
||||||
|
@ -54,7 +54,7 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup,
|
|||||||
|
|
||||||
val baseHexagon = if (strings().tileSetConfig.useColorAsBaseTerrain)
|
val baseHexagon = if (strings().tileSetConfig.useColorAsBaseTerrain)
|
||||||
listOf(strings().hexagon)
|
listOf(strings().hexagon)
|
||||||
else listOf()
|
else emptyList()
|
||||||
|
|
||||||
val tile = tileGroup.tile
|
val tile = tileGroup.tile
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user