mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-19 20:28:56 +07:00
Reassign population after selling a specialist-providing building
This commit is contained in:
@ -598,12 +598,13 @@ class CityInfo {
|
||||
|
||||
fun getGoldForSellingBuilding(buildingName:String) = getRuleset().buildings[buildingName]!!.cost / 10
|
||||
|
||||
fun sellBuilding(buildingName:String){
|
||||
cityConstructions.builtBuildings.remove(buildingName)
|
||||
fun sellBuilding(buildingName:String) {
|
||||
cityConstructions.removeBuilding(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()
|
||||
civInfo.updateDetailedCivResources() // this building could be a resource-requiring one
|
||||
}
|
||||
|
@ -79,33 +79,33 @@ class PopulationManager {
|
||||
// if small city, favor production above all, ignore gold!
|
||||
// if larger city, food should be worth less!
|
||||
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 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)
|
||||
|
||||
val bestJob: String? = getMaxSpecialists()
|
||||
.filter { specialistAllocations[it.key]!! < it.value }
|
||||
.map { it.key }
|
||||
.maxBy { Automation.rankSpecialist(getStatsOfSpecialist(it), cityInfo) }
|
||||
val bestJob: String? = getMaxSpecialists()
|
||||
.filter { specialistAllocations[it.key]!! < it.value }
|
||||
.map { it.key }
|
||||
.maxBy { Automation.rankSpecialist(getStatsOfSpecialist(it), cityInfo) }
|
||||
|
||||
|
||||
var valueBestSpecialist = 0f
|
||||
if (bestJob != null) {
|
||||
val specialistStats = getStatsOfSpecialist(bestJob)
|
||||
valueBestSpecialist = Automation.rankSpecialist(specialistStats, cityInfo)
|
||||
var valueBestSpecialist = 0f
|
||||
if (bestJob != null) {
|
||||
val specialistStats = getStatsOfSpecialist(bestJob)
|
||||
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() {
|
||||
|
@ -74,9 +74,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() {
|
||||
|
||||
leftSideTable.add(civIndicator).row()
|
||||
|
||||
civIndicator.onClick {
|
||||
updateRightSide(civ)
|
||||
}
|
||||
civIndicator.onClick { updateRightSide(civ) }
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user