Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

ITSBTH

By: a guest on Apr 18th, 2009  |  syntax: AutoIt  |  size: 3.12 KB  |  hits: 38  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #cs
  2. # Dwarf Fortress functions
  3. # All functions expects the mode be set beforehand, because the cursor is not guaranteed to be in the same spot after leaving and returning to it.
  4. #ce
  5.  
  6. #Include <NomadMemory.au3>
  7.  
  8. Global $Rows = 4
  9.  
  10. Global $CorridorWidth = 2
  11. Global $RoomLength = 3
  12. Global $XAddress = 0x009FC294, $YAddress = 0x009FC298
  13. Global $UpZKey = "'", $DownZKey = "-"
  14. Global $DFProcess, $DFHandle
  15.  
  16. ; The current X and Y position, relative to the start
  17. Global $CurX = 0, $CurY = 0, $CurZ = 0
  18.  
  19. Func Setup()
  20.         SetPrivilege("SeDebugPrivilege", 1)
  21.         $DFProcess = WinGetProcess("Dwarf Fortress")
  22.         If $DFProcess == -1 Then
  23.                 MsgBox(16, "Error", "Unable to find Dwarf Fortress")
  24.                 Exit()
  25.         EndIF
  26.         $DFHandle = _MemoryOpen($DFProcess)
  27.  
  28. Func Update()
  29.         $CurX = _MemoryRead($XAddress, $DFHandle)
  30.         $CurY = _MemoryRead($YAddress, $DFHandle)
  31.  
  32. Func SendSleep($String)
  33.         Sleep(25)
  34.         Send($String)
  35.         Sleep(25)
  36.  
  37. Func MoveCursor($x, $y, $z = -1)
  38.         Update()
  39.         While $x <> $CurX
  40.                 If $x > $CurX Then
  41.                         SendSleep("{RIGHT}")
  42.                 Else
  43.                         SendSleep("{LEFT}")
  44.                 EndIf
  45.                 Update()
  46.         WEnd
  47.         While $y <> $CurY
  48.                 If $y > $CurY Then
  49.                         SendSleep("{DOWN}")
  50.                 Else
  51.                         SendSleep("{UP}")
  52.                 EndIf
  53.                 Update()
  54.         WEnd
  55.         If $z <> -1 Then       
  56.                 MoveCursorZ($z)
  57.         EndIf
  58.  
  59. Func MoveCursorZ($Z)
  60.         While $z <> $CurZ
  61.                 If $Z > $CurZ Then
  62.                         SendSleep($UpZKey)
  63.                         $CurZ += 1
  64.                 Else
  65.                         SendSleep($DownZKey)
  66.                         $CurZ -= 1
  67.                 EndIf
  68.         WEnd
  69.  
  70. Func DigMultiLevel($StartX, $StartY, $StartZ, $EndX, $EndY, $EndZ)
  71.         If $StartZ > $EndZ Then ; Swap start and end Z if StartZ is greater than EndZ
  72.                 Local $tmp = $StartZ
  73.                 $StartZ = $EndZ
  74.                 $EndZ = $tmp
  75.         EndIf
  76.         $EZ = $StartZ
  77.         Do
  78.                 MoveCursorZ($EZ)
  79.                 Dig($StartX, $StartY, $EndX, $EndY)
  80.                 $EZ += 1
  81.         Until $EZ == $EndZ
  82.  
  83. Func Dig($StartX, $StartY, $EndX, $EndY)
  84.         SendSleep("d")
  85.         MoveCursor($StartX, $StartY)
  86.         SendSleep("{ENTER}")
  87.         MoveCursor($EndX, $EndY)
  88.         SendSleep("{ENTER}")
  89.         EndFunc
  90.  
  91. Func CreateStairWell($X, $Y, $StartZ, $EndZ)
  92.         If $StartZ > $EndZ Then ; Swap start and end Z if StartZ is greater than EndZ
  93.                 Local $tmp = $StartZ
  94.                 $StartZ = $EndZ
  95.                 $EndZ = $tmp
  96.         EndIf
  97.         MoveCursor($X, $Y, $StartZ)
  98.         SendSleep("j")
  99.         SendSleep("{ENTER}")
  100.         SendSleep("{ENTER}")
  101.         Local $EZ = $EndZ + 1
  102.         While $CurZ <> $EZ
  103.                 MoveCursorZ($CurZ - 1)
  104.                 SendSleep("i")
  105.                 SendSleep("{ENTER}")
  106.                 SendSleep("{ENTER}")
  107.         WEnd
  108.         MoveCursorZ($CurZ - 1)
  109.         SendSleep("u")
  110.         SendSleep("{ENTER}")
  111.         SendSleep("{ENTER}")
  112.  
  113. Func Build($X, $Y, $Z, $BuildString)
  114.         SendSleep($BuildString)
  115.         MoveCursor($X, $Y, $Z)
  116.         SendSleep("{ENTER}")
  117.         SendSleep("{ENTER}") ; Select topmost material / building
  118.  
  119. ; Specialized functions
  120.  
  121. Func CreateQuarter($X, $Y, $D)
  122.         Dig($x - 1, $Y, $X + 1, $Y)
  123.         Dig($X, $Y + $D, $X, $Y + $D)
  124.  
  125. Func CreateQuarters($StartX, $StartY, $Rows)
  126.         Dig($StartX, $StartY, $StartX + 1 + $Rows * 4, $StartY + 2)
  127.         For $I = 0 To $Rows
  128.                 CreateQuarter($StartX + 1 + $I * 4, $StartY - 2, 1)
  129.                 CreateQuarter($StartX + 1 + $I * 4, $StartY + 4, -1)
  130.         Next
  131.  
  132. WinActivate("Dwarf Fortress")
  133.  
  134. Setup()
  135. ; MoveCursor(10, 10, -3)
  136. CreateQuarters(120, 20, 10)