mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Simplified check for enabled religion and added it in more places (#5218)
* Reworked `hasReligionEnabled` * Added more checks for enabled religion * Consistisized spelling
This commit is contained in:
parent
fe3220299c
commit
fe60c100fa
@ -12,6 +12,7 @@ import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.Religion
|
||||
import com.unciv.models.metadata.GameParameters
|
||||
import com.unciv.models.ruleset.Difficulty
|
||||
import com.unciv.models.ruleset.ModOptionsConstants
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.RulesetCache
|
||||
import java.util.*
|
||||
@ -131,10 +132,14 @@ class GameInfo {
|
||||
it.setTransients()
|
||||
}
|
||||
|
||||
fun hasReligionEnabled() =
|
||||
// Temporary function to check whether religion should be used for this game
|
||||
(gameParameters.religionEnabled || ruleSet.hasReligion())
|
||||
&& (ruleSet.eras.isEmpty() || !ruleSet.eras[gameParameters.startingEra]!!.hasUnique("Starting in this era disables religion"))
|
||||
fun isReligionEnabled(): Boolean {
|
||||
if (ruleSet.eras[gameParameters.startingEra]!!.hasUnique("Starting in this era disables religion")
|
||||
|| ruleSet.modOptions.uniques.contains(ModOptionsConstants.disableReligion)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
return gameParameters.religionEnabled
|
||||
}
|
||||
|
||||
//endregion
|
||||
//region State changing functions
|
||||
|
@ -538,7 +538,7 @@ class CityInfo {
|
||||
} else population.nextTurn(foodForNextTurn())
|
||||
|
||||
// This should go after the population change, as that might impact the amount of followers in this city
|
||||
if (civInfo.gameInfo.hasReligionEnabled()) religion.endTurn()
|
||||
if (civInfo.gameInfo.isReligionEnabled()) religion.endTurn()
|
||||
|
||||
if (this in civInfo.cities) { // city was not destroyed
|
||||
health = min(health + 20, getMaxHealth())
|
||||
|
@ -272,7 +272,7 @@ class CityInfoConquestFunctions(val city: CityInfo){
|
||||
}
|
||||
}
|
||||
|
||||
if (civInfo.gameInfo.hasReligionEnabled()) religion.removeUnknownPantheons()
|
||||
if (civInfo.gameInfo.isReligionEnabled()) religion.removeUnknownPantheons()
|
||||
|
||||
tryUpdateRoadStatus()
|
||||
cityStats.update()
|
||||
|
@ -82,6 +82,7 @@ class CityInfoReligionManager {
|
||||
}
|
||||
|
||||
fun addPressure(religionName: String, amount: Int, shouldUpdateFollowers: Boolean = true) {
|
||||
if (!cityInfo.civInfo.gameInfo.isReligionEnabled()) return // No religion, no pressures
|
||||
pressures.add(religionName, amount)
|
||||
|
||||
if (shouldUpdateFollowers) {
|
||||
@ -232,6 +233,7 @@ class CityInfoReligionManager {
|
||||
}
|
||||
|
||||
private fun getAffectedBySurroundingCities() {
|
||||
if (!cityInfo.civInfo.gameInfo.isReligionEnabled()) return // No religion, no spreading
|
||||
// We don't update the amount of followers yet, as only the end result should matter
|
||||
// If multiple religions would become the majority religion due to pressure,
|
||||
// this will make it so we only receive a notification for the last one.
|
||||
|
@ -88,7 +88,8 @@ class PopulationManager {
|
||||
autoAssignPopulation()
|
||||
}
|
||||
|
||||
cityInfo.religion.updatePressureOnPopulationChange(changedAmount)
|
||||
if (cityInfo.civInfo.gameInfo.isReligionEnabled())
|
||||
cityInfo.religion.updatePressureOnPopulationChange(changedAmount)
|
||||
}
|
||||
|
||||
internal fun setPopulation(count: Int) {
|
||||
|
@ -69,7 +69,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
fun giveGreatPersonToPatron(receivingCiv: CivilizationInfo) {
|
||||
|
||||
var giftableUnits = civInfo.gameInfo.ruleSet.units.values.filter { it.isGreatPerson() }
|
||||
if (!civInfo.gameInfo.hasReligionEnabled()) giftableUnits = giftableUnits.filterNot { it.uniques.contains("Great Person - [Faith]")}
|
||||
if (!civInfo.gameInfo.isReligionEnabled()) giftableUnits = giftableUnits.filterNot { it.uniques.contains("Hidden when religion is disabled")}
|
||||
if (giftableUnits.isEmpty()) // For badly defined mods that don't have great people but do have the policy that makes city states grant them
|
||||
return
|
||||
val giftedUnit = giftableUnits.random()
|
||||
|
@ -564,7 +564,7 @@ class CivilizationInfo {
|
||||
fun getGreatPeople(): HashSet<BaseUnit> {
|
||||
val greatPeople = gameInfo.ruleSet.units.values.asSequence()
|
||||
.filter { it.isGreatPerson() }.map { getEquivalentUnit(it.name) }
|
||||
return if (!gameInfo.hasReligionEnabled()) greatPeople.filter { !it.uniques.contains("Great Person - [Faith]")}.toHashSet()
|
||||
return if (!gameInfo.isReligionEnabled()) greatPeople.filter { !it.uniques.contains("Hidden when religion is disabled")}.toHashSet()
|
||||
else greatPeople.toHashSet()
|
||||
}
|
||||
|
||||
@ -883,7 +883,7 @@ class CivilizationInfo {
|
||||
addNotification("A [${unit.name}] has been born in [${cityToAddTo.name}]!", placedUnit.getTile().position, unit.name)
|
||||
}
|
||||
|
||||
if (placedUnit.hasUnique("Religious Unit")) {
|
||||
if (placedUnit.hasUnique("Religious Unit") && gameInfo.isReligionEnabled()) {
|
||||
placedUnit.religion =
|
||||
when {
|
||||
placedUnit.hasUnique("Takes your religion over the one in their birth city") ->
|
||||
|
@ -1,11 +1,9 @@
|
||||
package com.unciv.logic.civilization
|
||||
|
||||
import com.unciv.logic.civilization.diplomacy.RelationshipLevel
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.models.Religion
|
||||
import com.unciv.models.ruleset.Belief
|
||||
import com.unciv.models.ruleset.BeliefType
|
||||
import com.unciv.models.ruleset.Era
|
||||
import com.unciv.ui.pickerscreens.BeliefContainer
|
||||
import com.unciv.ui.utils.toPercent
|
||||
import kotlin.random.Random
|
||||
@ -87,7 +85,7 @@ class ReligionManager {
|
||||
10 + (civInfo.gameInfo.civilizations.count { it.isMajorCiv() && it.religionManager.religion != null } + additionalCivs) * 5
|
||||
|
||||
fun canFoundPantheon(): Boolean {
|
||||
if (!civInfo.gameInfo.hasReligionEnabled()) return false
|
||||
if (!civInfo.gameInfo.isReligionEnabled()) return false
|
||||
if (religionState != ReligionState.None) return false
|
||||
if (!civInfo.isMajorCiv()) return false
|
||||
if (civInfo.gameInfo.ruleSet.beliefs.values.none { isPickablePantheonBelief(it) })
|
||||
@ -130,6 +128,7 @@ class ReligionManager {
|
||||
}
|
||||
|
||||
private fun canGenerateProphet(): Boolean {
|
||||
if (!civInfo.gameInfo.isReligionEnabled()) return false // No religion, no prophets
|
||||
if (religion == null || religionState == ReligionState.None) return false // First get a pantheon, then we'll talk about a real religion
|
||||
if (getGreatProphetEquivalent() == null) return false
|
||||
if (storedFaith < faithForNextGreatProphet()) return false
|
||||
@ -159,6 +158,8 @@ class ReligionManager {
|
||||
}
|
||||
|
||||
fun mayFoundReligionAtAll(prophet: MapUnit): Boolean {
|
||||
if (!civInfo.gameInfo.isReligionEnabled()) return false // No religion
|
||||
|
||||
if (religionState >= ReligionState.Religion) return false // Already created a major religion
|
||||
|
||||
// Already used its power for other things
|
||||
@ -256,6 +257,7 @@ class ReligionManager {
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -41,7 +41,7 @@ class RuinsManager {
|
||||
|
||||
for (possibleReward in possibleRewards) {
|
||||
if (civInfo.gameInfo.difficulty in possibleReward.excludedDifficulties) continue
|
||||
if (Constants.hiddenWithoutReligionUnique in possibleReward.uniques && !civInfo.gameInfo.hasReligionEnabled()) continue
|
||||
if (Constants.hiddenWithoutReligionUnique in possibleReward.uniques && !civInfo.gameInfo.isReligionEnabled()) continue
|
||||
if ("Hidden after generating a Great Prophet" in possibleReward.uniques
|
||||
&& civInfo.civConstructions.boughtItemsWithIncreasingPrice[civInfo.religionManager.getGreatProphetEquivalent()] ?: 0 > 0
|
||||
) continue
|
||||
|
@ -35,7 +35,7 @@ class Belief : INamed, ICivilopediaText, IHasUniques {
|
||||
private fun getBeliefsMatching(name: String, ruleset: Ruleset): Sequence<Belief> {
|
||||
if (!UncivGame.isCurrentInitialized()) return sequenceOf()
|
||||
if (!UncivGame.Current.isGameInfoInitialized()) return sequenceOf()
|
||||
if (!UncivGame.Current.gameInfo.hasReligionEnabled()) return sequenceOf()
|
||||
if (!UncivGame.Current.gameInfo.isReligionEnabled()) return sequenceOf()
|
||||
return ruleset.beliefs.asSequence().map { it.value }
|
||||
.filter { belief -> belief.uniqueObjects.any { unique -> unique.params.any { it == name } }
|
||||
}
|
||||
|
@ -464,7 +464,7 @@ class Building : NamedStats(), INonPerpetualConstruction, ICivilopediaText {
|
||||
rejectionReasons.add(RejectionReason.Obsoleted.apply { errorMessage = unique.text })
|
||||
|
||||
Constants.hiddenWithoutReligionUnique ->
|
||||
if (!civInfo.gameInfo.hasReligionEnabled())
|
||||
if (!civInfo.gameInfo.isReligionEnabled())
|
||||
rejectionReasons.add(RejectionReason.DisabledBySetting)
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ object ModOptionsConstants {
|
||||
const val convertGoldToScience = "Can convert gold to science with sliders"
|
||||
const val allowCityStatesSpawnUnits = "Allow City States to spawn with additional units"
|
||||
const val tradeCivIntroductions = "Can trade civilization introductions for [] Gold"
|
||||
const val disableReligion = "Disable religion"
|
||||
}
|
||||
|
||||
class ModOptions : IHasUniques {
|
||||
|
@ -111,7 +111,7 @@ class Technology: INamed, ICivilopediaText, IHasUniques {
|
||||
// Helper: common filtering for both getEnabledBuildings and getObsoletedBuildings, difference via predicate parameter
|
||||
private fun getFilteredBuildings(civInfo: CivilizationInfo, predicate: (Building)->Boolean): Sequence<Building> {
|
||||
val nuclearWeaponsEnabled = civInfo.gameInfo.gameParameters.nuclearWeaponsEnabled
|
||||
val religionEnabled = civInfo.gameInfo.hasReligionEnabled()
|
||||
val religionEnabled = civInfo.gameInfo.isReligionEnabled()
|
||||
|
||||
return civInfo.gameInfo.ruleSet.buildings.values.asSequence()
|
||||
.filter {
|
||||
@ -130,7 +130,7 @@ class Technology: INamed, ICivilopediaText, IHasUniques {
|
||||
// Used for Civilopedia, Alert and Picker, so if any of these decide to ignore the "Will not be displayed in Civilopedia" unique this needs refactoring
|
||||
fun getEnabledUnits(civInfo: CivilizationInfo): Sequence<BaseUnit> {
|
||||
val nuclearWeaponsEnabled = civInfo.gameInfo.gameParameters.nuclearWeaponsEnabled
|
||||
val religionEnabled = civInfo.gameInfo.hasReligionEnabled()
|
||||
val religionEnabled = civInfo.gameInfo.isReligionEnabled()
|
||||
|
||||
return civInfo.gameInfo.ruleSet.units.values.asSequence()
|
||||
.filter {
|
||||
|
@ -163,7 +163,7 @@ class TileImprovement : NamedStats(), ICivilopediaText, IHasUniques {
|
||||
|
||||
if (isAncientRuinsEquivalent() && ruleset.ruinRewards.isNotEmpty()) {
|
||||
val difficulty = UncivGame.Current.gameInfo.gameParameters.difficulty
|
||||
val religionEnabled = UncivGame.Current.gameInfo.hasReligionEnabled()
|
||||
val religionEnabled = UncivGame.Current.gameInfo.isReligionEnabled()
|
||||
textList += FormattedLine()
|
||||
textList += FormattedLine("The possible rewards are:")
|
||||
ruleset.ruinRewards.values.asSequence()
|
||||
|
@ -394,7 +394,7 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText {
|
||||
unit.currentMovement = 0f
|
||||
|
||||
// If this unit has special abilities that need to be kept track of, start doing so here
|
||||
if (unit.hasUnique("Religious Unit")) {
|
||||
if (unit.hasUnique("Religious Unit") && civInfo.gameInfo.isReligionEnabled()) {
|
||||
unit.religion =
|
||||
if (unit.hasUnique("Takes your religion over the one in their birth city"))
|
||||
civInfo.religionManager.religion?.name
|
||||
|
@ -29,7 +29,7 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||
|
||||
val miniStatsTable = Table()
|
||||
for ((stat, amount) in cityInfo.cityStats.currentCityStats) {
|
||||
if (stat == Stat.Faith && !cityInfo.civInfo.gameInfo.hasReligionEnabled()) continue
|
||||
if (stat == Stat.Faith && !cityInfo.civInfo.gameInfo.isReligionEnabled()) continue
|
||||
miniStatsTable.add(ImageGetter.getStatIcon(stat.name)).size(20f).padRight(5f)
|
||||
val valueToDisplay = if (stat == Stat.Happiness) cityInfo.cityStats.happinessList.values.sum() else amount
|
||||
miniStatsTable.add(round(valueToDisplay).toInt().toLabel()).padRight(10f)
|
||||
@ -43,7 +43,7 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||
innerTable.add(SpecialistAllocationTable(cityScreen).apply { update() }).row()
|
||||
}
|
||||
|
||||
if (cityInfo.religion.getNumberOfFollowers().isNotEmpty())
|
||||
if (cityInfo.religion.getNumberOfFollowers().isNotEmpty() && cityInfo.civInfo.gameInfo.isReligionEnabled())
|
||||
addReligionInfo()
|
||||
|
||||
pack()
|
||||
|
@ -158,7 +158,7 @@ class CivilopediaScreen(
|
||||
val imageSize = 50f
|
||||
onBackButtonClicked { UncivGame.Current.setWorldScreen() }
|
||||
|
||||
val hideReligionItems = !game.gameInfo.hasReligionEnabled()
|
||||
val hideReligionItems = !game.gameInfo.isReligionEnabled()
|
||||
|
||||
fun shouldBeDisplayed(uniqueObjects: List<Unique>): Boolean {
|
||||
val uniques = uniqueObjects.map { it.placeholderText }
|
||||
|
@ -24,7 +24,7 @@ class CityOverviewTable(private val viewingPlayer: CivilizationInfo, private val
|
||||
}
|
||||
|
||||
private val columnsNames = arrayListOf("Population", "Food", "Gold", "Science", "Production", "Culture", "Happiness")
|
||||
.apply { if (viewingPlayer.gameInfo.hasReligionEnabled()) add("Faith") }
|
||||
.apply { if (viewingPlayer.gameInfo.isReligionEnabled()) add("Faith") }
|
||||
|
||||
init {
|
||||
val numHeaderCells = columnsNames.size + 2 // +1 City +1 Filler
|
||||
|
@ -86,7 +86,7 @@ class EmpireOverviewScreen(private var viewingPlayer:CivilizationInfo, defaultPa
|
||||
addCategory("Units", UnitOverviewTable(viewingPlayer, this), viewingPlayer.getCivUnits().none())
|
||||
addCategory("Diplomacy", DiplomacyOverviewTable(viewingPlayer, this), viewingPlayer.diplomacy.isEmpty())
|
||||
addCategory("Resources", ResourcesOverviewTable(viewingPlayer, this), viewingPlayer.detailedCivResources.isEmpty())
|
||||
if (viewingPlayer.gameInfo.hasReligionEnabled())
|
||||
if (viewingPlayer.gameInfo.isReligionEnabled())
|
||||
addCategory("Religion", ReligionOverviewTable(viewingPlayer, this), viewingPlayer.gameInfo.religions.isEmpty())
|
||||
|
||||
val closeButton = Constants.close.toTextButton().apply {
|
||||
|
@ -125,7 +125,7 @@ class WorldScreenTopBar(val worldScreen: WorldScreen) : Table() {
|
||||
cultureLabel.onClick(invokePoliciesPage)
|
||||
cultureImage.onClick(invokePoliciesPage)
|
||||
|
||||
if(worldScreen.gameInfo.hasReligionEnabled()) {
|
||||
if(worldScreen.gameInfo.isReligionEnabled()) {
|
||||
statsTable.add(faithLabel).padLeft(20f)
|
||||
val faithImage = ImageGetter.getStatIcon("Faith")
|
||||
statsTable.add(faithImage).padBottom(6f).size(20f)
|
||||
|
@ -533,13 +533,13 @@ object UnitActions {
|
||||
private fun useActionWithLimitedUses(unit: MapUnit, action: String) {
|
||||
unit.abilityUsesLeft[action] = unit.abilityUsesLeft[action]!! - 1
|
||||
if (unit.abilityUsesLeft[action]!! <= 0) {
|
||||
if (unit.isGreatPerson())
|
||||
addStatsPerGreatPersonUsage(unit)
|
||||
addStatsPerGreatPersonUsage(unit)
|
||||
unit.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
private fun addSpreadReligionActions(unit: MapUnit, actionList: ArrayList<UnitAction>, city: CityInfo) {
|
||||
if (!unit.civInfo.gameInfo.isReligionEnabled()) return
|
||||
val blockedByInquisitor =
|
||||
city.getCenterTile()
|
||||
.getTilesInDistance(1)
|
||||
@ -565,6 +565,7 @@ object UnitActions {
|
||||
}
|
||||
|
||||
private fun addRemoveHeresyActions(unit: MapUnit, actionList: ArrayList<UnitAction>, city: CityInfo) {
|
||||
if (!unit.civInfo.gameInfo.isReligionEnabled()) return
|
||||
if (city.civInfo != unit.civInfo) return
|
||||
// Only allow the action if the city actually has any foreign religion
|
||||
// This will almost be always due to pressure from cities close-by
|
||||
|
Loading…
x
Reference in New Issue
Block a user