mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-02 04:14:15 +07:00
Cities now unassign speciallists when razed/starve and don't go into "negative population" - thanks am-per-sand!
This commit is contained in:
parent
87c3d18ac7
commit
44be2b6d67
@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.unciv.logic.automation.Automation
|
import com.unciv.logic.automation.Automation
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.models.stats.Stats
|
import com.unciv.models.stats.Stats
|
||||||
|
import com.unciv.ui.utils.getRandom
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
class PopulationManager {
|
class PopulationManager {
|
||||||
@ -24,15 +25,7 @@ class PopulationManager {
|
|||||||
return toReturn
|
return toReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
// fun getSpecialists(): Stats {
|
|
||||||
// val allSpecialists = Stats()
|
|
||||||
// for (stats in buildingsSpecialists.values)
|
|
||||||
// allSpecialists.add(stats)
|
|
||||||
// return allSpecialists
|
|
||||||
// }
|
|
||||||
|
|
||||||
fun getNumberOfSpecialists(): Int {
|
fun getNumberOfSpecialists(): Int {
|
||||||
//val specialists = getSpecialists()
|
|
||||||
return (specialists.science + specialists.production + specialists.culture + specialists.gold).toInt()
|
return (specialists.science + specialists.production + specialists.culture + specialists.gold).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,12 +86,19 @@ class PopulationManager {
|
|||||||
cityInfo.workedTiles.remove(tile.position)
|
cityInfo.workedTiles.remove(tile.position)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (cityInfo.workedTiles.size > population) {
|
while (getFreePopulation()<0) {
|
||||||
|
if(getNumberOfSpecialists()>0){
|
||||||
|
val specialistTypeToUnassign = specialists.toHashMap().filter { it.value>0 }.map { it.key }.getRandom()
|
||||||
|
specialists.add(specialistTypeToUnassign,-1f)
|
||||||
|
}
|
||||||
|
else {
|
||||||
val lowestRankedWorkedTile = cityInfo.workedTiles
|
val lowestRankedWorkedTile = cityInfo.workedTiles
|
||||||
|
.asSequence()
|
||||||
.map { cityInfo.tileMap[it] }
|
.map { cityInfo.tileMap[it] }
|
||||||
.minBy { Automation().rankTile(it, cityInfo.civInfo) }!!
|
.minBy { Automation().rankTile(it, cityInfo.civInfo) }!!
|
||||||
cityInfo.workedTiles.remove(lowestRankedWorkedTile.position)
|
cityInfo.workedTiles.remove(lowestRankedWorkedTile.position)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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().toHashMap()
|
val maxSpecialists = getMaxSpecialists().toHashMap()
|
||||||
|
Loading…
Reference in New Issue
Block a user