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