Advertisement
FluttyProger

Kopalkavx13

Feb 6th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- FORKED FROM http://pastebin.com/gqZ1Qdqi
  2. -- http://computercraft.ru/topic/1031-geokopatel-ili-stan-millionerom/
  3. -- v0.7.6
  4.  
  5. ---------------------------------------------------------
  6. local nrob="1"
  7. local energyGenPercent = 50
  8. local energyReturnPercent = 20
  9. local energyStartPercent = 99
  10. local minHardness = 2.05
  11. local maxHardness = 40
  12. local scanRadius = 5
  13. local bedrockWidth = 5
  14. local maxTry = 255
  15. local chkPeriod = 30
  16.  
  17. --"chisel:limestone", "chisel:marble", "chisel:diorite", "chisel: granite", "chisel:andesite"
  18. local scrap = {
  19.   "minecraft:stone",
  20.   "minecraft:cobblestone",
  21.   "minecraft:dirt",
  22.   "minecraft:gravel",
  23.   "minecraft:sand",
  24.   "minecraft:grass",
  25.   "minecraft:sandstone",
  26.   "minecraft:mossy_cobblestone",
  27.   "minecraft:stonebrick",
  28.   "minecraft:brown_mushroom",
  29.   "minecraft:red_mushroom",
  30.   "minecraft:netherrack"
  31. }
  32.  
  33. local fuel_list = {
  34.   "minecraft:fence",
  35.   "minecraft:planks",
  36.   "minecraft:log",
  37.   "minecraft:coal_block",
  38.   "minecraft:coal"
  39. }
  40.  
  41. local mining_tools_list = {
  42.   "minecraft:iron_pickaxe",
  43.   "minecraft:golden_pickaxe",
  44.   "appliedenergistics2:item.ToolCertusQuartzPickaxe",
  45.   "appliedenergistics2:item.ToolNetherQuartzPickaxe",
  46.   "IC2:itemToolBronzePickaxe",
  47.   "Forestry:bronzePickaxe",
  48.   "minecraft:diamond_pickaxe",
  49.   "IC2:itemToolDrill",
  50.   "IC2:itemToolDDrill",
  51.   "IC2:itemToolIridiumDrill",
  52.   "GraviSuite:advDDrill"
  53. }
  54. ---------------------------------------------------------
  55.  
  56. local shell = require "shell"
  57. local sides = require("sides")
  58. local term = require("term")
  59. local r = require("robot")
  60. local comp = require("component")
  61. local computer = require("computer")
  62. local ser=require("serialization")
  63. local inv = comp.inventory_controller
  64. local geolyzer
  65. local KOPALKA = {}
  66. local inv_size = r.inventorySize()
  67. local inv_side = sides.back
  68. local charge_side = sides.left
  69. local temp_state = {x=0, y=0, z=0, dr=3}
  70. local lc = {x=0, y=0, z=0, dr=3, xMax = 0, zMax = 0}
  71. local way = 0
  72. local warp = false
  73. local MINE, BACK_TO_BASE, BACK_TO_MINE, EMERGENCY = 0, 1, 2, 3
  74. local mode = MINE
  75. local directives = {
  76.   pause = false,
  77.   home = false,
  78.   report = false,
  79.   move = false    
  80. }
  81. local progress, internet, save, save2, save3
  82. local otrobota, inven = "start", {}
  83.  
  84. --RoboCraft-server
  85. if computer.maxEnergy() >= 200000 then
  86.   print("RoboCraft server detected")
  87.   energyStartPercent = 30
  88.   energyGenPercent = 20
  89.   energyReturnPercent = 10
  90. end
  91.  
  92. local clusterHeight --вычисляется при запуске
  93. local worldHeight = 256
  94.  
  95. local function sprintf(s, ...)
  96.   return s:format(...)
  97. end
  98.  
  99. function pause()
  100.   os.sleep(0)
  101. end
  102.  
  103. local function CheckInv()
  104.   save  = ser.serialize(lc)
  105.   save2 = ser.serialize(progress)
  106.   save3 = ser.serialize(inven)
  107.  
  108.   inven = {}
  109.  
  110.   for i=1,inv_size do
  111.     local item=inv.getStackInInternalSlot(i)
  112.     if item ~= nil then
  113.       inven[i]=({item.label, item.size})
  114.     end
  115.   end
  116. end
  117.  
  118. CheckInv()
  119.  
  120. local function sendSt2() -- ОТПРАВКА СТАТУСНОГО СООБЩЕНИЯ ЧЕРЕЗ ТУННЕЛЬ
  121.   if warp and save ~=" " and save2 ~=" " then
  122.     internet.request("http://FluttyProger.ru/robo"..nrob..".php?cords="..save.."&robo="..string.gsub(otrobota,"% ","_").."&progress="..save2.."&inv="..string.gsub(save3,"% ","_"))
  123.   end
  124. end
  125.  
  126. local function sendSt(message)
  127.   if warp then
  128.     otrobota=message
  129.     sendSt2()
  130.   end
  131. end
  132.  
  133. local function printSt(message) -- ОТПРАВКА СТАТУСНОГО СООБЩЕНИЯ ЧЕРЕЗ ТУННЕЛЬ
  134.   --print(message)
  135.   sendSt(message)
  136. end
  137.  
  138. local actionCnt = 0
  139. local function incActionCnt(energyOnly)
  140.   -- не проверяем состояние в режимах возврата на базу
  141.   if (mode == EMERGENCY) or (mode == BACK_TO_BASE) then
  142.     return
  143.   end
  144.   if actionCnt%chkPeriod == 0 then
  145.     if energyOnly then
  146.       KOPALKA.check_state(false, false, true)
  147.     else
  148.       KOPALKA.check_state(true, true, true)
  149.     end
  150.   end
  151.   actionCnt = actionCnt + 1
  152.   if (actionCnt%4)==0 then
  153.     CheckInv()
  154.     sendSt2()
  155.   end
  156. end
  157.  
  158. -- function KOPALKA.duster(tmr)
  159. --   while true do
  160. --     for i=1,7 do
  161. --       local temp = inv.getStackInSlot(3,i)
  162. --       if temp then
  163. --         if temp.name == "IC2:itemDustSmall" and math.floor(temp.size/9) > 0 then
  164. --           for j=1,3 do
  165. --             r.select(j)
  166. --             inv.suckFromSlot(3,i,math.floor(temp.size/9))
  167. --           end
  168. --           for j=5,7 do
  169. --             r.select(j)
  170. --             inv.suckFromSlot(3,i,math.floor(temp.size/9))
  171. --           end
  172. --           for j=9,11 do
  173. --             r.select(j)
  174. --             inv.suckFromSlot(3,i,math.floor(temp.size/9))
  175. --           end
  176. --             r.select(4)
  177. --             require("component").crafting.craft(math.floor(temp.size/9))
  178. --             r.drop()
  179. --         end
  180. --       end
  181. --     end
  182. --     os.sleep(tmr)
  183. --   end
  184. -- end
  185.  
  186. function KOPALKA.charge_tool(chargerSide, slot)
  187.   local side = 3
  188.   local tool = nil
  189.  
  190.   if chargerSide == 1 then
  191.     side=1
  192.   elseif chargerSide == 0 then
  193.     side=0
  194.   end
  195.  
  196.   if r.durability() == nil then
  197.     return false
  198.   end
  199.  
  200.   if r.durability() < 0.3 then
  201.     r.select(slot)
  202.     inv.equip()
  203.     tool = inv.getStackInInternalSlot(slot)
  204.     inv.equip()
  205.     if not(lc.x == 0 and lc.y == 0 and lc.z == 0) then
  206.       return true
  207.     end
  208.   else
  209.     return false
  210.   end
  211.  
  212.   local function isElectric(device)
  213.     if device.maxCharge ~= nil then
  214.       return true
  215.     else
  216.       return false
  217.     end
  218.   end
  219.  
  220.   local function find_new_tool()
  221.     KOPALKA.rot(inv_side)
  222.     local temp = KOPALKA.inv_scaner(mining_tools_list, false, start_slot)
  223.     printSt("Поиск замены инструменту в сундуке.")
  224.     while temp ~= 0 do
  225.       local temp_device = inv.getStackInSlot(3, temp)
  226.       if isElectric(temp_device) then
  227.         if temp_device.charge/temp_device.maxCharge > 0.6 then
  228.           break
  229.         else
  230.           temp = KOPALKA.inv_scaner(mining_tools_list, false, temp+1)
  231.         end
  232.       else
  233.         if temp_device.damage/temp_device.maxDamage < 0.4 then
  234.           break
  235.         else
  236.           temp = KOPALKA.inv_scaner(mining_tools_list, false, temp+1)
  237.         end
  238.       end
  239.     end
  240.     return temp
  241.   end
  242.  
  243.   local function service(device)
  244.     if isElectric(device) then
  245.       KOPALKA.rot(chargerSide)  
  246.       if (inv.getInventorySize(3) or 0) == 0 then
  247.         printSt("Зарядник не найден. Установите зарядник.")
  248.         while (inv.getInventorySize(3) or 0) == 0  do
  249.           os.sleep(5)
  250.         end
  251.       end
  252.       r.select(slot)
  253.       inv.equip()
  254.       inv.dropIntoSlot(3,1)
  255.       printSt("Зарядка инструмента.")
  256.       while inv.getStackInSlot(3,1).charge < device.maxCharge do
  257.         os.sleep(10)
  258.       end
  259.       inv.suckFromSlot(3,1)
  260.       inv.equip()            
  261.     else
  262.       printSt("Поиск инструмента в сундуке.")
  263.       KOPALKA.rot(inv_side)
  264.       while true do
  265.         local temp = find_new_tool()
  266.         if temp ~= 0 then
  267.           r.select(slot)
  268.           inv.equip()
  269.           if not r.drop() then
  270.             printSt("Нет места в сундуке. Освободите место.")
  271.             while not r.drop() do
  272.               os.sleep(10)
  273.             end
  274.           end
  275.           inv.suckFromSlot(3, temp)
  276.           inv.equip()
  277.           r.select(1)
  278.           break
  279.         end
  280.       end
  281.     end
  282.   end
  283.  
  284.   if lc.x == 0 and lc.y == 0 and lc.z == 0 then
  285.   printSt("Сервис инструмента.")
  286.     service(tool)
  287.   else
  288.     return false
  289.   end  
  290. end
  291.  
  292. -- function KOPALKA.use(s)
  293. --   if s == 1 then
  294. --     r.useUp()
  295. --   elseif s == 2 then
  296. --     r.turnAround()
  297. --     r.use()
  298. --     r.turnAround()
  299. --   elseif s == 3 then
  300. --     r.use()
  301. --   elseif s == 4 then
  302. --     r.turnRight()
  303. --     r.use()
  304. --     r.turnLeft()
  305. --   elseif s==5 then
  306. --     r.turnLeft()
  307. --     r.use()
  308. --     r.turnRight()
  309. --   else
  310. --     r.useDown()
  311. --   end
  312. -- end
  313.  
  314. function KOPALKA.drop() --функция дропа всего инвентаря в сундук, если таковой стоит перед носом
  315.   while true do
  316.     if r.detect() then
  317.       if inv.getInventorySize(3) ~= nil then
  318.         for i=1,inv_size-1 do
  319.           if inv.getStackInInternalSlot(i) ~= nil then
  320.             r.select(i)
  321.             if not r.drop() then
  322.               printSt("Сундук переполнен. Освободите место под складирование.")
  323.               while not r.drop() do
  324.                 os.sleep(5)
  325.               end
  326.             end
  327.           end
  328.         end
  329.         break
  330.       else
  331.         printSt("Блок не является сундуком.")
  332.         os.sleep(5)
  333.       end
  334.     else
  335.       printSt("Установите сундук!")
  336.       os.sleep(5)
  337.     end
  338.   end
  339. end
  340.  
  341. function KOPALKA.isScrap(name) -- ПРОВЕРКА ПРЕДМЕТА, ЯВЛЯЕТСЯ ЛИ ОН МУСОРОМ
  342.   for i, nm in pairs(scrap) do
  343.     if name == nm then  
  344.       return true
  345.     end
  346.   end
  347.   return false
  348. end
  349.  
  350. -- function KOPALKA.ore_analyze(arg) -- АНАЛИЗ БЛОКА, ЯВЛЯЕТСЯ ЛИ ОН МУСОРОМ
  351. --   if arg ~= nil then
  352. --     if comp.isAvailable("geolyzer") then
  353. --       local lyz = comp.geolyzer
  354. --       if KOPALKA.isScrap(lyz.analyze(arg).name) then
  355. --         return false
  356. --       else
  357. --         return true
  358. --       end
  359. --     else
  360. --       print("Геолайзер не обнаружен в системе.")
  361. --       return false
  362. --     end
  363. --   else
  364. --     print("Не указан аргумент(сторона проверки).")
  365. --   end
  366. -- end
  367.  
  368. local dont_drop_scrap
  369. function KOPALKA.drop_scrap()
  370.   if dont_drop_scrap then
  371.     return
  372.   end
  373.   for i=1, inv_size do  
  374.     local slot = inv.getStackInInternalSlot(i)
  375.     if slot ~= nil then  
  376.       if KOPALKA.isScrap(slot.name) then
  377.         r.select(i)
  378.         r.dropDown()
  379.       end
  380.     end
  381.   end
  382.   return KOPALKA.inv_sorting()  
  383. end
  384.  
  385. -----------------------------------ДВИЖЕНИЕ СКВОЗЬ ПОРОДУ [BEGIN]
  386. local compR = comp.robot
  387. if (maxTry  or 0 ) < 1 then
  388.   maxTry = 255
  389. end
  390.  
  391. local function hiver(direction) --ДОБЫЧА УЛЬЯ
  392.   if geolyzer and geolyzer.analyze(direction).name == "ExtraBees:hive" then
  393.     if pcall(r.select, KOPALKA.inv_scaner("Forestry:scoop", true)) then
  394.       inv.equip()
  395.       compR.swing(direction)
  396.       inv.equip()
  397.       r.select(1)
  398.     end
  399.     return true
  400.   end
  401. end
  402.  
  403. local function move(direction)
  404.   while true do
  405.     local ok, err = compR.move(direction)
  406.     if not ok and err == "already moving" then
  407.       os.sleep(0.5)
  408.     else
  409.       return ok, err
  410.     end
  411.   end
  412. end
  413.  
  414. function KOPALKA.swingmove(direction, doMove, action, arg)
  415.   if action ~= nil then
  416.     action(arg)
  417.   end
  418.   local detected, detectInf, moveOk, moveInf, rSwing, tSwing
  419.   local chkHiver = true
  420.   for try = 1, maxTry do
  421.     detected, detectInf =  compR.detect(direction)
  422.     if detected then
  423.       incActionCnt()
  424.       rSwing, tSwing = compR.swing(direction) --air, block, entity
  425.       if not rSwing and (tSwing ~= "air") then
  426.         local skipErr
  427.         if tSwing == "block" and chkHiver then
  428.           if hiver(direction) then
  429.             chkHiver = false
  430.             skipErr = true
  431.           end
  432.         end
  433.         if not skipErr then
  434.           return false, detectInf, "Неустранимое препятствие ("..tostring(tSwing)..")"
  435.         end
  436.       end
  437.     else
  438.       if doMove then
  439.         incActionCnt()
  440.         moveOk, moveInf = move(direction)
  441.         if moveOk then
  442.           way = way + 1
  443.           return true
  444.         elseif moveInf == "impossible move" then -- or moveInf == "not enough energy"
  445.           return false, detectInf, "Ошибка перемещения ("..tostring(moveInf)..")"
  446.         end
  447.       else
  448.         return true
  449.       end
  450.     end
  451.   end
  452.   return false, detectInf, "Лимит попыток передвижения исчерпан"
  453. end
  454.  
  455. local function makeMoveErrMsg(direction, detect, msg)
  456.   local directionText
  457.   local s  = msg.." у точки: x="..lc.x.." z="..lc.z.." y="..lc.y
  458.   if direction == sides.front then
  459.     directionText = "спереди"
  460.   elseif direction == sides.top then
  461.     directionText = "сверху"
  462.   elseif direction == sides.bottom then
  463.     directionText = "снизу"
  464.   else
  465.     directionText = "("..direction..")"
  466.   end
  467.   if geolyzer then
  468.     detect = detect.." ["..geolyzer.analyze(3).name.."]"
  469.   end
  470.   return  s.." Направление Dr="..lc.dr.." "..detect.." "..directionText
  471. end
  472.  
  473. function KOPALKA.mUp(action, arg)
  474.   local ok, detect, msg = KOPALKA.swingmove(sides.up, true, action, arg)
  475.   if ok then
  476.     lc.y = lc.y + 1
  477.   else
  478.     printSt(makeMoveErrMsg(sides.down, detect, msg))
  479.     -- KOPALKA.mTo(lc.x+2,lc.y,lc.z) --?? Нужно ли? Совместимость с ЧЛ DA?
  480.     if mode ~= EMERGENCY then  -- в режиме аварийного возврата долбимся до упора
  481.       os.exit(1)
  482.     else
  483.       os.sleep(1)
  484.     end
  485.   end
  486. end
  487.  
  488. function KOPALKA.mDown(action, arg)
  489.   local ok, detect, msg = KOPALKA.swingmove(sides.down, true, action, arg)
  490.   if ok then
  491.     lc.y = lc.y - 1
  492.   else
  493.     printSt(makeMoveErrMsg(sides.down, detect, msg))
  494.     if mode ~= EMERGENCY then -- в режиме аварийного возврата долбимся до упора
  495.       os.exit(1)
  496.     else
  497.       os.sleep(1)
  498.     end
  499.   end
  500. end
  501.  
  502. function KOPALKA.mForw(action, arg)
  503.   local ok, detect, msg = KOPALKA.swingmove(sides.front, true, action, arg)
  504.   if ok then
  505.     if lc.dr==2 then
  506.       lc.x = lc.x - 1
  507.     elseif lc.dr==3 then
  508.       lc.x = lc.x + 1
  509.     elseif lc.dr==4 then
  510.       lc.z = lc.z + 1
  511.     elseif lc.dr==5 then
  512.       lc.z = lc.z - 1
  513.     end
  514.   else
  515.     printSt(makeMoveErrMsg(sides.front, detect, msg))
  516.     if mode ~= EMERGENCY then -- в режиме аварийного возврата долбимся до упора
  517.       os.exit(1)
  518.     else
  519.       os.sleep(1)
  520.     end
  521.   end
  522. end
  523. -----------------------------------ДВИЖЕНИЕ СКВОЗЬ ПОРОДУ [END]
  524.  
  525.  
  526. -----------------------------------ВРАЩЕНИЕ К ПРОГРАММНОЙ НАВИГАЦИИ [BEGIN]
  527. function KOPALKA.turnLeft()
  528.   r.turnLeft()
  529.   if lc.dr == 3 then
  530.     lc.dr = 5
  531.   elseif lc.dr == 4 then
  532.     lc.dr = 3
  533.   elseif lc.dr == 2 then
  534.     lc.dr = 4
  535.   elseif lc.dr == 5 then
  536.     lc.dr = 2
  537.   end
  538. end
  539.  
  540. function KOPALKA.turnRight()
  541.   r.turnRight()
  542.   if lc.dr == 3 then
  543.     lc.dr = 4
  544.   elseif lc.dr == 4 then
  545.     lc.dr = 2
  546.   elseif lc.dr == 2 then
  547.     lc.dr = 5
  548.   elseif lc.dr == 5 then
  549.     lc.dr = 3
  550.   end
  551. end
  552.  
  553. function KOPALKA.turnAround()
  554.   r.turnAround()
  555.   if lc.dr == 3 then
  556.     lc.dr = 2
  557.   elseif lc.dr == 4 then
  558.     lc.dr = 5
  559.   elseif lc.dr == 2 then
  560.     lc.dr = 3
  561.   elseif lc.dr == 5 then
  562.     lc.dr = 4
  563.   end
  564. end
  565.  
  566. function KOPALKA.rot(side) -- ВРАЩЕНИЕ С ЗАПОМИНАНИЕМ НАПРАВЛЕНИЯ
  567.   if (side ~= 1) and (side ~= 0) and lc.dr-side ~=0 then
  568.     if lc.dr == 3 then
  569.       if side == 4 then
  570.       KOPALKA.turnRight()
  571.       elseif side == 2 then
  572.       KOPALKA.turnAround()
  573.       elseif side == 5 then
  574.       KOPALKA.turnLeft()
  575.       end
  576.     elseif lc.dr == 4 then
  577.       if side == 2 then
  578.       KOPALKA.turnRight()
  579.       elseif side == 5 then
  580.       KOPALKA.turnAround()
  581.       elseif side == 3 then
  582.       KOPALKA.turnLeft()
  583.       end
  584.     elseif lc.dr == 2 then
  585.       if side == 5 then
  586.       KOPALKA.turnRight()
  587.       elseif side == 3 then
  588.       KOPALKA.turnAround()
  589.       elseif side == 4 then
  590.       KOPALKA.turnLeft()
  591.       end
  592.     else
  593.       if side == 3 then
  594.       KOPALKA.turnRight()
  595.       elseif side == 4 then
  596.       KOPALKA.turnAround()
  597.       elseif side == 2 then
  598.       KOPALKA.turnLeft()
  599.       end
  600.     end
  601.   end
  602. end
  603. -----------------------------------ВРАЩЕНИЕ К ПРОГРАММНОЙ НАВИГАЦИИ [END]
  604.  
  605.  
  606. -----------------------------------ДВИЖЕНИЕ С ПРОГРАММНОЙ НАВИГАЦИЕЙ [BEGIN]
  607. function KOPALKA.mTo(x, y, z, action, arg)
  608.   if directives.pause then
  609.     KOPALKA.execDirective()
  610.   end
  611.   if lc.x > x then
  612.     KOPALKA.rot(sides.back)
  613.     while lc.x > x do
  614.       KOPALKA.mForw(action,arg)
  615.     end
  616.   end
  617.   if lc.x < x then
  618.     KOPALKA.rot(sides.forward)
  619.     while lc.x < x do
  620.       KOPALKA.mForw(action,arg)
  621.     end
  622.   end
  623.   if lc.z > z then
  624.     KOPALKA.rot(sides.left)
  625.     while lc.z > z do
  626.       KOPALKA.mForw(action,arg)
  627.     end  
  628.   end
  629.   if lc.z < z then
  630.     KOPALKA.rot(sides.right)
  631.     while lc.z < z do
  632.       KOPALKA.mForw(action,arg)
  633.     end
  634.   end
  635.   while lc.y > y do
  636.     KOPALKA.mDown(action,arg)
  637.   end
  638.   while lc.y < y do
  639.     KOPALKA.mUp(action,arg)
  640.   end
  641. end
  642.  
  643. function KOPALKA.home(service, emergency)
  644.   if (mode == BACK_TO_BASE) or (mode == EMERGENCY) then
  645.     return
  646.   end
  647.   if emergency then
  648.     mode = EMERGENCY
  649.     KOPALKA.mTo(lc.x, 0, lc.z)
  650.   else
  651.     if mode == BACK_TO_MINE then
  652.       printSt("Не могу добраться до точки возобновления работы. Вероятно карьер слишком большой")
  653.       os.exit(1)
  654.     end
  655.     mode = BACK_TO_BASE
  656.   end
  657.   sendSt("Возвращаюсь на базу.")
  658.   temp_state.x = lc.x
  659.   temp_state.y = lc.y
  660.   temp_state.z = lc.z
  661.   temp_state.dr = lc.dr
  662.   KOPALKA.mTo(0, 0, 0)
  663.   KOPALKA.rot(2)
  664.   KOPALKA.drop_scrap()
  665.   KOPALKA.drop()
  666.   --KOPALKA.rot(3)
  667.   if service then
  668.     service()
  669.   end
  670. end
  671.  
  672. function KOPALKA.back_to_mine(action, arg)
  673.   printSt("Продолжаю работу.")
  674.   mode = BACK_TO_MINE
  675.   KOPALKA.mTo(0, temp_state.y, 0, action, arg)
  676.   KOPALKA.mTo(temp_state.x, temp_state.y, temp_state.z, action, arg)
  677.   KOPALKA.rot(temp_state.dr)
  678.   temp_state.x = 0
  679.   temp_state.y = 0
  680.   temp_state.z = 0
  681.   temp_state.dr = 3
  682.   mode = MINE
  683. end
  684.  
  685. -----------------------------------ДВИЖЕНИЕ С ПРОГРАММНОЙ НАВИГАЦИЕЙ [END]
  686.  
  687.  
  688. function KOPALKA.check_inv()
  689.   return r.inventorySize()
  690. end
  691.  
  692. function KOPALKA.inv_sorting()
  693.   local items_stored = 0
  694.  
  695.   for i=1, inv_size-1 do
  696.     if r.count(i) == 0 then
  697.       for j=inv_size-1, 1, -1 do
  698.         if r.count(j) > 0 then
  699.           if j<i then
  700.             break
  701.           end
  702.           r.select(j)
  703.           r.transferTo(i)
  704.           break
  705.         end
  706.       end
  707.     end
  708.   end
  709.   for i=1,inv_size do
  710.     if r.count(i) > 0 then
  711.       items_stored = items_stored + 1
  712.     end
  713.   end
  714.   r.select(1)
  715.   return items_stored/inv_size
  716. end
  717.  
  718. function KOPALKA.check_state(chkInventory, chkTool, chkEnergy)
  719.   chkInventory = chkInventory or true
  720.   chkTool = chkTool or true
  721.   chkEnergy = chkEnergy or true
  722.   --printSt(sprintf("Проверка состояния (время работы: %d)", computer.uptime()))
  723.   local function inventory()
  724.     local need_to_home = false
  725.     if (r.count(inv_size-2) > 0) then  
  726.       if KOPALKA.drop_scrap() > 0.9 then
  727.         need_to_home = true
  728.       else
  729.         need_to_home = false
  730.       end
  731.     end
  732.     if need_to_home then
  733.       sendSt("Инвентарь заполнен.")
  734.     end
  735.     return need_to_home
  736.   end
  737.  
  738.   local function wayChargeService()
  739.     local need_energy = computer.energy() < (computer.maxEnergy()*energyGenPercent/100)
  740.     local need_to_home = computer.energy() < (computer.maxEnergy()*energyReturnPercent/100)
  741.     if need_energy and comp.isAvailable("generator") and comp.generator.count() == 0 then
  742.       local slt = KOPALKA.inv_scaner(fuel_list, true)
  743.       if slt ~= 0 then  
  744.         r.select(slt)
  745.         sendSt("Запускаю генератор.")
  746.         comp.generator.insert()
  747.         r.select(1)
  748.       end
  749.     end
  750.     if need_to_home then
  751.       sendSt("Недостаточно энергии.")
  752.     end
  753.     return need_to_home
  754.   end
  755.  
  756.   local function chargeService()
  757.     while computer.energy() < (computer.maxEnergy()*energyStartPercent/100) do
  758.       printSt("Недостаточно энергии.")
  759.       if comp.isAvailable("generator") and comp.generator.count() == 0 then
  760.         local slt = KOPALKA.inv_scaner(fuel_list, false)
  761.         if slt ~= 0 then
  762.           r.select(inv_size-2)
  763.           inv.suckFromSlot(3, slt)
  764.           printSt("Запускаю генератор.")
  765.           comp.generator.insert()
  766.           r.select(1)
  767.         end
  768.       end
  769.       os.sleep(15)
  770.     end
  771.     printSt("Аккумулятор заряжен.")
  772.   end
  773.  
  774.   local function homeService()
  775.     KOPALKA.charge_tool(charge_side, inv_size-2)  
  776.     chargeService()
  777.   end
  778.  
  779.   if (chkInventory and inventory()) or (chkEnergy and wayChargeService()) or
  780.     (chkTool and KOPALKA.charge_tool(charge_side, inv_size-2)) then
  781.     KOPALKA.home(homeService)
  782.     KOPALKA.back_to_mine()
  783.   end    
  784. end
  785.  
  786. function KOPALKA.inv_scaner(filter, internal, start_slot) --автопоисковик заданного итема в своем инвентаре по системному имени. возвращает номер ячейки итема, первого найденного от начала ивентаря.
  787.   ins = inv.getInventorySize(3)
  788.   if start_slot == nil then
  789.     start_slot = 1
  790.   end
  791.   if filter == "empty" then
  792.     if internal then
  793.       for i=start_slot, inv_size do
  794.         if inv.getStackInInternalSlot(i) == nil then
  795.           return i
  796.         end
  797.       end
  798.     else
  799.       for i=start_slot, inv.getInventorySize(3) do
  800.         if inv.getStackInSlot(3, i) == nil then
  801.           return i
  802.         end
  803.       end
  804.     end
  805.   end  
  806.   if internal then
  807.     for i=start_slot, inv_size do
  808.       if inv.getStackInInternalSlot(i) ~= nil then
  809.         if pcall(pairs, filter) then
  810.           for j, name in pairs(filter) do
  811.             if inv.getStackInInternalSlot(i).name == name then
  812.               return i
  813.             end
  814.           end
  815.         else
  816.           if inv.getStackInInternalSlot(i).name == filter then
  817.             return i
  818.           end
  819.         end
  820.       end
  821.     end
  822.     return 0  
  823.   else
  824.     if ins ~= nil  then
  825.       for i=start_slot, ins do
  826.         if inv.getStackInSlot(3, i) ~= nil then
  827.           if pcall(pairs, filter) then
  828.             for j, name in pairs(filter) do
  829.               if inv.getStackInSlot(3, i).name == name then
  830.                 return i
  831.               end
  832.             end
  833.           else
  834.             if inv.getStackInSlot(3, i).name == filter then
  835.               return i
  836.             end
  837.           end
  838.         end
  839.       end
  840.       return 0
  841.     else
  842.       return 0
  843.     end
  844.   end
  845. end
  846.  
  847. function KOPALKA.distance(blockA, blockB)
  848.   local dist = math.sqrt(math.pow(blockA.x - blockB.x,2) +
  849.   math.pow(blockA.z - blockB.z,2) + math.pow(blockA.y - blockB.y,2))
  850.   return dist
  851. end
  852.  
  853. function KOPALKA.closest_point(point, points)
  854.   local cl_num = 1
  855.   local length = KOPALKA.distance(point, points[1])
  856.   for i=1, #points do
  857.     local l = KOPALKA.distance(point, points[i])
  858.     if l < length then
  859.       cl_num = i
  860.       length = l
  861.     end
  862.   end
  863.   return cl_num
  864. end
  865.  
  866. function KOPALKA.waypoints(ores_table, last)
  867.   local yeildGuard = 0
  868.   local way_table = {}
  869.   local count = #ores_table
  870.   table.insert(way_table, {x=lc.x, z=lc.z, y=lc.y})
  871.   while count ~= #way_table - 1 do
  872.     yeildGuard = yeildGuard + 1
  873.     if yeildGuard == 100 then
  874.       yeildGuard = 0
  875.       pause()
  876.     end
  877.     local j = KOPALKA.closest_point(way_table[#way_table], ores_table)
  878.     table.insert(way_table, ores_table[j])
  879.     table.remove(ores_table, j)
  880.   end
  881.   return way_table, last
  882. end
  883.  
  884. function KOPALKA.scanVolume(xn, zn, side, hiLayer, loLayer) --сканирование карьерного "этажа" заданного радиуса -10 блоков вниз+сканер+10 блоков вверх; bedrock - верхний уровень бедрока
  885.   local geo = geolyzer
  886.   local ores_table = {}
  887.   local last = false
  888.   local x_limit = 0
  889.   local z_limit = 0
  890.   local x_increment = 1
  891.   local z_increment = 1
  892.   if side == "north" or side == "север" then
  893.     x_limit = zn
  894.     x_increment = 1
  895.     z_limit = -xn
  896.     z_increment = -1
  897.   elseif side == "west" or side == "запад" then
  898.     x_limit = -xn
  899.     x_increment = -1
  900.     z_limit = -zn
  901.     z_increment = -1
  902.   elseif side == "south" or side == "юг" then
  903.     x_limit = -zn
  904.     x_increment = -1
  905.     z_limit = xn
  906.     z_increment = 1
  907.    elseif side == "east" or side == "восток" or side == nil then
  908.      x_limit = xn
  909.      x_increment = 1
  910.     z_limit = zn
  911.     z_increment = 1
  912.   end
  913.  
  914.   for xt=0,x_limit,x_increment do
  915.     for zt=0,z_limit,z_increment do
  916.       local scan = KOPALKA.scanPilar(xt, zt)
  917.       for yt = hiLayer, loLayer, -1 do
  918.         local y = lc.y + yt
  919.         local hardness = scan[33 + yt]
  920.         if hardness > minHardness and hardness < maxHardness and not (yt == 0 and zt == 0 and xt == 0) then
  921.           if side == "north" or side == "север" then
  922.             table.insert(ores_table, {x=math.abs(zt)+lc.x, z=math.abs(xt)+lc.z, y = y})
  923.           elseif side == "west" or side == "запад" then
  924.             table.insert(ores_table, {x=math.abs(xt)+lc.x, z=math.abs(zt)+lc.z, y = y})
  925.           elseif side == "south" or side == "юг" then
  926.             table.insert(ores_table, {x=math.abs(zt)+lc.x, z=math.abs(xt)+lc.z, y = y})
  927.           elseif side == "east" or side == "восток" or side == nil then
  928.             table.insert(ores_table, {x=math.abs(xt)+lc.x, z=math.abs(zt)+lc.z, y = y})
  929.           end    
  930.         end
  931.       end
  932.     end
  933.   end
  934.   return ores_table
  935. end
  936.  
  937. function KOPALKA.whatsSide()
  938.   printSt("Ориентирование в пространстве.")
  939.   local function isBlock(dens)
  940.     if dens ~= nil and dens ~= 0 then
  941.       return 1
  942.     elseif dens == 0 then
  943.       return 0
  944.     end
  945.   end
  946.  
  947.   local function check(fig, front)
  948.     local figure1 = {
  949.       east = isBlock(KOPALKA.scanPilar(1,0)[33]),
  950.       south = isBlock(KOPALKA.scanPilar(0,1)[33]),
  951.       west = isBlock(KOPALKA.scanPilar(-1,0)[33]),  
  952.       north = isBlock(KOPALKA.scanPilar(0,-1)[33])
  953.     }  
  954.     if front then
  955.       if fig.east > figure1.east  then
  956.         return "east"
  957.       elseif fig.south > figure1.south then
  958.         return "south"
  959.       elseif fig.west > figure1.west then
  960.         return "west"
  961.       elseif fig.north > figure1.north then
  962.         return "north"
  963.       end
  964.     elseif not front then
  965.       if fig.east < figure1.east  then
  966.         return "east"
  967.       elseif fig.south < figure1.south then
  968.         return "south"
  969.       elseif fig.west < figure1.west then
  970.         return "west"
  971.       elseif fig.north < figure1.north then
  972.         return "north"
  973.       end  
  974.     end
  975.   end
  976.   local figure = {
  977.     east = isBlock(KOPALKA.scanPilar(1,0)[33]),
  978.     south = isBlock(KOPALKA.scanPilar(0,1)[33]),
  979.     west = isBlock(KOPALKA.scanPilar(-1,0)[33]),  
  980.     north = isBlock(KOPALKA.scanPilar(0,-1)[33])
  981.   }
  982.   KOPALKA.rot(3)
  983.   while true do
  984.     if r.detect() then
  985.       r.swing()
  986.       local direction = check(figure, true)
  987.       r.place()
  988.       return direction
  989.     elseif r.detectDown() then
  990.       r.swingDown()
  991.       r.place()
  992.       local direction = check(figure, false)
  993.       r.swing()
  994.       r.placeDown()
  995.       return direction
  996.     end
  997.     printSt("Для ориентирования в пространстве недостаточно данных.")
  998.     printSt("Пожалуйста установите любой блок перед или под роботом и повторите попытку")
  999.     os.exit(1)
  1000.   end
  1001. end
  1002.  
  1003. function KOPALKA.scanPilar(x, z)
  1004.   local scan = geolyzer.scan(x, z, true)
  1005.   incActionCnt()
  1006.   return scan, bedrock
  1007. end
  1008.  
  1009. local testBedrock
  1010. local flatBedrock
  1011. function KOPALKA.findoutBedrockLevel()
  1012.   printSt("Проверка уровня бедрока. Вертикальная шахта до дна и обратно.")
  1013.   for i = lc.y, -worldHeight + 1, -scanRadius do
  1014.     local tempr = KOPALKA.scanPilar(0, 0)
  1015.     for i = 1, scanRadius do
  1016.       if tempr[33 - i] < -0.3 then
  1017.         local bedrockHi = lc.y - i
  1018.         if testBedrock then
  1019.           printSt("Бедрок обнаружен на уровне "..bedrockHi)
  1020.         end
  1021.         KOPALKA.mTo(lc.x, bedrockHi + 1, lc.z)
  1022.         local tempr = KOPALKA.scanPilar(0, 0)
  1023.         local bedrockLo = bedrockHi
  1024.         for i = 5, 1, -1 do
  1025.           if tempr[33 - i] < -0.3 then
  1026.             bedrockLo = lc.y - i
  1027.             if testBedrock then
  1028.               printSt("Нижний уровень бедрока "..bedrockLo)
  1029.             end
  1030.             break
  1031.           end
  1032.         end
  1033.         local scannedBedrockWidth = bedrockHi - bedrockLo + 1
  1034.         local bedrock
  1035.         if flatBedrock then
  1036.           bedrock = bedrockHi
  1037.         else
  1038.           bedrock = bedrockLo + (bedrockWidth - 1)
  1039.         end
  1040.         if testBedrock then
  1041.           printSt("Толщина бедрока в точке старта "..scannedBedrockWidth)
  1042.           printSt("Уровень бедрока установлен "..bedrock)
  1043.         end
  1044.         return bedrock
  1045.       end
  1046.     end
  1047.     KOPALKA.mTo(lc.x, i, lc.z)
  1048.   end
  1049.   printSt("Бедрок не обнаружен")
  1050.   os.exit(1)
  1051. end
  1052.  
  1053. function KOPALKA.quarry(quarryLength, quarryWidth, quarryHeight, side)
  1054.   if side == nil then
  1055.     side = sides.front
  1056.   end
  1057.   function dig(h)
  1058.     local try = 0
  1059.     if h >= 3 then
  1060.       KOPALKA.swingmove(sides.up, false)
  1061.     end
  1062.     if h >=2 then
  1063.       KOPALKA.swingmove(sides.down, false)
  1064.     end
  1065.   end
  1066.   if not quarryHeight then
  1067.     quarryHeight = 255
  1068.   end
  1069.   local doTurnRight = true
  1070.   for yy = 0, math.ceil(quarryHeight / 3) * 3 - 1, 3 do
  1071.     local h = quarryHeight - yy
  1072.     if yy > 0 then
  1073.       if h >= 3 then
  1074.         n = 3
  1075.       else
  1076.         n = 2
  1077.       end
  1078.       for n = n, 1, -1 do
  1079.         KOPALKA.mDown()
  1080.       end
  1081.       KOPALKA.turnAround()
  1082.     elseif h >= 3 then
  1083.       KOPALKA.mDown()
  1084.     end
  1085.     for zz = 1, quarryWidth do
  1086.       for xx = 1, quarryLength - 1 do
  1087.         KOPALKA.mForw(dig, h)
  1088.       end
  1089.       if zz < quarryWidth then
  1090.         if doTurnRight then
  1091.           KOPALKA.turnRight()
  1092.         else
  1093.           KOPALKA.turnLeft()
  1094.         end
  1095.         KOPALKA.mForw(dig, h)
  1096.         if doTurnRight then
  1097.           KOPALKA.turnRight()
  1098.         else
  1099.           KOPALKA.turnLeft()
  1100.         end
  1101.         doTurnRight = not doTurnRight
  1102.       end
  1103.     end
  1104.     dig(h)
  1105.   end
  1106.   KOPALKA.home()
  1107.   KOPALKA.rot(3)
  1108.   printSt("Всего блоков пройдено: "..way)
  1109. end
  1110.  
  1111. function KOPALKA.geoMiner(mineLength, mineWidth, mineHeight, side, clusterLength, clusterWidth)
  1112.   progress = { oreCount = 0 }
  1113.   if side == nil then
  1114.     side = KOPALKA.whatsSide()
  1115.   end
  1116.   mineHeight = mineHeight or -KOPALKA.findoutBedrockLevel()
  1117.   progress.mineLength  = mineLength
  1118.   progress.mineWidth = mineWidth
  1119.   progress.mineHeight = mineHeight
  1120.   progress.numClusters = math.ceil(mineLength / clusterLength)
  1121.     * math.ceil(mineWidth / clusterWidth)
  1122.     * math.ceil(mineHeight / clusterHeight)
  1123.   progress.currentCluster =  0
  1124.   for x = 0, mineLength - 1, clusterLength do
  1125.     l = clusterLength
  1126.     if x + clusterLength > mineLength then
  1127.       l = mineLength - x
  1128.     end
  1129.     for z = 0, mineWidth - 1, clusterWidth do
  1130.       w = clusterWidth
  1131.       if z + clusterWidth > mineWidth then
  1132.         w = mineWidth - z
  1133.       end
  1134.       local bottomLayer = mineHeight - 1
  1135.       for y = scanRadius, math.ceil(mineHeight / clusterHeight) * clusterHeight, clusterHeight do
  1136.         local loLayer = -math.min(scanRadius, bottomLayer - y)
  1137.         local hiLayer = scanRadius
  1138.         if y >= mineHeight then
  1139.           hiLayer = 0
  1140.           loLayer = -math.min(scanRadius, scanRadius - (y - bottomLayer))
  1141.           y = mineHeight - mineHeight%clusterHeight
  1142.         end
  1143.         progress.currentCluster =  progress.currentCluster + 1
  1144.         progress.clusterStartPoint = {x = x, y = -y, z = z}
  1145.         progress.clusterOreCount = 0
  1146.         progress.clusterNumOres = 0
  1147.         KOPALKA.clusterDigger(progress.clusterStartPoint, l, w, side, hiLayer, loLayer)
  1148.       end
  1149.     end
  1150.   end
  1151.   KOPALKA.home()
  1152.   KOPALKA.rot(3)
  1153.   printSt("Итого руды добыто: "..progress.oreCount)
  1154. end
  1155.  
  1156. function KOPALKA.clusterDigger(start_point, l, w, side, hiLayer, loLayer)
  1157.   sendSt(sprintf("Кластер: (%d, %d) размером (%d, %d) на уровне %d (%d->%d)",
  1158.     start_point.x, start_point.z, l, w, start_point.y, loLayer, hiLayer))
  1159.   KOPALKA.mTo(start_point.x, start_point.y, start_point.z)
  1160.   sendSt("Сканирование...")
  1161.   local arr = KOPALKA.scanVolume(l-1, w-1, side, hiLayer, loLayer)
  1162.   progress.clusterNumOres = #arr
  1163.   if progress.clusterNumOres > 0 then
  1164.     sendSt("Найдено "..tostring(progress.clusterNumOres).." блока(ов)...")
  1165.     arr = KOPALKA.waypoints(arr)
  1166.     local n = #arr
  1167.     for i = 2, n do
  1168.       KOPALKA.mTo(arr[i].x, arr[i].y, arr[i].z)
  1169.       progress.clusterOreCount = progress.clusterOreCount + 1
  1170.       progress.oreCount = progress.oreCount + 1
  1171.       if (i % 10 == 1 or i == n) then
  1172.         sendSt(sprintf("%d из %d", progress.clusterOreCount, progress.clusterNumOres))
  1173.       end
  1174.     end
  1175.   end
  1176.   sendSt(sprintf("Кластер: (%d, %d) на уровне %d (%d->%d) обработан",
  1177.     start_point.x, start_point.z, start_point.y, loLayer, hiLayer))
  1178. end
  1179.  
  1180. function KOPALKA.check_components(ignoreCheck)
  1181.   ignoreCheck = ignoreCheck or { }
  1182.   local function stop()
  1183.     print('> ')
  1184.     if tonumber(io.read()) == 0 then
  1185.       os.exit()
  1186.     end
  1187.   end
  1188.   if comp.isAvailable("internet") then
  1189.     warp = true
  1190.     internet = require("internet")
  1191.     print("\t Связанная карта....доступна.")
  1192.   else
  1193.     print("\t Связанная карта не обнаружена. Начать работу? (0/1)")
  1194.     stop()
  1195.   end
  1196.   if comp.isAvailable("chunkloader") then
  1197.     comp.chunkloader.setActive(true)
  1198.     print("\t Чанклоадер....доступен.")
  1199.   else
  1200.     print("\t Чанклоадер не обнаружен, возможны проблемы и ошибки. Начать работу без чанклоадера? (0/1)")
  1201.     stop()
  1202.   end
  1203.   if comp.isAvailable("inventory_controller") then
  1204.     print("\t Контроллер инвентаря....доступен.")
  1205.   else
  1206.     print("\t Контроллер инвентаря не обнаружен, возможны проблемы и ошибки. Принудительная остановка программы.")
  1207.     os.exit()
  1208.   end
  1209.   if comp.isAvailable("generator") then
  1210.     print("\t Генератор....доступен.")
  1211.   else
  1212.     print("\t Генератор не обнаружен, возможны проблемы и ошибки. Начать работу без генератора? (0/1)")
  1213.     stop()
  1214.   end
  1215.   if comp.isAvailable("geolyzer") then
  1216.     print("\t Геосканер....доступен.")
  1217.     geolyzer = comp.geolyzer
  1218.   else
  1219.     if not ignoreCheck.geolyzer then
  1220.       print("\t Геосканер не обнаружен, возможны проблемы и ошибки. Принудительная остановка программы.")
  1221.       os.exit()
  1222.     end
  1223.   end
  1224.   if pcall(r.select,KOPALKA.inv_scaner("Forestry:scoop", true)) then
  1225.     r.transferTo(inv_size)
  1226.     r.select(1)
  1227.     print("\t Сачок....доступен.")
  1228.   else
  1229.     if not ignoreCheck.scoop then
  1230.       print("\t Сачок не обнаружен, возможны проблемы и ошибки. Начать работу без сачка?")
  1231.       stop()
  1232.     end
  1233.   end
  1234.   if r.durability() ~= nil then
  1235.     print("\t Инструмент....доступен.")
  1236.   else
  1237.     print("\t Инструмент не обнаружен, возможны проблемы и ошибки. Принудительная остановка программы.")
  1238.     os.exit()
  1239.   end
  1240.   print("\n Все компоненты в наличии.\n Программа может быть запущена.")
  1241. end
  1242.  
  1243. function KOPALKA.mine(x, z, mineHeight, side, x_lim, z_lim, quarry, ignoreCheck)
  1244.   if quarry then
  1245.     ignoreCheck = { geolyzer = true }
  1246.   end
  1247.   KOPALKA.check_components(ignoreCheck)
  1248.   lc.xMax = x
  1249.   lc.zMax = z
  1250.   way = 0
  1251.   term.clear()
  1252.   printSt("Старт карьера: "..x.."x"..z.." блоков.")
  1253.   local worker = KOPALKA.geoMiner
  1254.   if quarry then
  1255.     worker = KOPALKA.quarry
  1256.   end
  1257.   local ok, err = pcall(worker, x, z, mineHeight, side, x_lim, z_lim)
  1258.   if not ok then
  1259.     if type(err) ~= "table" then
  1260.       printSt(err)
  1261.     end
  1262.     printSt('Ошибка/препятствие. Возврат робота.')
  1263.     KOPALKA.home(nil, true)
  1264.     KOPALKA.rot(3)
  1265.   end
  1266. end
  1267.  
  1268. function main(tArgs, options)
  1269.   local function argNumber(x)
  1270.     local v = tonumber(x)
  1271.     if type(v) ~= 'number' then
  1272.       io.write("Аргументы должны быть заданы в виде чисел.\n")
  1273.       os.exit(1)
  1274.     end
  1275.     return v
  1276.   end
  1277.  
  1278.   local function getNumberOption(name)
  1279.     local v = options[name]
  1280.     if v then
  1281.       v = argNumber(v)
  1282.     end
  1283.     return v
  1284.   end
  1285.   if options.help then
  1286.     io.write("Установите робота в левом верхнем углу карьера.  \n")
  1287.     io.write("За спиной робота — сундук. Слева — зарядник IC2/ \n")
  1288.     io.write("OC. Если размер_вниз не указан робот будет копать\n")
  1289.     io.write("до бедрока. В этом случае укажите ширину бедрока \n")
  1290.     io.write("опцией --bedrock-width. Или добавте опцию -f, ес-\n")
  1291.     io.write("ли бедрок плоский. Робот будет добывать блоки,   \n")
  1292.     io.write("плотность которых находится в интервале (a, b).  \n")
  1293.     io.write("a - мин. плотность, b - макс. плотность.         \n")
  1294.     io.write("Опция --scan-radius устанавливает радиус сканиро-\n")
  1295.     io.write("вания по вертикали. Для ванильного конфига OC ре-\n")
  1296.     io.write("комендуется значение 5. Также можно указать его  \n")
  1297.     io.write("в 11 строке программы. Опция --estart - заряд    \n")
  1298.     io.write("акк.(%), необходимый для старта. При заряде акк. \n")
  1299.     io.write("ниже --egen - вкл. ген-р; --ereturn - возврат.   \n")
  1300.     io.write("Для выкапывания карьера, укажите опцию --quarry  \n")
  1301.     return
  1302.   end
  1303.   if #tArgs == 2 or #tArgs == 3 then
  1304.     bedrockWidth = getNumberOption("bedrock-width") or bedrockWidth
  1305.     minHardness = getNumberOption("min-hardness") or minHardness
  1306.     maxHardness = getNumberOption("max-hardness") or maxHardness
  1307.     scanRadius = getNumberOption("scan-radius") or scanRadius
  1308.     clusterHeight = scanRadius * 2 + 1
  1309.     local clusterSize = getNumberOption("cluster-size") or 32
  1310.     local bedrockWidth = getNumberOption("bedrock-width") or bedrockWidth
  1311.     testBedrock = options["test-bedrock"]
  1312.     flatBedrock = options["flat-bedrock"] or options.f
  1313.     local x = argNumber(tArgs[1])
  1314.     local z = argNumber(tArgs[2])
  1315.     local mineHeight = tArgs[3] and argNumber(tArgs[3])
  1316.     dont_drop_scrap = options["dont-drop-scrap"]
  1317.     KOPALKA.mine(x, z, mineHeight, nil, clusterSize, clusterSize, options.quarry or options.q)
  1318.   else
  1319.     io.write("Запуск:\nkopalka размер_вперёд размер_справа [размер_вниз]\n")
  1320.     io.write("Опции:\n")
  1321.     io.write("--help — информация о программе\n")
  1322.     io.write("--flat-bedrock, -f — если бедрок плоский \n")
  1323.     io.write(sprintf("--bedrock-width=<ширина слоя бедрока> [%d]\n", bedrockWidth))
  1324.     io.write(sprintf("--scan-radius=<радиус сканирования по верт.> [%d]\n", scanRadius))
  1325.     io.write(sprintf("--cluster-size=<размер кластера> [32]\n"))
  1326.     io.write(sprintf("--min-hardness=<мин. плотность>  [%s]\n", minHardness))
  1327.     io.write(sprintf("--max-hardness=<макс. плотность> [%s]\n", maxHardness))
  1328.     io.write(sprintf("--estart=<уровень заряда для старта> [%s%%]\n", energyStartPercent))
  1329.     io.write(sprintf("--egen=<уровень заряда вкл. генератора> [%s%%]\n", energyGenPercent))
  1330.     io.write(sprintf("--ereturn=<уровень заряда для возврата> [%s%%]\n", energyReturnPercent))
  1331.     io.write("--quarry, -q — карьер\n")
  1332.   end
  1333. end
  1334.  
  1335. main(shell.parse(...))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement