Advertisement
TraerAlone

Untitled

Aug 25th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Leroki's smart miner on EEPROM --
  2.  
  3. -- Умный робот карьер, капает все в указанных параметрах
  4.  
  5. -- Настройки --
  6.  
  7. trashSlots = 2 -- кол-во слотов под мусор, с 1 по указанный
  8. lengh = 7 -- Длинна карьера
  9. width = 4 -- Ширина карьера !!! ТОЛЬКО ЧЕТНЫЕ ЧИСЛА !!!
  10. deepM = 9 -- Высота карьера !!! ЧМСЛА КРАТНЫЕ 3 !!!
  11.  
  12. --------------------------------------------------------
  13. toolSwich = false -- смена инструментов роботом true - да / false - нет
  14. tool1 = 5 -- 1 слот для инструмента
  15. tool2 = 9 -- последний слот для инструмента
  16. --------------------------------------------------------
  17.  
  18. -- functions --
  19.  
  20. robot = component.proxy(component.list("robot")())
  21. if toolSwich then
  22.     inventory = component.proxy(component.list("inventory_controller")())
  23. end
  24.  
  25. function sw(side)
  26.   while robot.swing(side) do end
  27. end
  28.  
  29. function moveFd()
  30.     if direction == 0 then
  31.         robot.move(3)
  32.         z = z + 1
  33.     elseif direction == 1 then
  34.         robot.move(3)
  35.         x = x - 1
  36.     elseif direction == 2 then
  37.         robot.move(3)
  38.         z = z - 1
  39.     elseif direction ==  3 then
  40.         robot.move(3)
  41.         x = x + 1
  42.     end
  43. end
  44.  
  45. function moveDn()
  46.     robot.move(0)
  47.     y = y - 1
  48. end
  49.  
  50. function moveUp()
  51.     robot.move(1)
  52.     y = y + 1
  53. end
  54.  
  55. function tollCheck()
  56.     if robot.durability() < 0.1 and tool1 <= tool2 and toolSwichw then
  57.         robot.select(tool1)
  58.         inventory.equip()
  59.         tool1 = tool1 + 1
  60.     end
  61. end
  62.  
  63. function mine()
  64.     for i=1, (lengh - 1) do
  65.         check(1)
  66.         check(0)
  67.         robot.sw(3)
  68.         tollCheck()
  69.         dropIt()
  70.         moveFd()
  71.     end
  72. end
  73.  
  74. function turn(dir)
  75.     if dir then
  76.         direction = direction - 1
  77.         robot.turn(dir)
  78.     else
  79.         direction = direction + 1
  80.         robot.turn(dir)
  81.     end
  82.     if direction == -1 then
  83.         direction = 3
  84.     elseif direction == 4 then
  85.         direction = 0
  86.     end
  87. end
  88.  
  89. function corner(engl)
  90.     check(1)
  91.     check(0)
  92.     turn(engl)
  93.     robot.sw(3)
  94.     tollCheck()
  95.     dropIt()
  96.     moveFd()
  97.     turn(engl)
  98. end
  99.  
  100. function check(side)
  101.     for inv = 1, trashSlots do
  102.         robot.select(inv)
  103.         if robot.compare(side) then
  104.             return
  105.         end
  106.     end
  107.     robot.sw(side)
  108. end
  109.  
  110. function dropIt()
  111.     for inv = 1, trashSlots do
  112.         if robot.count(inv) >= 10 then
  113.             robot.select(inv)
  114.             robot.drop(0, 9)
  115.         end
  116.     end
  117. end
  118.  
  119. function turnAround()
  120.     check(1)
  121.     for i = 1, 3 do
  122.         robot.sw(0)
  123.         tollCheck()
  124.         dropIt()
  125.         moveDn()
  126.     end
  127.     turn(true)
  128.     turn(true)
  129. end
  130.  
  131. -- main programm --
  132. x = 0
  133. y = 0
  134. z = 0
  135. direction = 0
  136.  
  137. deepM = deepM - (deepM % 3)
  138.  
  139. width = width - (width % 2)
  140.  
  141. for i = 1, 2 do
  142.     robot.sw(0)
  143.     tollCheck()
  144.     dropIt()
  145.     moveDn()
  146. end
  147.  
  148. for deep = 1, (deepM / 3) do
  149.     if (deep % 2) == 0 then
  150.         for j = 1, (width / 2) do
  151.             mine()
  152.             corner(true)
  153.             mine()
  154.             if j == (width / 2) then
  155.                 if deep == (deepM / 3) then
  156.                     check(0)
  157.                     check(1)
  158.                     break
  159.                 end
  160.                 turnAround()
  161.                 break
  162.             end
  163.             corner(false)
  164.         end
  165.     else
  166.         for j = 1, (width / 2) do
  167.             mine()
  168.             corner(false)
  169.             mine()
  170.             if j == (width / 2) then
  171.                 if deep == (deepM / 3) then
  172.                     check(0)
  173.                     check(1)
  174.                     break
  175.                 end
  176.                 turnAround()
  177.                 break
  178.             end
  179.             corner(true)
  180.         end
  181.     end
  182. end
  183.  
  184. if x ~= 0 then
  185.     turn(false)
  186.     while x ~= 0 do
  187.         robot.sw(3)
  188.         tollCheck()
  189.         dropIt()
  190.         moveFd()
  191.     end
  192.     turn(false)
  193. end
  194.  
  195.  
  196. while y ~= 0 do
  197.     robot.sw(1)
  198.     tollCheck()
  199.     dropIt()
  200.     moveUp()
  201. end
  202.  
  203. robot.select(trashSlots)
  204. robot.place(0)
  205. if direction ~= 0 then
  206.     turn(false)
  207.     turn(false)
  208. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement