mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 22:00:24 +07:00
Fixed crashes on loading save games with religion (#4479)
This commit is contained in:
@ -286,7 +286,7 @@ class GameInfo {
|
|||||||
|
|
||||||
difficultyObject = ruleSet.difficulties[difficulty]!!
|
difficultyObject = ruleSet.difficulties[difficulty]!!
|
||||||
|
|
||||||
|
for (religion in religions.values) religion.setTransients(this)
|
||||||
|
|
||||||
// This doesn't HAVE to go here, but why not.
|
// This doesn't HAVE to go here, but why not.
|
||||||
|
|
||||||
|
@ -35,12 +35,12 @@ class ReligionManager {
|
|||||||
// Find our religion from the map of founded religions.
|
// Find our religion from the map of founded religions.
|
||||||
// First check if there is any major religion
|
// First check if there is any major religion
|
||||||
religion = civInfo.gameInfo.religions.values.firstOrNull {
|
religion = civInfo.gameInfo.religions.values.firstOrNull {
|
||||||
it.foundingCiv.civName == civInfo.civName && it.isMajorReligion()
|
it.foundingCivName == civInfo.civName && it.isMajorReligion()
|
||||||
}
|
}
|
||||||
// If there isn't, check for just pantheons.
|
// If there isn't, check for just pantheons.
|
||||||
if (religion != null) return
|
if (religion != null) return
|
||||||
religion = civInfo.gameInfo.religions.values.firstOrNull {
|
religion = civInfo.gameInfo.religions.values.firstOrNull {
|
||||||
it.foundingCiv.civName == civInfo.civName
|
it.foundingCivName == civInfo.civName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ class ReligionManager {
|
|||||||
|
|
||||||
fun choosePantheonBelief(belief: Belief) {
|
fun choosePantheonBelief(belief: Belief) {
|
||||||
storedFaith -= faithForPantheon()
|
storedFaith -= faithForPantheon()
|
||||||
religion = Religion(belief.name, civInfo)
|
religion = Religion(belief.name, civInfo.gameInfo, civInfo.civName)
|
||||||
religion!!.pantheonBeliefs.add(belief.name)
|
religion!!.pantheonBeliefs.add(belief.name)
|
||||||
civInfo.gameInfo.religions[belief.name] = religion!!
|
civInfo.gameInfo.religions[belief.name] = religion!!
|
||||||
// This should later be changed when religions can have multiple beliefs
|
// This should later be changed when religions can have multiple beliefs
|
||||||
|
@ -1,26 +1,42 @@
|
|||||||
package com.unciv.models
|
package com.unciv.models
|
||||||
|
|
||||||
|
import com.unciv.logic.GameInfo
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.models.ruleset.Unique
|
import com.unciv.models.ruleset.Unique
|
||||||
import com.unciv.models.stats.INamed
|
import com.unciv.models.stats.INamed
|
||||||
|
|
||||||
/** Data object for Religions */
|
/** Data object for Religions */
|
||||||
class Religion(override var name: String, val foundingCiv: CivilizationInfo) : INamed {
|
class Religion() : INamed {
|
||||||
|
|
||||||
var pantheonBeliefs: HashSet<String> = hashSetOf()
|
var pantheonBeliefs: HashSet<String> = hashSetOf()
|
||||||
var founderBeliefs: HashSet<String> = hashSetOf()
|
var founderBeliefs: HashSet<String> = hashSetOf()
|
||||||
var followerBeliefs: HashSet<String> = hashSetOf()
|
var followerBeliefs: HashSet<String> = hashSetOf()
|
||||||
|
override lateinit var name: String
|
||||||
|
lateinit var foundingCivName: String
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
lateinit var gameInfo: GameInfo
|
||||||
|
|
||||||
|
constructor(name: String, gameInfo: GameInfo, foundingCivName: String) : this() {
|
||||||
|
this.name = name
|
||||||
|
this.foundingCivName = foundingCivName
|
||||||
|
this.gameInfo = gameInfo
|
||||||
|
}
|
||||||
|
|
||||||
fun clone(): Religion {
|
fun clone(): Religion {
|
||||||
val toReturn = Religion(name, foundingCiv)
|
val toReturn = Religion(name, gameInfo, foundingCivName)
|
||||||
toReturn.pantheonBeliefs.addAll(pantheonBeliefs)
|
toReturn.pantheonBeliefs.addAll(pantheonBeliefs)
|
||||||
toReturn.founderBeliefs.addAll(founderBeliefs)
|
toReturn.founderBeliefs.addAll(founderBeliefs)
|
||||||
toReturn.followerBeliefs.addAll(followerBeliefs)
|
toReturn.followerBeliefs.addAll(followerBeliefs)
|
||||||
return toReturn
|
return toReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setTransients(gameInfo: GameInfo) {
|
||||||
|
this.gameInfo = gameInfo
|
||||||
|
}
|
||||||
|
|
||||||
private fun getUniquesOfBeliefs(beliefs: HashSet<String>): Sequence<Unique> {
|
private fun getUniquesOfBeliefs(beliefs: HashSet<String>): Sequence<Unique> {
|
||||||
val rulesetBeliefs = foundingCiv.gameInfo.ruleSet.beliefs
|
val rulesetBeliefs = gameInfo.ruleSet.beliefs
|
||||||
return beliefs.mapNotNull {
|
return beliefs.mapNotNull {
|
||||||
if (it !in rulesetBeliefs) null
|
if (it !in rulesetBeliefs) null
|
||||||
else rulesetBeliefs[it]!!.uniqueObjects
|
else rulesetBeliefs[it]!!.uniqueObjects
|
||||||
|
Reference in New Issue
Block a user