Advertisement
kyle1320

Untitled

Mar 28th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. os.loadAPI("file")
  2.  
  3. parent = 1637
  4. stop = 0
  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 == 1 then
  86. print("Received kill message! Stopping..")
  87. send("stop", true)
  88. end
  89. end
  90. js = 1
  91. turtle.turnRight()
  92. end
  93. is = 1
  94. end
  95. end
  96.  
  97. rednetWait = function()
  98. while true do
  99. ID, message = rednet.receive()
  100. if message == "stop" then
  101. stop = 1
  102. else
  103. send(message, false)
  104. end
  105. end
  106. end
  107.  
  108. start = function(dist, i, j)
  109. dists = dist
  110. is = i
  111. js = j
  112.  
  113. rednet.open("right")
  114.  
  115. send("start", false)
  116.  
  117. parallel.waitForAny(spiral, rednetWait)
  118. end
  119.  
  120. send = function(msg, quit)
  121. --0 for start signal, 1 for kill signal
  122. rednet.send(parent, msg)
  123. if quit then
  124. os.reboot()
  125. end
  126. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement