This is a Windows Batch script which automatically generates as many worlds as you want, and also organizes the maps and info files. It can be run while AFK, and is extremely useful for generating old (1000+ years) worlds, because even if DF crashes while generating a world, it will keep trying until it outputs your desired number of worlds.
To use, create a file named GenerateWorlds.bat file in your DF game folder, paste this code into it and save. Or you can name it whatever you want, as long as it's in the game folder, where "Dwarf Fortress.exe" is.
Or you can also download the file directly from:
https://github.com/Nikorasu/DwarfGenManagerThen either, choose one of the preexisting generator presets found in the world_gen.txt, or create your own custom one using the "Design New World with Advanced Parameters" in the game's main menu.
When you run GenerateWorlds.bat, it will ask for that title (spelling/capitalization must be exact), and how many worlds you want it to generate, just make sure your computer has enough space for the number you give it. It'll then load up the game window and start generating. It should do everything automatically at that point, tho the df game window will popup every so often and get in the way if you're watching something while you wait lol, so you might wanna go afk and do something else till it finishes. heh
@ECHO OFF
TITLE Generation Manager - by Nik
IF NOT EXIST "Dwarf Fortress.exe" (
ECHO ERROR: "Dwarf Fortress.exe" not found, place script into same folder.
PAUSE && EXIT /b
)
IF EXIST data\save\region0 (
ECHO ERROR: region0 folder already present, rename/move it then try again.
PAUSE && EXIT /b
)
SETLOCAL EnableDelayedExpansion
FOR /f %%G IN ('find /c "[TITLE:" ^< data\init\world_gen.txt') DO SET gnum=%%G
ECHO There are %gnum% available generator pesets in your world_gen file:
ECHO,
FOR /f "delims=" %%T IN ('find "[TITLE:" ^< data\init\world_gen.txt') DO (
SET gparam=%%T
IF %gnum% LEQ 20 (ECHO !gparam:~8,-1!) ELSE (SET outlist=!outlist!, !gparam:~8,-1!)
)
IF %gnum% GTR 20 ECHO %outlist:~2%
ECHO,
SET /p genparam=Which preset do you want to use?:
SET /p maxcount=How many worlds to generate?:
SET /a wcount=1
SET logfile=GenLog_%date:~10,4%-%date:~4,2%-%date:~7,2%_%time:~0,2%-%time:~3,2%.txt
SET logfile=%logfile: =%
:GEN
ECHO, && ECHO,
ECHO Generating World %wcount%..
"Dwarf Fortress.exe" -gen 0 RANDOM "%genparam%"
IF NOT EXIST data\save\region0 (
ECHO Something happened, world was not generated! Trying again..
TIMEOUT 10 /nobreak
GOTO GEN
)
FOR %%F IN (region0*world_history.txt) DO SET histfile=%%~nxF
SET /p worldname=<%histfile%
ECHO,
ECHO World name is %worldname%. Organizing files now..
ECHO,
optipng -q -zc9 -zm9 -zs0 -f0 region0*.bmp
DEL region0*.bmp
MD data\save\region0\info
MOVE region0* data\save\region0\info
REN "data\save\region0\info\region0-world_gen_param.txt" "%worldname: =%-world_gen_param.txt"
SET charin=%worldname%
SET charout=
SET map=abcdefghijklmnopqrstuvwxyz
:CHARFIX
IF NOT DEFINED charin GOTO ENDFIX
FOR /f "delims=* eol=*" %%C IN ("!charin:~0,1!") DO (
IF "!map:%%C=!" NEQ "!map!" SET charout=!charout!%%C
)
SET charin=%charin:~1%
GOTO CHARFIX
:ENDFIX
SET worldname=%charout%
:DUPCHECK
IF EXIST data\save\%worldname% (
SET worldname=%worldname%_2
GOTO DUPCHECK
)
ECHO %worldname% %histfile:~8,5%>>%logfile%
ECHO,>>%logfile%
FOR %%P IN (data\save\region0\info\region0*world_sites_and_pops.txt) DO SET popfile=%%~fsP
FOR /f %%L IN ('find " Dwarves" ^< %popfile%') DO SET lPop= %%L
IF NOT DEFINED lPop SET lPop= 0
ECHO Dwarves: %lPop:~-9% >> %logfile%
SET lPop=
FOR /f %%L IN ('find " Goblins" ^< %popfile%') DO SET lPop= %%L
IF NOT DEFINED lPop SET lPop= 0
ECHO Goblins: %lPop:~-9% >> %logfile%
SET lPop=
FOR /f %%L IN ('find " Elves" ^< %popfile%') DO SET lPop= %%L
IF NOT DEFINED lPop SET lPop= 0
ECHO Elves: %lPop:~-9% >> %logfile%
SET lPop=
FOR /f %%L IN ('find " Humans" ^< %popfile%') DO SET lPop= %%L
IF NOT DEFINED lPop SET lPop= 0
ECHO Humans: %lPop:~-9% >> %logfile%
SET lPop=
FOR /f %%L IN ('find " Kobolds" ^< %popfile%') DO SET lPop= %%L
IF NOT DEFINED lPop SET lPop= 0
ECHO Kobolds: %lPop:~-9% >> %logfile%
SET lPop=
FOR /f %%L IN ('find /c ", tower" ^< %popfile%') DO SET tCount= %%L
ECHO Towers: %tCount:~-9% >> %logfile%
FOR /f "delims=" %%L IN ('find "Total: " ^< %popfile%') DO SET tcPop=%%L
SET tcPop= %tcPop:~8%
ECHO TotalPop:%tcPop:~-9% >> %logfile%
ECHO,>>%logfile%
ECHO,>>%logfile%
REN data\save\region0 %worldname%
IF %wcount% EQU %maxcount% (
ECHO, && ECHO,
ECHO All %wcount% worlds complete. Summary saved to: %logfile%
ECHO,
PAUSE && EXIT /b
)
ECHO,
ECHO World %wcount% done. Waiting in case user wants to abort..
TIMEOUT 20 /nobreak
SET /a wcount+=1
GOTO GEN
REM script by Nik - https://github.com/Nikorasu/DwarfGenManager
If anyone has any suggestions to improve this, feel free to let me know!
User Ralpha created a similar Linux version, with some more advanced legends exporting features and dfhack implementation, which I'll try to add to this script eventually.
https://gitlab.com/df_storyteller/df-worldgenUPDATE 5/27/20 : Added a fix for special characters in the world-name which the game couldn't load. Also added an error check and fixed a typo.
UPDATE 6/2/20 : New feature! Now it displays a list of available world_gen presets before the question!
UPDATE 6/10/20 : Another New Feature! This version creates a timestamped GenLog file in the df folder, containing a summary of the populations and tower-count for each world generated that session. I tried to format it to make it easier to read, and all in one place, hopefully this will help users narrow-down which worlds they want to keep. Previous version still available as a Release on the GitHub page.
UPDATE 6/20/20 : Added an error check, then removed it later same day, was unnecessary. heh Also tweaked/fixed the code here and there, and added the world's year to the GenLog. Also, fixed a bug with the genlog variables not resetting to 0.
UPDATE 6/30/2020 : Put up a new Release marked r2, which includes the GenLog feature and should be bug-free, in case people were waiting on that. Also switched to r1 style versioning, and added a ReadMe to the GitHub.