Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Yet another DF World Generation question  (Read 1607 times)

DollMaker

  • Bay Watcher
    • View Profile
Yet another DF World Generation question
« on: February 28, 2021, 07:26:04 am »

Hi everyone! My name is Artem. I started playing Dwarf Fortress about 10 years ago and still play it from time to time. It's a facinating game in many aspects and I wanted to say thank you to the creator and this awesome community.
There is one thing I have been wondering about recently. Its not about the gameplay, but rather about the game itself. I didn't know where to ask this question and didn't find any forum topic for questions like this so I'll ask it here. I hope it's okay. I also have to apologize for my English.

Recently I became interested in the world generation aspect of this game. I have always liked how this game can re-create any world exactly the same each time if you use the same seed values over and over. I read about procedural generated worlds, about different ways to do this kind of stuff, and the complex approach Dwarf Fortress use. Mostly, I got the info from a couple of interviews with Toady that are exist in the web (like this, and this). I know that DF generates worlds by doing a robust work on randomization and simulation things like tectonic plates, mountains, temperature, drainage, rainfalls and so on.

What I don't understand is on what level of abstraction Dwarf Fortress operates the world when generating it? Most articles and information on the internet which cover procedural world generation view this "world generation" thing as just "lets generate a 2D map in several dimensions, some of them are: elevation, temperature, etc." And the map in these cases is usually not that big and the smallest "tile" in these algorithms is usually a very large area in the resulting world.
But as far as I can understand, in Dwarf Fortress things are a bit different. We know that at the generation step world can be looked upon as a map with a certain size (for example, 65x65 for the small size world). We see this map on the world generation screen. Each tile there (let's call them region tiles) represents a 16x16 local area blocks of 48x48 real-game tiles each (these are the tiles we see in the fortress/adventure mode) (source). So in total the small region would contain (65 * 16 * 48)^2 = 2492006400 real-game tiles for the small world! It's a huge amount, isn't it? And it is only covers one Z-dimension, but I also can imagine that there's some world generation work below the surface (at least for the caverns). I would say it is impossible to generate and simulate a world of this size without consuming a lot of memory and time.
So the question is, does the game really generate the world tile by tile using the smallest real-game tile as the smallest part of it's grid? Or it uses some kind of approximation and just operates region tiles at the world generation step? And if that is the case, at which step does it generate real-game tiles for each region tile?
Logged

Nopenope

  • Bay Watcher
    • View Profile
Re: Yet another DF World Generation question
« Reply #1 on: February 28, 2021, 07:49:52 am »

Nope, the game generates stuff for you as you discover the world. However, if you leave and come back, the region generated for you will persist. How it generates stuff depends on the abstracted things it has in store about a region (like biome information, sites, historical figures) and there's separate code to translate the abstract worldgen stuff into concrete stuff on the map, and that code is used only as necessary when your adventurer (or fortress) stumbles upon it. This is why many features never make it out of worldgen, because Toady doesn't have the time to render them properly in any of the actual game modes. Look up the article on historical figures (http://dwarffortresswiki.org/index.php/DF2014:Historical_figure) to understand what the game keeps track of and what it dismisses as you leave the map.
Logged

delphonso

  • Bay Watcher
  • menaces with spikes of pine
    • View Profile
Re: Yet another DF World Generation question
« Reply #2 on: February 28, 2021, 07:52:08 am »

Posting mostly to learn more.

Someone more educated on this topic may give more information, but as I understand it, some aspects are genned on embark/visit and is only pulling from the seed/a local seed. I think that's stuff like soil type.

I have no source for this, so it could be completely wrong.

Edit: ninja'd

PatrikLundell

  • Bay Watcher
    • View Profile
Re: Yet another DF World Generation question
« Reply #3 on: February 28, 2021, 08:16:57 am »

As noted, the world consists of World Tiles, each of which contains 16*16 Mid Level Tiles (MLTs), and each of those contains 48*48 in-game tiles (nominally 2*2*2.5 meters, I think).

The game does not have plate tectonics, but it does have volcanism.

The world tiles are generated upon world generation, and that, somehow, generates seeds for MLTs that somehow contain seeds for in-game tiles (the location where those seeds are stored have not been mapped). Thus, these levels are generated on the fly from the seeds, using delta information to change things that have been changed by the player (or, in principle, any actor, but the player is the only one currently).

The Z dimension is largely controlled by the Geo Biome tied to the world tile. Each geo biome is usually shared between multiple world tiles, so they may number in the hundreds in a max size world, rather than tens of thousands.

World gen consists of several stages with placement of civ starting sites being the last one (then history starts).

As you probably know, there are three seeds for each world, with one controlling geography (which is the one I've tended to "lock" when finding a nice looking world).

If you're interested in the details I'd recommend looking at the XML representations of the DF Structures mapped by DFHack, and use gui/gm-editor to look at what these structures contain in a particular world.

The above is only the broad strokes, of course. There's a lot that has been mapped (and a lot that hasn't). The world gen sequence stages, for instance have been mapped, and it's possible to interrupt world gen at these stages (or, in fact, any tick) to see what the world looks like at that stage. You can interrupt world gen manually or use a script to get a somewhat finer control (although it's still not perfect).
Logged

DollMaker

  • Bay Watcher
    • View Profile
Re: Yet another DF World Generation question
« Reply #4 on: February 28, 2021, 10:15:18 am »

Thanks for the answers! I see, so it makes more sense now. During the world generation it only creates World Tiles and Mid Level Tiles, right? I would think in only creates World Tiles, but at the embark screen we actually see MLTs so I assume they are fully generated as well before the actual game at a certain place in the world starts.
I'm still struggling with understanding some concepts behind the scenes. First of all, I understand how it is possible to generate the same nature in-game tiles for the same MLT each time, because of the seed. What I cannot understand is how the game knows how to generate non-natural structures like homes in hillocks, for example. Can I assume it does the same thing? I mean that it keeps the information about the site existing in a certain area and use this info when generating in-game tiles from a seed? In this case, does that mean that it is not possible for a certain site (e.g. hillock) change it's structure over time? I'd say, if a hillock A exist in the area B it will always contain the same amount of homes at the exast same places, doesn't matter if the historical events are changes and the hillock population has increased over time, for example?
I didn't examine DFHack's structures info yet. Btw, thanks for this insight, PatrikLundell.
Also thanks for linking the historical figure article, Nopenope. That shed some light on the matter of how the game shows the same NPCs each time you visit a place in the Adventure mode. As I understand, each person you've contacted becomes a historical fugure and the game starts to keep close attention to them, their position and events related to them. Might be wrong though, but I think I'm getting the concept.
« Last Edit: February 28, 2021, 10:19:04 am by DollMaker »
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: Yet another DF World Generation question
« Reply #5 on: February 28, 2021, 11:31:18 am »

No. MLTs are generated on demand. The actually only exist within the current world tile pre embark, and within a 3*3 world tile block centered around the embark world tile post embark. I think the 3*3 world tile block logic also applies to adventure mode, but haven't looked at that.

Yes, it does the same thing. The homes are RNG generated (how would they be generated originally otherwise) and are done so every time the MLT is generated.

Sites can get additional buildings over time, and I assume it can also grow over time, but I'd expect the same site would grow and contract in exactly the same way if it's only changed by size, while additional specific buildings use the same RNG logic to add them in the same order every re-generation. Note that apart from general size and specific building changes, the means by which those are effected are speculation on my side. I don't even play adventure mode.

There's not really anything that blocks the site generation logic from expanding and contracting differently each time, though, as you could add and remove "virtual" buildings each time you generate the site, leaving a gradually lengthening trail of modifications, but you'd probably have to play for a very long time before anything like that became an issue.
Logged