mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 23:10:39 -04:00
Autoassign the population when the manual assignment fails (#7028)
* Whitespaces "magic" * Fallback to assign the worker automatically
This commit is contained in:
parent
8e5a9a3385
commit
cd9746560e
@ -77,12 +77,12 @@ class PopulationManager {
|
|||||||
}
|
}
|
||||||
if (foodStored >= getFoodToNextPopulation()) { // growth!
|
if (foodStored >= getFoodToNextPopulation()) { // growth!
|
||||||
foodStored -= getFoodToNextPopulation()
|
foodStored -= getFoodToNextPopulation()
|
||||||
var percentOfFoodCarriedOver =
|
var percentOfFoodCarriedOver =
|
||||||
cityInfo.getMatchingUniques(UniqueType.CarryOverFood)
|
cityInfo.getMatchingUniques(UniqueType.CarryOverFood)
|
||||||
.filter { cityInfo.matchesFilter(it.params[1]) }
|
.filter { cityInfo.matchesFilter(it.params[1]) }
|
||||||
.sumOf { it.params[0].toInt() }
|
.sumOf { it.params[0].toInt() }
|
||||||
// Try to avoid runaway food gain in mods, just in case
|
// Try to avoid runaway food gain in mods, just in case
|
||||||
if (percentOfFoodCarriedOver > 95) percentOfFoodCarriedOver = 95
|
if (percentOfFoodCarriedOver > 95) percentOfFoodCarriedOver = 95
|
||||||
foodStored += (getFoodToNextPopulation() * percentOfFoodCarriedOver / 100f).toInt()
|
foodStored += (getFoodToNextPopulation() * percentOfFoodCarriedOver / 100f).toInt()
|
||||||
addPopulation(1)
|
addPopulation(1)
|
||||||
cityInfo.updateCitizens = true
|
cityInfo.updateCitizens = true
|
||||||
@ -93,7 +93,7 @@ class PopulationManager {
|
|||||||
private fun getStatsOfSpecialist(name: String) = cityInfo.cityStats.getStatsOfSpecialist(name)
|
private fun getStatsOfSpecialist(name: String) = cityInfo.cityStats.getStatsOfSpecialist(name)
|
||||||
|
|
||||||
fun addPopulation(count: Int) {
|
fun addPopulation(count: Int) {
|
||||||
val changedAmount =
|
val changedAmount =
|
||||||
if (population + count < 0) -population
|
if (population + count < 0) -population
|
||||||
else count
|
else count
|
||||||
population += changedAmount
|
population += changedAmount
|
||||||
@ -121,7 +121,7 @@ class PopulationManager {
|
|||||||
if (cityInfo.matchesFilter(unique.params[1]))
|
if (cityInfo.matchesFilter(unique.params[1]))
|
||||||
specialistFoodBonus *= unique.params[0].toPercent()
|
specialistFoodBonus *= unique.params[0].toPercent()
|
||||||
specialistFoodBonus = 2f - specialistFoodBonus
|
specialistFoodBonus = 2f - specialistFoodBonus
|
||||||
|
|
||||||
for (i in 1..getFreePopulation()) {
|
for (i in 1..getFreePopulation()) {
|
||||||
//evaluate tiles
|
//evaluate tiles
|
||||||
val (bestTile, valueBestTile) = cityInfo.getTiles()
|
val (bestTile, valueBestTile) = cityInfo.getTiles()
|
||||||
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -211,4 +219,4 @@ class PopulationManager {
|
|||||||
counter.add(building.newSpecialists())
|
counter.add(building.newSpecialists())
|
||||||
return counter
|
return counter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user