mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-26 15:49:14 +07:00
Better performance for reassigning population - important, since AI does this every city every turn
This commit is contained in:
@ -143,8 +143,12 @@ class CityPopulationManager : IsPartOfGameInfoSerialization {
|
|||||||
addPopulation(-population + count)
|
addPopulation(-population + count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Only assigns free population */
|
||||||
internal fun autoAssignPopulation() {
|
internal fun autoAssignPopulation() {
|
||||||
city.cityStats.update() // calculate current stats with current assignments
|
city.cityStats.update() // calculate current stats with current assignments
|
||||||
|
val freePopulation = getFreePopulation()
|
||||||
|
if (freePopulation <= 0) return
|
||||||
|
|
||||||
val cityStats = city.cityStats.currentCityStats
|
val cityStats = city.cityStats.currentCityStats
|
||||||
city.currentGPPBonus = city.getGreatPersonPercentageBonus() // pre-calculate for use in Automation.rankSpecialist
|
city.currentGPPBonus = city.getGreatPersonPercentageBonus() // pre-calculate for use in Automation.rankSpecialist
|
||||||
var specialistFoodBonus = 2f // See CityStats.calcFoodEaten()
|
var specialistFoodBonus = 2f // See CityStats.calcFoodEaten()
|
||||||
@ -157,11 +161,16 @@ class CityPopulationManager : IsPartOfGameInfoSerialization {
|
|||||||
.filter { !it.isBlockaded() }.toList().asSequence()
|
.filter { !it.isBlockaded() }.toList().asSequence()
|
||||||
|
|
||||||
val localUniqueCache = LocalUniqueCache()
|
val localUniqueCache = LocalUniqueCache()
|
||||||
repeat(getFreePopulation()) {
|
// Calculate stats once - but the *ranking of those stats* is dynamic and depends on what the city needs
|
||||||
|
val tileStats = tilesToEvaluate
|
||||||
|
.filterNot { it.providesYield() }
|
||||||
|
.associateWith { it.stats.getTileStats(city, city.civ, localUniqueCache)}
|
||||||
|
|
||||||
|
repeat(freePopulation) {
|
||||||
//evaluate tiles
|
//evaluate tiles
|
||||||
val bestTileAndRank = tilesToEvaluate
|
val bestTileAndRank = tilesToEvaluate
|
||||||
.filterNot { it.providesYield() }
|
.filterNot { it.providesYield() } // Changes with every tile assigned
|
||||||
.associateWith { Automation.rankTileForCityWork(it, city, localUniqueCache) }
|
.associateWith { Automation.rankStatsForCityWork(tileStats[it]!!, city, false, localUniqueCache) }
|
||||||
// We need to make sure that we work the same tiles as last turn on a tile
|
// We need to make sure that we work the same tiles as last turn on a tile
|
||||||
// so that our workers know to prioritize this tile and don't move to the other tile
|
// so that our workers know to prioritize this tile and don't move to the other tile
|
||||||
// This was just the easiest way I could think of.
|
// This was just the easiest way I could think of.
|
||||||
|
Reference in New Issue
Block a user