r/howdidtheycodeit • • Feb 25 '20

Dwarf Fortress Map Generation

Post image
164 Upvotes

9 comments sorted by

51

u/MyPunsSuck Feb 26 '20

To my recollection, they modeled geological forces themselves; up to and including soil erosion. Similar results are possible by much much simpler means

11

u/Zoltarr777 Feb 26 '20

Do you know if there's a tutorial for something like that? I don't mean the exact way they did it, I'm more talking about getting a program to generate a map in a similar ascii art style.

19

u/MyPunsSuck Feb 26 '20

I would recommend looking into Perlin noise generation. With a bit of math, it's actually very approachable

7

u/gingerbreadfetus Feb 26 '20

I found a good gentle video on the basics of it:

https://www.youtube.com/watch?v=bG0uEXV6aHQ

7

u/MyPunsSuck Feb 26 '20

That looks like a pretty good tutorial. Perlin noise gives you the ability to feed in any coordinates, and get a return value. The next step is to use more than one layer of noise.

For map generation, you'll generally want two or three for altitude; each scaled to a different size (So one is returning big "blobs", one returning medium, and one small). By multiplying each return value by a weight and adding them together (It'll take some fiddling to get the weights right), it is possible to get some very convincing continent-like altitude maps.

Then you add more layers, like humidity and such, and color each part of the map based on its local values. I recommend building a biome definition map (Like this https://en.wikipedia.org/wiki/Biome#/media/File:Lifezones_Pengo.svg except using the factors your map uses)

6

u/corvidsarecrows Feb 26 '20

The ascii art style is the easy part: if you have a 2D array of terrain types, you just need to assign a character and a color to each terrain type and output it as a string.

The question then becomes how many terrain types do you have and how do you arrange them? The limit there is just up to your imagination. The classic procedural generation algorithm is to generate some perlin noise and assign a sea level, everything below sea level is water, everything tall is a mountain, everything along the water is coast, and the rest is grass.

For something like Dwarf Fortress, they have a much deeper model, but I don't think there's a good tutorial out there: I'd say start from the default procedural world generation and then add features one-by-one: plate tectonics to generate mountains, oceans, and islands; rain shadows to generate deserts; erosion to generate canyons, floodplains, and deltas; etc.

6

u/CoInitializeEx_ Feb 28 '20

That's an endless pit.

It's important to keep in mind that Dwarf Fortress isn't a game, it's some kind of attempt at creating a machine god or something else ... it's more like that creepy 5 yr old next door breaking rocks with a hammer and examining them with a magnifying glass while he's got a ladybug wired to a battery than it is a game.

Erosion specifically has more ideal but fake solutions like [Talus erosion](https://web.mit.edu/cesium/Public/terrain.pdf) whereas DF almost certainly eschewed any convenience for shortening the road to sentient dwarf mutilator.

1

u/Drag0nV3n0m231 Feb 26 '20

I did something similar for my highschool java project lmao, could you not just create a 2D array with the same dimensions as the map rows and columns, and then output the map tile image based on what number is in that space in the array?

12

u/sirmonko Feb 26 '20

I'm more talking about getting a program to generate a map in a similar ascii art style.

so, this is actually two parts: map generation and map display (rendering). they're pretty much independent; you could also generate a 3d world out of the map or use an isometric view.

the map rendering here is the easy part - almost trivial compared to the generation.

with an ascii map, you have a limited way of representing the tile and what's on it:

  • the ascii character

  • the ascii characters' base color (hue)

  • the ascii characters' saturation/brightness

  • the background color (not used here)

  • possibly animation (i.e. displaying different aspects over time)

dwarf fortress creates a ton of information about its maps, more than any other computer game. among other things:

  • elevation, temperature, rainfall

  • which leads to rivers, influences erosion

  • which leads to flora and fauna

  • and thus settlements, buildings, roads, mines, artefacts, etc.

  • and all this over time (thousands of years) as the history of the world

it's far more nuanced than that.

anyway, once the map is generated you look at each part (square) and decide what to represent there, as your palette is rather limited. here we see the ascii characters and color mostly displaying vegetation/biomes (greens are tropical and temperate forests, brown are probably swamps, gray are mountains, blue is, of course, water. on tiles featuring special entities like cities, rivers or roads, those are displayed instead.