Enum rename: OnlyAvailableWhen -> OnlyAvailable

This commit is contained in:
Yair Morgenstern 2024-01-25 21:58:49 +02:00
parent 197ec9dc9a
commit ab7f23835e
20 changed files with 30 additions and 30 deletions

View File

@ -470,7 +470,7 @@ object ReligionAutomation {
(it.type == beliefType || beliefType == BeliefType.Any)
&& !additionalBeliefsToExclude.contains(it)
&& civInfo.religionManager.getReligionWithBelief(it) == null
&& it.getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals)
&& it.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals)
.none { unique -> !unique.conditionalsApply(civInfo) }
}
.maxByOrNull { ReligionAutomation.rateBelief(civInfo, it) }

View File

@ -129,7 +129,7 @@ object UnitAutomation {
internal fun tryUpgradeUnit(unit: MapUnit): Boolean {
if (unit.civ.isHuman() && (!UncivGame.Current.settings.automatedUnitsCanUpgrade
|| UncivGame.Current.settings.autoPlay.isAutoPlayingAndFullAI())) return false
val upgradeUnits = getUnitsToUpgradeTo(unit)
if (upgradeUnits.none()) return false // for resource reasons, usually
val upgradedUnit = upgradeUnits.minBy { it.cost }
@ -153,7 +153,7 @@ object UnitAutomation {
fun isInvalidUpgradeDestination(baseUnit: BaseUnit): Boolean {
if (!unit.civ.tech.isResearched(baseUnit))
return true
return baseUnit.getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals)
return baseUnit.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals)
.any { !it.conditionalsApply(StateForConditionals(unit.civ, unit = unit)) }
}

View File

@ -166,7 +166,7 @@ class PolicyManager : IsPartOfGameInfoSerialization {
if (policy.policyBranchType == PolicyBranchType.BranchComplete) return false
if (!getAdoptedPolicies().containsAll(policy.requires!!)) return false
if (checkEra && civInfo.gameInfo.ruleset.eras[policy.branch.era]!!.eraNumber > civInfo.getEraNumber()) return false
if (policy.uniqueObjects.filter { it.type == UniqueType.OnlyAvailableWhen }
if (policy.uniqueObjects.filter { it.type == UniqueType.OnlyAvailable }
.any { !it.conditionalsApply(civInfo) }) return false
return true
}
@ -256,7 +256,7 @@ class PolicyManager : IsPartOfGameInfoSerialization {
}
}
fun getCultureFromGreatWriter(): Int {
return (cultureOfLast8Turns.sum() * civInfo.gameInfo.speed.cultureCostModifier).toInt()
}

View File

@ -40,7 +40,7 @@ class RuinsManager(
|| civInfo.gameInfo.difficulty in possibleReward.excludedDifficulties
|| possibleReward.hasUnique(UniqueType.HiddenWithoutReligion) && !civInfo.gameInfo.isReligionEnabled()
|| possibleReward.hasUnique(UniqueType.HiddenAfterGreatProphet) && civInfo.religionManager.greatProphetsEarned() > 0
|| possibleReward.getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals)
|| possibleReward.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals)
.any { !it.conditionalsApply(stateForOnlyAvailableWhen) }
}
// This might be a dirty way to do this, but it works (we do have randomWeighted in CollectionExtensions, but below we

View File

