diff --git a/core/src/com/unciv/logic/civilization/ReligionManager.kt b/core/src/com/unciv/logic/civilization/ReligionManager.kt index dc89aa5465..c947c2d6a7 100644 --- a/core/src/com/unciv/logic/civilization/ReligionManager.kt +++ b/core/src/com/unciv/logic/civilization/ReligionManager.kt @@ -7,6 +7,7 @@ import com.unciv.models.ruleset.Belief import com.unciv.models.ruleset.BeliefType import com.unciv.models.ruleset.unique.UniqueType import com.unciv.ui.utils.extensions.toPercent +import java.lang.Integer.min import kotlin.random.Random class ReligionManager { @@ -150,6 +151,29 @@ class ReligionManager { fun amountOfFoundableReligions() = civInfo.gameInfo.civilizations.count { it.isMajorCiv() } / 2 + 1 + fun remainingFoundableReligions(): Int { + val foundedReligionsCount = civInfo.gameInfo.civilizations.count { + it.religionManager.religion != null && it.religionManager.religionState >= ReligionState.Religion + } + + // count the number of foundable religions left given defined ruleset religions and number of civs in game + val maxNumberOfAdditionalReligions = min(civInfo.gameInfo.ruleSet.religions.size, + amountOfFoundableReligions()) - foundedReligionsCount + + val availableBeliefsToFound = min( + civInfo.gameInfo.ruleSet.beliefs.values.count { + it.type == BeliefType.Follower + && civInfo.gameInfo.religions.values.none { religion -> it in religion.getBeliefs(BeliefType.Follower) } + }, + civInfo.gameInfo.ruleSet.beliefs.values.count { + it.type == BeliefType.Founder + && civInfo.gameInfo.religions.values.none { religion -> it in religion.getBeliefs(BeliefType.Founder) } + } + ) + + return min(maxNumberOfAdditionalReligions, availableBeliefsToFound) + } + fun mayFoundReligionAtAll(prophet: MapUnit): Boolean { if (!civInfo.gameInfo.isReligionEnabled()) return false // No religion @@ -160,25 +184,9 @@ class ReligionManager { if (!civInfo.isMajorCiv()) return false // Only major civs may use religion - val foundedReligionsCount = civInfo.gameInfo.civilizations.count { - it.religionManager.religion != null && it.religionManager.religionState >= ReligionState.Religion - } - - if (foundedReligionsCount >= amountOfFoundableReligions()) + if (remainingFoundableReligions() == 0) return false // Too bad, too many religions have already been founded - if (foundedReligionsCount >= civInfo.gameInfo.ruleSet.religions.size) - return false // Mod maker did not provide enough religions for the amount of civs present - - if (civInfo.gameInfo.ruleSet.beliefs.values.none { - it.type == BeliefType.Follower - && civInfo.gameInfo.religions.values.none { religion -> it in religion.getBeliefs(BeliefType.Follower) } - }) return false // Mod maker did not provide enough follower beliefs - - // Shortcut as each religion will always have exactly one founder belief - if (foundedReligionsCount >= civInfo.gameInfo.ruleSet.beliefs.values.count { it.type == BeliefType.Founder }) - return false // Mod maker did not provide enough founder beliefs - return true } diff --git a/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt b/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt index e39300dd53..7fb6a1a9e5 100644 --- a/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt +++ b/core/src/com/unciv/ui/overviewscreen/ReligionOverviewTable.kt @@ -79,9 +79,7 @@ class ReligionOverviewTab( } add("Religions to be founded:".toLabel()) - - val foundedReligions = viewingPlayer.gameInfo.civilizations.count { it.religionManager.religionState >= ReligionState.Religion } - add((viewingPlayer.religionManager.amountOfFoundableReligions() - foundedReligions).toLabel()).right().row() + add((viewingPlayer.religionManager.remainingFoundableReligions()).toLabel()).right().row() add("Religious status:".toLabel()).left() add(viewingPlayer.religionManager.religionState.toString().toLabel()).right().row()