mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-23 21:22:39 +07:00
Coast spread algorithm (#10741)
* new algo for coast placement * optimization? * change default max coast extension * put spreadcoast in a function * default change back, nextBoolean() and for loop
This commit is contained in:
parent
af4dea60e0
commit
3797817291
@ -238,6 +238,31 @@ class MapGenerator(val ruleset: Ruleset, private val coroutineScope: CoroutineSc
|
||||
}
|
||||
}
|
||||
|
||||
private fun spreadCoast(map: TileMap) {
|
||||
for (i in 1..map.mapParameters.maxCoastExtension) {
|
||||
val toCoast = mutableListOf<Tile>()
|
||||
for (tile in map.values.filter { it.baseTerrain == Constants.ocean }) {
|
||||
val tilesInDistance = tile.getTilesInDistance(1)
|
||||
for (neighborTile in tilesInDistance) {
|
||||
if (neighborTile.isLand) {
|
||||
toCoast.add(tile)
|
||||
break
|
||||
} else if (neighborTile.baseTerrain == Constants.coast) {
|
||||
val randbool = randomness.RNG.nextBoolean()
|
||||
if (randbool) {
|
||||
toCoast.add(tile)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
for (tile in toCoast) {
|
||||
tile.baseTerrain = Constants.coast
|
||||
tile.setTransients()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun spawnLakesAndCoasts(map: TileMap) {
|
||||
|
||||
if (ruleset.terrains.containsKey(Constants.lakes)) {
|
||||
@ -277,14 +302,7 @@ class MapGenerator(val ruleset: Ruleset, private val coroutineScope: CoroutineSc
|
||||
|
||||
//Coasts
|
||||
if (ruleset.terrains.containsKey(Constants.coast)) {
|
||||
for (tile in map.values.filter { it.baseTerrain == Constants.ocean }) {
|
||||
val coastLength =
|
||||
max(1, randomness.RNG.nextInt(max(1, map.mapParameters.maxCoastExtension)))
|
||||
if (tile.getTilesInDistance(coastLength).any { it.isLand }) {
|
||||
tile.baseTerrain = Constants.coast
|
||||
tile.setTransients()
|
||||
}
|
||||
}
|
||||
spreadCoast(map)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user