Advertisement
Guest User

kopalka v0.7.6

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