mirror of
https://github.com/yairm210/Unciv.git
synced 2024-12-22 22:54:44 +07:00
Resolved #12572 - "Stats from tiles" uniques work with terrain + improvement filter combos
This commit is contained in:
parent
3194af64d4
commit
d0a3b37f74
@ -469,15 +469,14 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 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, ignoreImprovement: Boolean = false): Boolean {
|
fun matchesFilter(filter: String, civInfo: Civilization? = null): Boolean {
|
||||||
return MultiFilter.multiFilter(filter, { matchesSingleFilter(it, civInfo, ignoreImprovement) })
|
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 (matchesSingleTerrainFilter(filter, civInfo)) return true
|
||||||
if ((improvement == null || improvementIsPillaged) && filter == "unimproved") return true
|
if ((improvement == null || improvementIsPillaged) && filter == "unimproved") return true
|
||||||
if (improvement != null && !improvementIsPillaged && filter == "improved") return true
|
if (improvement != null && !improvementIsPillaged && filter == "improved") return true
|
||||||
if (ignoreImprovement) return false
|
|
||||||
if (getUnpillagedTileImprovement()?.matchesFilter(filter, stateThisTile, false) == true) return true
|
if (getUnpillagedTileImprovement()?.matchesFilter(filter, stateThisTile, false) == true) return true
|
||||||
return getUnpillagedRoadImprovement()?.matchesFilter(filter, stateThisTile, false) == true
|
return getUnpillagedRoadImprovement()?.matchesFilter(filter, stateThisTile, false) == true
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,10 @@ class TileStatFunctions(val tile: Tile) {
|
|||||||
|
|
||||||
for (unique in statsFromTilesUniques + statsFromObjectsUniques + statsFromTilesWithoutUniques) {
|
for (unique in statsFromTilesUniques + statsFromObjectsUniques + statsFromTilesWithoutUniques) {
|
||||||
val tileType = unique.params[1]
|
val tileType = unique.params[1]
|
||||||
if (tile.matchesFilter(tileType, observingCiv, true))
|
if (improvement != null && improvement.matchesFilter(tileType, stateForConditionals))
|
||||||
listOfStats.add("{${unique.sourceObjectName}} ({${unique.getDisplayText()}})" to unique.stats)
|
|
||||||
else if (improvement != null && improvement.matchesFilter(tileType, stateForConditionals))
|
|
||||||
improvementStats.add(unique.stats)
|
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))
|
else if (road != null && road.matchesFilter(tileType, stateForConditionals))
|
||||||
roadStats.add(unique.stats)
|
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() }
|
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 {
|
private fun missingFromMinimum(current: Stats, minimumStats: Stats): Stats {
|
||||||
// Note: Not `for ((stat, value) in other)` - that would skip zero values
|
// Note: Not `for ((stat, value) in other)` - that would skip zero values
|
||||||
val missingStats = Stats()
|
val missingStats = Stats()
|
||||||
@ -184,10 +184,10 @@ class TileStatFunctions(val tile: Tile) {
|
|||||||
val roadStats = Stats()
|
val roadStats = Stats()
|
||||||
|
|
||||||
fun addStats(filter: String, stat: Stat, amount: Float) {
|
fun addStats(filter: String, stat: Stat, amount: Float) {
|
||||||
if (tile.matchesFilter(filter, observingCiv, true))
|
if (improvement != null && improvement.matchesFilter(filter, stateForConditionals))
|
||||||
terrainStats.add(stat, amount)
|
|
||||||
else if (improvement != null && improvement.matchesFilter(filter, stateForConditionals))
|
|
||||||
improvementStats.add(stat, amount)
|
improvementStats.add(stat, amount)
|
||||||
|
else if (tile.matchesFilter(filter, observingCiv))
|
||||||
|
terrainStats.add(stat, amount)
|
||||||
else if (road != null && road.matchesFilter(filter, stateForConditionals))
|
else if (road != null && road.matchesFilter(filter, stateForConditionals))
|
||||||
roadStats.add(stat, amount)
|
roadStats.add(stat, amount)
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,19 @@ class GlobalUniquesTests {
|
|||||||
Assert.assertTrue(tile2.stats.getTileStats(city, civInfo).gold == 4f)
|
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
|
@Test
|
||||||
fun statsFromTilesWithout() {
|
fun statsFromTilesWithout() {
|
||||||
game.makeHexagonalMap(3)
|
game.makeHexagonalMap(3)
|
||||||
|
Loading…
Reference in New Issue
Block a user