Advertisement
kyle1320

Untitled

Mar 28th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. os.loadAPI("file")
  2.  
  3. parent = 1637
  4. stop = false
  5. dists = 1
  6. is = 1
  7. js = 1
  8.  
  9. fwd = function()
  10. refuel()
  11.  
  12. turtle.digUp()
  13.  
  14. turtle.digDown()
  15.  
  16. while turtle.forward()==false do
  17. turtle.dig()
  18. end
  19. end
  20.  
  21. refuel = function()
  22. if turtle.getFuelLevel()<20 then
  23. if turtle.getItemCount(16)==1 then
  24. send(":OOF", true)
  25. end
  26.  
  27. turtle.select(16)
  28.  
  29. if turtle.refuel(1)==false then
  30. send(":PF", true)
  31. end
  32.  
  33. turtle.select(15)
  34. end
  35.  
  36. if isfull()==true then
  37. empty()
  38. end
  39. end
  40.  
  41. isfull = function()
  42. local full = true
  43.  
  44. for i=1,14 do
  45. if turtle.getItemCount(i)==0 then
  46. full = false
  47. end
  48. end
  49.  
  50. return full
  51. end
  52.  
  53. empty = function()
  54. turtle.digDown()
  55. turtle.select(15)
  56. turtle.placeDown()
  57. for i=1,14 do
  58. turtle.select(i)
  59. turtle.dropDown()
  60. end
  61. turtle.select(15)
  62. turtle.digDown()
  63. end
  64.  
  65. write = function(dist, i, j)
  66. file.write("state", {dist, i, j})
  67. end
  68.  
  69. spiral = function()
  70. dist = dists
  71.  
  72. turtle.select(15)
  73. if turtle.detectDown()==true then
  74. turtle.digDown()
  75. end
  76.  
  77. while true do
  78. dist = dist + 1
  79.  
  80. for i=is,2 do
  81. for j=js,dist do
  82. fwd()
  83. write(dist-1, i, j+1)
  84.  
  85. if stop then
  86. print("Received kill message! Stopping..")
  87. send("stop", true)
  88. end
  89. end
  90. js = 1
  91. turtle.turnRight()
  92. write(dist-1, i+1, 1)
  93. end
  94. is = 1
  95. end
  96. end
  97.  
  98. rednetWait = function()
  99. while true do
  100. ID, message = rednet.receive()
  101. if message == "stop" then
  102. stop = true
  103. else
  104. send(message, false)
  105. end
  106. end
  107. end
  108.  
  109. start = function(dist, i, j)
  110. dists = dist
  111. is = i
  112. js = j
  113. stop = false
  114.  
  115. rednet.open("right")
  116.  
  117. send("start", false)
  118.  
  119. parallel.waitForAny(spiral, rednetWait)
  120. end
  121.  
  122. send = function(msg, quit)
  123. --0 for start signal, 1 for kill signal
  124. rednet.send(parent, msg)
  125. if quit then
  126. os.reboot()
  127. end
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement