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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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] */
fun matchesFilter(filter: String, civInfo: Civilization? = null): Boolean {
if (matchesTerrainFilter(filter, civInfo)) return true
if (improvement != null && !improvementIsPillaged && ruleset.tileImprovements[improvement]!!.matchesFilter(filter)) return true
return improvement == null && filter == "unimproved"
if ((improvement == null || improvementIsPillaged) && filter == "unimproved") return true
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 {
@ -495,7 +496,7 @@ 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" -> true
"All", "Terrain" -> true
baseTerrain -> true
"Water" -> isWater
"Land" -> isLand
@ -510,6 +511,7 @@ open class Tile : IsPartOfGameInfoSerialization {
"Enemy Land", "Enemy" -> observingCiv != null && isEnemyTerritory(observingCiv)
resource -> observingCiv != null && hasViewableResource(observingCiv)
"resource" -> observingCiv != null && hasViewableResource(observingCiv)
"Water resource" -> isWater && observingCiv != null && hasViewableResource(observingCiv)
"Natural Wonder" -> naturalWonder != null
"Featureless" -> terrainFeatures.isEmpty()

View File

@ -307,9 +307,9 @@ 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",
Constants.coastal, Constants.river, "Open terrain", "Rough terrain", "Water resource",
"Foreign Land", "Foreign", "Friendly Land", "Friendly", "Enemy Land", "Enemy",
"All", "Terrain",
Constants.coastal, Constants.river, "Open terrain", "Rough terrain", "Water resource",
"resource", "Foreign Land", "Foreign", "Friendly Land", "Friendly", "Enemy Land", "Enemy",
"Featureless", Constants.freshWaterFilter, "non-fresh water", "Natural Wonder",
"Impassable", "Land", "Water"
) +
@ -337,7 +337,7 @@ enum class UniqueParameterType(
/** 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") {
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):
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.
- `All`
- `City-states`
- `Major`
- `Human player`
- `AI player`
- Nation name
- A unique a Nation has (verbatim, no placeholders)
- [nationFilter](#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
- Or the filter is a constant string choosing a derived test:
- `All`
- `Terrain`
- `Water`, `Land`
- `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')
@ -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
- `Foreign Land` - any land that isn't friendly land
- `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)
Please note all of these are _case-sensitive_.
@ -227,7 +224,7 @@ Any of:
- [terrainFilter](#terrainfilter) 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
## terrainQuality