Importing coarse terrain information from Dwarf Fortress

For people working on the C++ code.
Post Reply
User avatar
jwmhjwmh
Developer
Posts: 125
Joined: Sun Jul 18, 2021 14:10
GitHub: TurkeyMcMac

Importing coarse terrain information from Dwarf Fortress

by jwmhjwmh » Post

screenshot_20220123_132646.png
screenshot_20220123_132646.png (758.63 KiB) Viewed 1190 times
Dwarf Fortress generates terrain by simulating a bunch of processes, e.g. erosion. I wanted to make use of Dwarf Fortress' map generation procedure in Minetest. This is a WIP mapgen which gets its information from Dwarf Fortress worlds.

You can clone the code from this branch: https://github.com/TurkeyMcMac/minetest/tree/dfimport

To use the code, you first have to get data from Dwarf Fortress. Go into Legends mode and export maps of elevation, temperature, and rainfall. Rename the bitmaps to el.bmp, tmp.bmp, and rain.bmp, respectively. Now run this Python script:

Code: Select all

#!/usr/bin/python3

from PIL import Image

el = Image.open("el.bmp")

def u16_bytes(value):
    b1 = value // 256
    b0 = value % 256
    return (b1, b0)

def serialize_grid(img, f):
    out = []
    out += u16_bytes(img.width)
    out += u16_bytes(img.height)
    for z in range(img.height):
        for x in range(img.width):
            r, g, b = img.getpixel((x, z))
            out += u16_bytes(f(r, g, b))
    return out


with open("el.dat", "wb") as out:
    el = Image.open("el.bmp")
    def f(r, g, b):
        if r > 0 and g == r and b == r:
            return round(r * 99 / 74)
        elif r == 0 and g == 0:
            return b
    out.write(bytearray(serialize_grid(el, f)))

with open("tmp.dat", "wb") as out:
    tmp = Image.open("tmp.bmp")
    def f(r, g, b):
        return r
    out.write(bytearray(serialize_grid(tmp, f)))

with open("rain.dat", "wb") as out:
    rain = Image.open("rain.bmp")
    def f(r, g, b):
        return r
    out.write(bytearray(serialize_grid(rain, f)))
The output files are el.dat, tmp.dat, and rain.dat.

If you don't want to go through the trouble of the above procedure, I have attached an archive "dfdata.zip" containing three files produced in this way.

For now, the output files need to be in the current working directory when you run Minetest. Open Minetest and create a world with the mapgen "dfimport".

Instead of using noise, terrain is generated by interpolating between the data points provided by Dwarf Fortress. One pixel in one of the source bitmaps corresponds to one Minetest mapchunk. The generated terrain is very large-scale. Mountains can rise over 400 nodes above sea level. Biomes are generated according to the set of registered biomes; they are not hard-coded. Besides fixing bugs, I still have to add cave and river generation (I plan on importing river information from Dwarf Fortress, but not cave information.)
Attachments
dfdata.zip
(61.6 KiB) Downloaded 41 times
Last edited by jwmhjwmh on Tue Jan 25, 2022 00:22, edited 1 time in total.

User avatar
philipbenr
Member
Posts: 1897
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: robinspi
Location: United States

Re: Importing coarse terrain information from Dwarf Fortress

by philipbenr » Post

Interesting idea, the scale of the implementation will certainly make for a different experience. I don't know much about Dwarf Fortress, is it theoretically possible to decouple this mapgen from Dwarf Fortress or not?

User avatar
jwmhjwmh
Developer
Posts: 125
Joined: Sun Jul 18, 2021 14:10
GitHub: TurkeyMcMac

Re: Importing coarse terrain information from Dwarf Fortress

by jwmhjwmh » Post

philipbenr wrote:
Mon Jan 24, 2022 02:59
Interesting idea, the scale of the implementation will certainly make for a different experience. I don't know much about Dwarf Fortress, is it theoretically possible to decouple this mapgen from Dwarf Fortress or not?
Yes, it can be decoupled. You just need to create bitmaps the same way Dwarf Fortress does but encoding your own data. I've attached the bitmaps produced by Dwarf Fortress for reference.
Attachments
bitmaps.zip
(67.62 KiB) Downloaded 39 times

User avatar
jwmhjwmh
Developer
Posts: 125
Joined: Sun Jul 18, 2021 14:10
GitHub: TurkeyMcMac

Re: Importing coarse terrain information from Dwarf Fortress

by jwmhjwmh » Post

You will now spawn at ground level.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests