Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Question: Batch World Generator - is this possible?  (Read 1546 times)

Ledi

  • Bay Watcher
    • View Profile
Question: Batch World Generator - is this possible?
« on: April 14, 2011, 11:29:10 pm »

Hi, sorry if this sounds insane but I'm not a modder, so... >.> I don't know what is or isn't possible.

With the new embark not showing specific ores anymore, it takes a lot more world gens to find that one spot where I want to settle.

I seem to remember there being a "perfect embark" finder which could make a world, search for an embark, save it if there was one within certain parameters, and then continue creating worlds until you had the amount you wanted created.

I know the entire program would be complex to recreate/update, but the part I'm most interested in is the batch world generator - I'd like to be able to, say, start it up and tell it to gen 30 worlds (using the same parameters, of course), accepting all errors, and save them all off while I go do something else. Then I could come back and manually search them for the area I want.

Would anyone be interested in taking a poke at this?
Logged
So Ledi's been training the cats into an army of disposable warbeasts?  Why did no-one think of this sooner?!
Hellcannon seemed to be constantly on the verge of death and Levergedon before my turn helped, but ultimately what killed it was Ledi's cat army.

Artanis00

  • Bay Watcher
    • View Profile
Re: Question: Batch World Generator - is this possible?
« Reply #1 on: April 15, 2011, 12:21:25 am »

Already (mostly) implemented. See "command line.txt" in the DF folder.

You'll have to open up a command line or terminal window in the DF folder and run the program with a '-gen' argument. If you want multiple worlds, build a .bat (windows) or .sh (linux/mac) script to run the command several times.

Automatically searching for an embark sounds like it needs some hacking, though.

The relevant portion (of an absurdly short file):
Quote
FORMAT:   "Dwarf Fortress.exe" -gen <id number> <seed> <world gen param title>
EXAMPLE:   "Dwarf Fortress.exe" -gen 1 3498 STANDARD
EXAMPLE:   "Dwarf Fortress.exe" -gen 2 RANDOM CUSTOM6

This will open a silent, introless dwarf fortress, generate a world with the given id number and seed, export the region files and a picture, and finally quit.  The window remains open so you can see what's going on.  You can still abort world generation while it is running.  If you attempt to create a world number that already exists, it will abort immediately.
« Last Edit: April 15, 2011, 12:24:59 am by Artanis00 »
Logged
Git - fast, efficient, distributed version control system
Github - Free public repositories, issue tracking, wikis, downloads...

Ledi

  • Bay Watcher
    • View Profile
Re: Question: Batch World Generator - is this possible?
« Reply #2 on: April 15, 2011, 01:07:59 am »

So I can just go down a list of IDs, incrementing by one, and copy/paste the params?

Excellent. </burns>

To the .bat-mobile!

Logged
So Ledi's been training the cats into an army of disposable warbeasts?  Why did no-one think of this sooner?!
Hellcannon seemed to be constantly on the verge of death and Levergedon before my turn helped, but ultimately what killed it was Ledi's cat army.

Reelyanoob

  • Bay Watcher
    • View Profile
Re: Question: Batch World Generator - is this possible?
« Reply #3 on: April 15, 2011, 03:58:18 am »

