Revert "Cache 'majority religion' and uniques, recalc when updating followers (#11804)" (#11815)

This reverts commit 2087c36c6d.
This commit is contained in:
Oskar Niesen
2024-06-22 22:29:56 -05:00
committed by GitHub
parent 0e4aeef8bc
commit 5ab535badc
2 changed files with 20 additions and 18 deletions

View File

@ -492,9 +492,8 @@ class City : IsPartOfGameInfoSerialization, INamed {
fun getLocalMatchingUniques(uniqueType: UniqueType, stateForConditionals: StateForConditionals = StateForConditionals(this)): Sequence<Unique> { fun getLocalMatchingUniques(uniqueType: UniqueType, stateForConditionals: StateForConditionals = StateForConditionals(this)): Sequence<Unique> {
val uniques = cityConstructions.builtBuildingUniqueMap.getUniques(uniqueType).filter { it.isLocalEffect } + val uniques = cityConstructions.builtBuildingUniqueMap.getUniques(uniqueType).filter { it.isLocalEffect } +
religion.getUniques().filter { it.type == uniqueType } religion.getUniques().filter { it.type == uniqueType }
return if (uniques.any()) return if (uniques.any()) uniques.filter { !it.isTimedTriggerable && it.conditionalsApply(stateForConditionals) }
uniques.filter { !it.isTimedTriggerable && it.conditionalsApply(stateForConditionals) } .flatMap { it.getMultiplied(stateForConditionals) }
.flatMap { it.getMultiplied(stateForConditionals) }
else uniques else uniques
} }

View File

@ -24,9 +24,6 @@ class CityReligionManager : IsPartOfGameInfoSerialization {
@Transient @Transient
private val followers: Counter<String> = Counter() private val followers: Counter<String> = Counter()
@Transient
private var majorityReligion: Religion? = null
@delegate:Transient @delegate:Transient
private val pressureFromAdjacentCities: Int by lazy { city.civ.gameInfo.speed.religiousPressureAdjacentCity } private val pressureFromAdjacentCities: Int by lazy { city.civ.gameInfo.speed.religiousPressureAdjacentCity }
@ -50,7 +47,10 @@ class CityReligionManager : IsPartOfGameInfoSerialization {
fun setTransients(city: City) { fun setTransients(city: City) {
this.city = city this.city = city
updateNumberOfFollowers(true) // We don't need to check for changes in the majority religion, and as this
// loads in the religion, _of course_ the religion changes, but it shouldn't
// have any effect
updateNumberOfFollowers(false)
} }
fun endTurn() { fun endTurn() {
@ -139,7 +139,11 @@ class CityReligionManager : IsPartOfGameInfoSerialization {
religionsAtSomePointAdopted.add(newMajorityReligion) religionsAtSomePointAdopted.add(newMajorityReligion)
} }
private fun updateNumberOfFollowers(initializationPhase: Boolean = false) { private fun updateNumberOfFollowers(checkForReligionAdoption: Boolean = true) {
val oldMajorityReligion =
if (checkForReligionAdoption) getMajorityReligionName()
else null
val previousFollowers = followers.clone() val previousFollowers = followers.clone()
followers.clear() followers.clear()
@ -171,20 +175,17 @@ class CityReligionManager : IsPartOfGameInfoSerialization {
followers.remove(Constants.noReligionName) followers.remove(Constants.noReligionName)
val oldMajorityReligion = majorityReligion
val newMajorityReligion = calculateMajorityReligionName()
if (initializationPhase) { if (checkForReligionAdoption) {
if (oldMajorityReligion?.name != newMajorityReligion && newMajorityReligion != null) { val newMajorityReligion = getMajorityReligionName()
if (oldMajorityReligion != newMajorityReligion && newMajorityReligion != null) {
triggerReligionAdoption(newMajorityReligion) triggerReligionAdoption(newMajorityReligion)
} }
if (oldMajorityReligion?.name != newMajorityReligion) if (oldMajorityReligion != newMajorityReligion)
city.civ.cache.updateCivResources() // follower uniques can provide resources city.civ.cache.updateCivResources() // follower uniques can provide resources
if (followers != previousFollowers) if (followers != previousFollowers)
city.cityStats.update() city.cityStats.update()
} }
majorityReligion = city.civ.gameInfo.religions[newMajorityReligion]
} }
fun getNumberOfFollowers(): Counter<String> { fun getNumberOfFollowers(): Counter<String> {
@ -225,7 +226,7 @@ class CityReligionManager : IsPartOfGameInfoSerialization {
updateNumberOfFollowers() updateNumberOfFollowers()
} }
fun calculateMajorityReligionName(): String? { fun getMajorityReligionName(): String? {
if (followers.isEmpty()) return null if (followers.isEmpty()) return null
val religionWithMaxPressure = pressures.maxByOrNull { it.value }!!.key val religionWithMaxPressure = pressures.maxByOrNull { it.value }!!.key
return when { return when {
@ -235,8 +236,10 @@ class CityReligionManager : IsPartOfGameInfoSerialization {
} }
} }
fun getMajorityReligionName(): String? = majorityReligion?.name fun getMajorityReligion(): Religion? {
fun getMajorityReligion() = majorityReligion val majorityReligionName = getMajorityReligionName() ?: return null
return city.civ.gameInfo.religions[majorityReligionName]
}
private fun getAffectedBySurroundingCities() { private fun getAffectedBySurroundingCities() {
if (!city.civ.gameInfo.isReligionEnabled()) return // No religion, no spreading if (!city.civ.gameInfo.isReligionEnabled()) return // No religion, no spreading