mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-13 09:18:43 +07:00
Probably resolved #9320 - AI 'found religion' crash
This commit is contained in:
@ -652,12 +652,16 @@ object NextTurnAutomation {
|
|||||||
if (civInfo.religionManager.religionState != ReligionState.FoundingReligion) return
|
if (civInfo.religionManager.religionState != ReligionState.FoundingReligion) return
|
||||||
val availableReligionIcons = civInfo.gameInfo.ruleset.religions
|
val availableReligionIcons = civInfo.gameInfo.ruleset.religions
|
||||||
.filterNot { civInfo.gameInfo.religions.values.map { religion -> religion.name }.contains(it) }
|
.filterNot { civInfo.gameInfo.religions.values.map { religion -> religion.name }.contains(it) }
|
||||||
|
val favoredReligion = civInfo.nation.favoredReligion
|
||||||
val religionIcon =
|
val religionIcon =
|
||||||
if (civInfo.nation.favoredReligion in availableReligionIcons) civInfo.nation.favoredReligion
|
if (favoredReligion != null && favoredReligion in availableReligionIcons) favoredReligion
|
||||||
else availableReligionIcons.randomOrNull()
|
else availableReligionIcons.randomOrNull()
|
||||||
?: return // Wait what? How did we pass the checking when using a great prophet but not this?
|
?: return // Wait what? How did we pass the checking when using a great prophet but not this?
|
||||||
|
|
||||||
|
civInfo.religionManager.foundReligion(religionIcon, religionIcon)
|
||||||
|
|
||||||
val chosenBeliefs = chooseBeliefs(civInfo, civInfo.religionManager.getBeliefsToChooseAtFounding()).toList()
|
val chosenBeliefs = chooseBeliefs(civInfo, civInfo.religionManager.getBeliefsToChooseAtFounding()).toList()
|
||||||
civInfo.religionManager.chooseBeliefs(chosenBeliefs, religionIcon, religionIcon)
|
civInfo.religionManager.chooseBeliefs(chosenBeliefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun enhanceReligion(civInfo: Civilization) {
|
private fun enhanceReligion(civInfo: Civilization) {
|
||||||
|
@ -340,10 +340,8 @@ class ReligionManager : IsPartOfGameInfoSerialization {
|
|||||||
fun getBeliefsToChooseAtFounding(): Counter<BeliefType> = getBeliefsToChooseAtProphetUse(false)
|
fun getBeliefsToChooseAtFounding(): Counter<BeliefType> = getBeliefsToChooseAtProphetUse(false)
|
||||||
fun getBeliefsToChooseAtEnhancing(): Counter<BeliefType> = getBeliefsToChooseAtProphetUse(true)
|
fun getBeliefsToChooseAtEnhancing(): Counter<BeliefType> = getBeliefsToChooseAtProphetUse(true)
|
||||||
|
|
||||||
fun chooseBeliefs(beliefs: List<Belief>, iconName: String? = null, religionName: String? = null, useFreeBeliefs: Boolean = false) {
|
fun chooseBeliefs(beliefs: List<Belief>, useFreeBeliefs: Boolean = false) {
|
||||||
when (religionState) {
|
when (religionState) {
|
||||||
ReligionState.FoundingReligion ->
|
|
||||||
foundReligion(iconName!!, religionName!!)
|
|
||||||
ReligionState.EnhancingReligion -> {
|
ReligionState.EnhancingReligion -> {
|
||||||
religionState = ReligionState.EnhancedReligion
|
religionState = ReligionState.EnhancedReligion
|
||||||
for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponEnhancingReligion))
|
for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponEnhancingReligion))
|
||||||
@ -381,7 +379,7 @@ class ReligionManager : IsPartOfGameInfoSerialization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun foundReligion(displayName: String, name: String) {
|
internal fun foundReligion(displayName: String, name: String) {
|
||||||
val newReligion = Religion(name, civInfo.gameInfo, civInfo.civName)
|
val newReligion = Religion(name, civInfo.gameInfo, civInfo.civName)
|
||||||
newReligion.displayName = displayName
|
newReligion.displayName = displayName
|
||||||
if (religion != null) {
|
if (religion != null) {
|
||||||
|
@ -75,7 +75,8 @@ class ReligiousBeliefsPickerScreen (
|
|||||||
if (pickIconAndName) "Choose a Religion"
|
if (pickIconAndName) "Choose a Religion"
|
||||||
else "Enhance [${currentReligion.getReligionDisplayName()}]"
|
else "Enhance [${currentReligion.getReligionDisplayName()}]"
|
||||||
) {
|
) {
|
||||||
chooseBeliefs(beliefsToChoose.map { it.belief!! }, displayName, religionName, usingFreeBeliefs())
|
civInfo.religionManager.foundReligion(displayName!!, religionName!!)
|
||||||
|
chooseBeliefs(beliefsToChoose.map { it.belief!! }, usingFreeBeliefs())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user