Advertisement
Guest User

digCircle v1.0

a guest
Jul 11th, 2013
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.90 KB | None | 0 0
  1. --------------------
  2. -- Made by nDoorn --
  3. --------------------
  4. --- Version 1.0 ---
  5. ------------------------------
  6. -- How to use this program? --
  7. ------------------------------
  8. -- Place an Fuel chest in slot 16
  9. -- Place an Item chest in slot 15
  10. -- Set the settings
  11. -- Start the program!
  12.  
  13. ------------------
  14. ---- SETTINGS ----
  15. ------------------
  16. local radius        = 5
  17. local depth         = 5
  18. local quarters      = 1
  19. local minFuelLevel  = 600
  20.  
  21. --------------------------------------------
  22. ---------------- FUNCTIONS -----------------
  23. --------------------------------------------
  24. function round(num) return math.floor(num + 0.5) end
  25.  
  26. function digCircle(grid)
  27. local X = 0
  28. local Y = 0
  29. local DigDepth = depth - 2
  30. local GridValue = 0
  31.  
  32. checkFuel()
  33.  
  34.     while true do
  35.         for i=1, quarters, 1 do
  36.             while true do
  37.                 if (grid[X][Y + 1] == 1) then
  38.                     tForwardDig(1)
  39.                     Y = Y + 1
  40.                 else
  41.                     tBack(Y)
  42.                     Y = 0
  43.                    
  44.                     depositItems()
  45.                     checkFuel()
  46.                    
  47.                     if (grid[X+1][Y] == 1) then
  48.                         turtle.turnRight()
  49.                         tForwardDig(1)
  50.                         X = X + 1
  51.                         turtle.turnLeft()
  52.                     else
  53.                         turtle.turnRight()
  54.                         tBack(X)
  55.                         X = 0
  56.                         break
  57.                     end
  58.                 end
  59.             end
  60.         end
  61.                
  62.         for i=1, quarters, 1 do
  63.             turtle.turnLeft()
  64.         end
  65.        
  66.         if (DigDepth == 0) then
  67.             break
  68.         end
  69.        
  70.         if (DigDepth == 1) then
  71.             turtle.digDown()
  72.             turtle.down()      
  73.             turtle.digDown()
  74.             DigDepth = DigDepth - 1
  75.         end
  76.        
  77.         if (DigDepth >= 2) then
  78.             turtle.digDown()
  79.             turtle.down()
  80.             turtle.digDown()
  81.             turtle.down()
  82.             turtle.digDown()
  83.             DigDepth = DigDepth - 2
  84.         end
  85.        
  86.         depositItems()
  87.  
  88.     end
  89.  
  90.     print("-----------------------------")
  91.     print("-- Yay, i am done. Phew :) --")
  92.     print("-----------------------------")
  93. end
  94.  
  95. function tForwardDig(steps)
  96.     for k=1, steps, 1 do
  97.         turtle.dig()
  98.         turtle.forward()
  99.         turtle.digDown()
  100.     end
  101. end
  102.  
  103. function tLeft(steps)
  104.     for k=1, steps, 1 do
  105.         turtle.turnLeft()
  106.     end
  107. end
  108.  
  109. function tRight(steps)
  110.     for k=1, steps, 1 do
  111.         turtle.turnRight()
  112.     end
  113. end
  114.  
  115. function tBack(steps)
  116.     for k=1, steps, 1 do
  117.         turtle.back()
  118.     end
  119. end
  120.  
  121. function checkFuel()
  122.     local fuel = turtle.getFuelLevel()
  123.     local refuelItems = 0
  124.     if fuel < minFuelLevel then
  125.         turtle.select(16)                       -- Select the Fuel chest
  126.         turtle.placeUp()                        -- Place the fuel chest
  127.         turtle.suckUp()                         -- Get some fuel from the chest
  128.         refuelItems = turtle.getItemCount(16)   -- Get the number of fuel items
  129.         turtle.refuel(refuelItems)              -- Refuel the turtle
  130.         turtle.digUp()                          -- Pickup the chest again
  131.     end
  132. end
  133.  
  134. function depositItems()
  135.     turtle.select(15)                           -- Select the item chest slot
  136.     turtle.placeUp()                            -- Place the item chest
  137.     for i=1, 14, 1 do                           -- Go through all the slots of the turtle
  138.         turtle.select(i)                        -- Select slot 1 - 14
  139.         if (turtle.getItemCount ~= 0) then      -- check if there is an item there
  140.             turtle.dropUp()                     -- If there is, put it in the chest
  141.         end
  142.     end
  143.     turtle.select(15)                           -- Select slot 15
  144.     turtle.digUp()                              -- Pick up the chest
  145. end
  146.  
  147. --------------------------------------------
  148. ------------------- CODE -------------------
  149. --------------------------------------------
  150. term.clear()
  151.  
  152. -- Create an array
  153. local grid = {}
  154.  
  155. for x=0, radius, 1 do
  156.     grid[x] = {}
  157.     for y=0, radius, 1 do
  158.         grid[x][y] = 0
  159.     end
  160. end
  161.  
  162. local original = {}
  163.  
  164. term.clear()
  165. term.setCursorPos(1,1)
  166.  
  167. print("Circle radius is : ", radius)
  168. print("Circle depth is  : ", depth)
  169. print("Turtle fuel level: ", turtle.getFuelLevel())
  170. print("")
  171. print("Calculating the grid")
  172. -- Calculate the step values
  173. for i=0, radius - 1, 1 do --for i=0, radius - 1, 1 do
  174.     local buffer    = 0
  175.    
  176.     buffer = math.sqrt(math.pow(radius, 2) - math.pow(i, 2))
  177.     buffer = round(buffer) - 1
  178.    
  179.     for j=i, buffer, 1 do
  180.         grid[i][j] = 1
  181.     end
  182.    
  183.     for j=i, buffer, 1 do
  184.         grid[j][i] = 1
  185.     end
  186. end
  187.  
  188. print ("Starting with digging")
  189. print ("")
  190. digCircle(grid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement