Resolved #12572 - "Stats from tiles" uniques work with terrain + improvement filter combos

This commit is contained in:
yairm210 2024-12-05 22:19:15 +02:00
parent 3194af64d4
commit d0a3b37f74
3 changed files with 23 additions and 11 deletions

View File

@ -469,15 +469,14 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
}
/** Implements [UniqueParameterType.TileFilter][com.unciv.models.ruleset.unique.UniqueParameterType.TileFilter] */
fun matchesFilter(filter: String, civInfo: Civilization? = null, ignoreImprovement: Boolean = false): Boolean {
return MultiFilter.multiFilter(filter, { matchesSingleFilter(it, civInfo, ignoreImprovement) })
fun matchesFilter(filter: String, civInfo: Civilization? = null): Boolean {
return MultiFilter.multiFilter(filter, { matchesSingleFilter(it, civInfo) })
}
private fun matchesSingleFilter(filter: String, civInfo: Civilization? = null, ignoreImprovement: Boolean = false): Boolean {
private fun matchesSingleFilter(filter: String, civInfo: Civilization? = null): Boolean {
if (matchesSingleTerrainFilter(filter, civInfo)) return true
if ((improvement == null || improvementIsPillaged) && filter == "unimproved") return true
if (improvement != null && !improvementIsPillaged && filter == "improved") return true
if (ignoreImprovement) return false
if (getUnpillagedTileImprovement()?.matchesFilter(filter, stateThisTile, false) == true) return true
return getUnpillagedRoadImprovement()?.matchesFilter(filter, stateThisTile, false) == true
}

View File

@ -76,10 +76,10 @@ class TileStatFunctions(val tile: Tile) {
for (unique in statsFromTilesUniques + statsFromObjectsUniques + statsFromTilesWithoutUniques) {
val tileType = unique.params[1]
if (tile.matchesFilter(tileType, observingCiv, true))
listOfStats.add("{${unique.sourceObjectName}} ({${unique.getDisplayText()}})" to unique.stats)
else if (improvement != null && improvement.matchesFilter(tileType, stateForConditionals))
if (improvement != null && improvement.matchesFilter(tileType, stateForConditionals))
improvementStats.add(unique.stats)
else if (tile.matchesFilter(tileType, observingCiv))
listOfStats.add("{${unique.sourceObjectName}} ({${unique.getDisplayText()}})" to unique.stats)
else if (road != null && road.matchesFilter(tileType, stateForConditionals))
roadStats.add(unique.stats)
}
@ -129,7 +129,7 @@ class TileStatFunctions(val tile: Tile) {
return listOfStats.filter { !it.second.isEmpty() }.map { it.first to it.second.clone() }
}
/** Ensures each stat is >= [other].stat - modifies in place */
/** Ensures each stat is >= [minimumStats].stat - modifies in place */
private fun missingFromMinimum(current: Stats, minimumStats: Stats): Stats {
// Note: Not `for ((stat, value) in other)` - that would skip zero values
val missingStats = Stats()
@ -184,10 +184,10 @@ class TileStatFunctions(val tile: Tile) {
val roadStats = Stats()
fun addStats(filter: String, stat: Stat, amount: Float) {
if (tile.matchesFilter(filter, observingCiv, true))
terrainStats.add(stat, amount)
else if (improvement != null && improvement.matchesFilter(filter, stateForConditionals))
if (improvement != null && improvement.matchesFilter(filter, stateForConditionals))
improvementStats.add(stat, amount)
else if (tile.matchesFilter(filter, observingCiv))
terrainStats.add(stat, amount)
else if (road != null && road.matchesFilter(filter, stateForConditionals))
roadStats.add(stat, amount)
}

View File

@ -133,6 +133,19 @@ class GlobalUniquesTests {
Assert.assertTrue(tile2.stats.getTileStats(city, civInfo).gold == 4f)
}
@Test
fun statsFromTilesMultifilter() {
game.makeHexagonalMap(2)
val civInfo = game.addCiv()
val city = game.addCity(civInfo, game.getTile(Vector2.Zero), true)
val building = game.createBuilding("[+4 Gold] from [{${Constants.grassland}} {Farm}] tiles [in all cities]")
city.cityConstructions.addBuilding(building)
val tile2 = game.setTileTerrain(Vector2(0f,1f), Constants.grassland)
tile2.setImprovement("Farm")
Assert.assertTrue(tile2.stats.getTileStats(city, civInfo).gold == 4f)
}
@Test
fun statsFromTilesWithout() {
game.makeHexagonalMap(3)