Advertisement
Guest User

quarry

a guest
Dec 21st, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | None | 0 0
  1. rednet.open("right")
  2.  
  3. jobAv = true
  4. manager = 5
  5.  
  6. xCoord = 238
  7. yCoord = 77
  8. zCoord = 492
  9.  
  10. xHome = xCoord
  11. yHome = yCoord
  12. zHome = zCoord
  13. oHome = "south"
  14.  
  15. xQuarry = 999
  16. yQuarry = 999
  17. zQuarry = 999
  18.  
  19. xProg = 999
  20. yProg = 999
  21. zProg = 999
  22. oProg = 1
  23.  
  24. yMin = 999
  25.  
  26. orient = 3
  27. orients = {"south","west","north","east"}
  28.  
  29. zDiff = {1, 0, -1, 0}
  30. xDiff = {0, -1, 0, 1}
  31.  
  32. lineLength = 8
  33. lines = 9
  34.  
  35. function invFull()
  36.   turtle.select(16)
  37.   full = turtle.getItemCount() > 0
  38.   turtle.select(1)
  39.   return full
  40. end
  41.  
  42. function forward()
  43.   xCoord = xCoord + xDiff[orient]
  44.   zCoord = zCoord + zDiff[orient]
  45.  
  46.   moved = false
  47.   while not moved do
  48.     turtle.dig()
  49.     moved = turtle.forward()
  50.   end
  51. end
  52.  
  53. function left()
  54.   orient = orient - 1
  55.   orient = (orient - 1) % 4
  56.   orient = orient + 1
  57.  
  58.   turtle.turnLeft()
  59. end
  60.  
  61. function right()
  62.   orient = orient - 1
  63.   orient = (orient + 1) % 4
  64.   orient = orient + 1
  65.  
  66.   turtle.turnRight()
  67. end
  68.  
  69. function up()
  70.   yCoord = yCoord + 1
  71.  
  72.   turtle.digUp()
  73.   moved = false
  74.   while not(moved) do
  75.     moved = turtle.up()
  76.   end
  77. end
  78.  
  79. function down()
  80.   yCoord = yCoord - 1
  81.  
  82.   turtle.digDown()
  83.  
  84.   moved = false
  85.   while not(moved) do
  86.     moved = turtle.down()
  87.   end
  88.   if yMin < yCoord then
  89.     yMin = yCoord
  90.   end
  91. end
  92.  
  93. function look(dir)
  94.   while dir ~= orients[orient] do
  95.     right()
  96.   end
  97. end
  98.  
  99. function goto(xTarget, yTarget, zTarget, travel)
  100.     if travel ~= 0 then
  101.       while 95 > yCoord do
  102.         up()
  103.       end
  104.     end
  105.    
  106.     if xTarget < xCoord then
  107.       look("west")
  108.       while xTarget < xCoord do
  109.         forward()
  110.       end
  111.     end
  112.    
  113.     if xTarget > xCoord then
  114.       look("east")
  115.       while xTarget > xCoord do
  116.         forward()
  117.       end
  118.     end
  119.    
  120.     if zTarget < zCoord then
  121.       look("north")
  122.       while zTarget < zCoord do
  123.         forward()
  124.       end
  125.     end
  126.    
  127.     if zTarget > zCoord then
  128.       look("south")
  129.       while zTarget > zCoord do
  130.         forward()
  131.       end
  132.     end
  133.    
  134.     while yTarget < yCoord do
  135.       down()
  136.     end
  137.    
  138.     while yTarget > yCoord do
  139.       up()
  140.     end
  141. end
  142.  
  143. function returnItems()
  144.   xProg = xCoord
  145.   yProg = yCoord
  146.   zProg = zCoord
  147.   oProg = orient
  148.  
  149.   goto(xHome, yHome, zHome)
  150.   look(oHome)
  151.   for i = 1,16 do
  152.     turtle.select(i)
  153.     turtle.drop(64)
  154.   end
  155.   turtle.select(1)
  156.  
  157.   goto(xProg, yProg, zProg)
  158.   look(orients[oProg])
  159. end
  160.  
  161. function digLine()
  162.   for i = 1,lineLength do
  163.     if invFull() then
  164.       returnItems()
  165.     end
  166.     forward()
  167.   end
  168. end
  169.  
  170. function digLayer()
  171.   qOrient = orient
  172.   for i = 1,lines do
  173.     digLine()
  174.     if (i%2) == 1 and i < lines then
  175.       right()
  176.       forward()
  177.       right()
  178.     elseif i < lines then
  179.       left()
  180.       forward()
  181.       left()
  182.     end
  183.   end
  184.   goto(xQuarry, yCoord, zQuarry, 0)
  185.   while orient ~= qOrient do
  186.     right()
  187.   end
  188.   down()
  189. end
  190.  
  191. function digQuarry(xTarget, yTarget, zTarget)
  192.   xQuarry = xTarget
  193.   yQuarry = yTarget
  194.   zQuarry = zTarget
  195.   goto(xQuarry, yQuarry, zQuarry)
  196.   look("south")
  197.   while yMin > 7 do
  198.     digLayer()
  199.   end
  200.   goto(xQuarry, yQuarry, zQuarry)
  201.   yMin = 999  
  202. end
  203.  
  204. function getJob()
  205.   while jobAv do
  206.     rednet.send(manager, "getJob")
  207.     id, msg, dis = rednet.receive()
  208.    
  209.     if msg == "yes" then
  210.       id, xQuarry, dis = rednet.receive()
  211.       id, yQuarry, dis = rednet.receive()
  212.       id, zQuarry, dis = rednet.receive()
  213.      
  214.       digQuarry(xQuarry, yQuarry, zQuarry)
  215.     elseif msg == "no" then
  216.       jobAv = false  
  217.     end
  218.   end
  219. end
  220.  
  221. getJob()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement