SHARE
TWEET

wood_no_gps

Clor Aug 2nd, 2014 634 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Var
  2. local robot = require("robot")
  3. local inv = require("component").inventory_controller
  4. local comp = require("computer")
  5. local s = require("sides")
  6. local tr = require("component").tractor_beam
  7.  
  8. Xn = 0
  9. Yn = 0
  10. Zn = 0
  11. nSide = 0
  12. Xc,Xt,Yc,Yt,Zc,Zt = 0,0,0,0,0,0
  13.  
  14. --Function
  15.  
  16. function Left()
  17. robot.turnLeft()
  18. nSide = nSide+1
  19. end
  20.  
  21. function Right()
  22. robot.turnRight()
  23. nSide = nSide-1
  24. end
  25.  
  26. function Around()
  27. robot.turnAround()
  28. nSide = nSide-2
  29. end
  30.  
  31. function forward()
  32. local n = 0
  33. while true do
  34. if robot.forward() then
  35. while tr.suck() do end
  36. nSide = nSide%4
  37. if nSide == 0 then Xt = Xt+1
  38. elseif nSide == 1 then Zt = Zt+1
  39. elseif nSide == 2 then Xt = Xt-1
  40. elseif nSide == 3 then Zt = Zt-1
  41. end
  42. return true
  43. else
  44. robot.swing()
  45. n = n+1
  46. end
  47. if n == 20 then print("no run forward, program stop!") os.exit() end
  48. end
  49. end
  50.  
  51. function up()
  52. local n = 0
  53. while true do
  54. if robot.up() then Yt = Yt+1 return true else
  55. robot.swingUp()
  56. n = n+1
  57. end
  58. if n == 20 then print("no run up, program stop!") os.exit() end
  59. end
  60. end
  61.  
  62. function down()
  63. local n = 0
  64. while true do
  65. if robot.down() then Yt = Yt-1 return true else
  66. robot.swingDown()
  67. n = n+1
  68. end
  69. if n == 20 then print("no run down, program stop!") os.exit() end
  70. end
  71. end
  72.  
  73.  
  74. function sapling()
  75. robot.select(2)
  76. up()
  77. forward()
  78. robot.placeDown()
  79. forward()
  80. robot.placeDown()
  81. Left()
  82. forward()
  83. robot.placeDown()
  84. Left()
  85. forward()
  86. robot.placeDown()
  87. forward()
  88. Left()
  89. forward()
  90. Left()
  91. down()
  92. end
  93.  
  94. function wood()
  95. local n=0
  96. robot.swing()
  97. forward()
  98. while true do
  99.   if robot.detectUp() then
  100.   n=n+1
  101.   robot.swing()
  102.   robot.swingUp()
  103.   up()
  104.   else break end
  105. end
  106. robot.swing()
  107. Left()
  108. robot.swing()
  109. forward()
  110. Right()
  111. for i=1,n do
  112. robot.swing()
  113. robot.swingDown()
  114. down()
  115. end
  116. robot.swing()
  117. Right()
  118. forward()
  119. Right()
  120. forward()
  121. Around()
  122. end
  123.  
  124. function new_tools()
  125.    if robot.durability() == nil then return false end
  126.    if robot.durability()<150 then
  127.    robot.select(1)
  128.    inv.equip()
  129.        if robot.durability()<150 then
  130.        return false
  131.        else
  132.        return true
  133.     end
  134.     else
  135.     return true
  136.     end
  137. end
  138.  
  139. function detect_wood()
  140.  if robot.detect() then
  141.   up()
  142.    if robot.detect() then
  143.     down()
  144.     return "wood"
  145.    else
  146.     down()
  147.     return "sapling"
  148.    end
  149.  else
  150.   return "clear"
  151.  end
  152. end
  153.  
  154. function run_a()
  155. Left()
  156. for i=1,10 do
  157. forward()
  158. end
  159. Right()
  160. end
  161.  
  162. function run_b()
  163. Right()
  164. forward()
  165. Right()
  166. for i=1,10 do
  167. forward()
  168. end
  169. Right()
  170. forward()
  171. Right()
  172. end
  173.  
  174. function run_c()
  175. Right()
  176. for i=1,10 do
  177. forward()
  178. end
  179. Left()
  180. end
  181.  
  182. function run_d()
  183. Left()
  184. forward()
  185. forward()
  186. Right()
  187. for i=1,10 do
  188. forward()
  189. end
  190. Right()
  191. forward()
  192. forward()
  193. Left()
  194. end
  195.  
  196. function bksp(area)
  197. if area == "chest" then
  198.   Left()
  199.   forward()
  200.   forward()
  201.   Right()
  202.  Xc=Xt Yc=Yt Zc=Zt
  203.       while Zn~=Zt do
  204.       forward()
  205.       end
  206.     Right()  
  207.       while Xn~=Xt do
  208.       forward()
  209.       end      
  210. elseif area == "wood" then
  211.     Around()
  212.       while Xc~=Xt do
  213.       forward()
  214.       end
  215.    Left()
  216.       while Zc~=Zt do
  217.       forward()
  218.       end
  219.    Left()
  220.    forward()
  221.    forward()
  222.    Left()
  223. end
  224. end
  225.  
  226. function chest(tools)
  227.     for i=3,16 do
  228.   robot.select(i)
  229.   if (robot.count(i) ~= 0) and (not robot.drop(64)) then Around() print("chest full, stop!") os.exit() end
  230.   end
  231.   Right()
  232.   robot.select(2)
  233.    for i=1,5 do
  234.    if robot.count(2) ~= 64 then robot.suck(robot.space(2)) else break end
  235.   end
  236.   Left()
  237.   if not count_sapl() then return "sapling" end
  238. if not tools then
  239.   robot.select(1)
  240.   robot.drop()
  241.   inv.equip()
  242.   robot.drop()
  243.   if not robot.suckDown(1) then return "tools" end
  244.   inv.equip()
  245.   if not robot.suckDown(1) then return "tools" end
  246.   end
  247.   return true
  248. end
  249.  
  250. function count_sapl()
  251. if robot.count(2) < 5 then return false else return true end
  252. end
  253.  
  254. function full()
  255. if robot.count(13) == 0  then return true else return false end
  256. end
  257.  
  258. function energy()
  259. if comp.energy() < 1800 then os.sleep(180) end
  260. end
  261.  
  262. -- MultiFunction
  263. function woodAll()
  264.   while true do
  265.        if count_sapl() and full() and new_tools() then
  266.            detect = detect_wood()
  267.            if detect == "clear" then sapling() break
  268.            elseif detect == "wood" then wood() sapling() break  
  269.            elseif detect == "sapling" then break end
  270.    else
  271.     bksp("chest")
  272.  _exit = chest(new_tools())
  273.    if "tools" == _exit then Around() print("not tools, stop!") os.exit()
  274.     elseif "sapling" ==_exit then Around() print("not sapling, stop!") os.exit()
  275.    end
  276.  bksp("wood")
  277.   end
  278.  end
  279. end
  280.  
  281. --Programs:
  282.  
  283. Right()
  284. while true do
  285.   for i=1,3 do
  286.    energy()
  287.    woodAll()
  288.    if i == 2 then os.sleep(10) else os.sleep(0) end
  289.    energy()
  290.    run_a()
  291.    end
  292. energy()
  293. woodAll()
  294. os.sleep(0)
  295. energy()
  296. run_b()
  297. for i=1,3 do
  298.    energy()
  299.    woodAll()
  300.    os.sleep(0)
  301.    energy()
  302.    run_c()
  303.   end
  304. energy()
  305. woodAll()
  306. os.sleep(0)
  307. energy()
  308. run_d()
  309. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top