mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-30 07:21:34 -04:00
Converted era parameter to a transient var (#6063)
The cost of casting getEra() constantly is definitely non-trivial, and why do we even generate the era every time? It only changes when we add a new tech! So we can save it as a transient in the civInfo.tech and be done with it!
This commit is contained in:
parent
7c478f4cd3
commit
957d5b4008
@ -572,30 +572,7 @@ class CivilizationInfo {
|
|||||||
else -> getCivUnits().none()
|
else -> getCivUnits().none()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEra(): Era {
|
fun getEra(): Era = tech.era
|
||||||
if (gameInfo.ruleSet.technologies.isEmpty() || tech.researchedTechnologies.isEmpty())
|
|
||||||
return Era()
|
|
||||||
val maxEraOfResearchedTechs = tech.researchedTechnologies
|
|
||||||
.asSequence()
|
|
||||||
.map { it.column!! }
|
|
||||||
.maxByOrNull { it.columnNumber }!!
|
|
||||||
.era
|
|
||||||
val maxEra = gameInfo.ruleSet.eras[maxEraOfResearchedTechs]!!
|
|
||||||
|
|
||||||
val researchedTechsHashset = tech.researchedTechnologies.toHashSet()
|
|
||||||
val minEraOfNonResearchedTechs = gameInfo.ruleSet.technologies.values
|
|
||||||
.asSequence()
|
|
||||||
.filter { it !in researchedTechsHashset }
|
|
||||||
.map { it.column!! }
|
|
||||||
.minByOrNull { it.columnNumber }
|
|
||||||
?.era
|
|
||||||
?: return maxEra
|
|
||||||
|
|
||||||
val minEra = gameInfo.ruleSet.eras[minEraOfNonResearchedTechs]!!
|
|
||||||
|
|
||||||
return if (minEra.eraNumber > maxEra.eraNumber) minEra
|
|
||||||
else maxEra
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getEraNumber(): Int = getEra().eraNumber
|
fun getEraNumber(): Int = getEra().eraNumber
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import com.unciv.logic.city.CityInfo
|
|||||||
import com.unciv.logic.map.MapSize
|
import com.unciv.logic.map.MapSize
|
||||||
import com.unciv.logic.map.RoadStatus
|
import com.unciv.logic.map.RoadStatus
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
|
import com.unciv.models.ruleset.Era
|
||||||
import com.unciv.models.ruleset.unique.UniqueMap
|
import com.unciv.models.ruleset.unique.UniqueMap
|
||||||
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
||||||
import com.unciv.models.ruleset.tech.Technology
|
import com.unciv.models.ruleset.tech.Technology
|
||||||
@ -20,6 +21,9 @@ import kotlin.math.max
|
|||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class TechManager {
|
class TechManager {
|
||||||
|
@Transient
|
||||||
|
var era: Era = Era()
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
lateinit var civInfo: CivilizationInfo
|
lateinit var civInfo: CivilizationInfo
|
||||||
/** This is the Transient list of Technologies */
|
/** This is the Transient list of Technologies */
|
||||||
@ -326,6 +330,37 @@ class TechManager {
|
|||||||
if (unique.params[1] != techName) continue
|
if (unique.params[1] != techName) continue
|
||||||
civInfo.addNotification("You have unlocked [The Long Count]!", MayaLongCountAction(), MayaCalendar.notificationIcon)
|
civInfo.addNotification("You have unlocked [The Long Count]!", MayaLongCountAction(), MayaCalendar.notificationIcon)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateEra()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateEra() {
|
||||||
|
val ruleset = civInfo.gameInfo.ruleSet
|
||||||
|
if (ruleset.technologies.isEmpty() || researchedTechnologies.isEmpty())
|
||||||
|
return
|
||||||
|
|
||||||
|
val maxEraOfResearchedTechs = researchedTechnologies
|
||||||
|
.asSequence()
|
||||||
|
.map { it.column!! }
|
||||||
|
.maxByOrNull { it.columnNumber }!!
|
||||||
|
.era
|
||||||
|
val maxEra = ruleset.eras[maxEraOfResearchedTechs]!!
|
||||||
|
|
||||||
|
val minEraOfNonResearchedTechs = ruleset.technologies.values
|
||||||
|
.asSequence()
|
||||||
|
.filter { it !in researchedTechnologies }
|
||||||
|
.map { it.column!! }
|
||||||
|
.minByOrNull { it.columnNumber }
|
||||||
|
?.era
|
||||||
|
if (minEraOfNonResearchedTechs == null) {
|
||||||
|
era = maxEra
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val minEra = ruleset.eras[minEraOfNonResearchedTechs]!!
|
||||||
|
|
||||||
|
era = if (minEra.eraNumber <= maxEra.eraNumber) maxEra
|
||||||
|
else minEra
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addTechToTransients(tech: Technology) {
|
fun addTechToTransients(tech: Technology) {
|
||||||
@ -337,6 +372,7 @@ class TechManager {
|
|||||||
researchedTechnologies.addAll(techsResearched.map { getRuleset().technologies[it]!! })
|
researchedTechnologies.addAll(techsResearched.map { getRuleset().technologies[it]!! })
|
||||||
researchedTechnologies.forEach { addTechToTransients(it) }
|
researchedTechnologies.forEach { addTechToTransients(it) }
|
||||||
updateTransientBooleans()
|
updateTransientBooleans()
|
||||||
|
updateEra()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateTransientBooleans() {
|
private fun updateTransientBooleans() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user