#SingleInstance force SetKeyDelay 70 dquote = " DebugOn := 0 mode := 0 KeySentLimit := 50 fname := "roomdef1.csv" ; Filename selector $!1:: fname:= "roomdef1.csv" $!2:: fname:= "roomdef2.csv" $!3:: fname:= "roomdef3.csv" $!4:: fname:= "roomdef4.csv" $!5:: fname:= "roomdef5.csv" $!6:: fname:= "roomdef6.csv" $!7:: fname:= "roomdef7.csv" $!8:: fname:= "roomdef8.csv" $!9:: fname:= "roomdef9.csv" ; Designation / Construction mode $!D:: mode := 0 $!C:: mode := 1 ; Start position switch $!Q:: startpos := 0 $!W:: startpos := 1 $!A:: startpos := 2 $!S:: startpos := 3 ; Helper to mass-demolish misplaced constuctions $!X:: Send {x 30} ; The actual builder $!B:: FileDelete, debug.txt if(mode = 0) { Perform("d","Starting Designation Mode...",1) fname_m := fname SetKeyDelay 45 } else { Perform("","Starting Construction Mode...",0) fname_m := "C" . fname SetKeyDelay 70 } ;Initial correction for different start positions FileReadLine, firstline, %fname_m%, 1 StringSplit, firstarr, firstline, `, numcols := firstarr0 - 2 numrows := 0 Loop, Read, %fname_m% { ; StringMid, firstchar, A_LoopReadLine, 2, 1 if(RegExMatch(A_LoopReadLine, "^" . dquote . "?#!-?[0-9]+")) { break } if(RegExMatch(A_LoopReadLine, "^" . dquote . "?#") == 0) { numrows += 1 } } numrows := numrows - 1 if(startpos == 1 or startpos == 3) Send {Left %numcols%} if(startpos == 2 or startpos == 3) Send {Up %numrows%} currdes := "" action := "" y := 0 z := 0 Loop, Read, %fname_m% { Perform("", A_LoopReadLine, 0) if(RegExMatch(A_LoopReadLine, "^" . dquote . "?#!(-?[0-9]+)" . dquote . "?|#!(-?[0-9]+)", ZLevel) > 0) { if(y > 0) { QuickNav("Up", "Return to y start", y) } y := 0 Perform("", "Create level " . ZLevel1, 0) diff := ZLevel1 - z if(diff < 0) { Perform("+{. ". diff * -1 . "}", "Move down ". diff * -1 . " levels", diff * -2) } else if(diff > 0) { Perform("+{, " . diff . "}", "Move up " . diff . " levels", diff * 2) } z := z + diff continue } Perform("","Create Row-" . y, 0) x := 0 action := "-1" countdes := 0 Loop, parse, A_LoopReadLine, `, { StringLower, reqdes, A_LoopField reqdes := RegExReplace(reqdes, dquote . "(.+)" . dquote, "$1") if(reqdes == "#" && action == "") { break } else if(action != reqdes) { if(countdes > 0) { x := x + countdes QuickNav("Right", "Jump to next", countdes) countdes := 0 } if(action != "" && action != "-1") { Perform("{Enter}", "End Designate", 1) } if(reqdes == "#") { break } if(A_Index > 1) { Perform("{Right}", "Next Tile", 1) x := x + 1 } action := reqdes if(action == "") { continue } else if(mode = 1) { Perform("{Space}","Go to menu", 1) Perform(action, "Select Construction", 1) Perform("{Enter 2}","C", 2) Perform("w","Return to movement", 1) Perform("", "Flush Buffer", -1) Sleep, 500 action := "" } else { if(currdes != action) { Perform(action, "Set designation " . action, 1) currdes := action } Perform("{Enter}","Begin designation", 1) } } else { countdes := countdes + 1 } } QuickNav("Left", "Carage Return", x) Perform("{Down}","Line Feed",1) y := y + 1 } if(y > 0) { QuickNav("Up", "Return to Starting y", y) } diff := -z if(diff < 0) { Perform("+{. ". diff * -1 . "}", "Move down ". diff * -1 . " levels", diff * -2) } else if(diff > 0) { Perform("+{, " . diff . "}", "Move up " . diff . " levels", diff * 2) } Perform("", "Flush Buff", -1) return QuickNav(key, str, n) { if(n < 1) { } else if(n == 1) { Perform("{" . key . "}", str, 1) } else if(n < 10) { Perform("{" . key . " " . n . "}", str, n) } else { mod := mod(n, 10) tens := (n - mod) / 10 cmd := "+{" . key . " " . tens . "}" total := tens * 2 if(mod > 0) { cmd := cmd . "{" . key . " " . mod . "}" total := total + mod } Perform(cmd, str, total) } } Perform(keys, debugstr, num) { global DebugOn static KeySentCount := 0 global KeySentLimit static KeySentBuf := "" if DebugOn { FileAppend, %debugstr%`n, debug.txt } if(num < 0) { SendInput %KeySentBuf% KeySentCount := 0 KeySentBuf := "" } else if(StrLen(keys) > 0) { if DebugOn { FileAppend, %keys%`n, debug.txt } if(KeySentCount + num > KeySentLimit) { SendInput %KeySentBuf% KeySentCount := 0 KeySentBuf := "" Sleep, 525 } KeySentBuf := KeySentBuf . keys KeySentCount := KeySentCount + num } }