From ec0cf575f40764b1c677d964abe109e6f81f8a2e Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 26 Jan 2024 15:15:16 +0200 Subject: [PATCH] Avoid modifying the ruleset object and unique stats (#11014) --- core/src/com/unciv/logic/map/tile/TileStatFunctions.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/logic/map/tile/TileStatFunctions.kt b/core/src/com/unciv/logic/map/tile/TileStatFunctions.kt index 8f5180937b..2eb1b05780 100644 --- a/core/src/com/unciv/logic/map/tile/TileStatFunctions.kt +++ b/core/src/com/unciv/logic/map/tile/TileStatFunctions.kt @@ -38,7 +38,7 @@ class TileStatFunctions(val tile: Tile) { val percentageStats = getTilePercentageStats(observingCiv, city, localUniqueCache) for (stats in statsBreakdown) { - val tileType = when(stats.first) { + val tileType = when (stats.first) { improvement -> "Improvement" road.name -> "Road" else -> "Terrain" @@ -121,11 +121,12 @@ class TileStatFunctions(val tile: Tile) { val statsFromMinimum = missingFromMinimum(listOfStats.toStats(), minimumStats) listOfStats.add("Minimum" to statsFromMinimum) - if (observingCiv != null && + if (observingCiv != null && listOfStats.toStats().gold != 0f && observingCiv.goldenAges.isGoldenAge()) listOfStats.add("Golden Age" to Stats(gold = 1f)) - return listOfStats.filter { !it.second.isEmpty() } + // To ensure that the original stats (in uniques, terrains, etc) are not modified in getTileStats, we clone them all + return listOfStats.filter { !it.second.isEmpty() }.map { it.first to it.second.clone() } } /** Ensures each stat is >= [other].stat - modifies in place */ @@ -180,7 +181,7 @@ class TileStatFunctions(val tile: Tile) { val road = tile.getUnpillagedRoadImprovement() val roadStats = Stats() - + fun addStats(filter: String, stat: Stat, amount: Float) { if (tile.matchesFilter(filter, observingCiv, true)) terrainStats.add(stat, amount)