mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-05 15:59:50 +07:00
MODDABLE SPECIALISTS ARE GO!
This commit is contained in:
@ -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]!!<it.value }
|
||||
.map { it.key }
|
||||
.maxBy { Automation.rankSpecialist(getStatsOfSpecialist(it), cityInfo) }
|
||||
@ -117,7 +116,7 @@ class PopulationManager {
|
||||
}
|
||||
|
||||
// unassign specialists that cannot be (e.g. the city was captured and one of the specialist buildings was destroyed)
|
||||
val maxSpecialists = getMaxSpecialistsNew()
|
||||
val maxSpecialists = getMaxSpecialists()
|
||||
val specialistsHashmap = specialistAllocations
|
||||
for ((specialistName, amount) in maxSpecialists)
|
||||
if (specialistsHashmap[specialistName]!! > amount)
|
||||
@ -157,7 +156,7 @@ class PopulationManager {
|
||||
|
||||
}
|
||||
|
||||
fun getMaxSpecialistsNew(): Counter<String> {
|
||||
fun getMaxSpecialists(): Counter<String> {
|
||||
val counter = Counter<String>()
|
||||
for (building in cityInfo.cityConstructions.getBuiltBuildings())
|
||||
counter.add(building.newSpecialists())
|
||||
|
@ -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<String>? = null
|
||||
fun newSpecialists(): Counter<String> {
|
||||
if(specialistSlots==null) return Counter<String>()
|
||||
return Specialist.convertStatsToSpecialistHashmap(specialistSlots!!)
|
||||
if (specialistSlots == null) return Counter<String>()
|
||||
// Could have old specialist values of "gold", "science" etc - change them to the new specialist names
|
||||
val counter = Counter<String>()
|
||||
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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user