From 9eaf4f4826377f0c659cc7d38f703777a4c3bf7a Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 11 Mar 2021 21:58:24 +0200 Subject: [PATCH] Copy all terrain features on clone(), not just first Use terrainFeatures in naturalWonderGenerator --- core/src/com/unciv/logic/GameInfo.kt | 2 +- core/src/com/unciv/logic/map/TileInfo.kt | 9 ++++-- .../mapgenerator/NaturalWonderGenerator.kt | 29 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index 5e5d3080df..3233982a42 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -206,7 +206,7 @@ class GameInfo { val tilesWithin3ofExistingEncampment = existingEncampments.asSequence() .flatMap { it.getTilesInDistance(3) }.toSet() val viableTiles = tileMap.values.filter { - it.isLand && it.terrainFeature == null + it.isLand && it.terrainFeatures.isEmpty() && !it.isImpassible() && it !in tilesWithin3ofExistingEncampment && it !in allViewableTiles diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 1afc20ebfb..c30cb88d21 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -50,6 +50,7 @@ open class TileInfo { var position: Vector2 = Vector2.Zero lateinit var baseTerrain: String val terrainFeatures: ArrayList = ArrayList() + @Transient // So it won't be serialized from now on var terrainFeature: String? = null get() = terrainFeatures.firstOrNull() ?: field //if terrainFeatures contains no terrainFeature maybe one got deserialized to field set(value) { @@ -86,7 +87,8 @@ open class TileInfo { for (airUnit in airUnits) toReturn.airUnits.add(airUnit.clone()) toReturn.position = position.cpy() toReturn.baseTerrain = baseTerrain - toReturn.terrainFeature = terrainFeature +// toReturn.terrainFeature = terrainFeature + toReturn.terrainFeatures.addAll(terrainFeatures) toReturn.naturalWonder = naturalWonder toReturn.resource = resource toReturn.improvement = improvement @@ -361,7 +363,7 @@ open class TileInfo { } } - fun cimatchesUniqueFilter(filter: String, civInfo: CivilizationInfo?=null): Boolean { + fun matchesUniqueFilter(filter: String, civInfo: CivilizationInfo?=null): Boolean { return filter == baseTerrain || filter == Constants.hill && isHill() || filter == "River" && isAdjacentToRiver() @@ -533,8 +535,9 @@ open class TileInfo { //region state-changing functions fun setTransients() { - if (terrainFeatures.firstOrNull() == null && terrainFeature != null)// -> terranFeature getter returns terrainFeature field + if (terrainFeatures.firstOrNull() == null && terrainFeature != null) {// -> terranFeature getter returns terrainFeature field terrainFeature = terrainFeature // getter returns field, setter calls terrainFeatures.add() + } setTerrainTransients() setUnitTransients(true) } diff --git a/core/src/com/unciv/logic/map/mapgenerator/NaturalWonderGenerator.kt b/core/src/com/unciv/logic/map/mapgenerator/NaturalWonderGenerator.kt index e50a680212..d95041c734 100644 --- a/core/src/com/unciv/logic/map/mapgenerator/NaturalWonderGenerator.kt +++ b/core/src/com/unciv/logic/map/mapgenerator/NaturalWonderGenerator.kt @@ -61,9 +61,9 @@ class NaturalWonderGenerator(val ruleset: Ruleset) { private fun trySpawnOnSuitableLocation(suitableLocations: List, wonder: Terrain): TileInfo? { if (suitableLocations.isNotEmpty()) { val location = suitableLocations.random() + clearTile(location) location.naturalWonder = wonder.name location.baseTerrain = wonder.turnsInto!! - location.terrainFeature = null return location } @@ -146,17 +146,13 @@ class NaturalWonderGenerator(val ruleset: Ruleset) { val location = trySpawnOnSuitableLocation(suitableLocations, wonder) if (location != null) { - val location2 = location.neighbors + val possibleLocations = location.neighbors .filter { it.resource == null && it.improvement == null && wonder.occursOn.contains(it.getLastTerrain().name) && it.neighbors.all { it.isWater } - } - .toList().random() - - location2.naturalWonder = wonder.name - location2.baseTerrain = wonder.turnsInto!! - location2.terrainFeature = null + }.toList() + trySpawnOnSuitableLocation(possibleLocations, wonder) } } @@ -178,10 +174,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset) { for (tile in location.neighbors) { if (tile.baseTerrain == Constants.coast) continue tile.baseTerrain = Constants.coast - tile.terrainFeature = null - tile.resource = null - tile.improvement = null - tile.setTerrainTransients() + clearTile(tile) } } } @@ -214,10 +207,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset) { } tile.baseTerrain = Constants.coast - tile.terrainFeature = null - tile.resource = null - tile.improvement = null - tile.setTerrainTransients() + clearTile(tile) } } } @@ -284,4 +274,11 @@ class NaturalWonderGenerator(val ruleset: Ruleset) { trySpawnOnSuitableLocation(suitableLocations, wonder) } + + private fun clearTile(tile: TileInfo){ + tile.terrainFeatures.clear() + tile.resource = null + tile.improvement = null + tile.setTerrainTransients() + } } \ No newline at end of file