Random Map Generation 101

Thoughts on the further development of Haven & Hearth? Feel free to opine!

Random Map Generation 101

Postby Peter » Wed Sep 30, 2009 9:38 pm

It does not take much exploration to realize that the H&H world map needs some improvement. Nonetheless, I'm not writing this to change J&L's minds about anything- though I'd be glad if they where interested in using something based on my designs. The point behind this discussion is just a little background on how random maps and images are made for the enlightenment of the general public.

A truly random image would be TV screen static (which is now an anachronism, at least in the US, but I think most readers understand what I mean). That is, each pixel that makes up a random image is completely random- simply rolling a die for each one. This is very different from the so-called "random maps" that are used in games, and both of these are different from truly procedural textures, images, and maps.

In the case of many conventional random maps- and particularly, H&H's current map- the world is defined by features that are plopped, top-down, onto a canvas. This can work well, but has some artifacts. We are familiar with this form of random map; it can be generated quickly, but is completely impossible to expand on-the-fly*. It is simple to code, but looks just as bad as that implies.

Procedural imaging, particularly when used for maps, uses the opposite approach. Using bottom-up rules, a complex image with large-scale features is created.

In essence, it works like this: If you where to transmit an entire picture of a black circle on a white plain, you would have to send a bit of information for each and every pixel in the image. To create this image procedurally, all one would need to do is to simply send this: "For each pixel, find the square root of (this pixel's X co-ord^2 + this pixel's Y co-ord^2). If this is greater than A, color the pixel white, otherwise color it black." Of course, not in those words, but that's the basic thrust of the message one would send.

When that is received, all that needs to be done is run that for each pixel in the image. If you want, you can even enlarge the image by increasing A or move the center of the circle by adding or subtracting from the X and Y co-ords before squaring them.

Now here's a key point that sets Procedural generation apart from conventional random maps: If we where to only run the circle program for, say, the left side of the image, then we would get the left side of the circle, and running it for the right side produces a second image that fits up with the first precisely! In fact, it doesn't matter in what order the pixels are queried in or when; we can only generate every other pixel, then come back three years with a different OS and fill in the rest.

That expandability and seemlessness are the same with any procedural map, though they naturally use larger and more complex instruction sets. In fact, most maps are based on Perlin Noise**, a code that creates a pattern of undulating highs and lows, overlayed over itself several times to create patters rich in detail. This Perlin Noize functions by, for each pixel, figuring out what the four closest pixels with co-ordinates ending in "00" are (so pixel 53:22 is closest to 0:0, 100:0, 100:100, and 0:100) and giving each of those a random value between 1 and 0, based on the position of this "key pixel"***. Then, it averages out those four values based on how far our queried pixel is from these four corners and assigns that value to our pixel. Since it does this for each pixel individually, there is no need for these corner pixels to actually exist!

That is the basic Perlin noise function, and usually it is run over and over again on different scales (for instance, having the corner pixels 10, 100, and 1000 points distant from one another). the closer, smaller scales give sharp detail, while the large, distant ones provide general shape.

Finally, we have defined the value of one pixel of our image or map. At this point, the code is run for however many pixels you like, in any order and any position. The large-scale and the finest details will still line up. It may seem like a lot of calculation, but even a poorly optimized version of that code running in java on this five year old computer can complete a few thousand pixels a minute at least.

We can then take this finished 5000:5000 pixel map and say that all pixels with a value below 0.5 are water, and all those below 0.45 are deep water. Then the remaining land areas can have further maps generated to define dirt and forest and swamp. This is all tweeking and fine-tuning, and is what really makes or breaks the map. There are several ways to interpret this raw procedural height map, but the best one depends on what you are looking to do with the finished map.

At that point you have a basic series of islands and continents. To add stuff like rivers and cliffs, while these can be implemented as a part of the procedural generator, it is often best to have these placed by a simple post-production program of some sort, such as something that randomly places springs and then draws rivers downhill from that point. That and other detail programs are usually better done once an entire area has been generated, so that adjacent terrain can be taken into account.

The point I want to get across about procedural map generation is that compared to conventional generation, it is more difficult to fine-tune, but it creates more realistic and attractive landscapes, it is inherently live-expandable, and it cures fail in 98% of test maps.

--------------------------------------------------------------------------------------------------

*As an aside, the current world with the ability to add new land mass onto the edges is a bit of a workaround of this- each new megagrid is an entirely new random map- but note that this means that rivers, forests, and other features cannot cross the borders between areas, and because of that all edges will always have to be the default type. Thus, multi-multigrid seas will remain impossible without some re-engineering.

**Perlin noise is actually the little brother of the significantly smoother and efficient Simplex noise. Perlin is a bit simpler, though.

***That is, the random number is seeded with the sum of the co-ordinates, or the sum of random numbers seeded by the co-ordinates.

Examples:
Image
Image
Image

Some more examples of Procedurally generated maps are available in my earlier thread.
Last edited by Peter on Tue Oct 26, 2010 8:59 pm, edited 1 time in total.
Surprise.
User avatar
Peter
 
Posts: 1491
Joined: Thu Jun 04, 2009 3:36 am

Re: Random Map Generation 101

Postby Fluffy » Wed Sep 30, 2009 10:02 pm

Those last 2 pictures are pure epic. I'd love to see a supergrid based off of those two.
Your ad here
User avatar
Fluffy
 
Posts: 363
Joined: Wed Aug 12, 2009 5:16 am

Re: Random Map Generation 101

Postby sabinati » Wed Sep 30, 2009 10:11 pm

now if you could minimize the very small areas of terrain, add in mountain, 3 kinds of swamp and 3 kinds of grassland, make it draw sensible rivers you'd really have something.
User avatar
sabinati
 
Posts: 15513
Joined: Mon Jul 13, 2009 4:25 am
Location: View active topics

Re: Random Map Generation 101

Postby Peter » Wed Sep 30, 2009 10:23 pm

Adding terrain types is as easy, if not easier, than with top-down generation.

As I said in the OP, river drawing and minima removal (one- and two-tile islands and lakes) is best done on a large scale. I would suggest that points are selected to be springs and then have rivers grow in a random direction weighted by the decrease in elevation in that direction- in other words, draw rivers downhill. Add something that will connect tributaries and then you'll have maps with rivers that are about one hundred zillion times better than the current ones.

As for minima, that is very easy to post process out of the image or map, though small sandbar islands or little tidepools or puddles aren't extremely objectionable.

I wanted to mention that since the terrain is inherently defined by the xy coords of a point, then there is no need to actually save what the terrain originally was in some place; just run the worldgen routine for that single tile/pixel (I admit I've used the terms interchangeably) and it will be what it was before.
Surprise.
User avatar
Peter
 
Posts: 1491
Joined: Thu Jun 04, 2009 3:36 am

Re: Random Map Generation 101

Postby Fluffy » Wed Sep 30, 2009 10:40 pm

Peter wrote:I wanted to mention that since the terrain is inherently defined by the xy coords of a point, then there is no need to actually save what the terrain originally was in some place; just run the worldgen routine for that single tile/pixel (I admit I've used the terms interchangeably) and it will be what it was before.


Which would allow for Loftar to make destroyable bridges without loosing the water underneath, right?
Your ad here
User avatar
Fluffy
 
Posts: 363
Joined: Wed Aug 12, 2009 5:16 am

Re: Random Map Generation 101

Postby Pacho » Wed Sep 30, 2009 10:53 pm

Sounds about right.
Pacho
 
Posts: 712
Joined: Wed Jun 10, 2009 2:21 am

Re: Random Map Generation 101

Postby theTrav » Wed Sep 30, 2009 11:28 pm

Please oh please Loftar, if you have to spend a month doing it it'd be worth it. A realistic, pleasing world layout would be the bees knees if not indeed the cats pyjamas. I am incredibly surprised that you haven't taken an interest in this form of generation already given the awesome mathsiness of it.
User avatar
theTrav
 
Posts: 3464
Joined: Fri May 29, 2009 11:25 pm

Re: Random Map Generation 101

Postby Peter » Thu Oct 01, 2009 5:08 pm

Indeed, such a feature would be the goat's ears, the chicken's shoes, and perhaps even the elephant's wallet.

However, it wouldn't be very useful for bridges because it would still leave some issues- such as having boats and swimmers cross under a bridge and walkers and carts cross over a bridge- open. I think that covered bridges are the way to go, at least at first. Then it's internal space and everybody's happy.

The alternative is to make it possible for multiple floor grids to interact, so you can have bridges over water. This would also allow for shooting out of houses, and let's not forget simply standing on deck of a boat.

If I ever get a chance to work on it, I'll put up a new map with all the new tile types. Of course, my maps aren't directly importable, so think of them as concept art.

That said, it IS good for decay. You can have a tile hit by a decay pulse simply have a chance to become whatever it once was... though things like rivers and minima correction might still interfere with this.
Surprise.
User avatar
Peter
 
Posts: 1491
Joined: Thu Jun 04, 2009 3:36 am

Re: Random Map Generation 101

Postby Gauteamus » Thu Oct 01, 2009 7:42 pm

Thanks for making this thread, Peter. Great reading!
Actually I have been thinking alot on mapmaking the last few days myself, also primarily as a sort of fan fic.
One thing I would find interesting is a list of properties a H&H map must have (as seen from the audience, not behind-the-scene-stuff like data storage)

As a beginning: What types of terrain are there, and what is the difference between, say, the different kinds of marsh?
Please help me expand:

Grassland
Heath (multiple types? - any thoughts on what set them apart, except for colour?)
Forest
-Conifer
-Broadleaf
Swamp (multiple types? how many?)
Clayflats/Dirt
Sand/Beach
Water
-Shallow
-Deep
Mountain (different types?)
Road/Paved

I am sure I missed some
Image<<Bottleneck>>
What if Rosa Parks had a car?
User avatar
Gauteamus
 
Posts: 858
Joined: Fri May 29, 2009 7:16 pm


Return to Critique & Ideas

Who is online

Users browsing this forum: Claude [Bot] and 2 guests