I just automated this further with vbs (windows only sorry, but it comes built-in, and i'm lazy)

gen.vbs :-
Code: [Select]
dim cmd_line_args
set cmd_line_args = wscript.Arguments
dim shell
set shell=createobject("wscript.shell")

Count = clng(cmd_line_args(0))
Start = clng(cmd_line_args(1))
Param = cmd_line_args(2)

For I = 0 to Count - 1
   Set oExec = shell.Exec("Dwarf Fortress -gen " + cstr(Start+I) + " RANDOM " + Param)
   Do While oExec.Status = 0
        WScript.Sleep 100
   Loop

Next

gen.bat :-
Code: [Select]
cscript gen.vbs <COUNT> <START> <PARAMS>
replace COUNT with how many worlds to create, START with the first region number to create, and PARAMS with the name of your worldgen settings, then run gen.bat. You could put more cscript lines in, there, and gen 10 with one lot of settings and 10 with another.
« Last Edit: April 15, 2011, 04:35:34 am by Reelyanoob »
Logged

Ledi

  • Bay Watcher
    • View Profile
Re: Question: Batch World Generator - is this possible?
« Reply #4 on: April 17, 2011, 04:46:16 am »

Thankyou, Reelya, put it together and got it to start up DF and a worldgen. ^^

Question again: is there any way to make it ignore that it can't place enough whatevers and just barrel on picking the first seed? I turn volcanism and rivers up to max to try and get as many as possible, which means when I'm making my own worlds manually I have to accept the parameters after it's gone through enough rejections. I'm currently up to 40k rejections of this first world and rising, with no way to tell it to just accept the thing. >.>

Edit (after turning down the params): Also... I have to hit enter after every gen? ;.; I wanted to be able to gen stuff while not around. >.< Is there a way around that?
« Last Edit: April 17, 2011, 04:51:42 am by Ledi »
Logged
So Ledi's been training the cats into an army of disposable warbeasts?  Why did no-one think of this sooner?!
Hellcannon seemed to be constantly on the verge of death and Levergedon before my turn helped, but ultimately what killed it was Ledi's cat army.

Starver

  • Bay Watcher
    • View Profile
Re: Question: Batch World Generator - is this possible?
« Reply #5 on: April 17, 2011, 05:53:58 am »

For I = 0 to Count - 1
   Set oExec = shell.Exec("Dwarf Fortress -gen " + cstr(Start+I) + " RANDOM " + Param)
   Do While oExec.Status = 0
        WScript.Sleep 100
   Loop
Next
[/code]
Perhaps you could also have done something with the command/batch-line command FOR and some other stuff.  e.g.
Code: [Select]
FOR /L %%W IN (%1,1,%2) DO (      <=Note, %%W for batch-file, %W at command line!
   ...whatever...
)

Noting that you could, in the "...whatever..." also do some "IF ERRORLEVEL 1" stuff to note anything that has a non-zero exit status, but what you do then is really up to what you feel like it doing...  But it looks like your status-checker is more to do with not running multiple world-creations in parallel, so probably not anything to be concerned about.

In which case, you don't even need to multi-line it...
FOR /L %%W IN (%1,1,%2) DO "Dwarf Fortress" -gen %%W RANDOM %3 %4 %5 %6 %7 %8 %9

(Going by what you've put, but noting that the batch-file params would be <start> <stop> <a limited set of params...>.  There's ways of bringing in the the %3* remainder down to one variable and of performing maths to derive the <start> and <stop> from the <start> and <count> you use in your code, but I won't go into that right now.)

((Also, E&OE, I just wrote off the top of my head, so might have typoed/thinkoed something. :) ))
Logged

Reelyanoob

  • Bay Watcher
    • View Profile
Re: Question: Batch World Generator - is this possible?
« Reply #6 on: April 17, 2011, 07:13:02 am »

@Starver : interesting, i had no idea they added a FOR command to bat files, been a long time since i bothered with them.

But the question is how to auto-close DF once worldgen's done, as Ledi suggested.

I can't see how to do that with the bat file FOR loop, but with VBS I could probably rig it up with AutoHotKey to spam a mouse click (or Enter key or something) every few seconds on the DF window, which would close it once worldgen is complete. EDIT: Actually this could work with just having AutoHotKey in the background, whichever script you use. I think AutoHotKey has some sort of Window-detect feature, so the script only runs when it detects the right type of window.
« Last Edit: April 17, 2011, 07:16:59 am by Reelyanoob »
Logged

Starver

  • Bay Watcher
    • View Profile
Re: Question: Batch World Generator - is this possible?
« Reply #7 on: April 17, 2011, 07:49:08 am »

@Starver : interesting, i had no idea they added a FOR command to bat files, been a long time since i bothered with them.

They've had a FOR for ages, wouldn't be surprised if it wasn't there in 1.0 (certainly 5.0).  But until 'recently' (number looping not being natively there in the 9x strand, IIRC, but certainly was around in 2K onwards, can't remember if its NT roots did, off-hand) it was largely just a "found-files looping"[1].  These days you can do matching against directories, recursive matching through sub-directories, comparative substringing of each output line of a command line run (at the time of the FOR) or ripped direct from file content[2], or just a static string supplied at save-time.  And then there's numeric looping (a la C-style 'for') as above.  Plus the ability to operate on multi-line segments "...DO (" then the lines then a ")" on a following line, and that's also doable for IF statements.  And you can nest.  Saves you having to do CALLs to further batch files to accomplish (some of) these same capabilities, as well, from times past.

