Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cs
- # Dwarf Fortress functions
- # 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.
- #ce
- #Include <NomadMemory.au3>
- Global $Rows = 4
- Global $CorridorWidth = 2
- Global $RoomLength = 3
- Global $XAddress = 0x009FC294, $YAddress = 0x009FC298
- Global $UpZKey = "'", $DownZKey = "-"
- Global $DFProcess, $DFHandle
- ; The current X and Y position, relative to the start
- Global $CurX = 0, $CurY = 0, $CurZ = 0
- Func Setup()
- SetPrivilege("SeDebugPrivilege", 1)
- $DFProcess = WinGetProcess("Dwarf Fortress")
- If $DFProcess == -1 Then
- MsgBox(16, "Error", "Unable to find Dwarf Fortress")
- Exit()
- EndIF
- $DFHandle = _MemoryOpen($DFProcess)
- EndFunc
- Func Update()
- $CurX = _MemoryRead($XAddress, $DFHandle)
- $CurY = _MemoryRead($YAddress, $DFHandle)
- EndFunc
- Func SendSleep($String)
- Sleep(25)
- Send($String)
- Sleep(25)
- EndFunc
- Func MoveCursor($x, $y, $z = -1)
- Update()
- While $x <> $CurX
- If $x > $CurX Then
- SendSleep("{RIGHT}")
- Else
- SendSleep("{LEFT}")
- EndIf
- Update()
- WEnd
- While $y <> $CurY
- If $y > $CurY Then
- SendSleep("{DOWN}")
- Else
- SendSleep("{UP}")
- EndIf
- Update()
- WEnd
- If $z <> -1 Then
- MoveCursorZ($z)
- EndIf
- EndFunc
- Func MoveCursorZ($Z)
- While $z <> $CurZ
- If $Z > $CurZ Then
- SendSleep($UpZKey)
- $CurZ += 1
- Else
- SendSleep($DownZKey)
- $CurZ -= 1
- EndIf
- WEnd
- EndFunc
- Func DigMultiLevel($StartX, $StartY, $StartZ, $EndX, $EndY, $EndZ)
- If $StartZ > $EndZ Then ; Swap start and end Z if StartZ is greater than EndZ
- Local $tmp = $StartZ
- $StartZ = $EndZ
- $EndZ = $tmp
- EndIf
- $EZ = $StartZ
- Do
- MoveCursorZ($EZ)
- Dig($StartX, $StartY, $EndX, $EndY)
- $EZ += 1
- Until $EZ == $EndZ
- EndFunc
- Func Dig($StartX, $StartY, $EndX, $EndY)
- SendSleep("d")
- MoveCursor($StartX, $StartY)
- SendSleep("{ENTER}")
- MoveCursor($EndX, $EndY)
- SendSleep("{ENTER}")
- EndFunc
- Func CreateStairWell($X, $Y, $StartZ, $EndZ)
- If $StartZ > $EndZ Then ; Swap start and end Z if StartZ is greater than EndZ
- Local $tmp = $StartZ
- $StartZ = $EndZ
- $EndZ = $tmp
- EndIf
- MoveCursor($X, $Y, $StartZ)
- SendSleep("j")
- SendSleep("{ENTER}")
- SendSleep("{ENTER}")
- Local $EZ = $EndZ + 1
- While $CurZ <> $EZ
- MoveCursorZ($CurZ - 1)
- SendSleep("i")
- SendSleep("{ENTER}")
- SendSleep("{ENTER}")
- WEnd
- MoveCursorZ($CurZ - 1)
- SendSleep("u")
- SendSleep("{ENTER}")
- SendSleep("{ENTER}")
- EndFunc
- Func Build($X, $Y, $Z, $BuildString)
- SendSleep($BuildString)
- MoveCursor($X, $Y, $Z)
- SendSleep("{ENTER}")
- SendSleep("{ENTER}") ; Select topmost material / building
- EndFunc
- ; Specialized functions
- Func CreateQuarter($X, $Y, $D)
- Dig($x - 1, $Y, $X + 1, $Y)
- Dig($X, $Y + $D, $X, $Y + $D)
- EndFunc
- Func CreateQuarters($StartX, $StartY, $Rows)
- Dig($StartX, $StartY, $StartX + 1 + $Rows * 4, $StartY + 2)
- For $I = 0 To $Rows
- CreateQuarter($StartX + 1 + $I * 4, $StartY - 2, 1)
- CreateQuarter($StartX + 1 + $I * 4, $StartY + 4, -1)
- Next
- EndFunc
- WinActivate("Dwarf Fortress")
- Setup()
- ; MoveCursor(10, 10, -3)
- CreateQuarters(120, 20, 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement