Game Development Community

Map Generation based on Seed

by Travis Evans · in Torque Game Builder · 03/17/2009 (8:41 am) · 13 replies

My buddies and I are working on an RTS and one thing that we are trying to add in is a Random Map Generator based off a Number Seed. I did a search and filtered for TGB and Resources but didn't find what I'm looking for. I'm wondering if any one has an idea how to generate a map based off a number.

What I'm looking to do is create my land where I have some bodies of water and some stone or mineral mine. But I have no idea where to even start.

I'm also looking at getting TGB Pro so any solutions requiring source modifications are welcome too.


Thanks

#1
03/17/2009 (11:44 am)
You mean like Civilization uses? If that's the case, you could probably do it, and it'd be easier if you use tiles along the way.

I would recommend very carefully and thoroughly reading:
http://tdn.garagegames.com/wiki/TGB/Reference:_t2dTileLayer
and
http://tdn.garagegames.com/wiki/TGB/Reference:_t2dTileMap
#2
03/17/2009 (12:41 pm)
I've never played Civilization but if it's like playing Age of Empires then yes.

An example of what I'm looking for is something like this:
www.gherrity.org/MapGen.html
But instead of different colors, I'd like to have objects placed. Black would be the main clearing, red could be dirt, green trees and the gray water.

The idea is once the player starts his own little world for the first time, a map is randomly generated with textures then resources placed. The level is then saved. The only time the map generation is needed is when some one start a new world.
#3
03/17/2009 (12:46 pm)
Yes, did you read the links I sent you? They explain how to make a tile, assign values to tiles by coordinates, etc. A Dwarven Fortress would be *sweet* using these. Just so you know.
#4
03/17/2009 (1:08 pm)
Yeah, I'm reading over the links you posted. Definitely something I'm going to need to know. I'll stick these links under my GG Bookmarks. But the problem I'm facing is, how do I create a "believable" world. Not just a bunch of randomly placed sprites.

So like the code below would work if I wanted random sprites through out the map.
for( i=0; i<=255; i++) {
for( j=0; j<=255; j++) {
place random sprite in this tile block
}
}

What I'm looking for is a way to place "splotches". One way I could do this is by creating a bunch of tile maps then run a for loop and place the tiles maps which would make it a little more clean.
#5
03/17/2009 (1:26 pm)
That would get you through your first run, probably not good looking, but you know that.

A plausible world would require more geophysics than I know, but you know certain things, water flows downhill, trees won't grow above certain elevations, etc.
#6
03/18/2009 (11:47 am)
Mathematically generating realistic terrain is pretty involved. Most techniques involve fractals. Google "fractal map generation" should get you started.
#7
03/18/2009 (1:26 pm)
Travis, if you made a great terrain generator for TGB, it would probably be something you could sell.
#8
03/19/2009 (7:00 am)
@David. Before you posted I was actually exploring Perlin, but I'll also take a look into fractal. I'm just having a hard time looking for some good source and examples. There's a lot of online generators just a lack of code. I'll find something sooner or later!

@Jason. That is an idea. I'm sure it'd help a few devs.

The only problem would be that not every one has the Pro version so that just adds to the challenge. But then again I'm not a programmer. I know some basics, though I'm sure some one would help out here.
#9
03/19/2009 (7:53 am)
Texturing and Modelling: A Procedural Approach, is a book I've used in the past to work with fractal stuff.

Midpoint displacement is on Wikipedia- no code, but it's simple enough to work with what's there. Also a good explanation here.

Or you can just go here and take Musgrave's .c file with fractal functions...

And if you want, the Julia set.

Mandelbrot set

Some code for animated fractals.

Fractal snowflakes. I'm just saying...

#10
03/19/2009 (11:51 am)
If I remember correctly, you can download the DLL for Civ IV for modding, but not the executable (thusly protecting their property at some point). It has some pretty good map generation in it. I don't know if that's in the DLL or not.
#11
03/22/2009 (1:47 pm)
Well, here's my opinion on the matter:

To create a map based off a seed number, you need to design an algorithm using random numbers to generate your map. Then, if you want to be able to generate the same map every time with a given seed, you need to set your random number generator's seed to the seed. And that's it in a nutshell.

But of course, generating a map based off a seed is relatively easy. Generating a GOOD map based off a seed, with some realistic features (as opposed to completely random tiles) is the hard part, because it requires your algorithm to be fairly complex.

How you accomplish that, I do not know. But try to think of other types games in which that is done and look for some source code. Roguelikes randomly generate rooms connected by paths and sometimes use pre-defined rooms. Dwarf Fortress's underground materials come in small clusters, large clusters, veins, etc. and pseudo randomly places those underground (depending on other factors such as Biomes). You could create a bunch of smaller, predefined areas and put them together like Legos or a mosaic.

How you do it is up to you and in my opinion, asking someone to tell you how to do it is like expecting TGB to have a "Make game" button that does the entire thing for you. Nobody can tell you how to do it. They might be able to direct you to material that explains geophysics and the likes, but I think that ultimately it's up to you to figure it out.

I myself am looking for ideas and information on how to do some of the things that Dwarf Fortress does. But right now I'm working on a much smaller project which will not need to be nearly so complex as DF.
#12
03/23/2009 (7:09 am)
Quote:asking someone to tell you how to do it is like expecting TGB to have a "Make game" button that does the entire thing for you.

I don't expect the answer to be just give to me. I like to figure things out on my own. I've been looking into the Fractal and Perlin algorithms. They maybe what I'm looking for but I'll need to work with it for a while.

A solution I though up are "brushes". This would probably would take quite a few cycles on the processor and there are plans to port this to the iPhone, but the idea is that the world is 256x256 blocks on a single Tile Layer. The brushes are then overlapped on the main tile map, assigning a texture to that block then assigning an object such as a stone or tree. It doesn't really support a seed like I want but if I hit up google for a few hours I can find something.
#13
03/23/2009 (1:03 pm)
Here's a wiki that has quite a bit of information on procedural content generation. Another thing you might look into are context sensitive grammars. Those, and other similar grammars, have been used to great effect to produce realistic maps.

Procedural content generation is a hard problem. People write Masters and Doctorate papers on the subject. It is possible to do, but it's going to take some serious work.