diff --git a/core/src/com/unciv/logic/city/PopulationManager.kt b/core/src/com/unciv/logic/city/PopulationManager.kt index a0290243ea..9d741e21e0 100644 --- a/core/src/com/unciv/logic/city/PopulationManager.kt +++ b/core/src/com/unciv/logic/city/PopulationManager.kt @@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.Color import com.unciv.logic.automation.Automation import com.unciv.logic.map.TileInfo import com.unciv.models.Counter -import com.unciv.models.ruleset.Specialist import com.unciv.models.stats.Stats import com.unciv.ui.utils.withItem import com.unciv.ui.utils.withoutItem @@ -89,7 +88,7 @@ class PopulationManager { val valueBestTile = if (bestTile == null) 0f else Automation.rankTileForCityWork(bestTile, cityInfo, foodWeight) - val bestJob: String? = getMaxSpecialistsNew() + val bestJob: String? = getMaxSpecialists() .filter { specialistAllocations[it.key]!! amount) @@ -157,7 +156,7 @@ class PopulationManager { } - fun getMaxSpecialistsNew(): Counter { + fun getMaxSpecialists(): Counter { val counter = Counter() for (building in cityInfo.cityConstructions.getBuiltBuildings()) counter.add(building.newSpecialists()) diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index 66671d8468..25dadcebe3 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -19,10 +19,19 @@ class Building : NamedStats(), IConstruction { var cost: Int = 0 var maintenance = 0 private var percentStatBonus: Stats? = null - var specialistSlots: Stats? = null + var specialistSlots: Counter? = null fun newSpecialists(): Counter { - if(specialistSlots==null) return Counter() - return Specialist.convertStatsToSpecialistHashmap(specialistSlots!!) + if (specialistSlots == null) return Counter() + // Could have old specialist values of "gold", "science" etc - change them to the new specialist names + val counter = Counter() + for ((entry, amount) in specialistSlots!!) { + val equivalentStat = Stat.values().firstOrNull { it.name.toLowerCase() == entry } + + if (equivalentStat != null) + counter[Specialist.specialistNameByStat(equivalentStat)] = amount + else counter[entry] = amount + } + return counter } var greatPersonPoints: Stats? = null /** Extra cost percentage when purchasing */ @@ -108,13 +117,8 @@ class Building : NamedStats(), IConstruction { if (gpp.culture != 0f) stringBuilder.appendln("+" + gpp.culture.toInt() + " "+"[Great Artist] points".tr()) } - if (this.specialistSlots != null) { - val ss = this.specialistSlots!! - if (ss.production != 0f) stringBuilder.appendln("+" + ss.production.toInt() + " " + "[Engineer specialist] slots".tr()) - if (ss.gold != 0f) stringBuilder.appendln("+" + ss.gold .toInt() + " " + "[Merchant specialist] slots".tr()) - if (ss.science != 0f) stringBuilder.appendln("+" + ss.science .toInt() + " " + "[Scientist specialist] slots".tr()) - if (ss.culture != 0f) stringBuilder.appendln("+" + ss.culture .toInt() + " " + "[Artist specialist] slots".tr()) - } + for((specialistName, amount) in newSpecialists()) + stringBuilder.appendln("+$amount "+"[$specialistName] slots".tr()) if (resourceBonusStats != null) { val resources = ruleset.tileResources.values.filter { name == it.building }.joinToString { it.name.tr() } @@ -394,7 +398,6 @@ class Building : NamedStats(), IConstruction { fun isStatRelated(stat: Stat): Boolean { if (get(stat) > 0) return true if (getStatPercentageBonuses(null).get(stat)>0) return true - if (specialistSlots!=null && specialistSlots!!.get(stat)>0) return true if(resourceBonusStats!=null && resourceBonusStats!!.get(stat)>0) return true return false } diff --git a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt index fe3ab20bf4..def6ee68fd 100644 --- a/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt +++ b/core/src/com/unciv/ui/cityscreen/CityInfoTable.kt @@ -132,7 +132,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS for (building in cityInfo.cityConstructions.getBuiltBuildings()) { when { building.isWonder || building.isNationalWonder -> wonders.add(building) - building.specialistSlots != null -> specialistBuildings.add(building) + !building.newSpecialists().isEmpty() -> specialistBuildings.add(building) else -> otherBuildings.add(building) } } @@ -151,11 +151,10 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS addBuildingInfo(building, specialistBuildingsTable) val specialistIcons = Table() specialistIcons.row().size(20f).pad(5f) - for (stat in building.specialistSlots!!.toHashMap()) { - if (stat.value == 0f) continue - val specialist = cityInfo.getRuleset().specialists[Specialist.specialistNameByStat(stat.key)] + for ((specialistName, amount) in building.newSpecialists()) { + val specialist = cityInfo.getRuleset().specialists[specialistName] if (specialist == null) continue // probably a mod that doesn't have the specialist defined yet - for (i in 0 until stat.value.toInt()) + for (i in 0 until amount) specialistIcons.add(ImageGetter.getSpecialistIcon(specialist.colorObject)).size(20f) } diff --git a/core/src/com/unciv/ui/cityscreen/SpecialistAllocationTable.kt b/core/src/com/unciv/ui/cityscreen/SpecialistAllocationTable.kt index 8b8454e16c..8a9a2f0fa1 100644 --- a/core/src/com/unciv/ui/cityscreen/SpecialistAllocationTable.kt +++ b/core/src/com/unciv/ui/cityscreen/SpecialistAllocationTable.kt @@ -5,8 +5,6 @@ import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Align import com.unciv.UncivGame -import com.unciv.models.ruleset.Specialist -import com.unciv.models.stats.Stat import com.unciv.ui.utils.* class SpecialistAllocationTable(val cityScreen: CityScreen): Table(CameraStageBaseScreen.skin){ @@ -15,10 +13,10 @@ class SpecialistAllocationTable(val cityScreen: CityScreen): Table(CameraStageBa fun update() { clear() - for ((specialistName, amount) in cityInfo.population.getMaxSpecialistsNew()) { + for ((specialistName, amount) in cityInfo.population.getMaxSpecialists()) { val newSpecialists = cityInfo.population.getNewSpecialists() val assignedSpecialists = newSpecialists[specialistName]!! - val maxSpecialists = cityInfo.population.getMaxSpecialistsNew()[specialistName]!! + val maxSpecialists = cityInfo.population.getMaxSpecialists()[specialistName]!! if (cityScreen.canChangeState) add(getUnassignButton(assignedSpecialists, specialistName)) add(getAllocationTable(assignedSpecialists, maxSpecialists, specialistName)).pad(10f)