Autoassign the population when the manual assignment fails (#7028)

* Whitespaces "magic"

* Fallback to assign the worker automatically
This commit is contained in:
Jack Rainy 2022-05-31 23:59:19 +03:00 committed by GitHub
parent 8e5a9a3385
commit cd9746560e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -197,10 +197,18 @@ class PopulationManager {
//un-assign population //un-assign population
if ((worstWorkedTile != null && valueWorstTile < valueWorstSpecialist) if (worstWorkedTile != null && valueWorstTile < valueWorstSpecialist) {
|| worstJob == null) { cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(worstWorkedTile.position)
cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(worstWorkedTile!!.position) } else if (worstJob != null) specialistAllocations.add(worstJob, -1)
} else specialistAllocations.add(worstJob, -1) else {
// It happens when "cityInfo.manualSpecialists == true"
// and population goes below the number of specialists, e.g. city is razing.
// Let's give a chance to do the work automatically at least.
val worstAutoJob = specialistAllocations.keys.minByOrNull {
Automation.rankSpecialist(it, cityInfo, cityInfo.cityStats.currentCityStats) }
?: break // sorry, we can do nothing about that
specialistAllocations.add(worstAutoJob, -1)
}
} }
} }