diff --git a/core/src/com/unciv/Constants.kt b/core/src/com/unciv/Constants.kt index 7f2526bb28..0300785b7c 100644 --- a/core/src/com/unciv/Constants.kt +++ b/core/src/com/unciv/Constants.kt @@ -3,8 +3,7 @@ package com.unciv object Constants { const val settler = "Settler" const val eraSpecificUnit = "Era Starting Unit" - const val spreadReligion = "Spread Religion" - const val removeHeresy = "Remove Foreign religions from your own cities" + val all = setOf("All", "all") const val english = "English" diff --git a/core/src/com/unciv/logic/battle/CityCombatant.kt b/core/src/com/unciv/logic/battle/CityCombatant.kt index 84dc6fd9e6..66d37f5467 100644 --- a/core/src/com/unciv/logic/battle/CityCombatant.kt +++ b/core/src/com/unciv/logic/battle/CityCombatant.kt @@ -1,5 +1,6 @@ package com.unciv.logic.battle +import com.unciv.Constants import com.unciv.logic.MultiFilter import com.unciv.logic.city.City import com.unciv.logic.civilization.Civilization @@ -24,7 +25,7 @@ class CityCombatant(val city: City) : ICombatant { override fun isDefeated(): Boolean = city.health == 1 override fun isInvisible(to: Civilization): Boolean = false override fun canAttack(): Boolean = city.canBombard() - override fun matchesFilter(filter: String) = MultiFilter.multiFilter(filter, {it == "City" || it == "All" || city.matchesFilter(it)}) + override fun matchesFilter(filter: String) = MultiFilter.multiFilter(filter, {it == "City" || it in Constants.all || city.matchesFilter(it)}) override fun getAttackSound() = UncivSound.Bombard override fun takeDamage(damage: Int) { diff --git a/core/src/com/unciv/logic/city/City.kt b/core/src/com/unciv/logic/city/City.kt index 72fc92b31c..b32dd8234f 100644 --- a/core/src/com/unciv/logic/city/City.kt +++ b/core/src/com/unciv/logic/city/City.kt @@ -1,6 +1,7 @@ package com.unciv.logic.city import com.badlogic.gdx.math.Vector2 +import com.unciv.Constants import com.unciv.GUI import com.unciv.logic.IsPartOfGameInfoSerialization import com.unciv.logic.MultiFilter @@ -486,7 +487,8 @@ class City : IsPartOfGameInfoSerialization { private fun matchesSingleFilter(filter: String, viewingCiv: Civilization? = civ): Boolean { return when (filter) { "in this city" -> true // Filtered by the way uniques are found - "in all cities", "All" -> true + "in all cities" -> true + in Constants.all -> true "in your cities", "Your" -> viewingCiv == civ "in all coastal cities", "Coastal" -> isCoastal() "in capital", "Capital" -> isCapital() diff --git a/core/src/com/unciv/logic/civilization/managers/TechManager.kt b/core/src/com/unciv/logic/civilization/managers/TechManager.kt index f9974f4e33..474050fde0 100644 --- a/core/src/com/unciv/logic/civilization/managers/TechManager.kt +++ b/core/src/com/unciv/logic/civilization/managers/TechManager.kt @@ -502,10 +502,10 @@ class TechManager : IsPartOfGameInfoSerialization { private fun updateTransientBooleans() { unitsCanEmbark = civInfo.hasUnique(UniqueType.LandUnitEmbarkation) val enterOceanUniques = civInfo.getMatchingUniques(UniqueType.UnitsMayEnterOcean) - allUnitsCanEnterOcean = enterOceanUniques.any { it.params[0] == "All" } + allUnitsCanEnterOcean = enterOceanUniques.any { it.params[0] in Constants.all } embarkedUnitsCanEnterOcean = allUnitsCanEnterOcean || enterOceanUniques.any { it.params[0] == Constants.embarked } - specificUnitsCanEnterOcean = enterOceanUniques.any { it.params[0] != "All" && it.params[0] != Constants.embarked } + specificUnitsCanEnterOcean = enterOceanUniques.any { it.params[0] !in Constants.all && it.params[0] != Constants.embarked } movementSpeedOnRoads = if (civInfo.hasUnique(UniqueType.RoadMovementSpeed)) RoadStatus.Road.movementImproved else RoadStatus.Road.movement diff --git a/core/src/com/unciv/logic/map/tile/Tile.kt b/core/src/com/unciv/logic/map/tile/Tile.kt index 8db4631604..325c834930 100644 --- a/core/src/com/unciv/logic/map/tile/Tile.kt +++ b/core/src/com/unciv/logic/map/tile/Tile.kt @@ -498,7 +498,8 @@ open class Tile : IsPartOfGameInfoSerialization { /** Implements [UniqueParameterType.TerrainFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TerrainFilter] */ fun matchesSingleTerrainFilter(filter: String, observingCiv: Civilization? = null): Boolean { return when (filter) { - "All", "Terrain" -> true + "Terrain" -> true + in Constants.all -> true baseTerrain -> true "Water" -> isWater "Land" -> isLand diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index 75297d2405..01b8e78e97 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -1,5 +1,6 @@ package com.unciv.models.ruleset +import com.unciv.Constants import com.unciv.logic.MultiFilter import com.unciv.logic.city.City import com.unciv.logic.city.CityConstructions @@ -447,9 +448,9 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction { return MultiFilter.multiFilter(filter, ::matchesSingleFilter) } - fun matchesSingleFilter(filter: String): Boolean { + private fun matchesSingleFilter(filter: String): Boolean { return when (filter) { - "All" -> true + in Constants.all -> true name -> true "Building", "Buildings" -> !isAnyWonder() "Wonder", "Wonders" -> isAnyWonder() diff --git a/core/src/com/unciv/models/ruleset/nation/Nation.kt b/core/src/com/unciv/models/ruleset/nation/Nation.kt index d5c9970640..379076507e 100644 --- a/core/src/com/unciv/models/ruleset/nation/Nation.kt +++ b/core/src/com/unciv/models/ruleset/nation/Nation.kt @@ -263,9 +263,9 @@ class Nation : RulesetObject() { return MultiFilter.multiFilter(filter, ::matchesSingleFilter) } - fun matchesSingleFilter(filter: String): Boolean { + private fun matchesSingleFilter(filter: String): Boolean { return when (filter) { - "All" -> true + in Constants.all -> true name -> true "Major" -> isMajorCiv // "CityState" to be deprecated, replaced by "City-States" diff --git a/core/src/com/unciv/models/ruleset/tech/Technology.kt b/core/src/com/unciv/models/ruleset/tech/Technology.kt index c165d85127..3380a56005 100644 --- a/core/src/com/unciv/models/ruleset/tech/Technology.kt +++ b/core/src/com/unciv/models/ruleset/tech/Technology.kt @@ -1,5 +1,6 @@ package com.unciv.models.ruleset.tech +import com.unciv.Constants import com.unciv.logic.civilization.Civilization import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.RulesetObject @@ -34,7 +35,7 @@ class Technology: RulesetObject() { fun matchesFilter(filter: String): Boolean { return when (filter) { - "All" -> true + in Constants.all -> true name -> true era() -> true else -> uniques.contains(filter) diff --git a/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt b/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt index 8db1280ef4..52d8a622f5 100644 --- a/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt +++ b/core/src/com/unciv/models/ruleset/tile/TileImprovement.kt @@ -93,10 +93,10 @@ class TileImprovement : RulesetStatsObject() { return MultiFilter.multiFilter(filter, ::matchesSingleFilter) } - fun matchesSingleFilter(filter: String): Boolean { + private fun matchesSingleFilter(filter: String): Boolean { return when (filter) { name -> true - "All" -> true + in Constants.all -> true "Improvement" -> true // For situations involving tileFilter "All Road" -> isRoad() "Great Improvement", "Great" -> isGreatImprovement() diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt index c94c07fb1a..a86f1ec573 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt @@ -77,7 +77,7 @@ enum class UniqueParameterType( // todo potentially remove if OneTimeRevealSpecificMapTiles changes KeywordAll("'all'", "All") { override fun getErrorSeverity(parameterText: String, ruleset: Ruleset) = - if (parameterText == "All") null else UniqueType.UniqueParameterErrorSeverity.RulesetInvariant + if (parameterText in Constants.all) null else UniqueType.UniqueParameterErrorSeverity.RulesetInvariant }, /** Implemented by [ICombatant.matchesCategory][com.unciv.logic.battle.ICombatant.matchesFilter] */ @@ -115,10 +115,10 @@ enum class UniqueParameterType( /** Implemented by [BaseUnit.matchesFilter][com.unciv.models.ruleset.unit.BaseUnit.matchesFilter] */ BaseUnitFilter("baseUnitFilter", "Melee") { private val knownValues = setOf( - "All", "Melee", "Ranged", "Civilian", "Military", "non-air", + "Melee", "Ranged", "Civilian", "Military", "non-air", "Nuclear Weapon", "Great Person", "Religious", "relevant", // used for UniqueType.UnitStartingPromotions - ) + ) + Constants.all override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset) @@ -222,7 +222,7 @@ enum class UniqueParameterType( /** Implemented by [Nation.matchesFilter][com.unciv.models.ruleset.nation.Nation.matchesFilter] */ NationFilter("nationFilter", Constants.cityStates) { - private val knownValues = setOf(Constants.cityStates, "Major", "All") + private val knownValues = setOf(Constants.cityStates, "Major") + Constants.all override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset) @@ -239,7 +239,7 @@ enum class UniqueParameterType( CityFilter("cityFilter", "in all cities", null, "City filters") { private val knownValues = setOf( "in this city", - "in all cities", "All", + "in all cities", "in your cities", "Your", "in all coastal cities", "Coastal", "in capital", "Capital", @@ -258,7 +258,7 @@ enum class UniqueParameterType( "in City-State cities", "in cities following this religion", "in cities following our religion", - ) + ) + Constants.all override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset) @@ -284,8 +284,8 @@ enum class UniqueParameterType( /** Implemented by [Building.matchesFilter][com.unciv.models.ruleset.Building.matchesFilter] */ BuildingFilter("buildingFilter", "Culture") { - private val knownValues = mutableSetOf("All", "Building", "Buildings", "Wonder", "Wonders", "National Wonder", "World Wonder") - .apply { addAll(Stat.names()) } + private val knownValues = mutableSetOf("Building", "Buildings", "Wonder", "Wonders", "National Wonder", "World Wonder") + .apply { addAll(Stat.names()); addAll(Constants.all) } override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset) @@ -298,7 +298,7 @@ enum class UniqueParameterType( } override fun isTranslationWriterGuess(parameterText: String, ruleset: Ruleset) = - parameterText != "All" && getErrorSeverity(parameterText, ruleset) == null + parameterText !in Constants.all && getErrorSeverity(parameterText, ruleset) == null }, /** Implemented by [PopulationManager.getPopulationFilterAmount][com.unciv.logic.city.managers.CityPopulationManager.getPopulationFilterAmount] */ @@ -317,13 +317,12 @@ enum class UniqueParameterType( /** Implemented by [Tile.matchesTerrainFilter][com.unciv.logic.map.tile.Tile.matchesTerrainFilter] */ TerrainFilter("terrainFilter", Constants.freshWaterFilter, null, "Terrain Filters") { private val knownValues = setOf( - "All", "Terrain", + "Terrain", Constants.coastal, Constants.river, "Open terrain", "Rough terrain", "Water resource", "resource", "Foreign Land", "Foreign", "Friendly Land", "Friendly", "Enemy Land", "Enemy", "your", "Featureless", Constants.freshWaterFilter, "non-fresh water", "Natural Wonder", "Impassable", "Land", "Water" - ) + - ResourceType.values().map { it.name + " resource" } + ) + ResourceType.values().map { it.name + " resource" } + Constants.all override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset) @@ -340,7 +339,7 @@ enum class UniqueParameterType( } override fun isTranslationWriterGuess(parameterText: String, ruleset: Ruleset) = - parameterText in ruleset.terrains || parameterText != "All" && parameterText in knownValues + parameterText in ruleset.terrains || parameterText !in Constants.all && parameterText in knownValues override fun getTranslationWriterStringsForOutput() = knownValues }, @@ -450,7 +449,7 @@ enum class UniqueParameterType( /** Implemented by [TileImprovement.matchesFilter][com.unciv.models.ruleset.tile.TileImprovement.matchesFilter] */ ImprovementFilter("improvementFilter", "All Road", null, "Improvement Filters") { - private val knownValues = setOf("All", "Improvement", "All Road", "Great Improvement", "Great") + private val knownValues = setOf("Improvement", "All Road", "Great Improvement", "Great") + Constants.all override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset) @@ -463,7 +462,7 @@ enum class UniqueParameterType( } override fun isTranslationWriterGuess(parameterText: String, ruleset: Ruleset) = - parameterText != "All" && getErrorSeverity(parameterText, ruleset) == null + parameterText !in Constants.all && getErrorSeverity(parameterText, ruleset) == null override fun getTranslationWriterStringsForOutput() = knownValues }, @@ -568,20 +567,6 @@ enum class UniqueParameterType( } }, - /** For untyped "Can [] [] times" unique */ - @Deprecated("As of 4.8.9") - Action("action", Constants.spreadReligion, "An action that a unit can perform. Currently, there are only two actions part of this: 'Spread Religion' and 'Remove Foreign religions from your own cities'", "Religious Action Filters") { - private val knownValues = setOf(Constants.spreadReligion, Constants.removeHeresy) - override fun getErrorSeverity( - parameterText: String, - ruleset: Ruleset - ): UniqueType.UniqueParameterErrorSeverity? { - return if (parameterText in knownValues) null - else UniqueType.UniqueParameterErrorSeverity.RulesetInvariant - } - override fun getTranslationWriterStringsForOutput() = knownValues - }, - /** Mod declarative compatibility: Define Mod relations by their name. */ ModName("modFilter", "DeCiv Redux", """A Mod name, case-sensitive _or_ a simple wildcard filter beginning and ending in an Asterisk, case-insensitive""", "Mod name filter") { override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt index b68bd3f93c..0f05c97cdb 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt @@ -598,7 +598,7 @@ object UniqueTriggerActivation { val filter = unique.params[1] val radius = unique.params[2].toInt() - val isAll = amount == "All" + val isAll = amount in Constants.all val positions = ArrayList() var explorableTiles = tile.getTilesInDistance(radius) diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index ca1d3699bd..07ac2b555d 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -1,5 +1,6 @@ package com.unciv.models.ruleset.unit +import com.unciv.Constants import com.unciv.logic.MultiFilter import com.unciv.logic.city.City import com.unciv.logic.city.CityConstructions @@ -315,7 +316,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction { unitType -> true name -> true replaces -> true - "All" -> true + in Constants.all -> true "Melee" -> isMelee() "Ranged" -> isRanged() diff --git a/core/src/com/unciv/models/ruleset/validation/UniqueValidator.kt b/core/src/com/unciv/models/ruleset/validation/UniqueValidator.kt index d1638d7759..aae99ef81c 100644 --- a/core/src/com/unciv/models/ruleset/validation/UniqueValidator.kt +++ b/core/src/com/unciv/models/ruleset/validation/UniqueValidator.kt @@ -1,5 +1,6 @@ package com.unciv.models.ruleset.validation +import com.unciv.Constants import com.unciv.logic.map.mapunit.MapUnitCache import com.unciv.models.ruleset.IRulesetObject import com.unciv.models.ruleset.Ruleset @@ -86,7 +87,7 @@ class UniqueValidator(val ruleset: Ruleset) { } if (unique.type in MapUnitCache.UnitMovementUniques - && unique.conditionals.any { it.type != UniqueType.ConditionalOurUnit || it.params[0] != "All" } + && unique.conditionals.any { it.type != UniqueType.ConditionalOurUnit || it.params[0] !in Constants.all } ) // (Stay silent if the only conditional is `` - as in G&K Denmark) // Not necessarily even a problem, but yes something mod maker should be aware of diff --git a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt index d9a237d106..199cf676bd 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt @@ -298,7 +298,7 @@ object UnitActionsFromUniques { // If a unit has terrainFilter "Land" or improvementFilter "All", then we may proceed. // If a unit only had improvement filter "Road" or "Railroad", then we need to also check if that tech is unlocked - val unitCanBuildRoad = uniquesToCheck.any { it.params[0] == "Land" || it.params[0] == "All" } + val unitCanBuildRoad = uniquesToCheck.any { it.params[0] == "Land" || it.params[0] in Constants.all } || uniquesToCheck.any {it.params[0] == "Road" } && (unitCivBestRoad == RoadStatus.Road || unitCivBestRoad == RoadStatus.Railroad) || uniquesToCheck.any {it.params[0] == "Railroad"} && (unitCivBestRoad == RoadStatus.Railroad)