Skip to content

Commit

Permalink
modding: 'Only available when' applies to beliefs
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Mar 20, 2023
1 parent 9201ea2 commit e5452f5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -601,13 +601,13 @@ object NextTurnAutomation {
}

private fun chooseBeliefOfType(civInfo: Civilization, beliefType: BeliefType, additionalBeliefsToExclude: HashSet<Belief> = 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) }
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/com/unciv/models/ruleset/unique/UniqueType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <after adopting [policy]> <while the empire is happy>"
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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<BeliefType>,
numberOfBeliefsCanChoose: Counter<BeliefType>,
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)
Expand All @@ -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<BeliefToChoose> =
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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/Modders/uniques.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e5452f5

Please sign in to comment.