Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues from gaining free beliefs #9764

Merged
merged 4 commits into from
Jul 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 41 additions & 43 deletions core/src/com/unciv/logic/civilization/managers/ReligionManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,37 @@ class ReligionManager : IsPartOfGameInfoSerialization {
UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo)
}

fun mayEnhanceReligionAtAll(prophet: MapUnit): Boolean {
if (!civInfo.gameInfo.isReligionEnabled()) return false // No religion, no enhancing
if (religion == null) return false // First found a pantheon
if (religionState != ReligionState.Religion) return false // First found an actual religion
// Already used its power for other things
if (prophet.abilityUsesLeft.any { it.value != prophet.maxAbilityUses[it.key] }) return false
if (!civInfo.isMajorCiv()) return false // Only major civs

if (numberOfBeliefsAvailable(BeliefType.Follower) == 0)
return false // Mod maker did not provide enough follower beliefs

if (numberOfBeliefsAvailable(BeliefType.Enhancer) == 0)
return false // Mod maker did not provide enough enhancer beliefs

return true
}

fun mayEnhanceReligionNow(prophet: MapUnit): Boolean {
if (!mayEnhanceReligionAtAll(prophet)) return false
if (!prophet.getTile().isCityCenter()) return false
return true
}

fun useProphetForEnhancingReligion(prophet: MapUnit) {
if (!mayEnhanceReligionNow(prophet)) return // How did you do this?
religionState = ReligionState.EnhancingReligion

for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponEnhancingReligion))
UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo)
}

/**
* Unifies the selection of what beliefs are available for when a great prophet is expended. Also
* accounts for the number of remaining beliefs of each type so that the player is not given a
Expand Down Expand Up @@ -317,7 +348,8 @@ class ReligionManager : IsPartOfGameInfoSerialization {

if (enhancingReligion) {
chooseBeliefToAdd(BeliefType.Enhancer, 1)
} else {
}
else {
chooseBeliefToAdd(BeliefType.Founder, 1)
if (shouldChoosePantheonBelief)
chooseBeliefToAdd(BeliefType.Pantheon, 1)
Expand All @@ -334,18 +366,23 @@ class ReligionManager : IsPartOfGameInfoSerialization {
chooseBeliefToAdd(BeliefType.Any, unique.params[0].toInt())
}

for (type in freeBeliefsAsEnums())
chooseBeliefToAdd(type.key, type.value)

return beliefsToChoose
}

fun getBeliefsToChooseAtFounding(): Counter<BeliefType> = getBeliefsToChooseAtProphetUse(false)
fun getBeliefsToChooseAtEnhancing(): Counter<BeliefType> = getBeliefsToChooseAtProphetUse(true)

fun chooseBeliefs(beliefs: List<Belief>, useFreeBeliefs: Boolean = false) {
// Remove the free beliefs in case we had them
// Must be done first in case when gain more later
freeBeliefs.clear()

when (religionState) {
ReligionState.EnhancingReligion -> {
religionState = ReligionState.EnhancedReligion
for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponEnhancingReligion))
UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo)
}
ReligionState.None -> {
foundPantheon(beliefs[0].name, useFreeBeliefs)
Expand All @@ -371,20 +408,9 @@ class ReligionManager : IsPartOfGameInfoSerialization {
triggerNotificationText = "due to adopting [${belief.name}]")

for (belief in beliefs)
for (unique in belief.uniqueObjects)
for (unique in belief.uniqueObjects.filter { !it.hasTriggerConditional() })
UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo)

// decrement free beliefs if used
if (useFreeBeliefs && hasFreeBeliefs()) {
for (belief in beliefs) {
freeBeliefs[belief.type.name] = max(freeBeliefs[belief.type.name] - 1, 0)
}
}
// limit the number of free beliefs available to number of remaining beliefs even if player
// didn't use free beliefs (e.g., used a prophet or pantheon)
for (type in freeBeliefs.keys) {
freeBeliefs[type] = min(freeBeliefs[type], numberOfBeliefsAvailable(BeliefType.valueOf(type)))
}
civInfo.updateStatsForNextTurn() // a belief can have an immediate effect on stats
}

Expand Down Expand Up @@ -414,34 +440,6 @@ class ReligionManager : IsPartOfGameInfoSerialization {
unit.religion = newReligion.name
}

fun mayEnhanceReligionAtAll(prophet: MapUnit): Boolean {
if (!civInfo.gameInfo.isReligionEnabled()) return false // No religion, no enhancing
if (religion == null) return false // First found a pantheon
if (religionState != ReligionState.Religion) return false // First found an actual religion
// Already used its power for other things
if (prophet.abilityUsesLeft.any { it.value != prophet.maxAbilityUses[it.key] }) return false
if (!civInfo.isMajorCiv()) return false // Only major civs

if (numberOfBeliefsAvailable(BeliefType.Follower) == 0)
return false // Mod maker did not provide enough follower beliefs

if (numberOfBeliefsAvailable(BeliefType.Enhancer) == 0)
return false // Mod maker did not provide enough enhancer beliefs

return true
}

fun mayEnhanceReligionNow(prophet: MapUnit): Boolean {
if (!mayEnhanceReligionAtAll(prophet)) return false
if (!prophet.getTile().isCityCenter()) return false
return true
}

fun useProphetForEnhancingReligion(prophet: MapUnit) {
if (!mayEnhanceReligionNow(prophet)) return // How did you do this?
religionState = ReligionState.EnhancingReligion
}

fun maySpreadReligionAtAll(missionary: MapUnit): Boolean {
if (!civInfo.isMajorCiv()) return false // Only major civs
if (!civInfo.gameInfo.isReligionEnabled()) return false // No religion, no spreading
Expand Down