mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 21:35:14 -04:00
Population reassignment bug fixes (#7221)
* Fix locked tiles not being unassigned after population decrease * Fix assigned specialists not updating after a building is removed
This commit is contained in:
parent
4955d35efb
commit
c2c991f8b8
@ -167,9 +167,9 @@ class PopulationManager {
|
|||||||
// unassign specialists that cannot be (e.g. the city was captured and one of the specialist buildings was destroyed)
|
// unassign specialists that cannot be (e.g. the city was captured and one of the specialist buildings was destroyed)
|
||||||
val maxSpecialists = getMaxSpecialists()
|
val maxSpecialists = getMaxSpecialists()
|
||||||
val specialistsHashmap = specialistAllocations
|
val specialistsHashmap = specialistAllocations
|
||||||
for ((specialistName, amount) in maxSpecialists)
|
for ((specialistName, amount) in specialistsHashmap)
|
||||||
if (specialistsHashmap[specialistName]!! > amount)
|
if (amount > maxSpecialists[specialistName]!!)
|
||||||
specialistAllocations[specialistName] = amount
|
specialistAllocations[specialistName] = maxSpecialists[specialistName]!!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -188,25 +188,33 @@ class PopulationManager {
|
|||||||
else Automation.rankTileForCityWork(worstWorkedTile, cityInfo, cityInfo.cityStats.currentCityStats)
|
else Automation.rankTileForCityWork(worstWorkedTile, cityInfo, cityInfo.cityStats.currentCityStats)
|
||||||
|
|
||||||
//evaluate specialists
|
//evaluate specialists
|
||||||
val worstJob: String? = if (cityInfo.manualSpecialists) null else specialistAllocations.keys
|
val worstAutoJob: String? = if (cityInfo.manualSpecialists) null else specialistAllocations.keys
|
||||||
.minByOrNull { Automation.rankSpecialist(it, cityInfo, cityInfo.cityStats.currentCityStats) }
|
.minByOrNull { Automation.rankSpecialist(it, cityInfo, cityInfo.cityStats.currentCityStats) }
|
||||||
var valueWorstSpecialist = 0f
|
var valueWorstSpecialist = 0f
|
||||||
if (worstJob != null)
|
if (worstAutoJob != null)
|
||||||
valueWorstSpecialist = Automation.rankSpecialist(worstJob, cityInfo, cityInfo.cityStats.currentCityStats)
|
valueWorstSpecialist = Automation.rankSpecialist(worstAutoJob, cityInfo, cityInfo.cityStats.currentCityStats)
|
||||||
|
|
||||||
|
|
||||||
//un-assign population
|
// un-assign population
|
||||||
if (worstWorkedTile != null && valueWorstTile < valueWorstSpecialist) {
|
when {
|
||||||
|
worstAutoJob != null && worstWorkedTile != null -> {
|
||||||
|
// choose between removing a specialist and removing a tile
|
||||||
|
if (valueWorstTile < valueWorstSpecialist)
|
||||||
cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(worstWorkedTile.position)
|
cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(worstWorkedTile.position)
|
||||||
} else if (worstJob != null) specialistAllocations.add(worstJob, -1)
|
else
|
||||||
else {
|
specialistAllocations.add(worstAutoJob, -1)
|
||||||
|
}
|
||||||
|
worstAutoJob != null -> specialistAllocations.add(worstAutoJob, -1)
|
||||||
|
worstWorkedTile != null -> cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(worstWorkedTile.position)
|
||||||
|
else -> {
|
||||||
// It happens when "cityInfo.manualSpecialists == true"
|
// It happens when "cityInfo.manualSpecialists == true"
|
||||||
// and population goes below the number of specialists, e.g. city is razing.
|
// 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.
|
// Let's give a chance to do the work automatically at least.
|
||||||
val worstAutoJob = specialistAllocations.keys.minByOrNull {
|
val worstJob = specialistAllocations.keys.minByOrNull {
|
||||||
Automation.rankSpecialist(it, cityInfo, cityInfo.cityStats.currentCityStats) }
|
Automation.rankSpecialist(it, cityInfo, cityInfo.cityStats.currentCityStats) }
|
||||||
?: break // sorry, we can do nothing about that
|
?: break // sorry, we can do nothing about that
|
||||||
specialistAllocations.add(worstAutoJob, -1)
|
specialistAllocations.add(worstJob, -1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user