Advertisement

Random Map Generation

Started by October 03, 2003 11:21 AM
24 comments, last by psyjax 21 years, 4 months ago
The code for my 2d ant map generator (which, by the way, I never ended up doing anything useful with) worked something like this:

// Random ant walk starting at middle of ''grid,''// an array of bools initialized to ''false.''unsigned int dir = rand(0, 3);unsigned int antX = GRID_X/2;unsigned int antY = GRID_Y/2;for(unsigned int i = 0; i < NUM_ITERATIONS; ++i){    grid[antX][antY] = true;    if(rand(0, 100) > PROB_TURN_PERCENT)    {        dir = rand(0, 3);    }    switch(dir)    {        case 0:           ++antX;           break;        case 1:           --antX;           break;        case 2:           ++antY;           break;        case 3:           --antY;           break;    }    //TODO: Add code to prevent ant from walking    // off grid, or to make it wrap around.} 


Note that there''s nothing to stop an ant from going where it has already been.

With a low PROB_TURN_PERCENT you get more paths, which are generally straighter, and fewer, smaller rooms. Larger PROB_TURN_PERCENT values give shorter, more twisting paths, and larger rooms. A large PROB_TURN_PERCENT will produce what appear to be continents linked together by one or more isthmi. Use more than one ant if you want seperate islands.
When I tried that erosion stuff some months ago, the results didn''t exactly impress me. The best results I had were with a different method. Basically, I''d fill the borders with water tiles and then work from there, assuming, that a certain terrain type would have a certain chance to appear after another.

For example, if the tile to the left is a water tile, the next one might have a chance of 75% of being water as well, 15% grass, 7% Wood and 3% Mountain. I''d add this for the tile on the left and on top of the current one and then randomly select one based on these chances. I did that for the whole map, and after that, I just tried to correct things like single pieces (by setting them to the type of terrain it was surrounded by), and voilà, I had a pretty nice map.
That way, it was also very easy to tweak how much of each type was there. I hope that explanation was clear enough... Guess I''m not too good at explaining things.
Advertisement
Hey all!

I used the fractal cloud algorithem and got some great results!

Here is a litte mock up version I did using DragonWarrior tiles

http://www.starmars.com/fractal.png

The actuall game will be OpenGL isometric.

Anyway, right now it makes great "coastline" maps. Countinents like the middle east etc. with mediterenian like gulphs.

One thing I don't like is the way trees band around mountains, and the way mountains cluster up. I know this is an inherent drawback to a heightmap but can anyone suggest a work around?

Also, How should I go about clustering the land tword the center to make one big island?

Thanks for all the help!

[edited by - psyjax on October 16, 2003 2:11:08 AM]
quote:
Original post by psyjax
Also, How should I go about clustering the land tword the center to make one big island?

this is the only problem i see with this method. it looks neat as hell, but very seldom do i get anything that could be used as a continent or island.

does anyone know ways to make it do this?

obviously i could take a continent-shaped heightmap and add them together and re-normalize, but then i need pre-defined continent shapes which defeats the whole purpose of randomly generating the land.

[edited by - krez on October 16, 2003 9:30:43 PM]
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
psyjax -

About your tree and mountain clustering - this is what I''m going to be doing for a TBS I''m creating. The way I see it is you have different layers to the terrain creating process, all involving different cloud generation height maps. First height map is for basic terrain such as ocean, coasline, grass, desert, etc. Another height map for trees, where only parts of the height map that are heigh enough and would be on a terrain tile that isn''t water. And then another layer for the mountains, doing the same thing as with the tree layer.
Unfortunatly, the AP beat me to it. :x

But yes, the general idea would be to use multiple maps for various purposes. Just create a height map (water -> sand -> grass -> hills -> mountains), a forest map, a desert map... superimpose them and enforce rules (ie, desert and forest can only be generated on grass or hills) then you''re pretty much set. Better yet, you could add a snow layer generated only on mountains. There might even be a quick and dirty way to add rivers like this...

As for continents, an interesting approach I''ve found is to create multiple sections in your map. Select a few rectangular regions here and there (making sure they do cover your map) and generate in them. It''s very easy to create islands using this method if you set a few starting pixels (tiles, actually, in your case) so you could have control over where continents are generated like this.

If you like this method, have a look at some of the more advanced methods, like perlin noise or fault generation. Both give pretty neat results, especially perlin noise IMHO.

This topic is closed to new replies.

Advertisement