serafim7

установщик схемы в реактор IC2 1.7.10 [OpenComputers]

Dec 4th, 2020 (edited)
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.63 KB | None | 0 0
  1. -- установщик схемы в реактор IC2(1.7.10) by serafim
  2. -- pastebin.com/xWhYcrgM             update 17.05.21
  3. -- https://i.imgur.com/GxOR7xv.gif
  4.  
  5. local circuits = {
  6.   [360] = {
  7.     5,6,4,5,6,4,5,6,4,
  8.     6,1,6,6,1,6,6,1,6,
  9.     4,6,5,4,6,5,4,6,5,
  10.     5,6,4,5,6,4,5,6,4,
  11.     6,1,6,6,1,6,6,1,6,
  12.     4,6,5,4,6,5,4,6,5
  13.   },
  14.   [420] = {
  15.     1,4,6,3,6,6,4,6,5,
  16.     5,4,6,6,4,6,6,1,6,
  17.     5,6,1,6,6,1,6,6,4,
  18.     4,6,6,4,6,6,4,6,5,
  19.     6,1,6,6,1,6,6,1,6,
  20.     5,6,4,5,6,4,5,6,4
  21.   },
  22.   [1056] = {
  23.     2,7,7,4,4,7,7,2,5,
  24.     7,3,3,7,7,3,3,7,5,
  25.     4,7,7,4,4,7,7,4,5,
  26.     4,7,7,4,4,7,7,4,5,
  27.     7,3,3,7,7,3,3,7,5,
  28.     2,7,7,4,4,7,7,2,5
  29.   },
  30.   [1308] = {
  31.     7,3,7,4,7,4,7,3,7,
  32.     4,7,2,7,4,7,2,7,4,
  33.     7,4,7,4,7,4,7,4,7,
  34.     3,7,4,7,2,7,4,7,3,
  35.     7,2,7,4,7,4,7,2,7,
  36.     4,7,3,7,4,7,3,7,4
  37.   }
  38. }
  39.  
  40. local components = {
  41.   [1] = "IC2:reactorUraniumQuad",
  42.   [2] = "IC2:reactorMOXQuad",
  43.   [3] = "IC2:reactorHeatSwitchSpread",
  44.   [4] = "IC2:reactorVentSpread",
  45.   [5] = "IC2:reactorPlating",
  46.   [6] = "IC2:reactorVentGold",
  47.   [7] = "IC2:reactorVentDiamond"
  48. }
  49.  
  50. local translate = {
  51.   [1] = "счетверённый стержень (УРАН)",
  52.   [2] = "счетверённый стержень (MOX)",
  53.   [3] = "компонентный теплообменник",
  54.   [4] = "компонентный теплоотвод",
  55.   [5] = "реакторная обшивка",
  56.   [6] = "разогнанный теплоотвод",
  57.   [7] = "улучшенный теплоотвод"
  58. }
  59.  
  60. local com = require('component')
  61. local computer = require("computer")
  62. local event = require("event")
  63. local gpu = com.gpu
  64. local w,h = gpu.getViewport()
  65.  
  66. if not com.isAvailable("robot") then
  67.   print("только роботы могут использовать эту программу")
  68.   os.exit()
  69. end
  70. local r = require("robot")
  71. local invsize = r.inventorySize()
  72.  
  73. if not com.isAvailable("inventory_controller") then
  74.   print("нет контроллера инвентаря")
  75.   os.exit()
  76. end
  77. local i_c = com.inventory_controller
  78.  
  79. os.execute("cls")
  80. local a,set = {...}
  81. local atr = tonumber(a[1])
  82. if atr and circuits[atr] then
  83.   set = atr
  84. else
  85.   gpu.set(1,1,"выберите схему :")
  86.   local x = 18
  87.   for i, d in pairs(circuits) do
  88.     gpu.set(x,1,tostring(i))
  89.     x = x + string.len(i) + 2
  90.   end
  91.   print()
  92.   set = tonumber(io.read())
  93.   if not circuits[set] then
  94.     print("схема не найдена")
  95.     os.exit()
  96.   end
  97. end
  98. gpu.fill(1,1,w,2," ")
  99. gpu.set(1,1,"выбрана схема : "..set.." eu/t")
  100. local circuit = {}
  101. for i, d in pairs(circuits) do
  102.   if set == i then
  103.     for a, b in ipairs(d) do
  104.       table.insert(circuit, b)
  105.     end
  106.     break
  107.   end
  108. end
  109.  
  110. gpu.set(1,5,"необходимые компоненты")
  111. gpu.set(1,6,string.rep("─",50))
  112. gpu.set(30,5,"всего")
  113.  
  114. local function status(msg)
  115.   gpu.fill(1,3,w,1," ")
  116.   gpu.set(1,3,msg)
  117. end
  118.  
  119. local drop = 0
  120. local scaninv = {}
  121.  
  122. local function scan()
  123.   for slot = 1, invsize do
  124.     if r.count(slot) == 0 then
  125.       r.select(slot)
  126.       i_c.equip()
  127.       break
  128.     end
  129.   end
  130.   status("сканирую инвентарь робота")
  131.   scaninv = {}
  132.   for inv = 1, invsize do
  133.     if r.count(inv) > 0 then
  134.       local item = i_c.getStackInInternalSlot(inv)
  135.       for key, val in ipairs(components) do
  136.         if item.name == components[key] then
  137.           table.insert(scaninv,{inv,val})
  138.           break
  139.         end
  140.       end
  141.     end
  142.   end
  143.   local count,y = 0,6
  144.   for key, val in ipairs(components) do
  145.     count = 0
  146.     for ind, dat in ipairs(circuit) do
  147.       if key == dat then
  148.         count = count + 1
  149.       end
  150.     end
  151.     if count > 0 then
  152.       y = y + 1
  153.       gpu.set(1,y,translate[key])
  154.       gpu.set(32,y,tostring(count))
  155.       count = 0
  156.       for ind, dat in ipairs(circuit) do
  157.         if ind >= drop + 1 and key == dat then
  158.           count = count + 1
  159.         end
  160.       end
  161.       for slot, d in ipairs(scaninv) do
  162.         if scaninv[slot][2] == val then
  163.           count = count - r.count(scaninv[slot][1])
  164.         end
  165.       end
  166.       if count > 0 then
  167.         gpu.set(40,5,"не хватает")
  168.         gpu.set(40,y,tostring(count).." ")
  169.       else
  170.         gpu.set(40,5,"хватает   ")
  171.         gpu.set(40,y,"  ")
  172.       end
  173.     end
  174.   end
  175. end
  176.  
  177. local time_start = computer.uptime()
  178. scan()
  179. for ind, d in ipairs(circuit) do
  180.   status("выставляю схему в реакторе")
  181.   while ind ~= drop do
  182.     for slot, val in ipairs(scaninv) do
  183.       if scaninv[slot][2] == components[d] then
  184.         if r.count(scaninv[slot][1]) > 0 then
  185.           r.select(scaninv[slot][1])
  186.           r.drop(1)
  187.           drop = drop + 1
  188.           if r.count(scaninv[slot][1]) == 0 then
  189.             table.remove(scaninv,slot)
  190.           end
  191.         end
  192.         break
  193.       end
  194.     end
  195.     if ind ~= drop then
  196.       status("требуется - "..translate[d])
  197.       while true do
  198.         local e = {event.pull()}    
  199.         if e[1] == "inventory_changed" and r.count(e[2]) > 0 then
  200.           status("ожидаю компоненты")
  201.           os.sleep(5)
  202.           scan()
  203.           break
  204.         elseif e[1] == "key_down" and e[4] == 29 or e[4] == 157 then
  205.           os.execute("cls")
  206.           os.exit()
  207.         end
  208.       end
  209.     end
  210.   end
  211. end
  212. os.execute("cls")
  213. print("готово "..os.date("%M:%S",computer.uptime()-time_start))
  214.  
  215. for i = 1, invsize do
  216.   if r.count(i) == 0 then
  217.     for j = invsize, 1, -1 do
  218.       if r.count(j) > 0 then
  219.         if j < i then
  220.           break
  221.         end
  222.         r.select(j)
  223.         r.transferTo(i)
  224.         break
  225.       end
  226.     end
  227.   end
  228. end
Add Comment
Please, Sign In to add comment