mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 15:27:50 +07:00
Hardcore typing for uniques in how to improve city UI performance
This commit is contained in:
@ -6,6 +6,7 @@ import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.ruleset.Belief
|
||||
import com.unciv.models.ruleset.BeliefType
|
||||
import com.unciv.models.ruleset.VictoryType
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
@ -44,7 +45,8 @@ object ChooseBeliefsAutomation {
|
||||
var bonusYield = 0f
|
||||
for (unique in belief.uniqueObjects) {
|
||||
when (unique.placeholderText) {
|
||||
"[] from every []" -> if (tile.matchesFilter(unique.params[1])) bonusYield += unique.stats.values.sum()
|
||||
UniqueType.StatsFromObject.placeholderText -> if (tile.matchesFilter(unique.params[1]))
|
||||
bonusYield += unique.stats.values.sum()
|
||||
"[] from [] tiles without [] []" ->
|
||||
if (city.matchesFilter(unique.params[3])
|
||||
&& tile.matchesFilter(unique.params[1])
|
||||
@ -76,7 +78,7 @@ object ChooseBeliefsAutomation {
|
||||
if (city.getCenterTile().matchesFilter(unique.params[1]))
|
||||
unique.stats.values.sum() // Modified by personality
|
||||
else 0f
|
||||
"[] from every []", "[] from every [] in cities where this religion has at least [] followers" ->
|
||||
UniqueType.StatsFromObject.placeholderText, "[] from every [] in cities where this religion has at least [] followers" ->
|
||||
when {
|
||||
ruleSet.buildings.containsKey(unique.params[1]) -> {
|
||||
unique.stats.values.sum() /
|
||||
|
@ -191,7 +191,7 @@ class CityStats(val cityInfo: CityInfo) {
|
||||
for (unique in cityInfo.getMatchingUniques(UniqueType.StatsFromSpecialist))
|
||||
if (cityInfo.matchesFilter(unique.params[1]))
|
||||
stats.add(unique.stats)
|
||||
for (unique in cityInfo.civInfo.getMatchingUniques("[] from every []"))
|
||||
for (unique in cityInfo.civInfo.getMatchingUniques(UniqueType.StatsFromObject))
|
||||
if (unique.params[1] == specialistName)
|
||||
stats.add(unique.stats)
|
||||
return stats
|
||||
|
@ -265,9 +265,9 @@ open class TileInfo {
|
||||
}
|
||||
|
||||
if (city != null) {
|
||||
var tileUniques = city.getMatchingUniques("[] from [] tiles []")
|
||||
var tileUniques = city.getMatchingUniques(UniqueType.StatsFromTiles)
|
||||
.filter { city.matchesFilter(it.params[2]) }
|
||||
tileUniques += city.getMatchingUniques("[] from every []")
|
||||
tileUniques += city.getMatchingUniques(UniqueType.StatsFromObject)
|
||||
for (unique in tileUniques) {
|
||||
val tileType = unique.params[1]
|
||||
if (tileType == improvement) continue // This is added to the calculation in getImprovementStats. we don't want to add it twice
|
||||
@ -363,7 +363,7 @@ open class TileInfo {
|
||||
stats.add(unique.stats)
|
||||
|
||||
if (city != null) {
|
||||
val tileUniques = city.getMatchingUniques("[] from [] tiles []")
|
||||
val tileUniques = city.getMatchingUniques(UniqueType.StatsFromTiles)
|
||||
.filter { city.matchesFilter(it.params[2]) }
|
||||
val improvementUniques = improvement.uniqueObjects.filter {
|
||||
it.placeholderText == "[] on [] tiles once [] is discovered"
|
||||
@ -378,7 +378,7 @@ open class TileInfo {
|
||||
stats.add(unique.stats)
|
||||
}
|
||||
|
||||
for (unique in city.getMatchingUniques("[] from every []")) {
|
||||
for (unique in city.getMatchingUniques(UniqueType.StatsFromObject)) {
|
||||
if (improvement.matchesFilter(unique.params[1])) {
|
||||
stats.add(unique.stats)
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
|
||||
private fun getUniquesStrings() = sequence {
|
||||
val tileBonusHashmap = HashMap<String, ArrayList<String>>()
|
||||
for (unique in uniqueObjects) when {
|
||||
unique.placeholderText == "[] from [] tiles []" && unique.params[2] == "in this city" -> {
|
||||
unique.isOfType(UniqueType.StatsFromTiles) && unique.params[2] == "in this city" -> {
|
||||
val stats = unique.params[0]
|
||||
if (!tileBonusHashmap.containsKey(stats)) tileBonusHashmap[stats] = ArrayList()
|
||||
tileBonusHashmap[stats]!!.add(unique.params[1])
|
||||
@ -158,7 +158,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
|
||||
if (city == null) return stats
|
||||
val civInfo = city.civInfo
|
||||
|
||||
for (unique in city.getMatchingUniques("[] from every []")) {
|
||||
for (unique in city.getMatchingUniques(UniqueType.StatsFromObject)) {
|
||||
if (!matchesFilter(unique.params[1])) continue
|
||||
stats.add(unique.stats)
|
||||
}
|
||||
@ -693,7 +693,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
|
||||
if (get(stat) > 0) return true
|
||||
if (getStatPercentageBonuses(null)[stat] > 0) return true
|
||||
if (uniqueObjects.any { it.placeholderText == "[] per [] population []" && it.stats[stat] > 0 }) return true
|
||||
if (uniqueObjects.any { it.placeholderText == "[] from [] tiles []" && it.stats[stat] > 0 }) return true
|
||||
if (uniqueObjects.any { it.isOfType(UniqueType.StatsFromTiles) && it.stats[stat] > 0 }) return true
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.unciv.models.ruleset.unique
|
||||
|
||||
import com.unciv.models.ruleset.BeliefType
|
||||
import com.unciv.models.ruleset.Building
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.ruleset.tile.TerrainType
|
||||
@ -209,6 +208,13 @@ enum class UniqueParameterType(val parameterName:String) {
|
||||
else -> UniqueType.UniqueComplianceErrorSeverity.RulesetSpecific
|
||||
}
|
||||
},
|
||||
Specialist("specialist") {
|
||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||
UniqueType.UniqueComplianceErrorSeverity? = when (parameterText) {
|
||||
in ruleset.specialists -> null
|
||||
else -> UniqueType.UniqueComplianceErrorSeverity.RulesetSpecific
|
||||
}
|
||||
},
|
||||
/** Behaves like [Unknown], but states explicitly the parameter is OK and its contents are ignored */
|
||||
Comment("comment") {
|
||||
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
|
||||
|
@ -74,7 +74,9 @@ enum class UniqueType(val text:String, vararg targets: UniqueTarget) {
|
||||
StatsPerPopulation("[stats] per [amount] population [cityFilter]", UniqueTarget.Global),
|
||||
|
||||
StatsSpendingGreatPeople("[stats] whenever a Great Person is expended", UniqueTarget.Global),
|
||||
|
||||
StatsFromTiles("[stats] from [tileFilter] tiles [cityFilter]", UniqueTarget.Global),
|
||||
// This is a doozy
|
||||
StatsFromObject("[stats] from every [tileFilter/specialist/buildingNam]", UniqueTarget.Global),
|
||||
|
||||
StatPercentBonus("[amount]% [stat]", UniqueTarget.Global),
|
||||
BonusStatsFromCityStates("[amount]% [stat] from City-States", UniqueTarget.Global),
|
||||
|
@ -201,7 +201,7 @@ class CityConstructionsTable(private val cityScreen: CityScreen) {
|
||||
availableConstructionsTable.add("Loading...".toLabel()).pad(10f)
|
||||
}
|
||||
|
||||
thread {
|
||||
thread(name = "Construction info gathering - ${cityScreen.city.name}") {
|
||||
// Since this can be a heavy operation and leads to many ANRs on older phones we put the metadata-gathering in another thread.
|
||||
val constructionButtonDTOList = getConstructionButtonDTOs()
|
||||
Gdx.app.postRunnable {
|
||||
|
Reference in New Issue
Block a user