I have water generating in my procedraly world using cellular automata. But I want better WorldBuilding. I want to have coastlines built around the water. This can be achieved using autotiling if I was placing tiles manually. How would I do it using ‘‘set_cell()’’
The only I can think of doing it is using if checks all around but it’s too much of a hastle.
Using wave function collapse is also an idea but the problem is the randomization isn’t to my liking. Cellular automata has a density value so I want to use that. I heard that u can use a bitmask but Im familiar with bits so I don’t know what to do.
It all depends on constructing an algorithm that fits what you need.
A coastline is the thin line that separates the sea from the land. Therefore you might need to check the neighbors of a land tile for any sea-tile neighbors. If yes, then the current-tile is infact a coastline-tile. That would be a corrective algorithm when the terrain is already constructed.
There are many ways on how to achieve this which purely depends on the data structure and tile dimensions. From the information presented in your post, I can only give straightforward answers and I suck at math.
It all depends on applying the right rules for the procedural terrain to pick up.
I have 9 biomes I want to generate. Further on I will expand it. The map size is 600x600 tiles.
To generate the biome shape and size, I split the biomes into 9 rectangles which are 200x200. For each rectangle I choose a random center. Then to generate the tiles I Loop through all the positions,get the closest center to the position then set the tile accordingly to the biome. This is the biomes.
To generate the water I’m using an algorithm called cellular automata. Basically we make a custom noise map by setting each position with a random number. You can modify the randomness by a Density value. Basically
For I in range(width * height):
Var random = Randi_range(0,100)
Var density = 60
If random > density:
noise_map.append(0)
Else:
noise_map.append(1)
#0 = water and 1 = land
Now we loop through each position, get the noise value of the neighbors and see which have more land than water. If more neighbors have land than water set the current cell to land. Else set it to water.
So that’s the generation. Now to add the coastlines i have to loop through all the cells and loop through the neighbors and find the right tile to switch land with.
I see, from what I understand you have it completely decoupled from any tileset logic. Your noise_map variable is essentially a really really large array of values 0 or 1.
You can loop through all noise_map entries and then apply our coast line logic.
Forgive my pseudo code.
const MAP_WIDTH: int = 8 # dunno how large your map is
const MAP_HEIGHT: int = 8 # dunno how large your map is
for i in range(0, noise_map.size()):
if noise_map[i] == 1: # Is this a land tile?
var neighbors = get_tile_neighbors(i) # Get neighbors of the land tile.
if neighbors.any(func(num)): num == 0): # Are any neighbors of land tile a sea tile?
noise_map[i] = 2 # The land tile is turned into a shoreline tile
func get_tile_neighbors(index: int) -> Array:
var neighbors: Array = []
if index - MAP_WIDTH >= 0: # Top neighbor
neighbors.append(noise_map[index - MAP_WIDTH])
if not index % MAP_WIDTH-1 == 0: # Right neighbor
neighbors.append(noise_map[index + 1])
[...] for the other neighbors
return neighbors
Thank you for that.Now the only problem is which coastline tile do I set based on the positions. Like do I make it a corner tile or do I make right coastline. So if I didn’t clarify that. That’s my main problem
I am a bit confused and maybe I completely misunderstood the question. I was under the impression that you required a way to effectively distinquish certain tile types. The algorithm that I proposed solely changed all land tiles to coast tiles if it directly touches sea tiles.
As to the question which coastline tile you choose or if there is a need to structure a more detailed coastline, you need to consult your game designer that.
I apologize for not being able to help you out more.