Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How does all that content get generated?  (Read 1505 times)

kojitakeo

  • Escaped Lunatic
    • View Profile
How does all that content get generated?
« on: June 17, 2010, 07:15:53 pm »

So Dwarf Fortress has got to be one of the most impressive games for me, because of all the content that is just procedurally generated the first time you sit down to play. And if that batch of content doesn't last you long enough (for real?) you can make another world, which might not even come out similar to your past worlds.

I was wondering, there are a lot of different complicated things being generated, and some of these things I cannot find good substantial documentation on how to do something like that anywhere. Are there any resources that explain how dwarf fortress's world generation works? I'd love to get a peek under the hood so to speak.
Logged

Tenth Speed Writer

  • Bay Watcher
  • Legendary Procrastinator
    • View Profile
Re: How does all that content get generated?
« Reply #1 on: June 17, 2010, 07:34:05 pm »

Google some of the interviews that Toady has done in the past; I know he addresses a few topics, especially flowing water and mountains, but much of the procedures behind the procedural generation are still rather secret.


He rarely posts on these forums freely, especially about these things, but it might be worth hoping for a response. This is a topic many of us are curious about. : )
Logged
Quote from: Pickled Tink
I don't believe in a standing army. I believe in cruel and unusual architecture.

Makbeth

  • Bay Watcher
  • His lower body is melted.
    • View Profile
Re: How does all that content get generated?
« Reply #2 on: June 17, 2010, 07:35:27 pm »

I was wondering about this as well.  Also curious about if the individual game tiles are set at world gen or only when their local tile is loaded.  Haven't found anything though.
Logged
Diso Faintpuzzles was born in 120.  Although accounts vary it is universally agreed that Diso was chosen by fate as the vanguard of destiny.

In the early spring of 143 Diso began wandering the wilds.

In the early spring of 143 Diso starved to death in the Horn of Striking.

Mel_Vixen

  • Bay Watcher
  • Hobby: accidently thread derailment
    • View Profile
Re: How does all that content get generated?
« Reply #3 on: June 17, 2010, 07:39:41 pm »

Toady one has given a number of interviews which included many details like this one.

DF uses many systems but Basicly rolls a number of n-sided dice and then applys rules and principles. Genetics for example (fur/eye colours etc.) work like simple real-life genetics. Other things like placing Stones and Minerals go by rules like "Only place ruby/Sapphire in bauxite". Some things like Souls just communicate with each other to change there state. 

To put it straight: DF uses real life theorys and mechanisms to create a world out of random numbers. If you want to know how something is moddeled in df try find the Theorys of the moddeled theme (for example: economics, sociologies, Geologies) instead of searching for a "how to" with code.
Logged
[sarcasm] You know what? I love grammar Nazis! They give me that warm and fuzzy feeling. I am so ashamed of my bad english and that my first language is German. [/sarcasm]

Proud to be a Furry.

Lemunde

  • Bay Watcher
    • View Profile
Re: How does all that content get generated?
« Reply #4 on: June 17, 2010, 07:43:08 pm »

I don't know exactly how Toady does it but I've messed around in randomly generated worlds before.  Here's how I do it.  Let's say I'm adding some water to a map.  I spread a few nodes around the map that will be the seeds of the lakes and ponds.  Then I do a for-loop that picks a random direction from those seeds and adds another seed.  As the loop continues it adds more and more seeds and slowly forms a fairly organic looking pond.  If you imagine how forests form naturally it works a lot like that.  It gets more complicated when making a seamless world like the one you see in DF as you run into data management issues.
Logged

Astramancer

  • Bay Watcher
    • View Profile
Re: How does all that content get generated?
« Reply #5 on: June 17, 2010, 07:46:47 pm »

If you want a quickie reference guide to procedural content generation, you want to look at Mad Libs.  You just have to figure out what the sentence should be, and the list of items that makes sense in the blanks, and a random number generator to pick from those lists.

Basically, instead of coming up with the world, you come up with the rules on how the world should be made, and feed random numbers into that rule set.

It's best to start with something simple.  Say you are making a space game, where the player controls star systems and attacks other systems to conquer them.

You can either design each system manually, say P3X-992 has 5 planets, 2 of which are habitable, and one is a gas giant.  Or you can decide that a star system can have 0-10 planets, of which 20% are habitable, and 10% are gas giants, and then the random number generator decides that P3X-992 has 5 planets, 2 of which are habitable, and one is a gas giant.

It's harder to come up with the rulesets, but then it's easier to make the actual maps because the RNG does the rest.  You just continue to scale it up, add complexity step by step.

Now to focus a bit more on DF.  Obviously, I'm not the Toady One (as evidenced by my username), so I don't really know how it all works under the hood, but the basic concepts are pretty simple.

When generating the world, the first thing you need to do is decide the basic layout - oceans, mountains, plains, ect.  You have to start at the bottom (no, not HFS), and work up.  So we have parameters that say about how much of the world should be ocean (say, 20% - that's not like our world, but it does give more playable space).  You can't just randomly turn 20% of the embark tiles into ocean, because that'll look wierd.  They'll need to clump together.  One giant ocean might look wierd, but it might also make sense, so we'll let the RNG handle it -- by adding a parameter to control how many oceans there are (and come up with rules on how to distribute the ocean tiles between them).  It can't be a perfect circle or square or whatever because that, too, would look weird, so you have to come up with a formula to make it more jaggy and irregular -- and guess what, you can use more random numbers plugged into that formula!  Yay!

So we haven't even gotten through laying down the surface, and we already have 2 parameters and a couple of places to throw random numbers.  This gives you some control over what the final result looks like, but also ensures that no two generations will be exactly the same.

But wait, what if you want it to look exactly the same?  Well, if you're asking about how to do procedural generation, I'm going to assume you know that random numbers aren't random at all, and that they require a seed to ... randomize the results.  Usually you use the time, but you can allow the user to input the seed -- just like DF!  Yay!  Of course, if you want a random seed, then you initiate the random numbers with the time and have it spit out a random seed.  Also Yay!

Long story short, you start small and keep building up rules on how the game should run itself, or how the playing field should be made.  Eventually, it will get complex enough that it will take all night to gen a world, only to find out everything interesting is dead and you have to start over   ::)

---------

The Game of Life is an excellent example of how a few simple rules can create complex results.  Procedural content is just the Game of Life writ large, and with random numbers thrown in.  I know this probably isn't quite what you were looking for, but
Logged

Mel_Vixen

  • Bay Watcher
  • Hobby: accidently thread derailment
    • View Profile
Re: How does all that content get generated?
« Reply #6 on: June 17, 2010, 07:49:35 pm »

I don't know exactly how Toady does it but I've messed around in randomly generated worlds before.  Here's how I do it.  Let's say I'm adding some water to a map.  I spread a few nodes around the map that will be the seeds of the lakes and ponds.  Then I do a for-loop that picks a random direction from those seeds and adds another seed.  As the loop continues it adds more and more seeds and slowly forms a fairly organic looking pond.  If you imagine how forests form naturally it works a lot like that.  It gets more complicated when making a seamless world like the one you see in DF as you run into data management issues.

Huh? Well i was thinking on filling oceans and then letting a weather-sim run for some time to get more reliable sources for rivers etc. A little bit of geology is in it too. This way i also can hopefully get dry places under the zero meter mark and lakes which arent maintained by rivers/brooks. 

edit:
A lengthy and detailed article on generating random landscapes can be found here .
« Last Edit: June 17, 2010, 07:56:03 pm by Heph »
Logged
[sarcasm] You know what? I love grammar Nazis! They give me that warm and fuzzy feeling. I am so ashamed of my bad english and that my first language is German. [/sarcasm]

Proud to be a Furry.

Lemunde

  • Bay Watcher
    • View Profile
Re: How does all that content get generated?
« Reply #7 on: June 17, 2010, 08:36:20 pm »

I don't know exactly how Toady does it but I've messed around in randomly generated worlds before.  Here's how I do it.  Let's say I'm adding some water to a map.  I spread a few nodes around the map that will be the seeds of the lakes and ponds.  Then I do a for-loop that picks a random direction from those seeds and adds another seed.  As the loop continues it adds more and more seeds and slowly forms a fairly organic looking pond.  If you imagine how forests form naturally it works a lot like that.  It gets more complicated when making a seamless world like the one you see in DF as you run into data management issues.

Huh? Well i was thinking on filling oceans and then letting a weather-sim run for some time to get more reliable sources for rivers etc. A little bit of geology is in it too. This way i also can hopefully get dry places under the zero meter mark and lakes which arent maintained by rivers/brooks. 

edit:
A lengthy and detailed article on generating random landscapes can be found here .

Well for my purposes I don't require something so complex.  I get pretty good results with my method but it doesn't rely on any real world geology or weather.


