mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 15:01:09 -04: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()
|
val tilesWithin3ofExistingEncampment = existingEncampments.asSequence()
|
||||||
.flatMap { it.getTilesInDistance(3) }.toSet()
|
.flatMap { it.getTilesInDistance(3) }.toSet()
|
||||||
val viableTiles = tileMap.values.filter {
|
val viableTiles = tileMap.values.filter {
|
||||||
it.isLand && it.terrainFeature == null
|
it.isLand && it.terrainFeatures.isEmpty()
|
||||||
&& !it.isImpassible()
|
&& !it.isImpassible()
|
||||||
&& it !in tilesWithin3ofExistingEncampment
|
&& it !in tilesWithin3ofExistingEncampment
|
||||||
&& it !in allViewableTiles
|
&& it !in allViewableTiles
|
||||||
|
@ -50,6 +50,7 @@ open class TileInfo {
|
|||||||
var position: Vector2 = Vector2.Zero
|
var position: Vector2 = Vector2.Zero
|
||||||
lateinit var baseTerrain: String
|
lateinit var baseTerrain: String
|
||||||
val terrainFeatures: ArrayList<String> = ArrayList()
|
val terrainFeatures: ArrayList<String> = ArrayList()
|
||||||
|
@Transient // So it won't be serialized from now on
|
||||||
var terrainFeature: String? = null
|
var terrainFeature: String? = null
|
||||||
get() = terrainFeatures.firstOrNull() ?: field //if terrainFeatures contains no terrainFeature maybe one got deserialized to field
|
get() = terrainFeatures.firstOrNull() ?: field //if terrainFeatures contains no terrainFeature maybe one got deserialized to field
|
||||||
set(value) {
|
set(value) {
|
||||||
@ -86,7 +87,8 @@ open class TileInfo {
|
|||||||
for (airUnit in airUnits) toReturn.airUnits.add(airUnit.clone())
|
for (airUnit in airUnits) toReturn.airUnits.add(airUnit.clone())
|
||||||
toReturn.position = position.cpy()
|
toReturn.position = position.cpy()
|
||||||
toReturn.baseTerrain = baseTerrain
|
toReturn.baseTerrain = baseTerrain
|
||||||
toReturn.terrainFeature = terrainFeature
|
// toReturn.terrainFeature = terrainFeature
|
||||||
|
toReturn.terrainFeatures.addAll(terrainFeatures)
|
||||||
toReturn.naturalWonder = naturalWonder
|
toReturn.naturalWonder = naturalWonder
|
||||||
toReturn.resource = resource
|
toReturn.resource = resource
|
||||||
toReturn.improvement = improvement
|
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
|
return filter == baseTerrain
|
||||||
|| filter == Constants.hill && isHill()
|
|| filter == Constants.hill && isHill()
|
||||||
|| filter == "River" && isAdjacentToRiver()
|
|| filter == "River" && isAdjacentToRiver()
|
||||||
@ -533,8 +535,9 @@ open class TileInfo {
|
|||||||
|
|
||||||
//region state-changing functions
|
//region state-changing functions
|
||||||
fun setTransients() {
|
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()
|
terrainFeature = terrainFeature // getter returns field, setter calls terrainFeatures.add()
|
||||||
|
}
|
||||||
setTerrainTransients()
|
setTerrainTransients()
|
||||||
setUnitTransients(true)
|
setUnitTransients(true)
|
||||||
}
|
}
|
||||||
|
@ -61,9 +61,9 @@ class NaturalWonderGenerator(val ruleset: Ruleset) {
|
|||||||
private fun trySpawnOnSuitableLocation(suitableLocations: List<TileInfo>, wonder: Terrain): TileInfo? {
|
private fun trySpawnOnSuitableLocation(suitableLocations: List<TileInfo>, wonder: Terrain): TileInfo? {
|
||||||
if (suitableLocations.isNotEmpty()) {
|
if (suitableLocations.isNotEmpty()) {
|
||||||
val location = suitableLocations.random()
|
val location = suitableLocations.random()
|
||||||
|
clearTile(location)
|
||||||
location.naturalWonder = wonder.name
|
location.naturalWonder = wonder.name
|
||||||
location.baseTerrain = wonder.turnsInto!!
|
location.baseTerrain = wonder.turnsInto!!
|
||||||
location.terrainFeature = null
|
|
||||||
return location
|
return location
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,17 +146,13 @@ class NaturalWonderGenerator(val ruleset: Ruleset) {
|
|||||||
|
|
||||||
val location = trySpawnOnSuitableLocation(suitableLocations, wonder)
|
val location = trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
val location2 = location.neighbors
|
val possibleLocations = location.neighbors
|
||||||
.filter {
|
.filter {
|
||||||
it.resource == null && it.improvement == null
|
it.resource == null && it.improvement == null
|
||||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||||
&& it.neighbors.all { it.isWater }
|
&& it.neighbors.all { it.isWater }
|
||||||
}
|
}.toList()
|
||||||
.toList().random()
|
trySpawnOnSuitableLocation(possibleLocations, wonder)
|
||||||
|
|
||||||
location2.naturalWonder = wonder.name
|
|
||||||
location2.baseTerrain = wonder.turnsInto!!
|
|
||||||
location2.terrainFeature = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,10 +174,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset) {
|
|||||||
for (tile in location.neighbors) {
|
for (tile in location.neighbors) {
|
||||||
if (tile.baseTerrain == Constants.coast) continue
|
if (tile.baseTerrain == Constants.coast) continue
|
||||||
tile.baseTerrain = Constants.coast
|
tile.baseTerrain = Constants.coast
|
||||||
tile.terrainFeature = null
|
clearTile(tile)
|
||||||
tile.resource = null
|
|
||||||
tile.improvement = null
|
|
||||||
tile.setTerrainTransients()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,10 +207,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tile.baseTerrain = Constants.coast
|
tile.baseTerrain = Constants.coast
|
||||||
tile.terrainFeature = null
|
clearTile(tile)
|
||||||
tile.resource = null
|
|
||||||
tile.improvement = null
|
|
||||||
tile.setTerrainTransients()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,4 +274,11 @@ class NaturalWonderGenerator(val ruleset: Ruleset) {
|
|||||||
|
|
||||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun clearTile(tile: TileInfo){
|
||||||
|
tile.terrainFeatures.clear()
|
||||||
|
tile.resource = null
|
||||||
|
tile.improvement = null
|
||||||
|
tile.setTerrainTransients()
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user