mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 11:34:54 -04:00
Add a filter for religions (#13016)
* Add a filter for religions * whoops * Convert if chain to jvm switch statement * Introduce inverse conditional * Irrelevant optimization: Checking if it is in the ruleset and returning null it unnecessary with mapNotNull * Add belief names to filter * Docs
This commit is contained in:
parent
7c8479326c
commit
72418972fd
@ -2,8 +2,11 @@ package com.unciv.models
|
||||
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||
import com.unciv.logic.MultiFilter
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.models.ruleset.Belief
|
||||
import com.unciv.models.ruleset.BeliefType
|
||||
import com.unciv.models.ruleset.unique.StateForConditionals
|
||||
import com.unciv.models.ruleset.unique.UniqueMap
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.stats.INamed
|
||||
@ -76,10 +79,7 @@ class Religion() : INamed, IsPartOfGameInfoSerialization {
|
||||
|
||||
private fun mapToExistingBeliefs(beliefs: Set<String>): Sequence<Belief> {
|
||||
val rulesetBeliefs = gameInfo.ruleset.beliefs
|
||||
return beliefs.asSequence().mapNotNull {
|
||||
if (it !in rulesetBeliefs) null
|
||||
else rulesetBeliefs[it]!!
|
||||
}
|
||||
return beliefs.asSequence().mapNotNull { rulesetBeliefs[it] }
|
||||
}
|
||||
|
||||
fun getBeliefs(beliefType: BeliefType): Sequence<Belief> {
|
||||
@ -114,6 +114,32 @@ class Religion() : INamed, IsPartOfGameInfoSerialization {
|
||||
|
||||
fun getFounder() = gameInfo.getCivilization(foundingCivName)
|
||||
|
||||
fun matchesFilter(filter: String, state: StateForConditionals = StateForConditionals.IgnoreConditionals, civ: Civilization? = null): Boolean {
|
||||
return MultiFilter.multiFilter(filter, { matchesSingleFilter(it, state, civ) })
|
||||
}
|
||||
|
||||
private fun matchesSingleFilter(filter: String, state: StateForConditionals = StateForConditionals.IgnoreConditionals, civ: Civilization? = null): Boolean {
|
||||
val foundingCiv = getFounder()
|
||||
when (filter) {
|
||||
"any" -> return true
|
||||
"major" -> return isMajorReligion()
|
||||
"enhanced" -> return isEnhancedReligion()
|
||||
"your" -> return civ == foundingCiv
|
||||
"foreign" -> return civ != null && civ != foundingCiv
|
||||
"enemy" -> {
|
||||
val known = civ != null && civ.knows(foundingCiv)
|
||||
return known && civ!!.isAtWarWith(foundingCiv)
|
||||
}
|
||||
else -> {
|
||||
if (filter == name) return true
|
||||
if (filter in getBeliefs(BeliefType.Any).map { it.name }) return true
|
||||
if (founderBeliefUniqueMap.hasMatchingUnique(filter, state)) return true
|
||||
if (followerBeliefUniqueMap.hasMatchingUnique(filter, state)) return true
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun unlockedBuildingsPurchasable(): List<String> {
|
||||
return getAllBeliefsOrdered().flatMap { belief ->
|
||||
belief.getMatchingUniques(UniqueType.BuyBuildingsWithStat).map { it.params[0] } +
|
||||
|
@ -194,6 +194,14 @@ object Conditionals {
|
||||
UniqueType.ConditionalInThisCity -> state.relevantCity != null
|
||||
UniqueType.ConditionalCityFilter -> checkOnCity { matchesFilter(conditional.params[0], state.relevantCiv) }
|
||||
UniqueType.ConditionalCityConnected -> checkOnCity { isConnectedToCapital() }
|
||||
UniqueType.ConditionalCityReligion -> checkOnCity {
|
||||
religion.getMajorityReligion()
|
||||
?.matchesFilter(conditional.params[0], state, state.relevantCiv) == true
|
||||
}
|
||||
UniqueType.ConditionalCityNotReligion -> checkOnCity {
|
||||
religion.getMajorityReligion()
|
||||
?.matchesFilter(conditional.params[0], state, state.relevantCiv) != true
|
||||
}
|
||||
UniqueType.ConditionalCityMajorReligion -> checkOnCity {
|
||||
religion.getMajorityReligion()?.isMajorReligion() == true }
|
||||
UniqueType.ConditionalCityEnhancedReligion -> checkOnCity {
|
||||
|
@ -511,6 +511,19 @@ enum class UniqueParameterType(
|
||||
override fun getKnownValuesForAutocomplete(ruleset: Ruleset) = ruleset.beliefs.keys
|
||||
},
|
||||
|
||||
/**Used by [UniqueType.ConditionalCityReligion]*/
|
||||
ReligionFilter("religionFilter", "major") {
|
||||
override val staticKnownValues = setOf("any", "major", "enhanced", "your", "foreign","enemy")
|
||||
override fun isKnownValue(parameterText: String, ruleset: Ruleset): Boolean {
|
||||
return when (parameterText) {
|
||||
in staticKnownValues -> true
|
||||
in ruleset.religions -> true
|
||||
in ruleset.beliefs -> true
|
||||
else -> ruleset.beliefs.values.any { it.hasTagUnique(parameterText) }
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/** Used by [UniqueType.FreeExtraBeliefs] and its any variant, see ReligionManager.getBeliefsToChooseAt* functions */
|
||||
FoundingOrEnhancing("foundingOrEnhancing", "founding", "`founding` or `enhancing`", "Prophet Action Filters",
|
||||
severityDefault = UniqueType.UniqueParameterErrorSeverity.RulesetInvariant
|
||||
|
@ -742,6 +742,8 @@ enum class UniqueType(
|
||||
ConditionalInThisCity("in this city", UniqueTarget.Conditional),
|
||||
ConditionalCityFilter("in [cityFilter] cities", UniqueTarget.Conditional),
|
||||
ConditionalCityConnected("in cities connected to the capital", UniqueTarget.Conditional),
|
||||
ConditionalCityReligion("in cities with a [religionFilter] religion", UniqueTarget.Conditional),
|
||||
ConditionalCityNotReligion("in cities not following a [religionFilter] religion", UniqueTarget.Conditional),
|
||||
ConditionalCityMajorReligion("in cities with a major religion", UniqueTarget.Conditional),
|
||||
ConditionalCityEnhancedReligion("in cities with an enhanced religion", UniqueTarget.Conditional),
|
||||
ConditionalCityThisReligion("in cities following our religion", UniqueTarget.Conditional),
|
||||
|
@ -171,6 +171,20 @@ Allowed values:
|
||||
- `Followers of the Majority Religion` or `Followers of this Religion`, both of which only apply when this religion is the majority religion in that city
|
||||
- Specialist names
|
||||
|
||||
## religionFilter
|
||||
|
||||
For filtering specific relgions
|
||||
|
||||
- `any`
|
||||
- `major`
|
||||
- `enhanced`
|
||||
- `your`
|
||||
- `foriegn`
|
||||
- `enemy`
|
||||
- The name of a relgion symbol
|
||||
- The name of a belief
|
||||
- A unique of a belief the religion has
|
||||
|
||||
## policyFilter
|
||||
|
||||
Allowed values:
|
||||
|
Loading…
x
Reference in New Issue
Block a user