Advertisement
Guest User

ComputerCraft Turtle-Mining-Drones

a guest
Oct 20th, 2012
2,630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.93 KB | None | 0 0
  1. --[[
  2.  
  3. ===================================
  4.     DRONES
  5. ===================================
  6. Originally created by Pooslice <[email protected]> (replace underscore with dot)
  7. Previous version: http://pastebin.com/AEqwuC5b
  8.  
  9.  
  10. What does it do?
  11.  
  12. * Clears a whole chunk (16x16 blocks) down to bedrock.
  13.  
  14. Features:
  15.  
  16. * Automatically refuels from drone inventory or refuel station.
  17. * Usually clears a chunk in less than 30 minutes using a total of 17 wireless mining turtles.
  18. * User interaction is required only at setup.
  19. * Immune against lava, water, mobs and any combination of those.
  20. * All collected blocks are placed in chests at the top.
  21. * Has some cleverness to save on fuel.
  22.  
  23. Restrictions:
  24.  
  25. * Water, lava and mobs will still slow down the mining process.
  26. * Will leave out blocks that are located in a vertical gap between bedrock blocks.
  27. * Will leave some cobblestone blocks when lava and water merge after a drone has already passed by.
  28. * Needs a clear starting area of 16x16x1 blocks as well as one block behind the starting block.
  29. * Will only work with iron chests or any other inventory that can be placed next to each other in a direct horizontal line.
  30. * Does not check for full chests on drop.
  31. * Not logoff- and server-shutdown-proof
  32. * My first real lua project. So the coding style is kind of sloppy and there are redundancies. Feel free to refactor and edit.
  33.  
  34. Usage:
  35.  
  36. Demonstration video: http://youtu.be/ehAHqZEZ66A
  37.  
  38. * Place a wireless mining turtle somewhere. The area that will be digged out will be 15 blocks forward and to the right of this turtle. There should be no blocks on the turtle's level (y coordinate) in this area.
  39. * Start the program with 'drone setup'
  40. * Follow the instructions. You will need 16 wireless mining turtles, 16 iron (or better) chests, one disk drive, one floppy disk and some fuel. I recommend at least three stacks of coal for one chunk.
  41. * Grab a coffee and watch the magic :)
  42.  
  43. The code is published with no rights reserved. If and how you make use of it is your own decision and I will not be held responsible. Also note that I do not have the time to make updates or regularly check the forums for comments. It was a fun little project to get used to some lua and I am releasing this to the community with the hope that it might be of use to someone.
  44.  
  45. I DO like feedback and will enjoy reading some posts occassionally. Credits are also always appreciated if you use any of this code in your own projects :)
  46. ]]--
  47.  
  48. STARTUPTIME = os.clock()
  49.  
  50. -- get call parameters
  51. local tArgs = { ... }
  52.  
  53. -- constants
  54. REFUELTHRESHOLD = 96 * 4 -- 4 coal per turtle -> one stack of coal initially plus one coal for the floppy setup
  55. DEBUGMODE = false
  56. LOGFILENAME = nil
  57.  
  58. function debug(message)
  59.     if DEBUGMODE then print(message) end
  60.     if LOGFILENAME then
  61.         local fp = fs.open(LOGFILENAME, "a")
  62.         if fp then
  63.             fp.writeLine(message)
  64.             fp.close()
  65.         end
  66.     end
  67. end
  68.  
  69. debug("Startup-Time: " .. STARTUPTIME)
  70.  
  71. -- compensate for fuelless mode
  72. if turtle.getFuelLevel() == "unlimited" then
  73.     turtle.getFuelLevel = function()
  74.         return 2 + REFUELTHRESHOLD
  75.     end
  76. end
  77.  
  78. -- don't care where
  79. rednet.open("right")
  80. rednet.open("left")
  81. rednet.open("top")
  82. rednet.open("bottom")
  83. rednet.open("front")
  84. rednet.open("back")
  85.  
  86. -- try to clear the space above the turtle
  87. -- this cannot be done 100% reliably, because dig() on water returns 'true', but detect() on water returns 'false' and water regenerates
  88. function clearUp()
  89.     debug("clearUp()")
  90.     if turtle.detectUp() then
  91.         if turtle.digUp() then
  92.             sleep(1)
  93.             turtle.digUp()
  94.         end
  95.     end
  96.     while turtle.attackUp() do end
  97.     return not turtle.detectUp()
  98. end
  99.  
  100. -- see clearUp()
  101. function clearDown()
  102.     debug("clearDown()")
  103.     if turtle.detectDown() then
  104.         turtle.digDown()
  105.     end
  106.     while turtle.attackDown() do end
  107.     return not turtle.detectDown()
  108. end
  109.  
  110. -- as clearUp(), but also tries to move up after digging
  111. function tryUp()
  112.     debug("tryUp()")
  113.     if turtle.detectUp() then
  114.         turtle.digUp()
  115.     end
  116.     while turtle.attackUp() do end
  117.     return turtle.up()
  118. end
  119.  
  120. -- see tryUp()
  121. function tryDown()
  122.     debug("tryDown()")
  123.     if turtle.detectDown() then
  124.         turtle.digDown()
  125.     end
  126.     while turtle.attackDown() do end
  127.     return turtle.down()
  128. end
  129.  
  130. -- see tryUp()
  131. -- with our digging strategy a maximum of 2 blocks must be digged out (one normal and one if it is falling sand or gravel)
  132. function tryForward()
  133.     debug("tryForward()")
  134.     if turtle.detect() then
  135.         if turtle.dig() then
  136.             sleep(1)
  137.             if turtle.dig() then
  138.                 sleep(1)
  139.                 turtle.dig()
  140.             end
  141.         end
  142.     end
  143.     while turtle.attack() do end
  144.     return turtle.forward()
  145. end
  146.  
  147. -- return to our chest, drop everything there and refuel if necessary
  148. -- returns new x, y, z and face which should be the same as when calling the function
  149. function maintenance(refuelId, x, y, z, face)
  150.     debug("maintenance(" .. refuelId .. ", " .. x .. ", " .. y .. ", " .. z .. ", ??)")
  151.     local dx, dy, dz, dface = x, y, z, face
  152.     -- move below our chest
  153.     while y > 4 do
  154.         if tryUp() then
  155.             y = y - 1
  156.         end
  157.     end
  158.     -- could come across other turtles -> no digging
  159.     while y > 0 do
  160.         while not turtle.up() do sleep(1) end
  161.         y = y - 1
  162.     end
  163.     if face then
  164.         turtle.turnRight()
  165.         turtle.turnRight()
  166.     end
  167.     while x > 0 do
  168.         while not turtle.forward() do sleep(5) end
  169.         x = x - 1
  170.     end
  171.     turtle.turnRight()
  172.     turtle.turnRight()
  173.     -- Try to refuel from inventory if necessary
  174.     if turtle.getFuelLevel() < REFUELTHRESHOLD then
  175.         debug("Refuel needed: " .. turtle.getFuelLevel() .. " < " .. REFUELTHRESHOLD)
  176.         debug("Trying to refuel from inventory")
  177.         for i = 1, 16 do
  178.             turtle.select(i)
  179.             repeat
  180.                 local fl = turtle.getFuelLevel()
  181.                 turtle.refuel(1)
  182.                 local fl2 = turtle.getFuelLevel()
  183.             until fl == fl2 or fl2 > REFUELTHRESHOLD
  184.             if turtle.getFuelLevel() >= REFUELTHRESHOLD then
  185.                 debug("Refuelling from inventory was successful: " .. turtle.getFuelLevel())
  186.                 break
  187.             end
  188.         end
  189.     end
  190.     -- drop all into the chest - overflow is ignored
  191.     for i = 1, 16 do
  192.         turtle.select(i)
  193.         turtle.dropUp()
  194.     end
  195.     -- refuel from station if still necessary
  196.     if turtle.getFuelLevel() < REFUELTHRESHOLD then
  197.         debug("Going to refuel at the station")
  198.         -- go to fuel station
  199.         -- from now on we could cross other turtles' lanes and will therefore only move, not dig
  200.         while not turtle.forward() do sleep(1) end
  201.         turtle.turnRight()
  202.         while z > 0 do
  203.             while not turtle.forward() do sleep(5) end
  204.             z = z - 1
  205.         end
  206.         turtle.turnRight()
  207.         turtle.turnRight()
  208.         while not turtle.up() do sleep(5) end
  209.         while not turtle.up() do sleep(5) end
  210.         -- refuel
  211.         while true do
  212.             -- refuel all and send fuel level until >  REFUELTHRESHOLD
  213.             for i = 1, 16 do
  214.                 turtle.select(i)
  215.                 turtle.refuel()
  216.             end
  217.             local message = {}
  218.             message["message"] = "fuelLevel"
  219.             message["fuelLevel"] = turtle.getFuelLevel()
  220.             rednet.send(refuelId, textutils.serialize(message))
  221.             if message["fuelLevel"] > REFUELTHRESHOLD then
  222.                 break
  223.             end
  224.         end
  225.         debug("Refuelling at station successful. Returning to lane.")
  226.         -- go back to lane
  227.         if dz == 0 then
  228.             turtle.turnRight()
  229.             while not turtle.forward() do sleep(5) end
  230.             while not turtle.down() do sleep(5) end
  231.             while not turtle.down() do sleep(5) end
  232.             while not turtle.down() do sleep(5) end
  233.             while not turtle.back() do sleep(5) end
  234.             while not turtle.back() do sleep(5) end
  235.             x = 0
  236.             y = 1
  237.             z = 0
  238.         else
  239.             while z < dz do
  240.                 while not turtle.forward() do sleep(5) end
  241.                 z = z + 1
  242.             end
  243.             turtle.turnRight()
  244.             while not turtle.down() do sleep(5) end
  245.             while not turtle.down() do sleep(5) end
  246.             y = 0
  247.             while not turtle.back() do sleep(1) end
  248.             x = 0
  249.         end
  250.     end
  251.     face = true
  252.     -- go back to old position
  253.     debug("Returning to old position before maintenance-call.")
  254.     while x < dx do
  255.         while not turtle.forward() do sleep(5) end
  256.         x = x + 1
  257.     end
  258.     if face ~= dface then
  259.         turtle.turnRight()
  260.         turtle.turnRight()
  261.         face = dface
  262.     end
  263.     while y < dy do
  264.         while not turtle.down() do sleep(1) end
  265.         y = y + 1
  266.     end
  267.     return x, y, z, face
  268. end
  269.  
  270. function isInventoryFull()
  271.     debug("isInventoryFull()")
  272.     for i = 1, 16 do
  273.         if turtle.getItemCount(i) == 0 then
  274.             return false
  275.         end
  276.     end
  277.     return true
  278. end
  279.  
  280. function diglane(lane, refuelId)
  281.     debug("digLane(" .. lane .. ", " .. refuelId .. ")")
  282.     -- x is forward (lane direction), y is depth below start (positive int), z is lane, true means facing in positive x direction
  283.     local x, y, z, face = 1, 0, lane, true
  284.     -- near bedrock we switch the digging strategy to vertical shafts instead of horizontal tunnels
  285.     local digVertical = false
  286.     -- big loop with many if-statements that magically does the right next step
  287.     while true do
  288.         -- required fuel back to station
  289.         -- back up + back zu x0 + one forward + to lane 0 + two up
  290.         local distToRefuelStation = y + x + 1 + z + 2
  291.         debug("Digging ... distToRefuelStation: " .. distToRefuelStation .. ", Fuel: " .. turtle.getFuelLevel())
  292.         if turtle.getFuelLevel() - distToRefuelStation < 10 then -- some safety margin that was chosen arbitrarily
  293.             debug("Trying to refuel from inventory.")
  294.             -- try to refuel from inventory
  295.             local fuelLevel = turtle.getFuelLevel()
  296.             for i = 1, 16 do
  297.                 turtle.select(i)
  298.                 repeat
  299.                     local fl = turtle.getFuelLevel()
  300.                     turtle.refuel(1)
  301.                     local fl2 = turtle.getFuelLevel()
  302.                 until fl2 > REFUELTHRESHOLD or fl == fl2
  303.             end
  304.             if turtle.getFuelLevel() <= fuelLevel then
  305.                 debug("Inventory was not enough. Starting maintenance routine.")
  306.                 -- did not work or was not enough -> start maintenance routine
  307.                 x, y, z, face = maintenance(refuelId, x, y, z, face)
  308.             end
  309.         elseif isInventoryFull() then
  310.             debug("Inventory is full. Starting maintenance routine.")
  311.             x, y, z, face = maintenance(refuelId, x, y, z, face)
  312.         else
  313.             -- dig
  314.             if not digVertical then
  315.                 if y % 3 > 0 then
  316.                     if tryDown() then
  317.                         y = y + 1
  318.                     else
  319.                         debug("Hit the ground. Will go to vertical mode.")
  320.                         digVertical = "start"
  321.                     end
  322.                 else
  323.                     if not clearUp() then
  324.                         debug("Seems, we moved one too far. Going back.")
  325.                         -- can only be the case if we accidently moved into a bedrock "gap"
  326.                         turtle.back()
  327.                         if face then
  328.                             x = x - 1
  329.                         else
  330.                             x = x + 1
  331.                         end
  332.                         if tryUp() then
  333.                             y = y - 1
  334.                         end
  335.                         debug("And starting vertical mode.")
  336.                         digVertical = "start"
  337.                     else
  338.                         if (not clearDown()) or (not tryForward()) then
  339.                             debug("Could not clear down or go forward. Starting vertical mode.")
  340.                             digVertical = "start"
  341.                         else
  342.                             if face then
  343.                                 x = x + 1
  344.                             else
  345.                                 x = x - 1
  346.                             end
  347.                             clearUp()
  348.                             if x == 0 or x == 15 then
  349.                                 turtle.turnRight()
  350.                                 turtle.turnRight()
  351.                                 face = not face
  352.                                 if not tryDown() then
  353.                                     debug("At a border and could not go down. Starting vertical mode.")
  354.                                     digVertical = "start"
  355.                                 else
  356.                                     y = y + 1
  357.                                 end
  358.                             end
  359.                         end
  360.                     end
  361.                 end
  362.             else
  363.                 if digVertical == "start" then
  364.                     -- make next step towards x15 with face towards x0
  365.                     if not face then
  366.                         turtle.turnRight()
  367.                         turtle.turnRight()
  368.                         face = not face
  369.                     end
  370.                     if x < 15 then
  371.                         debug("Moving towards the end of the lane.")
  372.                         if not tryForward() then
  373.                             if tryUp() then
  374.                                 y = y - 1
  375.                             else
  376.                                 -- need to backtrack
  377.                                 debug("Moved into a gap. Backtracking ...")
  378.                                 turtle.turnRight()
  379.                                 turtle.turnRight()
  380.                                 if tryForward() then
  381.                                     x = x - 1
  382.                                 end
  383.                                 if tryUp() then
  384.                                     y = y - 1
  385.                                 end
  386.                                 turtle.turnRight()
  387.                                 turtle.turnRight()
  388.                             end
  389.                         else
  390.                             x = x + 1
  391.                         end
  392.                     else
  393.                         debug("In position for vertical digging")
  394.                         digVertical = "digVertical"
  395.                         turtle.turnRight()
  396.                         turtle.turnRight()
  397.                         face = not face
  398.                     end
  399.                 elseif digVertical == "digVertical" then
  400.                     if tryDown() then
  401.                         y = y + 1
  402.                     else
  403.                         if x > 0 then
  404.                             debug("At the bottom. Going to next field.")
  405.                             -- bedrock has 5 layers at most
  406.                             while not tryUp() do sleep(1) end
  407.                             while not tryUp() do sleep(1) end
  408.                             while not tryUp() do sleep(1) end
  409.                             while not tryUp() do sleep(1) end
  410.                             y = y - 4
  411.                             while not tryForward() do sleep(1) end
  412.                             x = x - 1
  413.                         else
  414.                             debug("Cleared the last block. Returning now.")
  415.                             break
  416.                         end
  417.                     end
  418.                 end
  419.             end
  420.         end
  421.     end
  422.     -- we should be at x0. so we go up and drop everything to our chest
  423.     while y > 4 do
  424.         while not tryUp() do sleep(1) end
  425.         y = y - 1
  426.     end
  427.     -- could cross other turtles' paths -> no digging
  428.     while y > 0 do
  429.         while not turtle.up() do sleep(1) end
  430.         y = y - 1
  431.     end
  432.     debug("Placing everything into the chest.")
  433.     for i = 1, 16 do
  434.         turtle.select(i)
  435.         turtle.dropUp()
  436.     end
  437.     turtle.turnRight()
  438.     turtle.turnRight()
  439.     face = not face
  440.     -- send finished to control
  441.     local m = {}
  442.     m["message"] = "laneFinished"
  443.     rednet.send(refuelId, textutils.serialize(m))
  444. end
  445.  
  446. function setuplane()
  447.     local lane, refuelId
  448.     while true do
  449.         -- say hello
  450.         local broadcast = {}
  451.         broadcast["message"] = "hello"
  452.         rednet.broadcast(textutils.serialize(broadcast))
  453.         -- get welcome with our lane number
  454.         local id, message, distance = rednet.receive(5)
  455.         if message and distance < 2 then
  456.             local m = {}
  457.             m = textutils.unserialize(message)
  458.             if m["message"] == "welcome" and m["lane"] > -1 then
  459.                 lane = m["lane"] + 0
  460.                 refuelId = id
  461.                 break
  462.             end
  463.         end
  464.     end
  465.  
  466.     -- send fuel level, then get and use one fuel
  467.     for i = 1, 16 do
  468.         if turtle.getItemCount(i) == 0 then
  469.             turtle.select(i)
  470.             break
  471.         end
  472.     end
  473.     local message = {}
  474.     message["message"] = "fuelLevel"
  475.     message["fuelLevel"] = turtle.getFuelLevel()
  476.     message["lane"] = lane
  477.     rednet.send(refuelId, textutils.serialize(message))
  478.     local chestSlot
  479.     while true do
  480.         -- refuel all and send fuel level until >  REFUELTHRESHOLD
  481.         for i = 1, 16 do
  482.             local fl = turtle.getFuelLevel()
  483.             turtle.select(i)
  484.             turtle.refuel()
  485.             if turtle.getFuelLevel() > fl then
  486.                 break
  487.             end
  488.         end
  489.         -- select lowest empty slot (to detect chest placement later on)
  490.         for i = 1, 16 do
  491.             if turtle.getItemCount(i) == 0 then
  492.                 chestSlot = i
  493.                 break
  494.             end
  495.         end
  496.         message["fuelLevel"] = turtle.getFuelLevel()
  497.         rednet.send(refuelId, textutils.serialize(message))
  498.         if message["fuelLevel"] > REFUELTHRESHOLD then
  499.             break
  500.         end
  501.     end
  502.     -- get chest
  503.     while turtle.getItemCount(chestSlot) < 1 do sleep(1) end
  504.     -- only the first turtle needs to clear a path
  505.     if lane == 15 then
  506.         while not tryDown() do sleep(1) end
  507.     else
  508.         while not turtle.down() do sleep(1) end
  509.     end
  510.     -- dig/go to our lane
  511.     for i = 1, lane do
  512.         if lane == 15 then
  513.             while not tryForward() do sleep(1) end
  514.         else
  515.             while not turtle.forward() do sleep(1) end
  516.         end
  517.     end
  518.     turtle.turnRight()
  519.     -- place chest
  520.     turtle.select(chestSlot)
  521.     clearUp()
  522.     clearDown()
  523.     turtle.placeUp()
  524.     while not tryForward() do sleep(1) end
  525.  
  526.     -- dig lane
  527.     shell.run("drone", "diglane", lane, refuelId)
  528. end
  529.  
  530. function refuelStation(workers)
  531.     debug("refuelStation: " .. textutils.serialize(workers))
  532.     workers = workers or {}
  533.     turtle.turnRight()
  534.     print("Waiting for refuel requests. Will automatically exit if all lanes are complete. Press SPACE to exit early.")
  535.     print()
  536.     while true do
  537.         if #workers < 1 then
  538.             print("All lanes are done.")
  539.             break
  540.         end
  541.         local event, id, message, distance = os.pullEvent()
  542.         if event == "rednet_message" and distance < 2 and message then
  543.             local m = {}
  544.             m = textutils.unserialize(message)
  545.             if m["message"] == "fuelLevel" and m["fuelLevel"] <= REFUELTHRESHOLD then
  546.                 for i = 5, 16 do
  547.                     if turtle.getItemCount(i) > 0 then
  548.                         turtle.select(i)
  549.                         turtle.drop(1)
  550.                         break
  551.                     end
  552.                 end
  553.             end
  554.         elseif event == "rednet_message" and message then
  555.             local m = {}
  556.             m = textutils.unserialize(message)
  557.             if m["message"] == "laneFinished" then
  558.                 for i = 1, 16 do
  559.                     if workers[i] == id then
  560.                         workers[i] = nil
  561.                         break
  562.                     end
  563.                 end
  564.             end
  565.         elseif event == "key" and id == 57 then
  566.             break
  567.         end
  568.     end
  569.     turtle.turnLeft()
  570. end
  571.  
  572. function setup()
  573.     print("Please put ...")
  574.     print("... 16 wireless mining turtles in slot 1.")
  575.     print("... 16 iron or better chests in slot 2.")
  576.     print("... a floppy disk in slot 3.")
  577.     print("... a disk drive in slot 4.")
  578.     print("... fuel of any kind in slots 5-16.")
  579.     print()
  580.     print("Press RETURN to start or SPACE to exit.")
  581.     print()
  582.    
  583.     while true do
  584.         local event, id, message = os.pullEvent()
  585.         if event == "key" and id == 28 then
  586.             break
  587.         elseif event == "key" and id == 57 then
  588.             return
  589.         end
  590.     end
  591.  
  592.     -- need 2 fuel to place the floppy
  593.     while turtle.getFuelLevel() < 2 do
  594.         for i = 1, 16 do
  595.             turtle.select(i)
  596.             turtle.refuel(1)
  597.             if turtle.getFuelLevel() > 1 then
  598.                 break
  599.             end
  600.         end
  601.         sleep(1)
  602.     end
  603.    
  604.     -- need some space below me
  605.     if not tryDown() then
  606.         print("No space below me")
  607.         return
  608.     end
  609.    
  610.     -- place the disk drive and insert floppy
  611.     turtle.turnRight()
  612.     turtle.turnRight()
  613.     if turtle.detect() and (not turtle.dig()) then
  614.         print("Could not clear the space for the disk drive.")
  615.         return
  616.     end
  617.     turtle.select(4)
  618.     while not turtle.place() do sleep(5) end
  619.     turtle.select(3)
  620.     while not turtle.drop() do sleep(5) end
  621.    
  622.     -- write startup file to floppy
  623.     local fp = fs.open("disk/startup", "w")
  624.     fp.writeLine("shell.run(\"drone\", \"setuplane\")")
  625.     fp.close()
  626.    
  627.     -- move back to our position
  628.     while not tryUp() do sleep(5) end
  629.     turtle.turnRight()
  630.     turtle.turnRight()
  631.    
  632.     -- list of worker computerIDs
  633.     local workers = {}
  634.    
  635.     -- place, refuel and send off 16 drones
  636.     for i = 0, 15 do
  637.         print("Placing drone " .. i + 1 .. " of 16.")
  638.         print()
  639.         -- place the drone
  640.         turtle.select(1)
  641.         while turtle.detectDown() do sleep(1) end
  642.         turtle.placeDown()
  643.         -- boot the drone, thanks to dustpuppy for reminding me about the peripheral API
  644.         peripheral.call("bottom", "turnOn")
  645.         -- wait for announce, send lane number, wait for confirmation
  646.         -- the drone id is stored in the workers table
  647.         while true do
  648.             local id, message, distance = rednet.receive(5)
  649.             local m = {}
  650.             if message then
  651.                 m = textutils.unserialize(message)
  652.             end
  653.             if m["message"] == "hello" and distance < 2 then
  654.                 local answer = {}
  655.                 answer["message"] = "welcome"
  656.                 answer["lane"] = 15 - i
  657.                 rednet.send(id, textutils.serialize(answer))
  658.             elseif m and m["message"] == "fuelLevel" and m["lane"] == 15 - i then
  659.                 workers[15 - i] = id
  660.                 break
  661.             end
  662.         end
  663.         -- refuel drone to at least the threshold
  664.         while true do
  665.             for j = 5, 16 do
  666.                 if turtle.getItemCount(j) > 0 then
  667.                     turtle.select(j)
  668.                     turtle.dropDown(1)
  669.                     break
  670.                 end
  671.             end
  672.             local id, message, distance = rednet.receive(5)
  673.             local m = {}
  674.             if message then
  675.                 m = textutils.unserialize(message)
  676.             end
  677.             if m["message"] == "fuelLevel" and m["fuelLevel"] > REFUELTHRESHOLD then
  678.                 break
  679.             end
  680.         end
  681.         -- place chest in drone inventory
  682.         turtle.select(2)
  683.         turtle.dropDown(1)
  684.     end
  685.    
  686.     -- All drones placed. We switch to refuelling mode
  687.     shell.run("drone", "refuelstation", textutils.serialize(workers))
  688. end
  689.  
  690. function printUsage()
  691.     print("Usage of drone command:")
  692.     print()
  693.     print("drone setup|setuplane|diglane <laneNo> <refuelId>|refuelstation <serializedIdList>")
  694.     print()
  695. end
  696.  
  697. -- =========================================
  698. --                  MAIN
  699. -- =========================================
  700.  
  701. if tArgs[1] == "setup" then
  702.     setup()
  703. elseif tArgs[1] == "setuplane" then
  704.     setuplane()
  705. elseif tArgs[1] == "diglane" and tArgs[2] and tArgs[3] and tArgs[2] + 0 > -1 and tArgs[3] + 0 > -1 then
  706.     diglane(tArgs[2] + 0, tArgs[3] + 0)
  707. elseif tArgs[1] == "refuelstation" and tArgs[2] then
  708.     refuelStation(textutils.unserialize(tArgs[2]))
  709. else
  710.     printUsage()
  711. end
  712.  
  713. rednet.close("right")
  714. rednet.close("left")
  715. rednet.close("top")
  716. rednet.close("bottom")
  717. rednet.close("front")
  718. rednet.close("back")
  719.  
  720. ENDTIME = os.clock()
  721. debug("Starttime:" .. STARTUPTIME)
  722. debug("Endtime: " .. ENDTIME)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement