diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index e634f25aab..ee0f71d33a 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -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 } diff --git a/core/src/com/unciv/logic/city/PopulationManager.kt b/core/src/com/unciv/logic/city/PopulationManager.kt index 1d8d0c3642..fcd83ea0f7 100644 --- a/core/src/com/unciv/logic/city/PopulationManager.kt +++ b/core/src/com/unciv/logic/city/PopulationManager.kt @@ -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() { diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index 7f98560ed0..84d6f159c7 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -74,9 +74,7 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { leftSideTable.add(civIndicator).row() - civIndicator.onClick { - updateRightSide(civ) - } + civIndicator.onClick { updateRightSide(civ) } } }