fm3d

nethercap.ahk, an automated wrapper around DFHack's hackwish

Jun 9th, 2014
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; vim: ft=autohotkey ff=dos
  2. #SingleInstance force
  3. ; reminder: default escape char is backtick
  4. ; license: public domain (with Creative Commons CC0 as fallback for countries without a legal concept of public domain)
  5.  
  6. ; Note that this script does not do any sanity-checking whatsoever!
  7. ; Making masterwork coins _WILL_ cause Dwarf Fortress to crash (this has been experimentally confirmed)!
  8.  
  9. ; Item type --> HackWish menu access key sequence mapping
  10. ; Comma location (start of each continuing line) and closing-brace location (end of last line) must be cargo-culted
  11. item_selectors := { "Bars" : "bars"
  12.     ,"Bed" : "bed"
  13.     ,"Bin" : "bin"
  14.     ,"Blocks" : "blocks"
  15.     ,"Cabinet" : "cabinet"
  16.     ,"Cage" : "cage"
  17.     ,"Chain" : "chain"
  18.     ,"Chest/Bag" : "box/bag"
  19.     ,"Door" : "door"
  20.     ,"Grate" : "grate"
  21.     ,"Hatch cover" : "hatch{Down}"
  22.     ,"Large Pot" : "pot{Down}{Down}"
  23.     ,"Logs" : "logs"
  24.     ,"Mechanisms" : "mechanism"
  25.     ,"Thread" : "thread" }
  26.     ;,"Coins" : "coin" ; crashes DF
  27.  
  28. ; Material name --> HackWish menu access key sequence mapping
  29. ; Comma location (start of each continuing line) and closing-brace location (end of last line) must be cargo-culted
  30. material_selectors := { "Nether-cap" : "Pnether{Down}{Enter}{Down}"
  31.     ,"Copper":"Icopper{Down}{Down}"
  32.     ,"Adamantine":"Iadamantine{Down}" }
  33.     ;; actually looks like gold, but crashes DF
  34.     ;,"Gold":"Igold{Down}{Down}{Down}{Down}"
  35.     ;; also crashes DF
  36.     ;,"Gold":"Igold{Down}{Down}{Down}{Down}{Down}{Down}"
  37.  
  38.  
  39. ; Item quality --> HackWish menu access key sequence mapping; this array is perfect, do not mess with it.
  40. quality_selectors := { "None" : "", "Well-crafted" : "{Down}", "Superior" : "{Down}{Down}", "Exceptional" : "{Up}{Up}", "Masterful" : "{Up}" }
  41.  
  42. Gui, Add, Text, section Right, Item Type:
  43. Gui, Add, Text, Right, Item Material:
  44. Gui, Add, Text, Right, Item Quality:
  45. Gui, Add, Text, Right, Item count:
  46. Gui, Add, Text, Right, Unroll factor:
  47. ;Gui, Add, Text, Right, Re-Enable MouseQuery:
  48.  
  49. Gui, Add, CheckBox, Checked venableMouseQuery, Enable mouse query after exec?
  50. Gui, Add, Button, gGuiClose, Quit
  51.  
  52. Gui, Add, DropDownList, ys vitemType
  53. for k, v in item_selectors
  54.     GuiControl, Text, itemType, %k%
  55.  
  56. Gui, Add, DropDownList, vitemMaterial
  57. for k, v in material_selectors
  58.     GuiControl, Text, itemMaterial, %k%
  59.  
  60. Gui, Add, DropDownList, vitemQuality
  61. for k,v in quality_selectors
  62.     GuiControl, Text, itemQuality, %k%
  63.  
  64. ; bumped Limit to 4 because I needed 5k gold coins to call a caravan
  65. Gui, Add, Edit, Number Limit4 vitemCount, 100
  66. Gui, Add, Edit, Number Limit3 vunrollCount, 20
  67.  
  68. Gui, Add, Button, gGuiGo, Go
  69.  
  70. Gui, Show, , Nether-Cap Item Spawner
  71.  
  72. Return
  73.  
  74. GuiGo:
  75. {
  76.     Gui, Submit, nohide
  77.     ; focus Dwarf Fortress
  78.     ; activate cursor
  79.     it := item_selectors[itemType]
  80.     im := material_selectors[itemMaterial]
  81.     iq := quality_selectors[itemQuality]
  82.     ;MsgBox, var it is %it%`, var im is %im%`, var iq is %iq%
  83.  
  84.     ; loop optimization
  85.     exact_loops := itemCount // unrollCount
  86.     remainder_loops := Mod(itemCount , unrollCount)
  87.    
  88.     MsgBox, Please select a target location with the `"k`" cursor in DF`, and make sure you didn`'t leave a stateful DFHack command (such as `"lua`" or `"liquids`") open`!
  89.  
  90.     loop %exact_loops% {
  91.         WinWait, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe,
  92.         IfWinNotActive, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe, , WinActivate, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe,
  93.         WinWaitActive, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe,
  94.         Send, mousequery plugin disabled{Enter}
  95.         Send, multicmd{Space} ; The only good thing about cmd.exe: it isn't very sensitive to input timing, so it doesn't need a ton of sleeps! Yay!
  96.         loop %unrollCount% {
  97.             Send, hackwish{Space}`;{Space}
  98.         }
  99.         Send, {Enter}
  100.         WinWait, Dwarf Fortress,
  101.         IfWinNotActive, Dwarf Fortress, , WinActivate, Dwarf Fortress,
  102.         WinWaitActive, Dwarf Fortress,
  103.         ; these sleeps help keep DF from getting confused
  104.         loop %unrollCount% {
  105.             sleep 10 ; Dwarf Fortress doesn't process the input properly unless we sleep after every Send command
  106.             Send, %it%{Enter}
  107.             sleep 10
  108.             Send, %im%{Enter}
  109.             sleep 10
  110.             Send, %iq%{Enter}
  111.             sleep 10
  112.         }
  113.     }
  114.  
  115.     loop %remainder_loops% {
  116.         WinWait, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe,
  117.         IfWinNotActive, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe, , WinActivate, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe,
  118.         WinWaitActive, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe,
  119.         Send, hackwish{Enter}
  120.         WinWait, Dwarf Fortress,
  121.         IfWinNotActive, Dwarf Fortress, , WinActivate, Dwarf Fortress,
  122.         WinWaitActive, Dwarf Fortress,
  123.         ; todo: this was actually caused by mouse movement + a DFHack plugin, re-test without sleeps
  124.         sleep 10 ; Dwarf Fortress doesn't process the input properly unless we sleep after every {Enter}
  125.         Send, %it%{Enter}
  126.         sleep 10
  127.         Send, %im%{Enter}
  128.         sleep 10
  129.         Send, %iq%{Enter}
  130.     }
  131.     if %enableMouseQuery% {
  132.         WinWait, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe,
  133.         IfWinNotActive, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe, , WinActivate, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe,
  134.         WinWaitActive, C:\Users\fm3d\Desktop\MasterworkDF V.5.05\Dwarf Fortress\Dwarf Fortress.exe,
  135.         Send, mousequery plugin enabled{Enter}
  136.         WinWait, Dwarf Fortress,
  137.         IfWinNotActive, Dwarf Fortress, , WinActivate, Dwarf Fortress,
  138.         WinWaitActive, Dwarf Fortress,
  139.     }
  140.     ;Gui,Show
  141. }
  142.  
  143. GuiClose:
  144. {
  145.     ExitApp
  146. }
Add Comment
Please, Sign In to add comment