mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-24 22:59:34 +07:00
City stats update now accepts construction - simplifies the CityConstructions.turnsToConstruction function
This commit is contained in:
@ -199,15 +199,11 @@ class CityConstructions {
|
||||
// and recalculating the entire city stats
|
||||
// We don't want to change our current construction queue - what if we have an empty queue, too many changes to check for -
|
||||
// So we must clone it and see what would happen if that was our construction
|
||||
val cityConstructionsClone = clone()
|
||||
cityConstructionsClone.currentConstructionFromQueue = constructionName
|
||||
cityConstructionsClone.cityInfo = cityInfo
|
||||
cityConstructionsClone.setTransients()
|
||||
cityInfo.cityConstructions = cityConstructionsClone
|
||||
cityInfo.cityStats.update()
|
||||
|
||||
val construction = cityInfo.cityConstructions.getConstruction(constructionName)
|
||||
cityInfo.cityStats.update(construction)
|
||||
cityStatsForConstruction = cityInfo.cityStats.currentCityStats
|
||||
// revert!
|
||||
cityInfo.cityConstructions = this
|
||||
cityInfo.cityStats.update()
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,8 @@ class CityStats {
|
||||
return stats
|
||||
}
|
||||
|
||||
private fun getStatPercentBonusesFromMarble(): Stats {
|
||||
private fun getStatPercentBonusesFromMarble(construction: IConstruction): Stats {
|
||||
val stats = Stats()
|
||||
val construction = cityInfo.cityConstructions.getCurrentConstruction()
|
||||
|
||||
if (construction is Building
|
||||
&& construction.isWonder
|
||||
@ -147,12 +146,11 @@ class CityStats {
|
||||
return stats
|
||||
}
|
||||
|
||||
private fun getStatPercentBonusesFromNationUnique(): Stats {
|
||||
private fun getStatPercentBonusesFromNationUnique(currentConstruction: IConstruction): Stats {
|
||||
val stats = Stats()
|
||||
|
||||
stats.add(getStatPercentBonusesFromUniques(cityInfo.civInfo.nation.uniqueObjects.asSequence()))
|
||||
stats.add(getStatPercentBonusesFromUniques(currentConstruction, cityInfo.civInfo.nation.uniqueObjects.asSequence()))
|
||||
|
||||
val currentConstruction = cityInfo.cityConstructions.getCurrentConstruction()
|
||||
if (currentConstruction is Building
|
||||
&& cityInfo.civInfo.getCapital().cityConstructions.builtBuildings.contains(currentConstruction.name)
|
||||
&& cityInfo.civInfo.hasUnique("+25% Production towards any buildings that already exist in the Capital"))
|
||||
@ -295,9 +293,8 @@ class CityStats {
|
||||
return stats
|
||||
}
|
||||
|
||||
private fun getStatPercentBonusesFromBuildings(): Stats {
|
||||
private fun getStatPercentBonusesFromBuildings(currentConstruction: IConstruction): Stats {
|
||||
val stats = cityInfo.cityConstructions.getStatPercentBonuses()
|
||||
val currentConstruction = cityInfo.cityConstructions.getCurrentConstruction()
|
||||
|
||||
// This is to be deprecated and converted to "+[]% production when building [] in this city" - keeping it here to that mods with this can still work for now
|
||||
if (currentConstruction is BaseUnit) {
|
||||
@ -320,10 +317,9 @@ class CityStats {
|
||||
return stats
|
||||
}
|
||||
|
||||
private fun getStatPercentBonusesFromUniques(uniques: Sequence<Unique>): Stats {
|
||||
private fun getStatPercentBonusesFromUniques(currentConstruction: IConstruction, uniques: Sequence<Unique>): Stats {
|
||||
val stats = Stats()
|
||||
|
||||
val currentConstruction = cityInfo.cityConstructions.getCurrentConstruction()
|
||||
if (currentConstruction.name == Constants.settler && cityInfo.isCapital()
|
||||
&& uniques.any { it.text == "Training of settlers increased +50% in capital" })
|
||||
stats.production += 50f
|
||||
@ -406,16 +402,16 @@ class CityStats {
|
||||
}
|
||||
|
||||
|
||||
fun updateStatPercentBonusList() {
|
||||
fun updateStatPercentBonusList(currentConstruction:IConstruction) {
|
||||
val newStatPercentBonusList = LinkedHashMap<String, Stats>()
|
||||
newStatPercentBonusList["Golden Age"] = getStatPercentBonusesFromGoldenAge(cityInfo.civInfo.goldenAges.isGoldenAge())
|
||||
newStatPercentBonusList["Policies"] = getStatPercentBonusesFromUniques(cityInfo.civInfo.policies.policyUniques.getAllUniques())
|
||||
newStatPercentBonusList["Buildings"] = getStatPercentBonusesFromBuildings()
|
||||
newStatPercentBonusList["Wonders"] = getStatPercentBonusesFromUniques(cityInfo.civInfo.getBuildingUniques())
|
||||
newStatPercentBonusList["Policies"] = getStatPercentBonusesFromUniques(currentConstruction, cityInfo.civInfo.policies.policyUniques.getAllUniques())
|
||||
newStatPercentBonusList["Buildings"] = getStatPercentBonusesFromBuildings(currentConstruction)
|
||||
newStatPercentBonusList["Wonders"] = getStatPercentBonusesFromUniques(currentConstruction, cityInfo.civInfo.getBuildingUniques())
|
||||
newStatPercentBonusList["Railroad"] = getStatPercentBonusesFromRailroad()
|
||||
newStatPercentBonusList["Marble"] = getStatPercentBonusesFromMarble()
|
||||
newStatPercentBonusList["Marble"] = getStatPercentBonusesFromMarble(currentConstruction)
|
||||
newStatPercentBonusList["Computers"] = getStatPercentBonusesFromComputers()
|
||||
newStatPercentBonusList["National ability"] = getStatPercentBonusesFromNationUnique()
|
||||
newStatPercentBonusList["National ability"] = getStatPercentBonusesFromNationUnique(currentConstruction)
|
||||
newStatPercentBonusList["Puppet City"] = getStatPercentBonusesFromPuppetCity()
|
||||
|
||||
if (UncivGame.Current.superchargedForDebug) {
|
||||
@ -427,13 +423,13 @@ class CityStats {
|
||||
statPercentBonusList = newStatPercentBonusList
|
||||
}
|
||||
|
||||
fun update() {
|
||||
fun update(currentConstruction: IConstruction = cityInfo.cityConstructions.getCurrentConstruction()) {
|
||||
// We need to compute Tile yields before happiness
|
||||
updateBaseStatList()
|
||||
updateCityHappiness()
|
||||
updateStatPercentBonusList()
|
||||
updateStatPercentBonusList(currentConstruction)
|
||||
|
||||
updateFinalStatList() // again, we don't edit the existing currentCityStats directly, in order to avoid concurrency exceptions
|
||||
updateFinalStatList(currentConstruction) // again, we don't edit the existing currentCityStats directly, in order to avoid concurrency exceptions
|
||||
|
||||
val newCurrentCityStats = Stats()
|
||||
for (stat in finalStatList.values) newCurrentCityStats.add(stat)
|
||||
@ -442,7 +438,7 @@ class CityStats {
|
||||
cityInfo.civInfo.updateStatsForNextTurn()
|
||||
}
|
||||
|
||||
private fun updateFinalStatList() {
|
||||
private fun updateFinalStatList(currentConstruction: IConstruction) {
|
||||
val newFinalStatList = LinkedHashMap<String, Stats>() // again, we don't edit the existing currentCityStats directly, in order to avoid concurrency exceptions
|
||||
|
||||
for (entry in baseStatList)
|
||||
@ -515,9 +511,8 @@ class CityStats {
|
||||
newFinalStatList["Maintenance"] = Stats().apply { gold -= buildingsMaintenance.toInt() }
|
||||
|
||||
|
||||
val currentconstruction = cityInfo.cityConstructions.currentConstructionFromQueue
|
||||
if (totalFood > 0 && cityInfo.getRuleset().units[currentconstruction]
|
||||
.let { it != null && it.uniques.contains("Excess Food converted to Production when under construction") }) {
|
||||
if (totalFood > 0 && currentConstruction is BaseUnit
|
||||
&& currentConstruction.uniques.contains("Excess Food converted to Production when under construction")) {
|
||||
newFinalStatList["Excess food to production"] =
|
||||
Stats().apply { production = totalFood; food = -totalFood }
|
||||
}
|
||||
|
@ -166,9 +166,10 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
||||
val specialConstructions = ArrayList<Table>()
|
||||
|
||||
thread {
|
||||
val constructionButtonDTOList = getConstructionButtonDTOs() // Since this can be a heavy operation and leads to many ANRs on older phones...
|
||||
|
||||
Gdx.app.postRunnable {
|
||||
// For some bizarre reason, moving this to another thread messes up the entire construction list?! Haven't figured out why yet
|
||||
val constructionButtonDTOList = getConstructionButtonDTOs() // Since this can be a heavy operation and leads to many ANRs on older phones...
|
||||
availableConstructionsTable.clear()
|
||||
|
||||
for (dto in constructionButtonDTOList) {
|
||||
|
Reference in New Issue
Block a user