You can either design each system manually, say P3X-992 has 5 planets, 2 of which are habitable, and one is a gas giant.  Or you can decide that a star system can have 0-10 planets, of which 20% are habitable, and 10% are gas giants, and then the random number generator decides that P3X-992 has 5 planets, 2 of which are habitable, and one is a gas giant.


Heh, that sounds pretty familiar.
« Last Edit: June 17, 2010, 08:42:50 pm by Lemunde »
Logged

eerr

  • Bay Watcher
    • View Profile
Re: How does all that content get generated?
« Reply #8 on: June 17, 2010, 09:31:27 pm »

semi-random.
Logged

Quatch

  • Bay Watcher
  • [CURIOUSBEAST_ GRADSTUDENT]
    • View Profile
    • Twitch? Sometimes..
Re: How does all that content get generated?
« Reply #9 on: June 17, 2010, 10:53:02 pm »

pseudo-random even?
Logged
SAVE THE PHILOSOPHER!
>>KillerClowns: It's faster to write "!!science!!" than any of the synonyms: "mad science", "dwarven science", or "crimes against the laws of god and man".
>>Orius: I plan my forts with some degree of paranoia.  It's kept me somewhat safe.

kojitakeo

  • Escaped Lunatic
    • View Profile
Re: How does all that content get generated?
« Reply #10 on: June 18, 2010, 12:27:13 am »

Frankly I'm shocked at all of you guys.

I know this interview was referenced early in the discussion but I don't think any of you, even the person who posted it, actually read the thing... http://www.gamasutra.com/view/feature/3549/interview_the_making_of_dwarf_.php

The method that is used to generate the world is much simpler than any of the mentioned methods: put plainly several terrain parameters are assigned to positions in your world according to a fractal or interpolation field with random control points (the value at any position is interpolated between the nearest control points inversely proportionate to their distances) and tweaked with respect to one another and simple rule sets. A combination of possible parameter values yields a terrain tile. The parameters mentioned in the article include altitude, precipitation, drainage, temperature and more. These parameters value fields are generated, the values of the parameters at every point in the map govern what tile is there.

After that, tiles falling into specific ranges of these parameters' values are attributed as being of a certain Biome (be it forest, swamp, desert, whatever) each cluster of such is then randomly named ala mad libs,

It's actually a lot simpler than I thought. of course there are special exceptions including positioning of small bodies of water and caverns, but the simulated water erosion may generate both as a coincidental byproduct. I'm unsure.

There is plenty of detail in the article to try your own hand at it. Thanks for pointing it out.
Logged

Cruxador

  • Bay Watcher
    • View Profile
Re: How does all that content get generated?
« Reply #11 on: June 18, 2010, 01:48:18 am »

Frankly I'm shocked at all of you guys.

I know this interview was referenced early in the discussion but I don't think any of you, even the person who posted it, actually read the thing... http://www.gamasutra.com/view/feature/3549/interview_the_making_of_dwarf_.php

The method that is used to generate the world is much simpler than any of the mentioned methods: put plainly several terrain parameters are assigned to positions in your world according to a fractal or interpolation field with random control points (the value at any position is interpolated between the nearest control points inversely proportionate to their distances) and tweaked with respect to one another and simple rule sets. A combination of possible parameter values yields a terrain tile. The parameters mentioned in the article include altitude, precipitation, drainage, temperature and more. These parameters value fields are generated, the values of the parameters at every point in the map govern what tile is there.

After that, tiles falling into specific ranges of these parameters' values are attributed as being of a certain Biome (be it forest, swamp, desert, whatever) each cluster of such is then randomly named ala mad libs,

It's actually a lot simpler than I thought. of course there are special exceptions including positioning of small bodies of water and caverns, but the simulated water erosion may generate both as a coincidental byproduct. I'm unsure.

There is plenty of detail in the article to try your own hand at it. Thanks for pointing it out.
Do note that the article is from 2008; it's likely that many have never seen it.
Logged

scira

  • Bay Watcher
    • View Profile
Re: How does all that content get generated?
« Reply #12 on: June 18, 2010, 09:56:46 am »

I can't verify to test because I'm lazy like that, but in 40d I think i have noticed with Reveal minerals Magnetite moving around and changing depending on the embark size and location. This probably has to do with game parameters saying there needs to be a certain amount of minerals per area/terrain.
With the magnetite i observed a cluster sometimes there sometimes not directly on/in a magma pipe, and a cluster that seemed to be inbetween two local region tiles, as it would only appear if both were selected for the embark.
Logged