Fix "Religions to be founded" count (#7278)

This commit is contained in:
OptimizedForDensity 2022-06-23 14:42:53 -04:00 committed by GitHub
parent e0a65fb95a
commit b716d4a68d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 20 deletions

View File

@ -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
}

View File

@ -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()