@ -161,7 +161,7 @@ class TechManager : IsPartOfGameInfoSerialization {
fun canBeResearched(techName: String): Boolean {
val tech = getRuleset().technologies[techName]!!
if (tech.uniqueObjects.any { it.type == UniqueType.OnlyAvailableWhen && !it.conditionalsApply(civInfo) })
if (tech.uniqueObjects.any { it.type == UniqueType.OnlyAvailable && !it.conditionalsApply(civInfo) })
return false
if (isResearched(tech.name) && !tech.isContinuallyResearchable())

View File

@ -118,7 +118,7 @@ class UnitPromotions : IsPartOfGameInfoSerialization {
.filter { unit.type.name in it.unitTypes && it.name !in promotions }
.filter { it.prerequisites.isEmpty() || it.prerequisites.any { p->p in promotions } }
.filter { promotion -> promotion.uniqueObjects
.none { it.type == UniqueType.OnlyAvailableWhen
.none { it.type == UniqueType.OnlyAvailable
&& !it.conditionalsApply(StateForConditionals(unit.civ, unit = unit)) }
}
}

View File

@ -60,7 +60,7 @@ class TileInfoImprovementFunctions(val tile: Tile) {
yield(ImprovementBuildingProblem.NotJustOutsideBorders)
}
if (improvement.getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals)
if (improvement.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals)
.any { !it.conditionalsApply(stateForConditionals) })
yield(ImprovementBuildingProblem.UnmetConditional)
@ -128,7 +128,7 @@ class TileInfoImprovementFunctions(val tile: Tile) {
// Can only remove roads if that road is actually there
RoadStatus.values().any { it.removeAction == improvement.name } -> tile.roadStatus.removeAction == improvement.name
// Can only remove features or improvement if that feature/improvement is actually there
improvement.name.startsWith(Constants.remove) -> tile.terrainFeatures.any { Constants.remove + it == improvement.name }
improvement.name.startsWith(Constants.remove) -> tile.terrainFeatures.any { Constants.remove + it == improvement.name }
|| Constants.remove + tile.improvement == improvement.name
// Can only build roads if on land and they are better than the current road
RoadStatus.values().any { it.name == improvement.name } -> !tile.isWater

View File

@ -241,7 +241,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
yield(RejectionReasonType.AlreadyBuilt.toInstance())
for (unique in uniqueObjects) {
if (unique.type != UniqueType.OnlyAvailableWhen &&
if (unique.type != UniqueType.OnlyAvailable &&
!unique.conditionalsApply(StateForConditionals(civ, cityConstructions.city))) continue
@Suppress("NON_EXHAUSTIVE_WHEN")
@ -251,7 +251,7 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
UniqueType.Unbuildable ->
yield(RejectionReasonType.Unbuildable.toInstance())
UniqueType.OnlyAvailableWhen ->
UniqueType.OnlyAvailable ->
if (!unique.conditionalsApply(civ, cityConstructions.city))
yield(RejectionReasonType.ShouldNotBeDisplayed.toInstance())

View File

@ -38,7 +38,7 @@ open class Policy : RulesetObject() {
return (if (policyBranchType == PolicyBranchType.Member) name.tr() + "\n" else "") +
uniqueObjects.filterNot {
it.isHiddenToUsers()
|| it.isOfType(UniqueType.OnlyAvailableWhen)
|| it.isOfType(UniqueType.OnlyAvailable)
|| it.isOfType(UniqueType.OneTimeGlobalAlert)
}
.joinToString("\n") { "${it.text.tr()}" }
@ -91,7 +91,7 @@ open class Policy : RulesetObject() {
}
fun isEnabledByPolicy(rulesetObject: IRulesetObject) =
rulesetObject.getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals).any { it.conditionals.any {
rulesetObject.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals).any { it.conditionals.any {
it.type == UniqueType.ConditionalAfterPolicyOrBelief && it.params[0] == name
} }
@ -108,7 +108,7 @@ open class Policy : RulesetObject() {
fun isDisabledByPolicy(rulesetObject: IRulesetObject) =
rulesetObject.getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals).any { it.conditionals.any {
rulesetObject.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals).any { it.conditionals.any {
it.type == UniqueType.ConditionalBeforePolicyOrBelief && it.params[0] == name
} }

View File

@ -72,7 +72,7 @@ class Era : RulesetObject() {
ruleset.allRulesetObjects()
.flatMap { obj ->
obj.getMatchingUniques(
UniqueType.OnlyAvailableWhen,
UniqueType.OnlyAvailable,
StateForConditionals.IgnoreConditionals
)
.map { unique -> obj to unique }

View File

@ -43,7 +43,7 @@ class Technology: RulesetObject() {
// Wrapper so that if the way to require a tech with a Unique ever changes, this only needs to change in one place.
fun uniqueIsRequirementForThisTech(unique: Unique): Boolean =
unique.type == UniqueType.OnlyAvailableWhen
unique.type == UniqueType.OnlyAvailable
// OnlyAvailableWhen can take multiple conditionals, in which case the true conditional is implicitly the conjunction of all those conditionals.
// If an OnlyAvailableWhen there are multiple conditionals, one of which requires this tech,
// then IHasUniques.techsRequiredByUniques() will list this tech as required (because it is),

View File

@ -47,7 +47,7 @@ interface IHasUniques : INamed {
fun hasUnique(uniqueType: UniqueType, stateForConditionals: StateForConditionals? = null) =
getMatchingUniques(uniqueType.placeholderText, stateForConditionals).any()
fun availabilityUniques(): Sequence<Unique> = getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals)
fun availabilityUniques(): Sequence<Unique> = getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals)
fun techsRequiredByUniques(): Sequence<String> {
return availabilityUniques()

View File

@ -263,7 +263,7 @@ enum class UniqueType(
MaxNumberBuildable("Limited to [amount] per Civilization", UniqueTarget.Building, UniqueTarget.Unit),
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,
OnlyAvailable("Only available", UniqueTarget.Unit, UniqueTarget.Building, UniqueTarget.Improvement,
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),

View File

@ -159,7 +159,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
}
val civInfo = cityConstructions.city.civ
for (unique in getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals))
for (unique in getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals))
if (!unique.conditionalsApply(civInfo, cityConstructions.city))
yield(RejectionReasonType.ShouldNotBeDisplayed.toInstance())

View File

@ -20,7 +20,7 @@ class PantheonPickerScreen(
if (belief.type != BeliefType.Pantheon) continue
val beliefButton = getBeliefButton(belief, withTypeLabel = false)
if (choosingCiv.religionManager.getReligionWithBelief(belief) == null
&& belief.getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals)
&& belief.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals)
.none { !it.conditionalsApply(choosingCiv) }) {
beliefButton.onClickSelect(selection, belief) {
selectedPantheon = belief

View File

@ -300,9 +300,9 @@ class PolicyPickerScreen(
label.wrap = true
labelTable.add(label).pad(7f, 20f, 10f, 20f).grow().row()
if (branch.uniqueMap.getUniques(UniqueType.OnlyAvailableWhen).any()) {
var warning = UniqueType.OnlyAvailableWhen.text.tr() + ":\n"
for (unique in branch.uniqueMap.getUniques(UniqueType.OnlyAvailableWhen))
if (branch.uniqueMap.getUniques(UniqueType.OnlyAvailable).any()) {
var warning = UniqueType.OnlyAvailable.text.tr() + ":\n"
for (unique in branch.uniqueMap.getUniques(UniqueType.OnlyAvailable))
for (conditional in unique.conditionals) {
warning += "" + conditional.text.tr() + "\n"
}

View File

@ -34,7 +34,7 @@ class PromotionTree(val unit: MapUnit) {
/** Off if there is only one "best" path of equal cost to adopt this node's promotion */
var pathIsAmbiguous = false
/** On for promotions having unavailable prerequisites (missing in ruleset, or not allowed for the unit's
* UnitType, and not already adopted either); or currently disabled by a [UniqueType.OnlyAvailableWhen] unique.
* UnitType, and not already adopted either); or currently disabled by a [UniqueType.OnlyAvailable] unique.
* (should never be on with a vanilla ruleset) */
var unreachable = false
@ -109,7 +109,7 @@ class PromotionTree(val unit: MapUnit) {
// defensive - I don't know how to provoke the situation, but if it ever occurs, disallow choosing that promotion
if (node.promotion.prerequisites.isNotEmpty() && node.parents.isEmpty())
node.unreachable = true
if (node.promotion.getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals)
if (node.promotion.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals)
.any { !it.conditionalsApply(state) })
node.unreachable = true
}
@ -118,7 +118,7 @@ class PromotionTree(val unit: MapUnit) {
// Also determine preferredParent / pathIsAmbiguous by weighing distanceToAdopted
for (node in allRoots()) {
node.depth = 0
node.distanceToAdopted = if (node.isAdopted) 0
node.distanceToAdopted = if (node.isAdopted) 0
else if (node.unreachable) Int.MAX_VALUE else 1
}
for (depth in 0..99) {

View File

@ -220,7 +220,7 @@ class ReligiousBeliefsPickerScreen (
// The Belief is not available because someone already has it
beliefButton.disable(redDisableColor)
}
belief.getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals)
belief.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals)
.any { !it.conditionalsApply(choosingCiv) } ->
// The Belief is blocked
beliefButton.disable(redDisableColor)

View File

@ -407,7 +407,7 @@ class TechPickerScreen(
val pathToTech = civTech.getRequiredTechsToDestination(tech)
for (requiredTech in pathToTech) {
for (unique in requiredTech.uniqueObjects
.filter { it.type == UniqueType.OnlyAvailableWhen && !it.conditionalsApply(civInfo) }) {
.filter { it.type == UniqueType.OnlyAvailable && !it.conditionalsApply(civInfo) }) {
rightSideButton.setText(unique.text.tr())
rightSideButton.disable()
return

View File

@ -305,7 +305,7 @@ object UnitActionsFromUniques {
val unitToTransformTo = civInfo.getEquivalentUnit(unique.params[0])
if (unitToTransformTo.getMatchingUniques(
UniqueType.OnlyAvailableWhen,
UniqueType.OnlyAvailable,
StateForConditionals.IgnoreConditionals
)
.any { !it.conditionalsApply(stateForConditionals) })