Advertisement
Leroki

smart miner on EEPROM

Aug 23rd, 2016
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.18 KB | None | 0 0
  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 moveFd()
  26.     if direction == 0 then
  27.         robot.move(3)
  28.         z = z + 1
  29.     elseif direction == 1 then
  30.         robot.move(3)
  31.         x = x - 1
  32.     elseif direction == 2 then
  33.         robot.move(3)
  34.         z = z - 1
  35.     elseif direction ==  3 then
  36.         robot.move(3)
  37.         x = x + 1
  38.     end
  39. end
  40.  
  41. function moveDn()
  42.     robot.move(0)
  43.     y = y - 1
  44. end
  45.  
  46. function moveUp()
  47.     robot.move(1)
  48.     y = y + 1
  49. end
  50.  
  51. function tollCheck()
  52.     if robot.durability() < 0.1 and tool1 <= tool2 and toolSwich then
  53.         robot.select(tool1)
  54.         inventory.equip()
  55.         tool1 = tool1 + 1
  56.     end
  57. end
  58.  
  59. function mine()
  60.     for i=1, (lengh - 1) do
  61.         check(1)
  62.         check(0)
  63.         robot.swing(3)
  64.         tollCheck()
  65.         dropIt()
  66.         moveFd()
  67.     end
  68. end
  69.  
  70. function turn(dir)
  71.     if dir then
  72.         direction = direction - 1
  73.         robot.turn(dir)
  74.     else
  75.         direction = direction + 1
  76.         robot.turn(dir)
  77.     end
  78.     if direction == -1 then
  79.         direction = 3
  80.     elseif direction == 4 then
  81.         direction = 0
  82.     end
  83. end
  84.  
  85. function corner(engl)
  86.     check(1)
  87.     check(0)
  88.     turn(engl)
  89.     robot.swing(3)
  90.     tollCheck()
  91.     dropIt()
  92.     moveFd()
  93.     turn(engl)
  94. end
  95.  
  96. function check(side)
  97.     for inv = 1, trashSlots do
  98.         robot.select(inv)
  99.         if robot.compare(side) then
  100.             return
  101.         end
  102.     end
  103.     robot.swing(side)
  104. end
  105.  
  106. function dropIt()
  107.     for inv = 1, trashSlots do
  108.         if robot.count(inv) >= 10 then
  109.             robot.select(inv)
  110.             robot.drop(0, 9)
  111.         end
  112.     end
  113. end
  114.  
  115. function turnAround()
  116.     check(1)
  117.     for i = 1, 3 do
  118.         robot.swing(0)
  119.         tollCheck()
  120.         dropIt()
  121.         moveDn()
  122.     end
  123.     turn(true)
  124.     turn(true)
  125. end
  126.  
  127. -- main programm --
  128. x = 0
  129. y = 0
  130. z = 0
  131. direction = 0
  132.  
  133. deepM = deepM - (deepM % 3)
  134.  
  135. width = width - (width % 2)
  136.  
  137. for i = 1, 2 do
  138.     robot.swing(0)
  139.     tollCheck()
  140.     dropIt()
  141.     moveDn()
  142. end
  143.  
  144. for deep = 1, (deepM / 3) do
  145.     if (deep % 2) == 0 then
  146.         for j = 1, (width / 2) do
  147.             mine()
  148.             corner(true)
  149.             mine()
  150.             if j == (width / 2) then
  151.                 if deep == (deepM / 3) then
  152.                     check(0)
  153.                     check(1)
  154.                     break
  155.                 end
  156.                 turnAround()
  157.                 break
  158.             end
  159.             corner(false)
  160.         end
  161.     else
  162.         for j = 1, (width / 2) do
  163.             mine()
  164.             corner(false)
  165.             mine()
  166.             if j == (width / 2) then
  167.                 if deep == (deepM / 3) then
  168.                     check(0)
  169.                     check(1)
  170.                     break
  171.                 end
  172.                 turnAround()
  173.                 break
  174.             end
  175.             corner(true)
  176.         end
  177.     end
  178. end
  179.  
  180. if x ~= 0 then
  181.     turn(false)
  182.     while x ~= 0 do
  183.         robot.swing(3)
  184.         tollCheck()
  185.         dropIt()
  186.         moveFd()
  187.     end
  188.     turn(false)
  189. end
  190.  
  191.  
  192. while y ~= 0 do
  193.     robot.swing(1)
  194.     tollCheck()
  195.     dropIt()
  196.     moveUp()
  197. end
  198.  
  199. robot.select(trashSlots)
  200. robot.place(0)
  201. if direction ~= 0 then
  202.     turn(false)
  203.     turn(false)
  204. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement