mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-10 23:37:31 +07:00
Copy all terrain features on clone(), not just first
Use terrainFeatures in naturalWonderGenerator
This commit is contained in:
parent
c7e424d661
commit
9eaf4f4826
@ -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
|
||||
|
@ -50,6 +50,7 @@ open class TileInfo {
|
||||
var position: Vector2 = Vector2.Zero
|
||||
lateinit var baseTerrain: String
|
||||
val terrainFeatures: ArrayList<String> = 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)
|
||||
}
|
||||
|
@ -61,9 +61,9 @@ class NaturalWonderGenerator(val ruleset: Ruleset) {
|
||||
private fun trySpawnOnSuitableLocation(suitableLocations: List<TileInfo>, 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()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user