Advertisement
Le_JuiceBOX

[App] fleet.lua

Jan 22nd, 2025 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.06 KB | None | 0 0
  1. local Brain = require("/turtleBrain"):new()
  2. local Terminal = require("/terminal"):new()
  3. local NetLib = require("/netLib"):new()
  4.  
  5. local Params = {
  6.     Width = nil,
  7.     Height = nil,
  8.     Depth = nil,
  9.     StartDepth = nil,
  10.     StartX = nil,
  11.     NumTurtles = nil,
  12. }
  13.  
  14. function writeHeader()
  15.     Terminal:reset()
  16.     Terminal:display(0,
  17.         "&c"..Terminal:makeSeperator("="),
  18.         " &dTurtle - Fleet Master ~",
  19.         "&c"..Terminal:makeSeperator("="),
  20.         ""
  21.     )
  22. end
  23.  
  24. function main()
  25.     Params = {
  26.         Width = nil,
  27.         Height = nil,
  28.         Depth = nil,
  29.         StartDepth = nil,
  30.         StartX = nil,
  31.         NumTurtles = nil,
  32.     }
  33.     repeat
  34.         writeHeader()
  35.         Terminal:print("(not including this one)")
  36.         Params.NumTurtles = Terminal:promptNum("How many turtles are in the fleet?")
  37.         writeHeader()
  38.         Params.Width = Terminal:promptNum("Input block width:")
  39.         Params.Height = Terminal:promptNum("Input block height:")
  40.         Params.Depth = Terminal:promptNum("Input block depth:")
  41.         writeHeader()
  42.         Params.StartDepth = Terminal:promptNum("Input start depth offset: (leave blank for none)") or 0
  43.         Params.StartX = Terminal:promptNum("Input start x offset: (leave blank for none)") or 0
  44.         writeHeader()
  45.         term.setCursorPos(1,5)
  46.         for name,val in pairs(Params) do
  47.             Terminal:print(" "..tostring(name).."  - &c"..tostring(val))
  48.         end
  49.         Terminal:print()
  50.     until Terminal:promptConf("Continue with these parameters?",true)
  51.     writeHeader()
  52.     Params.NumTurtles = Params.NumTurtles + 1 -- add this turtle to the total
  53.     local total = Params.Width
  54.     local placedTurts = 0
  55.     local div = math.ceil(Params.Width/Params.NumTurtles)
  56.     local i = 0
  57.     Brain:forceUp()
  58.     Brain:turnRight()
  59.     local packet = {}
  60.     total = total - div -- account for this turtle
  61.     while total > 0 do        
  62.         total = total - div
  63.         if total < div then
  64.             Brain:forceForward(div-total)
  65.         else
  66.             Brain:forceForward(div)
  67.         end
  68.         Brain:turnLeft()
  69.         turtle.select(1 + i)
  70.         turtle.placeDown()
  71.         os.sleep(1)
  72.         -- start fleet turtle
  73.         peripheral.call("bottom","turnOn")
  74.         local isOn = peripheral.call("bottom","isOn")
  75.         print("On?:",tostring(isOn))
  76.         rednet.open("left")
  77.         os.sleep(1)
  78.         local id = peripheral.call("bottom","getID")
  79.         os.sleep(2)
  80.         packet = NetLib:compilePacket("MINE",div,Params.Height,Params.Depth,Params.StartDepth,div*i,1)
  81.         rednet.send(id,packet)
  82.         rednet.close()
  83.  
  84.        
  85.         Brain:turnRight()
  86.         i = i + 1
  87.     end
  88.     Brain:turnToFace(Brain.Dir.W)
  89.     Brain:forceForward(Params.Width-div) -- -2 bc there is never a turtle on the last block
  90.     Brain:turnToFace(Brain.Dir.N)
  91.     Brain:forceDown()
  92.     shell.run("OS/Programs/Turtle/mine.lua "..div.." "..Params.Height.." "..Params.Depth.." "..Params.StartDepth.." ".."0".." "..1)
  93. end
  94.  
  95. main()
  96. -- OS/Programs/Turtle/mine.lua 2 2 4 0 0 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement