Advertisement
Guest User

ITSBTH

a guest
Apr 18th, 2009
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.12 KB | None | 0 0
  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. EndFunc
  28.  
  29. Func Update()
  30.     $CurX = _MemoryRead($XAddress, $DFHandle)
  31.     $CurY = _MemoryRead($YAddress, $DFHandle)
  32. EndFunc
  33.  
  34. Func SendSleep($String)
  35.     Sleep(25)
  36.     Send($String)
  37.     Sleep(25)
  38. EndFunc
  39.  
  40. Func MoveCursor($x, $y, $z = -1)
  41.     Update()
  42.     While $x <> $CurX
  43.         If $x > $CurX Then
  44.             SendSleep("{RIGHT}")
  45.         Else
  46.             SendSleep("{LEFT}")
  47.         EndIf
  48.         Update()
  49.     WEnd
  50.     While $y <> $CurY
  51.         If $y > $CurY Then
  52.             SendSleep("{DOWN}")
  53.         Else
  54.             SendSleep("{UP}")
  55.         EndIf
  56.         Update()
  57.     WEnd
  58.     If $z <> -1 Then   
  59.         MoveCursorZ($z)
  60.     EndIf
  61. EndFunc
  62.  
  63. Func MoveCursorZ($Z)
  64.     While $z <> $CurZ
  65.         If $Z > $CurZ Then
  66.             SendSleep($UpZKey)
  67.             $CurZ += 1
  68.         Else
  69.             SendSleep($DownZKey)
  70.             $CurZ -= 1
  71.         EndIf
  72.     WEnd
  73. EndFunc
  74.  
  75. Func DigMultiLevel($StartX, $StartY, $StartZ, $EndX, $EndY, $EndZ)
  76.     If $StartZ > $EndZ Then ; Swap start and end Z if StartZ is greater than EndZ
  77.         Local $tmp = $StartZ
  78.         $StartZ = $EndZ
  79.         $EndZ = $tmp
  80.     EndIf
  81.     $EZ = $StartZ
  82.     Do
  83.         MoveCursorZ($EZ)
  84.         Dig($StartX, $StartY, $EndX, $EndY)
  85.         $EZ += 1
  86.     Until $EZ == $EndZ
  87. EndFunc
  88.  
  89. Func Dig($StartX, $StartY, $EndX, $EndY)
  90.     SendSleep("d")
  91.     MoveCursor($StartX, $StartY)
  92.     SendSleep("{ENTER}")
  93.     MoveCursor($EndX, $EndY)
  94.     SendSleep("{ENTER}")
  95.     EndFunc
  96.  
  97. Func CreateStairWell($X, $Y, $StartZ, $EndZ)
  98.     If $StartZ > $EndZ Then ; Swap start and end Z if StartZ is greater than EndZ
  99.         Local $tmp = $StartZ
  100.         $StartZ = $EndZ
  101.         $EndZ = $tmp
  102.     EndIf
  103.     MoveCursor($X, $Y, $StartZ)
  104.     SendSleep("j")
  105.     SendSleep("{ENTER}")
  106.     SendSleep("{ENTER}")
  107.     Local $EZ = $EndZ + 1
  108.     While $CurZ <> $EZ
  109.         MoveCursorZ($CurZ - 1)
  110.         SendSleep("i")
  111.         SendSleep("{ENTER}")
  112.         SendSleep("{ENTER}")
  113.     WEnd
  114.     MoveCursorZ($CurZ - 1)
  115.     SendSleep("u")
  116.     SendSleep("{ENTER}")
  117.     SendSleep("{ENTER}")
  118. EndFunc
  119.  
  120. Func Build($X, $Y, $Z, $BuildString)
  121.     SendSleep($BuildString)
  122.     MoveCursor($X, $Y, $Z)
  123.     SendSleep("{ENTER}")
  124.     SendSleep("{ENTER}") ; Select topmost material / building
  125. EndFunc
  126.  
  127. ; Specialized functions
  128.  
  129. Func CreateQuarter($X, $Y, $D)
  130.     Dig($x - 1, $Y, $X + 1, $Y)
  131.     Dig($X, $Y + $D, $X, $Y + $D)
  132. EndFunc
  133.  
  134. Func CreateQuarters($StartX, $StartY, $Rows)
  135.     Dig($StartX, $StartY, $StartX + 1 + $Rows * 4, $StartY + 2)
  136.     For $I = 0 To $Rows
  137.         CreateQuarter($StartX + 1 + $I * 4, $StartY - 2, 1)
  138.         CreateQuarter($StartX + 1 + $I * 4, $StartY + 4, -1)
  139.     Next
  140. EndFunc
  141.  
  142. WinActivate("Dwarf Fortress")
  143.  
  144. Setup()
  145. ; MoveCursor(10, 10, -3)
  146. CreateQuarters(120, 20, 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement