mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-10 23:37:31 +07:00
All stat-based uniques are parsed EXACTLY once, for performance reasons and to avoid ANRs
This commit is contained in:
parent
a3bed178d0
commit
b2c6cc59b7
@ -73,8 +73,8 @@ class CityConstructions {
|
|||||||
stats.add(building.getStats(cityInfo.civInfo))
|
stats.add(building.getStats(cityInfo.civInfo))
|
||||||
|
|
||||||
for (unique in builtBuildingUniqueMap.getAllUniques()) when (unique.placeholderText) {
|
for (unique in builtBuildingUniqueMap.getAllUniques()) when (unique.placeholderText) {
|
||||||
"[] Per [] Population in this city" -> stats.add(Stats.parse(unique.params[0]).times(cityInfo.population.population / unique.params[1].toFloat()))
|
"[] Per [] Population in this city" -> stats.add(unique.stats!!.times(cityInfo.population.population / unique.params[1].toFloat()))
|
||||||
"[] once [] is discovered" -> if (cityInfo.civInfo.tech.isResearched(unique.params[1])) stats.add(Stats.parse(unique.params[0]))
|
"[] once [] is discovered" -> if (cityInfo.civInfo.tech.isResearched(unique.params[1])) stats.add(unique.stats!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is to be deprecated and converted to "[stats] Per [N] Population in this city" - keeping it here to that mods with this can still work for now
|
// This is to be deprecated and converted to "[stats] Per [N] Population in this city" - keeping it here to that mods with this can still work for now
|
||||||
|
@ -50,7 +50,7 @@ class CityStats {
|
|||||||
val civInfo = cityInfo.civInfo
|
val civInfo = cityInfo.civInfo
|
||||||
stats.gold = civInfo.getCapital().population.population * 0.15f + cityInfo.population.population * 1.1f - 1 // Calculated by http://civilization.wikia.com/wiki/Trade_route_(Civ5)
|
stats.gold = civInfo.getCapital().population.population * 0.15f + cityInfo.population.population * 1.1f - 1 // Calculated by http://civilization.wikia.com/wiki/Trade_route_(Civ5)
|
||||||
for (unique in civInfo.getMatchingUniques("[] from each Trade Route"))
|
for (unique in civInfo.getMatchingUniques("[] from each Trade Route"))
|
||||||
stats.add(Stats.parse(unique.params[0]))
|
stats.add(unique.stats!!)
|
||||||
if (civInfo.hasUnique("Gold from all trade routes +25%")) stats.gold *= 1.25f // Machu Pichu speciality
|
if (civInfo.hasUnique("Gold from all trade routes +25%")) stats.gold *= 1.25f // Machu Pichu speciality
|
||||||
}
|
}
|
||||||
return stats
|
return stats
|
||||||
@ -215,7 +215,7 @@ class CityStats {
|
|||||||
|
|
||||||
if (cityInfo.getCenterTile().militaryUnit != null)
|
if (cityInfo.getCenterTile().militaryUnit != null)
|
||||||
for (unique in civInfo.getMatchingUniques("[] in all cities with a garrison"))
|
for (unique in civInfo.getMatchingUniques("[] in all cities with a garrison"))
|
||||||
happinessFromPolicies += Stats.parse(unique.params[0]).happiness
|
happinessFromPolicies += unique.stats!!.happiness
|
||||||
|
|
||||||
newHappinessList["Policies"] = happinessFromPolicies
|
newHappinessList["Policies"] = happinessFromPolicies
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ class CityStats {
|
|||||||
else stats.add(stat, 2f) // science and gold specialists
|
else stats.add(stat, 2f) // science and gold specialists
|
||||||
|
|
||||||
for(unique in cityInfo.civInfo.getMatchingUniques("[] from every specialist"))
|
for(unique in cityInfo.civInfo.getMatchingUniques("[] from every specialist"))
|
||||||
stats.add(Stats.parse(unique.params[0]))
|
stats.add(unique.stats!!)
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ class CityStats {
|
|||||||
if (specialist == null) return Stats()
|
if (specialist == null) return Stats()
|
||||||
val stats = specialist.clone()
|
val stats = specialist.clone()
|
||||||
for (unique in cityInfo.civInfo.getMatchingUniques("[] from every specialist"))
|
for (unique in cityInfo.civInfo.getMatchingUniques("[] from every specialist"))
|
||||||
stats.add(Stats.parse(unique.params[0]))
|
stats.add(unique.stats!!)
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,10 +275,10 @@ class CityStats {
|
|||||||
if ((unique.placeholderText == "[] in capital" && cityInfo.isCapital())
|
if ((unique.placeholderText == "[] in capital" && cityInfo.isCapital())
|
||||||
|| unique.placeholderText == "[] in all cities"
|
|| unique.placeholderText == "[] in all cities"
|
||||||
|| (unique.placeholderText == "[] in all cities with a garrison" && cityInfo.getCenterTile().militaryUnit != null))
|
|| (unique.placeholderText == "[] in all cities with a garrison" && cityInfo.getCenterTile().militaryUnit != null))
|
||||||
stats.add(Stats.parse(unique.params[0]))
|
stats.add(unique.stats!!)
|
||||||
if (unique.placeholderText == "[] per [] population in all cities") {
|
if (unique.placeholderText == "[] per [] population in all cities") {
|
||||||
val amountOfEffects = (cityInfo.population.population / unique.params[1].toInt()).toFloat()
|
val amountOfEffects = (cityInfo.population.population / unique.params[1].toInt()).toFloat()
|
||||||
stats.add(Stats.parse(unique.params[0]).times(amountOfEffects))
|
stats.add(unique.stats!!.times(amountOfEffects))
|
||||||
}
|
}
|
||||||
if (unique.text == "+1 gold and -1 unhappiness for every 2 citizens in capital" && cityInfo.isCapital()) {
|
if (unique.text == "+1 gold and -1 unhappiness for every 2 citizens in capital" && cityInfo.isCapital()) {
|
||||||
stats.gold += (cityInfo.population.population / 2).toFloat()
|
stats.gold += (cityInfo.population.population / 2).toFloat()
|
||||||
|
@ -194,7 +194,7 @@ open class TileInfo {
|
|||||||
|| (resource == tileType && hasViewableResource(observingCiv))
|
|| (resource == tileType && hasViewableResource(observingCiv))
|
||||||
|| (tileType == "Strategic resource" && hasViewableResource(observingCiv) && getTileResource().resourceType == ResourceType.Strategic)
|
|| (tileType == "Strategic resource" && hasViewableResource(observingCiv) && getTileResource().resourceType == ResourceType.Strategic)
|
||||||
|| (tileType == "Water resource" && isWater && hasViewableResource(observingCiv))
|
|| (tileType == "Water resource" && isWater && hasViewableResource(observingCiv))
|
||||||
) stats.add(Stats.parse(unique.params[0]))
|
) stats.add(unique.stats!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ open class TileInfo {
|
|||||||
|
|
||||||
for (unique in improvement.uniqueObjects)
|
for (unique in improvement.uniqueObjects)
|
||||||
if (unique.placeholderText == "[] once [] is discovered" && observingCiv.tech.isResearched(unique.params[1]))
|
if (unique.placeholderText == "[] once [] is discovered" && observingCiv.tech.isResearched(unique.params[1]))
|
||||||
stats.add(Stats.parse(unique.params[0]))
|
stats.add(unique.stats!!)
|
||||||
|
|
||||||
if (city != null) {
|
if (city != null) {
|
||||||
val cityWideUniques = city.cityConstructions.builtBuildingUniqueMap.getUniques("[] from [] tiles in this city")
|
val cityWideUniques = city.cityConstructions.builtBuildingUniqueMap.getUniques("[] from [] tiles in this city")
|
||||||
@ -262,7 +262,7 @@ open class TileInfo {
|
|||||||
|| (unique.params[1] == "fresh water" && isAdjacentToFreshwater)
|
|| (unique.params[1] == "fresh water" && isAdjacentToFreshwater)
|
||||||
|| (unique.params[1] == "non-fresh water" && !isAdjacentToFreshwater)
|
|| (unique.params[1] == "non-fresh water" && !isAdjacentToFreshwater)
|
||||||
)
|
)
|
||||||
stats.add(Stats.parse(unique.params[0]))
|
stats.add(unique.stats!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ open class TileInfo {
|
|||||||
|| it.matchesUniqueFilter(adjacent)
|
|| it.matchesUniqueFilter(adjacent)
|
||||||
|| it.roadStatus.name == adjacent
|
|| it.roadStatus.name == adjacent
|
||||||
}
|
}
|
||||||
stats.add(Stats.parse(unique.params[0]).times(numberOfBonuses.toFloat()))
|
stats.add(unique.stats!!.times(numberOfBonuses.toFloat()))
|
||||||
}
|
}
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
@ -143,21 +143,21 @@ class Building : NamedStats(), IConstruction {
|
|||||||
|
|
||||||
for (unique in civInfo.getMatchingUniques("[] from every []")) {
|
for (unique in civInfo.getMatchingUniques("[] from every []")) {
|
||||||
if (unique.params[1] != baseBuildingName) continue
|
if (unique.params[1] != baseBuildingName) continue
|
||||||
stats.add(Stats.parse(unique.params[0]))
|
stats.add(unique.stats!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unique in uniqueObjects)
|
for (unique in uniqueObjects)
|
||||||
if (unique.placeholderText == "[] with []" && civInfo.hasResource(unique.params[1]) && Stats.isStats(unique.params[0]))
|
if (unique.placeholderText == "[] with []" && civInfo.hasResource(unique.params[1]) && Stats.isStats(unique.params[0]))
|
||||||
stats.add(Stats.parse(unique.params[0]))
|
stats.add(unique.stats!!)
|
||||||
|
|
||||||
if (!isWonder)
|
if (!isWonder)
|
||||||
for (unique in civInfo.getMatchingUniques("[] from all [] buildings")) {
|
for (unique in civInfo.getMatchingUniques("[] from all [] buildings")) {
|
||||||
if (isStatRelated(Stat.valueOf(unique.params[1])))
|
if (isStatRelated(Stat.valueOf(unique.params[1])))
|
||||||
stats.add(Stats.parse(unique.params[0]))
|
stats.add(unique.stats!!)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
for (unique in civInfo.getMatchingUniques("[] from every Wonder"))
|
for (unique in civInfo.getMatchingUniques("[] from every Wonder"))
|
||||||
stats.add(Stats.parse(unique.params[0]))
|
stats.add(unique.stats!!)
|
||||||
|
|
||||||
}
|
}
|
||||||
return stats
|
return stats
|
||||||
|
@ -2,12 +2,16 @@ package com.unciv.models.ruleset
|
|||||||
|
|
||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
|
import com.unciv.models.stats.Stats
|
||||||
import com.unciv.models.translations.getPlaceholderParameters
|
import com.unciv.models.translations.getPlaceholderParameters
|
||||||
import com.unciv.models.translations.getPlaceholderText
|
import com.unciv.models.translations.getPlaceholderText
|
||||||
|
|
||||||
class Unique(val text:String){
|
class Unique(val text:String){
|
||||||
val placeholderText = text.getPlaceholderText()
|
val placeholderText = text.getPlaceholderText()
|
||||||
val params = text.getPlaceholderParameters()
|
val params = text.getPlaceholderParameters()
|
||||||
|
/** This is so the heavy regex-based parsing is only activated once per unique, instead of every time it's called
|
||||||
|
* - for instance, in the city screen, we call every tile unique for every tile, which can lead to ANRs */
|
||||||
|
val stats = params.firstOrNull { Stats.isStats(it) }?.let { Stats.parse(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
class UniqueMap:HashMap<String, ArrayList<Unique>>() {
|
class UniqueMap:HashMap<String, ArrayList<Unique>>() {
|
||||||
|
Loading…
Reference in New Issue
Block a user