I am creating a turn based game which uses a map generator I made that uses Perlin Noises. I still didn’t put unique features on each map style, but I think it’s getting neat:
(Green/Red Cylinder is the Playing Area)
Earth:
Here is a problem though: How do I make the game choose a spawn point for each player on the area? I mean, I know I can make the game save points where solid terrain were generated and choose them randomly as spawn points, but what if the playing area has mostly water or empty space? A solution I thought could work was to check how much terrain is generated on random places but It would be too expensive for the server to do this.
It’s what I thought but also checking if there is enough solid terrain around the location, but it would take too much time to do so or lag, so I think it wouldn’t be the best option.
Its a 500500 loop to generate all of it. If I check each place for the positions it will take long. An AI for a game I had checked a grid map of 1515 and it already seemed to lag, so I can imagine the effect it should give here.
But I do think I have found a solution. Save positions where the generated terrain height is high enough on a table. Then I iterate only on these positions and check the one that has more of it on their areas. This becomes the place where they will spawn.
Yeah but its so much distance the players should start away from each other that it will loop a lot still. I think I should have made the map chunk based so I could get the chunk with the hugest amount of available spaces.
Okay, I finally figured an idea that will fix this issue:
I can check using the randomseed for some points in the center of the map before it generates, and if most of them are water I use a height compensator to instead generate the entire map higher, and the same if it’s too high, so I can still have some lakes and rivers.
From what I tested the following solution can be made:
When you generate terrain with perlin noise you get a value which you use to generate the terrain height, which varies on x and z coordinates. What I did was check the average height value generated on the playing area, which we can call averageH.
On my generator at least, the best outcome of ground/water proportions happens when the averageH is .6, so we will create a compensation value x = averageH-.6.
Now we can start the world generation, and every time a height value is generated we substract it by x. Example: noiseHeight-=x
This will make so the game always try to generate the map at the desired location closer to the height you want. In my case I wanted it to get closer to a height where it has some islands , which seems to work just fine. (tested about 30 times, and not even once spawned only water).