Advertisement
skidzt

Untitled

Feb 11th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. local location = ""
  2. local position = ""
  3.  
  4. local returnValue = ""
  5. local boolreturn = false;
  6.  
  7. local whatIHaveIs = "empty"
  8.  
  9. function teleport()
  10. tp = peripheral.wrap("bottom")
  11. tp.teleport()
  12. end
  13.  
  14. function isFull()
  15. boolreturn = false
  16. greader = peripheral.wrap("right")
  17. data = greader.get()
  18. boolreturn = data["Full Energy"]
  19. end
  20.  
  21.  
  22. function checkEmpty()
  23. greader = peripheral.wrap("right")
  24. data = greader.get()
  25. while not data["No Energy"] do
  26. sleep(15)
  27. data = greader.get()
  28. end
  29. turtle.dig()
  30. whatIHaveIs = "empty"
  31. end
  32.  
  33. function checkLoc()
  34. loc = turtle.detectUp()
  35. if loc == true then
  36. print ("I am at the charge station")
  37. location = "Charging"
  38. isCharging()
  39. if boolreturn == true then
  40. position = "charger"
  41. else
  42. position = "teleporter"
  43. end
  44. else
  45. print("I am at the quarry")
  46. location = "Quarry"
  47. end
  48. shell.run('clear')
  49. print("-------------------------")
  50. print("location = "..location)
  51. print("position = "..position)
  52. print("whatIHaveIs = "..whatIHaveIs)
  53. print("Fuel = "..tostring(turtle.getFuelLevel()))
  54. print("-------------------------")
  55.  
  56. end
  57.  
  58. function checkFuel()
  59. fuel = turtle.getFuelLevel()
  60. if fuel < 5000 then
  61. print("I need fuel")
  62. FuelUp()
  63. end
  64. end
  65.  
  66. function DeepCharge()
  67. checkLoc()
  68. if location == "Charging" then
  69. if position == "charger" then
  70. while turtle.getFuelLevel() < 15000 do
  71. shell.run('clear')
  72. print("-------------------------")
  73. print("location = "..location)
  74. print("position = "..position)
  75. print("whatIHaveIs = "..whatIHaveIs)
  76. print("Deep Fuel = "..tostring(turtle.getFuelLevel()))
  77. print("-------------------------")
  78. sleep(1)
  79. end
  80. end
  81. end
  82. end
  83.  
  84. function FuelUp()
  85. checkLoc()
  86. if location == "Charging" then
  87. if position == "charger" then
  88. while turtle.getFuelLevel() < 9000 do
  89. shell.run('clear')
  90. print("-------------------------")
  91. print("location = "..location)
  92. print("position = "..position)
  93. print("whatIHaveIs = "..whatIHaveIs)
  94. print("Fueling = "..tostring(turtle.getFuelLevel()))
  95. print("-------------------------")
  96. sleep(1)
  97. end
  98. end
  99. end
  100. end
  101.  
  102. function isCharging()
  103. boolreturn = false
  104. fuellevel = turtle.getFuelLevel()
  105. sleep(5)
  106. if fuellevel < turtle.getFuelLevel() then
  107. boolreturn = true
  108. end
  109. end
  110.  
  111.  
  112. function CheckChargeStationSpotPlacement()
  113. print("Spot Check 4 Place")
  114. boolreturn = false
  115. turtle.forward()
  116. turtle.turnLeft()
  117. loc = turtle.detect()
  118. if loc == false then
  119. boolreturn = true
  120. turtle.place()
  121. end
  122. turtle.turnRight()
  123. end
  124.  
  125. function CheckChargeStationSpotGet()
  126. print("Spot Check 4 Get")
  127. boolreturn = false
  128. turtle.forward()
  129. turtle.turnLeft()
  130. loc = turtle.detect()
  131. if loc == true then
  132. isFull()
  133. if boolreturn == true then
  134. whatIHaveIs = "full"
  135. turtle.dig()
  136. end
  137. end
  138. turtle.turnRight()
  139. end
  140.  
  141. function return2ChargeStation()
  142. turtle.turnLeft()
  143. turtle.turnLeft()
  144. while turtle.forward() do
  145. sleep(0.1)
  146. end
  147. turtle.turnRight()
  148. turtle.forward()
  149. FuelUp()
  150. end
  151.  
  152.  
  153. function Go()
  154. checkLoc()
  155. shell.run('clear')
  156. print("-----------GO------------")
  157. print("location = "..location)
  158. print("position = "..position)
  159. print("whatIHaveIs = "..whatIHaveIs)
  160. print("Fuel = "..tostring(turtle.getFuelLevel()))
  161. print("-------------------------")
  162.  
  163. if location == "Charging" then
  164. if position == "teleporter" then
  165. turtle.turnLeft()
  166. turtle.turnLeft()
  167. turtle.forward()
  168. turtle.forward()
  169. turtle.forward()
  170. end
  171. FuelUp()
  172. if turtle.getItemCount(1) >= 1 then
  173. if whatIHaveIs == "empty" then
  174.  
  175. turtle.turnLeft()
  176. turtle.turnLeft()
  177. turtle.forward()
  178. turtle.turnLeft()
  179. turtle.forward()
  180.  
  181. CheckChargeStationSpotPlacement()
  182. if boolreturn == true then
  183. return2ChargeStation()
  184. else
  185. CheckChargeStationSpotPlacement()
  186. if boolreturn == true then
  187. return2ChargeStation()
  188. else
  189. CheckChargeStationSpotPlacement()
  190. return2ChargeStation()
  191. end
  192. end
  193. return true
  194. end
  195.  
  196. if whatIHaveIs == "full" then
  197. turtle.turnLeft()
  198. turtle.turnLeft()
  199. turtle.forward()
  200. turtle.forward()
  201. turtle.forward()
  202. teleport()
  203. end
  204. else
  205. if whatIHaveIs == "nothing" then
  206. DeepCharge()
  207. turtle.turnLeft()
  208. turtle.turnLeft()
  209. turtle.forward()
  210. turtle.forward()
  211. turtle.forward()
  212. teleport()
  213. return true
  214. else
  215. turtle.turnLeft()
  216. turtle.turnLeft()
  217. turtle.forward()
  218. turtle.turnLeft()
  219. turtle.forward()
  220.  
  221. CheckChargeStationSpotGet()
  222. if boolreturn == true then
  223. return2ChargeStation()
  224. else
  225. CheckChargeStationSpotGet()
  226. if boolreturn == true then
  227. return2ChargeStation()
  228. else
  229. CheckChargeStationSpotGet()
  230. return2ChargeStation()
  231. end
  232. end
  233. end
  234. end
  235. else
  236. if turtle.getItemCount(1) >= 1 then
  237. whatIHaveIs = "full"
  238. turtle.turnLeft()
  239. turtle.place()
  240. whatIHaveIs = "nothing"
  241. turtle.turnRight()
  242. teleport()
  243. else
  244. whatIHaveIs = "nothing"
  245. turtle.turnLeft()
  246. checkEmpty()
  247. turtle.turnRight()
  248. teleport()
  249. end
  250. end
  251. return true
  252. end
  253.  
  254. while true do
  255. Go()
  256. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement