Advertisement
serafim7

quarry карьер + пчёлы из Extra Bees [OpenComputers]

Mar 23rd, 2020 (edited)
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.97 KB | None | 0 0
  1. --[[ opencomputers карьер by serafim pastebin.com/J0ZM8LbZ
  2.      для проекта   computercraft.ru        update 13.06.21
  3.  
  4. Копает змейкой квадрат проходя три слоя блоков за один подход,
  5. пока не выкопает весь объём до бэдрока или не упрётся в
  6. неразрушаемый блок, при этом вернётся к старту и сообщит о проблеме,
  7. также предложит продолжить копать с последней позиции.
  8. Умеет ломать сачком подземные улики.
  9.  
  10. требования:
  11. инвентарь, контроллер инвентаря, генератор, улучшение парение.
  12.  
  13. пример сборки для проекта computercraft.ru
  14. https://i.imgur.com/4M72obd.png
  15.  
  16. использование:
  17. на старте, сзади робота поставить сундук, положить в сундук
  18. запасной инструмент, уголь больше 20 штук, сачок из мода forestry.
  19. Робот может работать без сундука и всего прочего, нужна только кирка.
  20.  
  21. пример запуска: (по умолчанию один чанк)
  22. quarry 16 16 2  или  quarry
  23. -- 2 опустится в низ на 2 блока от старта.
  24.  
  25. получить список предметов:
  26. https://pastebin.com/au9etcfF
  27. ]]--
  28.  
  29. local a = {...}
  30. local width = tonumber(a[1]) or 16 --ширина
  31. local length = tonumber(a[2]) or 16 --длина
  32. local down = tonumber(a[3]) or 2 --опустится в низ
  33.  
  34. --список мусора
  35. local scrap = {
  36.   "cobblestone", --булыжник
  37.   "stone",       --камень
  38.   "dirt",        --земля
  39.   "gravel",      --гравий
  40.   "flint",       --кремень
  41.   "sand",        --песок
  42.   "sandstone"    --песчаник
  43. }
  44.  
  45. --список инструмента
  46. local toollist = {
  47.   "ickaxe",
  48.   "rill",
  49.   "pick",
  50.   "vajra"
  51. }
  52.  
  53. local event = require("event")
  54. local com = require('component')
  55. local computer = require("computer")
  56. local fuelchest,fuelinv,refuel,charger = true,true,true,false
  57. local cheststart,ridht,bedrock = true,true,false
  58. local depth,xPos,zPos,xDir,zDir = 0,0,0,0,1
  59. local timestart = computer.uptime()
  60. local unloaded,durability = 0,0
  61. local toolstrength = 0.07
  62. local x,y,z,xd,zd
  63.  
  64. if not com.isAvailable("robot") then
  65.   print("только роботы могут использовать эту программу")
  66.   os.exit()
  67. end
  68. local r = require("robot")
  69.  
  70. local invsize = r.inventorySize()
  71. local tools = invsize
  72. local coal = invsize-1
  73. local scoop = invsize-2
  74.  
  75. if not com.isAvailable("inventory_controller") then
  76.   print("нет контроллера инвентаря")
  77.   os.exit()
  78. end
  79. local i_c = com.inventory_controller
  80.  
  81. if not com.isAvailable("generator") then
  82.   print("нет генератора")
  83.   os.exit()
  84. end
  85. local gen = com.generator
  86.  
  87. --статус
  88. local function status(msg)
  89.   print("[ "..os.date("%H:%M:%S",computer.uptime()-timestart).." ] "..msg)
  90. end
  91.  
  92. --чанк лоадер
  93. local function chunkload(state)
  94.   if com.isAvailable("chunkloader") then
  95.     if state then
  96.       com.chunkloader.setActive(true)
  97.       print("чанк лоадер активен")
  98.     else
  99.       com.chunkloader.setActive(false)
  100.       print("чанк лоадер деактивирован".."\n")
  101.     end
  102.   end
  103. end
  104.  
  105. --поиск предмета в инвентаре робота
  106. local function slotitem(slot,list)
  107.   local item = i_c.getStackInInternalSlot(slot)
  108.   if item then
  109.     for j, name in pairs(list) do
  110.       if string.find(item.name,name) then
  111.         if item.charge == nil or item.charge/item.maxCharge > toolstrength then
  112.           return true
  113.         end
  114.       end
  115.     end
  116.   end
  117.   for i = 1,invsize do
  118.     if r.count(i) > 0 then
  119.       for j, name in pairs(list) do
  120.         local item = i_c.getStackInInternalSlot(i)
  121.         if item and string.find(item.name,name) then
  122.           if item.charge == nil or item.charge/item.maxCharge > toolstrength then
  123.             r.select(i)
  124.             r.transferTo(slot)
  125.             return true
  126.           end
  127.         end
  128.       end
  129.     end
  130.   end
  131.   return false
  132. end
  133.  
  134. --взять из сундука расходники
  135. local function servise(slotinv,list)
  136.   local inv = i_c.getInventorySize(3)
  137.   if inv then
  138.     if slotitem(slotinv,list) then
  139.       return true
  140.     end
  141.     r.select(slotinv)
  142.     if r.count(slotinv) > 0 and not r.drop() then
  143.       returnHome("в сундуке нет места")
  144.       return false
  145.     end
  146.     for slot = 1,inv do
  147.       for j, name in pairs(list) do
  148.         local item = i_c.getStackInSlot(3,slot)
  149.         if item and string.find(item.name,name) then
  150.           if item.charge == nil or item.charge/item.maxCharge > toolstrength then
  151.             i_c.suckFromSlot(3,slot)
  152.             return true
  153.           end
  154.         end
  155.       end
  156.     end
  157.     return false
  158.   else
  159.     returnHome("нет сундука")
  160.   end
  161. end
  162.  
  163. --заряжаемся от зарядчика
  164. local function charging()
  165.   local chardg = true
  166.   while true do
  167.     local e1 = computer.energy()
  168.     os.sleep(2)
  169.     local e2 = computer.energy()  
  170.     if e2 > e1 + 500 then
  171.       if chardg then
  172.         chardg = false
  173.         status("заряжаюсь...")
  174.       end
  175.       os.sleep(2)
  176.     else
  177.       break
  178.     end
  179.   end
  180. end
  181.  
  182. --сортируем лут
  183. local function sortlut(droplut)
  184.   status("сортирую лут...")
  185.   r.swingDown()
  186.   for i = 1,invsize do      
  187.     if r.count(i) > 0 then
  188.       local item = i_c.getStackInInternalSlot(i)
  189.       if string.find(item.name,"coal") then
  190.         r.select(i)
  191.         r.transferTo(coal)
  192.       else
  193.         for n = 1,#scrap do
  194.           if scrap[n] == item.name:gsub('%g+:','') then
  195.             r.select(i)
  196.             r.dropDown()
  197.             break
  198.           end
  199.         end
  200.       end
  201.     end
  202.   end
  203.   for i = 1,invsize-3 do
  204.     if r.count(i) == 0 then
  205.       for j = invsize-3,1,-1 do
  206.         if r.count(j) > 0 then
  207.           if j < i then
  208.             break
  209.           end
  210.           r.select(j)
  211.           r.transferTo(i)
  212.           break
  213.         end
  214.       end
  215.     end
  216.   end
  217.   local unload = function()
  218.     local inv = i_c.getInventorySize(3)
  219.     if inv then
  220.       cheststart = true
  221.       for i = 1,invsize-3 do
  222.         if r.count(i) > 0 then
  223.           r.select(i)
  224.           unloaded = unloaded + r.count(i)
  225.           if not r.drop() then
  226.             returnHome("в сундуке нет места")
  227.             return
  228.           end
  229.         end
  230.       end
  231.       if not charger then
  232.         servise(tools,toollist)
  233.       end
  234.       servise(scoop,{"scoop"})
  235.       r.select(coal)
  236.       gen.insert()
  237.       servise(coal,{"coal"})
  238.       charging()
  239.     elseif not cheststart then
  240.       returnHome("инвентарь заполнен")
  241.     else
  242.       returnHome("нет сундука")
  243.     end
  244.     fuelchest = true
  245.     status("всего добыто руды: "..unloaded)
  246.   end
  247.   if r.count(invsize-6) > 0 then
  248.     status("возвращаюсь к сундуку сложить лут")
  249.     x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
  250.     goTo( 0,0,0,0,-1 )
  251.     unload()
  252.     goTo( x,y,z,xd,zd )
  253.   end
  254.   if droplut and cheststart then
  255.     unload()
  256.   end
  257.   r.select(1)
  258. end
  259.  
  260. --стоп
  261. local function stop(msg)
  262.   print("\n".."!!! стоп !!!".."\n"..msg.."\n")
  263.   r.setLightColor(0xFF0000)
  264.   r.turnAround()
  265.   chunkload(false)
  266.   computer.beep(1000, 1)
  267.   status("программа завершена")
  268.   os.exit()
  269. end
  270.  
  271. --возврат к старту
  272. function returnHome(msg,save,reason)
  273.   r.setLightColor(0xFF0000)
  274.   if save then
  275.     x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
  276.   end
  277.   if y ~= nil then
  278.     print("последняя ширина "..width..", длина "..length..", глубина "..y)
  279.   end
  280.   goTo( 0,0,0,0,-1 )
  281.   if reason then
  282.     print("причина возврата: "..reason)
  283.   end
  284.   if save and cheststart and r.count(1) > 0 then
  285.     sortlut(true)
  286.   end
  287.   goTo( 0,0,0,0,1 )
  288.   status("!!! стоп !!!".."\n"..msg.."\n")
  289.   chunkload(false)
  290.   print("продолжить копать ? [Y/n]")
  291.   while true do
  292.     r.setLightColor(0xFFFFFF)
  293.     computer.beep(1000, 1)
  294.     r.setLightColor(0xFF0000)
  295.     local e = ({event.pull(10,"key_down")})[4]
  296.     if e == 49 then
  297.       computer.beep(500, 0.1)
  298.       print("программа завершена")
  299.       os.exit()
  300.     elseif e == 21 or e == 28 then
  301.       computer.beep(500, 0.1)
  302.       r.setLightColor(0xFFFFFF)
  303.       print("продолжаю копать...")
  304.       chunkload(true)
  305.       goTo( x,y,z,xd,zd )
  306.       break
  307.     end
  308.   end
  309. end
  310.  
  311. --дозаправка углём
  312. local function checkfuel()
  313.   if computer.energy() <= 6000 then
  314.     refuel = true
  315.   end
  316.   if gen.count() <= 10 and refuel then
  317.     for i = 1,invsize do
  318.       local item = i_c.getStackInInternalSlot(i)
  319.       if item and string.find(item.name,"coal") then
  320.         r.select(i)
  321.         r.transferTo(coal)
  322.       end
  323.     end
  324.     r.select(coal)
  325.     if gen.insert() then
  326.       fuelinv = true
  327.       status("заправился, угля в генераторе = "..gen.count())
  328.     elseif fuelchest and cheststart then
  329.       x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
  330.       status("возвращаюсь к сундуку за углем")
  331.       goTo( 0,0,0,0,-1 )
  332.       if servise(coal,{"coal"}) then
  333.         r.select(coal)
  334.         gen.insert()
  335.         status("заправился, угля в генераторе = "..gen.count())
  336.       else
  337.         fuelchest = false
  338.         status("в сундуке нет угля")
  339.       end
  340.       charging()
  341.       goTo( x,y,z,xd,zd )
  342.     else
  343.       refuel = false
  344.       if fuelinv then
  345.         fuelinv = false
  346.         status("нет угля в инвентаре робота !!!")
  347.       end
  348.     end
  349.     r.select(1)
  350.   end
  351.   if computer.energy() <= 5000 then
  352.     x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
  353.     status("энергии < 5 000 возвращаюсь")
  354.     goTo( 0,0,0,0,1 )
  355.     charging()
  356.     if computer.energy() >= 10000 then
  357.       status("зарядился :)")
  358.       goTo( x,y,z,xd,zd )
  359.       return
  360.     elseif gen.count() >= 10 then
  361.       status("мало энергии, заряжаюсь до 10 000")
  362.       while true do
  363.         os.sleep(10)
  364.         if computer.energy() >= 10000 then
  365.           status("зарядился :)")
  366.           goTo( x,y,z,xd,zd )
  367.           break
  368.         elseif gen.count() == 0 then
  369.           returnHome("закончился уголь")
  370.           break
  371.         end
  372.       end
  373.     else
  374.       returnHome("закончился уголь")
  375.     end
  376.   end
  377. end
  378.  
  379. --проверяем разряженный электроинструмент
  380. local function electric(eq1,eq2)
  381.   if eq1 then
  382.     r.select(tools)
  383.     i_c.equip()
  384.   end
  385.   local item = i_c.getStackInInternalSlot(tools)
  386.   if eq2 then
  387.     i_c.equip()
  388.   end
  389.   if item and item.charge ~= nil then
  390.     if item.charge/item.maxCharge <= toolstrength then
  391.       return true
  392.     end
  393.   end
  394.   return false
  395. end
  396.  
  397. --берем запасной инструмент
  398. local function tool(save)
  399.   local checktool = r.durability()
  400.   if checktool == nil or checktool <= toolstrength then
  401.     if save then
  402.       x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
  403.     end
  404.     if slotitem(tools,toollist) then
  405.       r.select(tools)
  406.       i_c.equip()
  407.       status("взял инструмент в инвентаре")
  408.       local item = i_c.getStackInInternalSlot(tools)
  409.       if item and item.charge == nil then
  410.         r.dropDown()
  411.       end
  412.       durability = 0
  413.     elseif charger and electric(true,true) then
  414.       local chargetool = function(msg)
  415.         local inv = i_c.getInventorySize(3)
  416.         if inv and inv <= 4 then
  417.           if not r.drop() then
  418.             charger = false
  419.             status("в зарядчике нет места")
  420.           else
  421.             status(msg)
  422.             while true do
  423.               local c1 = i_c.getStackInSlot(3,1)
  424.               os.sleep(2)
  425.               local c2 = i_c.getStackInSlot(3,1)
  426.               if c2.charge < c1.charge + 500 then
  427.                 break
  428.               end
  429.             end
  430.             if not r.suck() then
  431.               charger = false
  432.               status("не могу забрать инструмент")
  433.             elseif electric() then
  434.               charger = false
  435.               status("инструмент не заряжен")
  436.             end
  437.           end
  438.         else
  439.           charger = false
  440.           status("зарядчик не найден")
  441.         end
  442.         if charger == false then
  443.           tool()
  444.         end
  445.       end
  446.       status("возвращаюсь к зарядчику инструмента")
  447.       goTo( 0,0,0,-1,0 )
  448.       electric(true)
  449.       chargetool("заряжаю инструмент...")
  450.       if electric(true) then
  451.         chargetool("заряжаю запасной инструмент...")
  452.       end
  453.       durability = 0
  454.       goTo( x,y,z,xd,zd )
  455.       if testtool(true) then
  456.         i_c.equip()
  457.         status("возвращаюсь к зарядчику инструмента")
  458.         goTo( 0,0,0,-1,0 )
  459.         testtool(true)
  460.         chargetool("заряжаю инструмент...")
  461.         if testtool(true) then
  462.           chargetool("заряжаю запасной инструмент...")
  463.         end
  464.         charging()
  465.         durability = 0
  466.         goTo( x,y,z,xd,zd )
  467.       end
  468.     elseif cheststart then
  469.       local savetool = function()
  470.         local item = i_c.getStackInInternalSlot(tools)
  471.         if item and item.charge ~= nil then
  472.           local inv = i_c.getInventorySize(3)
  473.           if inv then
  474.             if not r.drop() then
  475.               returnHome("в сундуке нет места")
  476.               return
  477.             end
  478.           else
  479.             returnHome("нет сундука")
  480.             return
  481.           end
  482.         else
  483.           r.dropDown()
  484.         end
  485.       end
  486.       status("возвращаюсь к сундуку за инструментом")
  487.       goTo( 0,0,0,0,-1 )
  488.       r.select(tools)
  489.       savetool()
  490.       if servise(tools,toollist) then
  491.         i_c.equip()
  492.         savetool()
  493.         servise(tools,toollist)
  494.         status("взял инструмент из сундука")
  495.         charging()
  496.         durability = 0
  497.         goTo( x,y,z,xd,zd )
  498.       else
  499.         returnHome("в сундуке нет инструмента")
  500.       end
  501.     else
  502.       returnHome("нет инструмента")
  503.     end
  504.     r.select(1)
  505.   elseif r.detect() then
  506.     local d1 = string.format("%.3f",r.durability())
  507.     for i, side in ipairs({1,3,0}) do
  508.       com.robot.swing(side)
  509.       local d2 = string.format("%.3f",r.durability())
  510.       if d2 < d1 then
  511.         durability = math.floor(d2/(d1-d2))
  512.         break
  513.       end
  514.     end
  515.   end
  516. end
  517.  
  518. --движение в сторону side
  519. local function robotMove(side)
  520.   while true do
  521.     local ok,reason = com.robot.move(side)
  522.     if ok then
  523.       return true
  524.     elseif reason and reason == "already moving" then
  525.       os.sleep(0.1)
  526.     else
  527.       return false,reason
  528.     end
  529.   end
  530. end
  531.  
  532. --идём по Х в 0 координат
  533. local function x_forward()
  534.   for xx = 1,width-1 do
  535.     while true do
  536.       if robotMove(3) then
  537.         xPos = xPos - 1
  538.         break
  539.       else
  540.         r.swing()
  541.       end
  542.     end
  543.   end
  544. end
  545.  
  546. --движемся в верх
  547. local function tryUp()
  548.   local tru = 0
  549.   while true do
  550.     if robotMove(1) then
  551.       depth = depth - 1
  552.       break
  553.     else
  554.       r.swingUp()
  555.     end
  556.     tru = tru + 1
  557.     if tru >= 7 then
  558.       tru = 0
  559.       returnHome("не могу подняться",true)
  560.     end
  561.   end
  562. end
  563.  
  564. --обнаружение бедрока
  565. local function checkbedrock()
  566.   for i = 1,3 do
  567.     if r.detectDown() and not r.swingDown() then
  568.       if bedrock then
  569.         break
  570.       elseif i == 2 then
  571.         tool(true)
  572.       elseif i == 3 then
  573.         status("низ достигнут !")
  574.         bedrock = true
  575.         if y ~= nil then
  576.           status("глубина "..y)
  577.         end
  578.       end
  579.     else
  580.       break
  581.     end
  582.   end
  583. end
  584.  
  585. --сачком добываем улик
  586. local function hive(side)
  587.   if slotitem(scoop,{"scoop"}) then
  588.     r.select(scoop)
  589.     i_c.equip()
  590.     r.select(1)
  591.     if side == 3 then
  592.       r.swing()
  593.     elseif side == 1 then
  594.       r.swingUp()
  595.     elseif side == 0 then
  596.       checkbedrock()
  597.     end
  598.     r.select(scoop)
  599.     i_c.equip()
  600.     r.select(1)
  601.   elseif cheststart then
  602.     x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
  603.     status("возвращаюсь к сундуку за сачком")
  604.     goTo( 0,0,0,0,-1 )
  605.     if servise(scoop,{"scoop"}) then
  606.       status("взял сачок из сундука")
  607.     else
  608.       returnHome("в сундуке нет сачка")
  609.       return
  610.     end
  611.     goTo( x,y,z,xd,zd )
  612.   else
  613.     returnHome("в инвентаре нет сачка ",true)
  614.   end
  615. end
  616.  
  617. --копаем и движемся вперед
  618. local function digForward()
  619.   if durability <= 3 then
  620.     tool(true)
  621.   end
  622.   if r.detectUp() and not r.swingUp() then
  623.     hive(1)
  624.   end
  625.   if r.detect() and not r.swing() then
  626.     hive(3)
  627.   end
  628.   if r.detectDown() and not r.swingDown() then
  629.     if not bedrock then
  630.       hive(0)
  631.     end
  632.   end
  633.   durability = durability - 3
  634.   if r.count(invsize-3) > 0 then
  635.     sortlut()
  636.   end
  637.   local tru,reason = 0
  638.   while true do
  639.     if r.detect() then
  640.       _,reason = r.swing()
  641.       durability = durability - 1
  642.     else
  643.       ok,reason = robotMove(3)
  644.       if ok then
  645.         xPos = xPos + xDir
  646.         zPos = zPos + zDir
  647.         break
  648.       end
  649.     end
  650.     tru = tru + 1
  651.     if tru == 3 then
  652.       tool(true)
  653.     elseif tru == 4 or tru == 5 then
  654.       if bedrock then
  655.         tryUp()
  656.       end
  657.     elseif tru >= 20 then
  658.       tru = 0
  659.       returnHome("непреодолимое препятствие",true,reason)
  660.     end
  661.   end
  662. end
  663.  
  664. --спускаемся в низ
  665. local function go_down()
  666.   for zz = 1,down do
  667.     while true do
  668.       if r.detectDown() and not r.swingDown() then
  669.         hive(0)
  670.       end
  671.       if robotMove(0) then
  672.         depth = depth + 1
  673.         break
  674.       elseif bedrock then
  675.         while true do
  676.           r.swing()
  677.           if r.detect() then
  678.             tryUp()
  679.           else
  680.             return
  681.           end
  682.         end
  683.       end
  684.     end
  685.   end
  686. end
  687.  
  688. --поворот в лево
  689. local function turnLeft()
  690.   while not r.turnLeft() do
  691.     os.sleep(0.1)
  692.   end
  693.   xDir, zDir = -zDir, xDir
  694. end
  695.  
  696. --поворот в право
  697. local function turnRight()
  698.   while not r.turnRight() do
  699.     os.sleep(0.1)
  700.   end
  701.   xDir, zDir = zDir, -xDir
  702. end
  703.  
  704. --навигация к сундуку
  705. function goTo( x,y,z,xd,zd )
  706.   local Xposition = function()
  707.     if xPos > x then
  708.       while xDir ~= -1 do
  709.         turnLeft()
  710.       end
  711.       while xPos > x do
  712.         if robotMove(3) then
  713.           xPos = xPos - 1
  714.         else
  715.           r.swing()
  716.         end
  717.       end
  718.     elseif xPos < x then
  719.       while xDir ~= 1 do
  720.         turnRight()
  721.       end
  722.       while xPos < x do
  723.         if robotMove(3) then
  724.           xPos = xPos + 1
  725.         else
  726.           r.swing()
  727.         end
  728.       end
  729.     end
  730.   end
  731.   local Zposition = function()
  732.     if zPos > z then
  733.       while zDir ~= -1 do
  734.         turnLeft()
  735.       end
  736.       while zPos > z do
  737.         if robotMove(3) then
  738.           zPos = zPos - 1
  739.         else
  740.           r.swing()
  741.         end
  742.       end
  743.     elseif zPos < z then
  744.       while zDir ~= 1 do
  745.         turnRight()
  746.       end
  747.       while zPos < z do
  748.         if robotMove(3) then
  749.           zPos = zPos + 1
  750.         else
  751.           r.swing()
  752.         end
  753.       end
  754.     end
  755.   end
  756.   r.select(1)
  757.   while depth < y do
  758.     while xDir ~= 0 or zDir ~= 1 do
  759.       turnRight()
  760.     end
  761.     if robotMove(0) then
  762.       depth = depth + 1
  763.     else
  764.       r.swingDown()
  765.     end
  766.   end
  767.   if y > 0 then
  768.     Zposition()
  769.     Xposition()
  770.   else
  771.     Xposition()
  772.     Zposition()
  773.   end
  774.   while depth > y do
  775.     if robotMove(1) then
  776.       depth = depth - 1
  777.     else
  778.       r.swingUp()
  779.     end
  780.   end
  781.   while xDir ~= xd or zDir ~= zd do
  782.     turnRight()
  783.   end
  784. end
  785.  
  786. --копаем
  787. local function dig()
  788.   os.execute("cls")
  789.   print("размер карьера:  ширина "..width.."  длина "..length)
  790.   print("угля в генераторе = "..gen.count())
  791.   print("энергии = "..math.floor(100*computer.energy()/computer.maxEnergy()).." %")
  792.   print("подготовка...")
  793.   goTo( 0,0,0,0,-1 )
  794.   for slot = 1,invsize do
  795.     if r.count(slot) == 0 then
  796.       r.select(slot)
  797.       i_c.equip()
  798.       break
  799.     end
  800.     if slot == invsize then
  801.       stop("в инвентаре робота нет пустых слотов")
  802.     end
  803.   end
  804.   local inv = i_c.getInventorySize(3)
  805.   if inv then
  806.     cheststart = true
  807.     print("доступен сундук")
  808.     if servise(tools, toollist) then
  809.       r.select(tools)
  810.       i_c.equip()
  811.       servise(tools,toollist)
  812.     else
  813.       stop("нет инструмента")
  814.     end
  815.     if servise(coal,{"coal"}) then
  816.       r.select(coal)
  817.       if gen.insert() then
  818.         print("заправился, угля в генераторе = "..gen.count())
  819.         servise(coal,{"coal"})
  820.       end
  821.     else
  822.       fuelchest = false
  823.     end
  824.     servise(scoop,{"scoop"})
  825.   else
  826.     cheststart = false
  827.     print("сундук сзади робота не найден")
  828.     if slotitem(tools,toollist) then
  829.       r.select(tools)
  830.       i_c.equip()
  831.       slotitem(tools,toollist)
  832.     else
  833.       stop("нет инструмента")
  834.     end
  835.     checkfuel()
  836.     slotitem(scoop,{"scoop"})
  837.   end
  838.   goTo( 0,0,0,-1,0 )
  839.   local inv = i_c.getInventorySize(3)
  840.   if inv and inv <= 4 then
  841.     charger = true
  842.     print("доступен зарядчик")
  843.   end
  844.   goTo( 0,0,0,0,1 )
  845.   charging()
  846.   r.setLightColor(0xFFFFFF)
  847.   chunkload(true)
  848.   print("опускаюсь на "..down.." блока(ов)")
  849.   for height = 1,256 do
  850.     refuel = true
  851.     checkfuel()
  852.     go_down()
  853.     down = 3
  854.     for xx = 1,width do
  855.       for yy = 1,length-1 do
  856.         digForward()
  857.       end
  858.       checkfuel()
  859.       if xx ~= width then
  860.         if ridht then
  861.           turnRight()
  862.           digForward()
  863.           turnRight()
  864.           ridht = false
  865.         else
  866.           turnLeft()
  867.           digForward()
  868.           turnLeft()
  869.           ridht = true
  870.         end
  871.       end
  872.     end
  873.     r.swingUp()
  874.     r.swingDown()
  875.     if ridht then
  876.       turnLeft()
  877.       x_forward()
  878.       turnLeft()
  879.       ridht = false
  880.     else
  881.       turnRight()
  882.       x_forward()
  883.       turnRight()
  884.       ridht = true
  885.     end
  886.     if bedrock then
  887.       goTo( 0,0,0,0,-1 )
  888.       sortlut(true)
  889.       stop("завершил копать :)")
  890.     end
  891.   end
  892. end
  893.  
  894. dig()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement