From e5452f5605f1d8f383db079ad6fb6450b9c17c57 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 20 Mar 2023 22:18:55 +0200 Subject: [PATCH] modding: 'Only available when' applies to beliefs --- .../civilization/NextTurnAutomation.kt | 10 +++++----- .../unciv/models/ruleset/unique/UniqueType.kt | 2 +- .../pickerscreens/ReligionPickerScreenCommon.kt | 2 +- .../ReligiousBeliefsPickerScreen.kt | 16 +++++++++++----- docs/Modders/uniques.md | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt index 0aa94bfdf9..4c64b148f6 100644 --- a/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/civilization/NextTurnAutomation.kt @@ -601,13 +601,13 @@ object NextTurnAutomation { } private fun chooseBeliefOfType(civInfo: Civilization, beliefType: BeliefType, additionalBeliefsToExclude: HashSet = hashSetOf()): Belief? { - return civInfo.gameInfo.ruleset.beliefs + return civInfo.gameInfo.ruleset.beliefs.values .filter { - (it.value.type == beliefType || beliefType == BeliefType.Any) - && !additionalBeliefsToExclude.contains(it.value) - && civInfo.religionManager.getReligionWithBelief(it.value) == null + (it.type == beliefType || beliefType == BeliefType.Any) + && !additionalBeliefsToExclude.contains(it) + && civInfo.religionManager.getReligionWithBelief(it) == null + && it.getMatchingUniques(UniqueType.OnlyAvailableWhen).none { !it.conditionalsApply(civInfo) } } - .map { it.value } .maxByOrNull { ReligionAutomation.rateBelief(civInfo, it) } } diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index f9692cc1ce..845b7858e4 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -301,7 +301,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: HiddenBeforeAmountPolicies("Hidden until [amount] social policy branches have been completed", UniqueTarget.Building, UniqueTarget.Unit), // Meant to be used together with conditionals, like "Only available " OnlyAvailableWhen("Only available", UniqueTarget.Unit, UniqueTarget.Building, UniqueTarget.Improvement, - UniqueTarget.Policy, UniqueTarget.Tech, UniqueTarget.Promotion, UniqueTarget.Ruins), + UniqueTarget.Policy, UniqueTarget.Tech, UniqueTarget.Promotion, UniqueTarget.Ruins, UniqueTarget.FollowerBelief, UniqueTarget.FounderBelief), ConvertFoodToProductionWhenConstructed("Excess Food converted to Production when under construction", UniqueTarget.Building, UniqueTarget.Unit), RequiresPopulation("Requires at least [amount] population", UniqueTarget.Building, UniqueTarget.Unit), diff --git a/core/src/com/unciv/ui/screens/pickerscreens/ReligionPickerScreenCommon.kt b/core/src/com/unciv/ui/screens/pickerscreens/ReligionPickerScreenCommon.kt index 7186d2b346..65489b08ef 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/ReligionPickerScreenCommon.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/ReligionPickerScreenCommon.kt @@ -25,7 +25,7 @@ import com.unciv.ui.components.extensions.onClick import com.unciv.ui.components.extensions.toLabel abstract class ReligionPickerScreenCommon( - private val choosingCiv: Civilization, + protected val choosingCiv: Civilization, disableScroll: Boolean = false ) : PickerScreen(disableScroll) { diff --git a/core/src/com/unciv/ui/screens/pickerscreens/ReligiousBeliefsPickerScreen.kt b/core/src/com/unciv/ui/screens/pickerscreens/ReligiousBeliefsPickerScreen.kt index b50742619c..07f519a9c7 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/ReligiousBeliefsPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/ReligiousBeliefsPickerScreen.kt @@ -10,9 +10,8 @@ import com.unciv.models.Counter import com.unciv.models.Religion import com.unciv.models.ruleset.Belief import com.unciv.models.ruleset.BeliefType +import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.translations.tr -import com.unciv.ui.images.ImageGetter -import com.unciv.ui.popups.AskTextPopup import com.unciv.ui.components.AutoScrollPane import com.unciv.ui.components.extensions.addSeparator import com.unciv.ui.components.extensions.addSeparatorVertical @@ -21,10 +20,12 @@ import com.unciv.ui.components.extensions.enable import com.unciv.ui.components.extensions.onClick import com.unciv.ui.components.extensions.packIfNeeded import com.unciv.ui.components.extensions.surroundWithCircle +import com.unciv.ui.images.ImageGetter +import com.unciv.ui.popups.AskTextPopup class ReligiousBeliefsPickerScreen ( choosingCiv: Civilization, - newBeliefsToChoose: Counter, + numberOfBeliefsCanChoose: Counter, pickIconAndName: Boolean ): ReligionPickerScreenCommon(choosingCiv, disableScroll = true) { // Roughly follows the layout of the original (although I am not very good at UI designing, so please improve this) @@ -44,7 +45,7 @@ class ReligiousBeliefsPickerScreen ( // One entry per new Belief to choose - the left side will offer these below the choices from earlier in the game class BeliefToChoose(val type: BeliefType, var belief: Belief? = null) private val beliefsToChoose: Array = - newBeliefsToChoose.flatMap { entry -> (0 until entry.value).map { BeliefToChoose(entry.key) } }.toTypedArray() + numberOfBeliefsCanChoose.flatMap { entry -> (0 until entry.value).map { BeliefToChoose(entry.key) } }.toTypedArray() private var leftSelection = Selection() private var leftSelectedIndex = -1 @@ -193,8 +194,10 @@ class ReligiousBeliefsPickerScreen ( rightBeliefsToChoose.clear() rightSelection.clear() val availableBeliefs = ruleset.beliefs.values - .filter { (it.type == beliefType || beliefType == BeliefType.Any) } + .filter { it.type == beliefType || beliefType == BeliefType.Any } + val civReligionManager = currentReligion.getFounder().religionManager + for (belief in availableBeliefs) { val beliefButton = getBeliefButton(belief) when { @@ -213,6 +216,9 @@ class ReligiousBeliefsPickerScreen ( // The Belief is not available because someone already has it beliefButton.disable(redDisableColor) } + belief.getMatchingUniques(UniqueType.OnlyAvailableWhen).any { !it.conditionalsApply(choosingCiv) } -> + beliefButton.disable(redDisableColor) // Blocked + else -> beliefButton.onClickSelect(rightSelection, belief) { beliefsToChoose[leftButtonIndex].belief = belief diff --git a/docs/Modders/uniques.md b/docs/Modders/uniques.md index 9d0989d016..1cfb947976 100644 --- a/docs/Modders/uniques.md +++ b/docs/Modders/uniques.md @@ -881,7 +881,7 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl Applicable to: Tech ??? example "Only available" - Applicable to: Tech, Policy, Building, Unit, Promotion, Improvement, Ruins + Applicable to: Tech, Policy, FounderBelief, FollowerBelief, Building, Unit, Promotion, Improvement, Ruins ??? example "Cannot be hurried" Applicable to: Tech, Building