Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. local drone = component.proxy(component.list("drone")())
  2.  
  3. local FARM_DIRECTION_NS = 0
  4. local FARM_DIRECTION_EW = -1
  5. local FARM_WIDTH = 8
  6. local FARM_HEIGHT = 8
  7.  
  8. local function sleep(timeout)
  9. checkArg(1, timeout, "number", "nil")
  10. local deadline = computer.uptime() + (timeout or 0)
  11. repeat
  12. computer.pullSignal(deadline - computer.uptime())
  13. until computer.uptime() >= deadline
  14. end
  15.  
  16. local function checkE()
  17. local en = computer.energy()
  18. return en
  19. end
  20.  
  21. local function drop()
  22. drone.drop(2)
  23. end
  24.  
  25. local function dropAll()
  26. for i=4,2,-1
  27. do
  28. drone.select(i)
  29. drop()
  30. end
  31. drone.select(1)
  32. end
  33.  
  34. local function move(x,y,z)
  35. drone.move(x,y,z)
  36. travelx = travelx + x
  37. travely = travely + y
  38. travelz = travelz + z
  39. end
  40.  
  41. local function swing()
  42. for i=5,0,-1 do
  43. drone.swing(i)
  44. end
  45. sleep(0.2)
  46. end
  47.  
  48. local function swingHor()
  49. for i=1,5,1 do
  50. drone.swing(i)
  51. end
  52. sleep(0.2)
  53. end
  54.  
  55. local function suck(x)
  56. drone.suck(x)
  57. end
  58.  
  59. local function suckAll()
  60. for i=0,5,1 do
  61. suck(i)
  62. end
  63. end
  64.  
  65. local function layer(n)
  66. for i=3,1,-1 do
  67. suckAll()
  68. swingHor()
  69. move(-1,0,0)
  70. end
  71. end
  72.  
  73. local function placeD()
  74. drone.place(0)
  75. end
  76.  
  77. local function plant()
  78. drone.setStatusText("PLANTING")
  79. drone.select(1)
  80. move(-8,1,0)
  81. sleep(2)
  82. placeD()
  83.  
  84. move(-1,0,0)
  85. sleep(0.3)
  86. placeD()
  87.  
  88. move(0,0,-1)
  89. sleep(0.3)
  90. placeD()
  91.  
  92. move(1,0,0)
  93. sleep(0.3)
  94. placeD()
  95. returnHome()
  96. end
  97.  
  98. local function harvest()
  99. drone.setStatusText("CUTTING")
  100. move(0,30,0)
  101. sleep(3)
  102. move(-7,0,1)
  103. sleep(2)
  104.  
  105. layer(30)
  106.  
  107. swingHor()
  108.  
  109. move(0,0,-1)
  110. for i=1,4,1 do
  111. move(1,0,0)
  112. swingHor()
  113. suckAll()
  114. end
  115. returnHome()
  116. dropAll()
  117. sleep(2)
  118. end
  119.  
  120. local function resetP()
  121. travelx, travely, travelz = 0,0,0
  122. end
  123.  
  124. function returnHome()
  125. travelx = travelx * -1
  126. travely = travely * -1
  127. travelz = travelz * -1
  128. sleep(1)
  129. move(travelx,travely,travelz)
  130. sleep(2)
  131. resetP()
  132. end
  133.  
  134. local function getToPosition()
  135. for i=1,20,1 do
  136. local somethingInFront = drone.detect(4)
  137. if somethingInFront then
  138. -- Move on top of the fence
  139. sleep(0.5)
  140. move(0, 0, 1)
  141. sleep(0.5)
  142. move(FARM_DIRECTION_EW, FARM_DIRECTION_NS, 1)
  143. sleep(0.5)
  144.  
  145. -- Move to the left corner of the farm
  146. for i=1,20,1 do
  147. local somethingBelow = drone.detect(0)
  148. -- Then we went past the fence, go back in
  149. if not somethingBelow then
  150. sleep(0.5)
  151. if FARM_DIRECTION_EW ~= 0 then
  152. move(0, -2, 0)
  153. else
  154. move(-2, 0, 0)
  155. end
  156. sleep(0.5)
  157. move(FARM_DIRECTION_EW, FARM_DIRECTION_NS, 1)
  158. sleep(0.5)
  159. return
  160. end
  161.  
  162. -- Go left until we find the end
  163. sleep(0.5)
  164. if FARM_DIRECTION_EW ~= 0 then
  165. move(0, 1, 0)
  166. else
  167. move(1, 0, 0)
  168. end
  169. sleep(0.5)
  170. end
  171. end
  172.  
  173. sleep(0.5)
  174. move(FARM_DIRECTION_EW, FARM_DIRECTION_NS, 0)
  175. sleep(0.5)
  176. end
  177. returnHome()
  178. end
  179.  
  180. local function checkPlants()
  181. resetP()
  182. job = 0
  183. drone.setStatusText("CHECKING")
  184. for i=1,20,0 do
  185. local seedsBelow = drone.compare(0, true)
  186. drone.select(1)
  187. if seedsBelow then
  188. job = 1
  189. break
  190. end
  191. drone.select(2)
  192. local wheatBelow = drone.compare(0, true)
  193. if wheatBelow then
  194. job = 2
  195. break
  196. end
  197. move(FARM_DIRECTION_EW, FARM_DIRECTION_NS, 0)
  198. end
  199. returnHome()
  200. end
  201.  
  202. --start
  203. resetP()
  204. job = 0
  205. drone.setStatusText("ROM\nOK.v4.14.")
  206. sleep(1)
  207.  
  208. -- Main loop
  209.  
  210. checkPlants()
  211. drone.setStatusText(tostring(job))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement