Add terrain filters for resources, any terrain, or "improved" (#10878)

* Add terrain filters for resources, any terrain, or "improved"

* Add entry to validation
This commit is contained in:
SeventhM
2024-01-07 06:07:53 -08:00
committed by GitHub
parent 26fb286252
commit 9ae782b426
3 changed files with 13 additions and 14 deletions

View File

@ -484,8 +484,9 @@ open class Tile : IsPartOfGameInfoSerialization {
/** Implements [UniqueParameterType.TileFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TileFilter] */ /** Implements [UniqueParameterType.TileFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TileFilter] */
fun matchesFilter(filter: String, civInfo: Civilization? = null): Boolean { fun matchesFilter(filter: String, civInfo: Civilization? = null): Boolean {
if (matchesTerrainFilter(filter, civInfo)) return true if (matchesTerrainFilter(filter, civInfo)) return true
if (improvement != null && !improvementIsPillaged && ruleset.tileImprovements[improvement]!!.matchesFilter(filter)) return true if ((improvement == null || improvementIsPillaged) && filter == "unimproved") return true
return improvement == null && filter == "unimproved" if (improvement != null && !improvementIsPillaged && filter == "improved") return true
return improvement != null && !improvementIsPillaged && ruleset.tileImprovements[improvement]!!.matchesFilter(filter)
} }
fun matchesTerrainFilter(filter: String, observingCiv: Civilization? = null): Boolean { fun matchesTerrainFilter(filter: String, observingCiv: Civilization? = null): Boolean {
@ -495,7 +496,7 @@ open class Tile : IsPartOfGameInfoSerialization {
/** Implements [UniqueParameterType.TerrainFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TerrainFilter] */ /** Implements [UniqueParameterType.TerrainFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TerrainFilter] */
fun matchesSingleTerrainFilter(filter: String, observingCiv: Civilization? = null): Boolean { fun matchesSingleTerrainFilter(filter: String, observingCiv: Civilization? = null): Boolean {
return when (filter) { return when (filter) {
"All" -> true "All", "Terrain" -> true
baseTerrain -> true baseTerrain -> true
"Water" -> isWater "Water" -> isWater
"Land" -> isLand "Land" -> isLand
@ -510,6 +511,7 @@ open class Tile : IsPartOfGameInfoSerialization {
"Enemy Land", "Enemy" -> observingCiv != null && isEnemyTerritory(observingCiv) "Enemy Land", "Enemy" -> observingCiv != null && isEnemyTerritory(observingCiv)
resource -> observingCiv != null && hasViewableResource(observingCiv) resource -> observingCiv != null && hasViewableResource(observingCiv)
"resource" -> observingCiv != null && hasViewableResource(observingCiv)
"Water resource" -> isWater && observingCiv != null && hasViewableResource(observingCiv) "Water resource" -> isWater && observingCiv != null && hasViewableResource(observingCiv)
"Natural Wonder" -> naturalWonder != null "Natural Wonder" -> naturalWonder != null
"Featureless" -> terrainFeatures.isEmpty() "Featureless" -> terrainFeatures.isEmpty()

View File

@ -307,9 +307,9 @@ enum class UniqueParameterType(
/** Implemented by [Tile.matchesTerrainFilter][com.unciv.logic.map.tile.Tile.matchesTerrainFilter] */ /** Implemented by [Tile.matchesTerrainFilter][com.unciv.logic.map.tile.Tile.matchesTerrainFilter] */
TerrainFilter("terrainFilter", Constants.freshWaterFilter, null, "Terrain Filters") { TerrainFilter("terrainFilter", Constants.freshWaterFilter, null, "Terrain Filters") {
private val knownValues = setOf( private val knownValues = setOf(
"All", "All", "Terrain",
Constants.coastal, Constants.river, "Open terrain", "Rough terrain", "Water resource", Constants.coastal, Constants.river, "Open terrain", "Rough terrain", "Water resource",
"Foreign Land", "Foreign", "Friendly Land", "Friendly", "Enemy Land", "Enemy", "resource", "Foreign Land", "Foreign", "Friendly Land", "Friendly", "Enemy Land", "Enemy",
"Featureless", Constants.freshWaterFilter, "non-fresh water", "Natural Wonder", "Featureless", Constants.freshWaterFilter, "non-fresh water", "Natural Wonder",
"Impassable", "Land", "Water" "Impassable", "Land", "Water"
) + ) +
@ -337,7 +337,7 @@ enum class UniqueParameterType(
/** Implemented by [Tile.matchesFilter][com.unciv.logic.map.tile.Tile.matchesFilter] */ /** Implemented by [Tile.matchesFilter][com.unciv.logic.map.tile.Tile.matchesFilter] */
TileFilter("tileFilter", "Farm", "Anything that can be used either in an improvementFilter or in a terrainFilter can be used here, plus 'unimproved'", "Tile Filters") { TileFilter("tileFilter", "Farm", "Anything that can be used either in an improvementFilter or in a terrainFilter can be used here, plus 'unimproved'", "Tile Filters") {
private val knownValues = setOf("unimproved", "All Road", "Great Improvement") private val knownValues = setOf("unimproved", "improved", "All Road", "Great Improvement")
override fun getErrorSeverity(parameterText: String, ruleset: Ruleset): override fun getErrorSeverity(parameterText: String, ruleset: Ruleset):
UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset) UniqueType.UniqueParameterErrorSeverity? = getErrorSeverityForFilter(parameterText, ruleset)

View File

@ -33,13 +33,9 @@ This is because to the player, the text will be `non-Wounded Armor units`, which
Allows filtering for specific civs. Allows filtering for specific civs.
- `All`
- `City-states`
- `Major`
- `Human player` - `Human player`
- `AI player` - `AI player`
- Nation name - [nationFilter](#nationfilter)
- A unique a Nation has (verbatim, no placeholders)
## nationFilter ## nationFilter
@ -205,6 +201,7 @@ This indicates the terrain on a single tile. The following values are allowed:
- A [nationFilter](#nationfilter) matching the tile owner - A [nationFilter](#nationfilter) matching the tile owner
- Or the filter is a constant string choosing a derived test: - Or the filter is a constant string choosing a derived test:
- `All` - `All`
- `Terrain`
- `Water`, `Land` - `Water`, `Land`
- `Coastal` (at least one direct neighbor is a coast) - `Coastal` (at least one direct neighbor is a coast)
- `River` (as in all 'river on tile' contexts, it means 'adjacent to a river on at least one side') - `River` (as in all 'river on tile' contexts, it means 'adjacent to a river on at least one side')
@ -212,7 +209,7 @@ This indicates the terrain on a single tile. The following values are allowed:
- `Friendly Land` - land belonging to you, or other civs with open borders to you - `Friendly Land` - land belonging to you, or other civs with open borders to you
- `Foreign Land` - any land that isn't friendly land - `Foreign Land` - any land that isn't friendly land
- `Enemy land` - any land belonging to a civ you are at war with - `Enemy land` - any land belonging to a civ you are at war with
- `Water resource`, `Strategic resource`, `Luxury resource`, `Bonus resource` - `Water resource`, `Strategic resource`, `Luxury resource`, `Bonus resource`, `resource`
- `Natural Wonder` (as opposed to above which means testing for a specific Natural Wonder by name, this tests for any of them) - `Natural Wonder` (as opposed to above which means testing for a specific Natural Wonder by name, this tests for any of them)
Please note all of these are _case-sensitive_. Please note all of these are _case-sensitive_.
@ -227,7 +224,7 @@ Any of:
- [terrainFilter](#terrainfilter) for this tile - [terrainFilter](#terrainfilter) for this tile
- [improvementFilter](#improvementfilter) for this tile - [improvementFilter](#improvementfilter) for this tile
- `Improvement` for tiles with any improvements - `Improvement` or `improved` for tiles with any improvements
- `unimproved` for tiles with no improvement - `unimproved` for tiles with no improvement
## terrainQuality ## terrainQuality