mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
The O(n^2) is noticable in the flame graphs, I kid you not
This commit is contained in:
parent
cd05fe6ac8
commit
1732d951d2
@ -30,7 +30,6 @@ import com.unciv.ui.utils.MayaCalendar
|
|||||||
import com.unciv.ui.utils.toPercent
|
import com.unciv.ui.utils.toPercent
|
||||||
import com.unciv.ui.victoryscreen.RankingType
|
import com.unciv.ui.victoryscreen.RankingType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.collections.HashMap
|
import kotlin.collections.HashMap
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
@ -389,7 +388,7 @@ class CivilizationInfo {
|
|||||||
// Does not return local uniques, only global ones.
|
// Does not return local uniques, only global ones.
|
||||||
/** Destined to replace getMatchingUniques, gradually, as we fill the enum */
|
/** Destined to replace getMatchingUniques, gradually, as we fill the enum */
|
||||||
fun getMatchingUniques(uniqueType: UniqueType, stateForConditionals: StateForConditionals? = StateForConditionals(this), cityToIgnore: CityInfo? = null) = sequence {
|
fun getMatchingUniques(uniqueType: UniqueType, stateForConditionals: StateForConditionals? = StateForConditionals(this), cityToIgnore: CityInfo? = null) = sequence {
|
||||||
yieldAll(nation.uniqueObjects.asSequence().filter { it.isOfType(uniqueType) })
|
yieldAll(nation.getMatchingUniques(uniqueType,stateForConditionals))
|
||||||
yieldAll(cities.asSequence()
|
yieldAll(cities.asSequence()
|
||||||
.filter { it != cityToIgnore }
|
.filter { it != cityToIgnore }
|
||||||
.flatMap { city -> city.getMatchingUniquesWithNonLocalEffects(uniqueType) }
|
.flatMap { city -> city.getMatchingUniquesWithNonLocalEffects(uniqueType) }
|
||||||
@ -576,22 +575,23 @@ class CivilizationInfo {
|
|||||||
fun getEra(): Era {
|
fun getEra(): Era {
|
||||||
if (gameInfo.ruleSet.technologies.isEmpty() || tech.researchedTechnologies.isEmpty())
|
if (gameInfo.ruleSet.technologies.isEmpty() || tech.researchedTechnologies.isEmpty())
|
||||||
return Era()
|
return Era()
|
||||||
val maxEraName = tech.researchedTechnologies
|
val maxEraOfResearchedTechs = tech.researchedTechnologies
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.map { it.column!! }
|
.map { it.column!! }
|
||||||
.maxByOrNull { it.columnNumber }!!
|
.maxByOrNull { it.columnNumber }!!
|
||||||
.era
|
.era
|
||||||
val maxEra = gameInfo.ruleSet.eras[maxEraName]!!
|
val maxEra = gameInfo.ruleSet.eras[maxEraOfResearchedTechs]!!
|
||||||
|
|
||||||
val minEraName = gameInfo.ruleSet.technologies.values
|
val researchedTechsHashset = tech.researchedTechnologies.toHashSet()
|
||||||
|
val minEraOfNonResearchedTechs = gameInfo.ruleSet.technologies.values
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filter { it !in tech.researchedTechnologies }
|
.filter { it !in researchedTechsHashset }
|
||||||
.map { it.column!! }
|
.map { it.column!! }
|
||||||
.minByOrNull { it.columnNumber }
|
.minByOrNull { it.columnNumber }
|
||||||
?.era
|
?.era
|
||||||
?: return maxEra
|
?: return maxEra
|
||||||
|
|
||||||
val minEra = gameInfo.ruleSet.eras[minEraName]!!
|
val minEra = gameInfo.ruleSet.eras[minEraOfNonResearchedTechs]!!
|
||||||
|
|
||||||
return if (minEra.eraNumber > maxEra.eraNumber) minEra
|
return if (minEra.eraNumber > maxEra.eraNumber) minEra
|
||||||
else maxEra
|
else maxEra
|
||||||
@ -781,9 +781,9 @@ class CivilizationInfo {
|
|||||||
.any { gameInfo.ruleSet.terrains[it.params[0]]!!.damagePerTurn != it.params[1].toInt() }
|
.any { gameInfo.ruleSet.terrains[it.params[0]]!!.damagePerTurn != it.params[1].toInt() }
|
||||||
|
|
||||||
// Cache the last era each resource is used for buildings or units respectively for AI building evaluation
|
// Cache the last era each resource is used for buildings or units respectively for AI building evaluation
|
||||||
for (resource in gameInfo.ruleSet.tileResources.values.filter { it.resourceType == ResourceType.Strategic }.map { it.name }) {
|
for (resource in gameInfo.ruleSet.tileResources.values.asSequence().filter { it.resourceType == ResourceType.Strategic }.map { it.name }) {
|
||||||
val applicableBuildings = gameInfo.ruleSet.buildings.values.filter { getEquivalentBuilding(it) == it && it.requiresResource(resource) }
|
val applicableBuildings = gameInfo.ruleSet.buildings.values.filter { it.requiresResource(resource) && getEquivalentBuilding(it) == it }
|
||||||
val applicableUnits = gameInfo.ruleSet.units.values.filter { getEquivalentUnit(it) == it && it.requiresResource(resource) }
|
val applicableUnits = gameInfo.ruleSet.units.values.filter { it.requiresResource(resource) && getEquivalentUnit(it) == it }
|
||||||
|
|
||||||
val lastEraForBuilding = applicableBuildings.map { gameInfo.ruleSet.eras[gameInfo.ruleSet.technologies[it.requiredTech]?.era()]?.eraNumber ?: 0 }.maxOrNull()
|
val lastEraForBuilding = applicableBuildings.map { gameInfo.ruleSet.eras[gameInfo.ruleSet.technologies[it.requiredTech]?.era()]?.eraNumber ?: 0 }.maxOrNull()
|
||||||
val lastEraForUnit = applicableUnits.map { gameInfo.ruleSet.eras[gameInfo.ruleSet.technologies[it.requiredTech]?.era()]?.eraNumber ?: 0 }.maxOrNull()
|
val lastEraForUnit = applicableUnits.map { gameInfo.ruleSet.eras[gameInfo.ruleSet.technologies[it.requiredTech]?.era()]?.eraNumber ?: 0 }.maxOrNull()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user