Reassign population after selling a specialist-providing building

This commit is contained in:
Yair Morgenstern
2020-12-10 10:10:14 +02:00
parent d3ba68f7d3
commit 4578994adf
3 changed files with 28 additions and 29 deletions

View File

@ -598,12 +598,13 @@ class CityInfo {
fun getGoldForSellingBuilding(buildingName:String) = getRuleset().buildings[buildingName]!!.cost / 10 fun getGoldForSellingBuilding(buildingName:String) = getRuleset().buildings[buildingName]!!.cost / 10
fun sellBuilding(buildingName:String){ fun sellBuilding(buildingName:String) {
cityConstructions.builtBuildings.remove(buildingName)
cityConstructions.removeBuilding(buildingName) cityConstructions.removeBuilding(buildingName)
civInfo.gold += getGoldForSellingBuilding(buildingName) civInfo.gold += getGoldForSellingBuilding(buildingName)
hasSoldBuildingThisTurn=true hasSoldBuildingThisTurn = true
population.unassignExtraPopulation() // If the building provided specialists, release them to other work
population.autoAssignPopulation()
cityStats.update() cityStats.update()
civInfo.updateDetailedCivResources() // this building could be a resource-requiring one civInfo.updateDetailedCivResources() // this building could be a resource-requiring one
} }

View File

@ -79,33 +79,33 @@ class PopulationManager {
// if small city, favor production above all, ignore gold! // if small city, favor production above all, ignore gold!
// if larger city, food should be worth less! // if larger city, food should be worth less!
internal fun autoAssignPopulation(foodWeight: Float = 1f) { internal fun autoAssignPopulation(foodWeight: Float = 1f) {
if (getFreePopulation() == 0) return for (i in 1..getFreePopulation()) {
//evaluate tiles
val bestTile: TileInfo? = cityInfo.getTiles()
.filter { it.aerialDistanceTo(cityInfo.getCenterTile()) <= 3 }
.filterNot { it.isWorked() || cityInfo.location == it.position }
.maxBy { Automation.rankTileForCityWork(it, cityInfo, foodWeight) }
val valueBestTile = if (bestTile == null) 0f
else Automation.rankTileForCityWork(bestTile, cityInfo, foodWeight)
//evaluate tiles val bestJob: String? = getMaxSpecialists()
val bestTile: TileInfo? = cityInfo.getTiles() .filter { specialistAllocations[it.key]!! < it.value }
.filter { it.aerialDistanceTo(cityInfo.getCenterTile()) <= 3 } .map { it.key }
.filterNot { it.isWorked() || cityInfo.location == it.position } .maxBy { Automation.rankSpecialist(getStatsOfSpecialist(it), cityInfo) }
.maxBy { Automation.rankTileForCityWork(it, cityInfo, foodWeight) }
val valueBestTile = if (bestTile == null) 0f
else Automation.rankTileForCityWork(bestTile, cityInfo, foodWeight)
val bestJob: String? = getMaxSpecialists()
.filter { specialistAllocations[it.key]!! < it.value }
.map { it.key }
.maxBy { Automation.rankSpecialist(getStatsOfSpecialist(it), cityInfo) }
var valueBestSpecialist = 0f var valueBestSpecialist = 0f
if (bestJob != null) { if (bestJob != null) {
val specialistStats = getStatsOfSpecialist(bestJob) val specialistStats = getStatsOfSpecialist(bestJob)
valueBestSpecialist = Automation.rankSpecialist(specialistStats, cityInfo) valueBestSpecialist = Automation.rankSpecialist(specialistStats, cityInfo)
}
//assign population
if (valueBestTile > valueBestSpecialist) {
if (bestTile != null)
cityInfo.workedTiles = cityInfo.workedTiles.withItem(bestTile.position)
} else if (bestJob != null) specialistAllocations.add(bestJob, 1)
} }
//assign population
if (valueBestTile > valueBestSpecialist) {
if (bestTile != null)
cityInfo.workedTiles = cityInfo.workedTiles.withItem(bestTile.position)
} else if (bestJob != null) specialistAllocations.add(bestJob, 1)
} }
fun unassignExtraPopulation() { fun unassignExtraPopulation() {

View File

@ -74,9 +74,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
leftSideTable.add(civIndicator).row() leftSideTable.add(civIndicator).row()
civIndicator.onClick { civIndicator.onClick { updateRightSide(civ) }
updateRightSide(civ)
}
} }
} }