But that's just to let you know.  And reminds me that I have a shell-script needing debugging. :)


[1] FOR %F IN (*.TXT) DO MORE %F
     FOR %F IN (*.TMP) DO DEL %F

[2] Not quite regexp, but certainly a lot more powerful than previously available without 3rd-party addins.  And you can really develop some massively obfuscated batch-files if you try... :)
Logged

Reelyanoob

  • Bay Watcher
    • View Profile
Re: Question: Batch World Generator - is this possible?
« Reply #8 on: April 17, 2011, 08:02:50 am »

Yeah i read about them appearing in NT just now, but basically I don't do a lot of stuff with bat, mainly c++ and some vbs recently

Anyway, back on topic i just put together this AutoHotKey script which will auto-close DF in worldgen mode. Just remember to turn off the script while playing normally. All it does is have a timer, see if Dwarf Fortress is running, make it foreground, and spam a mouse click every 1/2 second.

Code: [Select]
#Persistent
SetDefaultMouseSpeed, 20
SetTimer, CloseDF, 500
return
CloseDF:
IfWinExist, Dwarf Fortress
{
WinActivate
        MouseClick,Left,50,50
}
return

I just grabbed AutoHotKey Basic from this link (1.95 MB) :-
http://www.autohotkey.com/download/

EDIT : this is not working 100% i think i have to modify it to slow the mouse down. FIXED
« Last Edit: April 17, 2011, 08:14:15 am by Reelyanoob »
Logged

Dr. Hieronymous Alloy

  • Bay Watcher
    • View Profile
Re: Question: Batch World Generator - is this possible?
« Reply #9 on: June 12, 2011, 08:56:02 am »


Edit (after turning down the params): Also... I have to hit enter after every gen? ;.; I wanted to be able to gen stuff while not around. >.< Is there a way around that?

Yeah,  any way to do this? I used to use a "worldgen.bat" file with this command line:

for /L %%i in (10,1,30) do start /wait /high "" "dwarf fortress" -gen %%i RANDOM <nameofparameterset>

But now the "press enter to accept" derails that. Any way to make this thing auto accept each world as it generates it?
Logged

Starver

  • Bay Watcher
    • View Profile
Re: Question: Batch World Generator - is this possible?
« Reply #10 on: June 12, 2011, 04:03:59 pm »

Not sure if this helps with what you want, but in the old, old days when TIME and DATE didn't have a /T option to just output the date and exit, I used to have a file alongside certain record-keeping batch-files called "LF" which contained (essentially) a single line-feed.  Then DATE < LF >> RECORD.LOG or similar[1], and a similar one for the TIME command would get past the bit where it was waiting for the <enter> key to be pressed but the user didn't (unless one had ECHOed a "Please press <enter> for me" in the self-same batch-file) know it had to be done.

Would redirecting in (or piping through) such a "line-feed file" help?  I could try myself, but I don't have DF on this particular machine, at the moment.  It could be that the DF executable won't accept that input, but unless the development kit is configured against it by default it usually needs a deliberate effort to block that sort of thing from being possible by the programmer.

You could always, petition Toady to have an "-autoaccept" or "-unattended" type of parameter, for the next version, I suppose.


[1] Probably something more like TYPE LF | DATE | FIND "current" >> RECORD.LOG, actually, to strip it down to just the line wanted...
« Last Edit: June 12, 2011, 04:06:07 pm by Starver »
Logged