Advertisement
markov2019

Untitled

May 7th, 2021
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.61 KB | None | 0 0
  1. -- установщик схемы в реактор IC2 by serafim
  2. -- pastebin.com/xWhYcrgM     update 19.12.20
  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.   [1320] = {
  31.     7,3,7,3,7,3,7,3,7,
  32.     2,7,4,7,4,7,4,7,2,
  33.     7,3,7,3,7,4,7,3,7,
  34.     4,7,4,7,2,7,4,7,4,
  35.     7,3,7,3,7,3,7,3,7,
  36.     2,7,4,7,4,7,4,7,2
  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 pairs(d) do
  104.       table.insert(circuit, b)
  105.     end
  106.   end
  107. end
  108.  
  109. gpu.set(1,5,"необходимые компоненты")
  110. gpu.set(1,6,string.rep("─",50))
  111. gpu.set(30,5,"всего")
  112.  
  113. local function status(msg)
  114.   gpu.fill(1,3,w,1," ")
  115.   gpu.set(1,3,msg)
  116. end
  117.  
  118. local drop = 0
  119. local scaninv = {}
  120.  
  121. local function scan()
  122.   for slot = 1, invsize do
  123.     if r.count(slot) == 0 then
  124.       r.select(slot)
  125.       i_c.equip()
  126.       break
  127.     end
  128.   end
  129.   status("сканирую инвентарь робота")
  130.   scaninv = {}
  131.   for inv = 1, invsize do
  132.     if r.count(inv) > 0 then
  133.       local item = i_c.getStackInInternalSlot(inv)
  134.       for key, val in ipairs(components) do
  135.         if item.name == components[key] then
  136.           table.insert(scaninv,{inv,val})
  137.           break
  138.         end
  139.       end
  140.     end
  141.   end
  142.   local count,y = 0,6
  143.   for key, val in ipairs(components) do
  144.     count = 0
  145.     for ind, dat in ipairs(circuit) do
  146.       if key == dat then
  147.         count = count + 1
  148.       end
  149.     end
  150.     if count > 0 then
  151.       y = y + 1
  152.       gpu.set(1,y,translate[key])
  153.       gpu.set(32,y,tostring(count))
  154.       count = 0
  155.       for ind, dat in ipairs(circuit) do
  156.         if ind >= drop + 1 and key == dat then
  157.           count = count + 1
  158.         end
  159.       end
  160.       for slot, d in ipairs(scaninv) do
  161.         if scaninv[slot][2] == val then
  162.           count = count - r.count(scaninv[slot][1])
  163.         end
  164.       end
  165.       if count > 0 then
  166.         gpu.set(40,5,"не хватает")
  167.         gpu.set(40,y,tostring(count).." ")
  168.       else
  169.         gpu.set(40,5,"хватает   ")
  170.         gpu.set(40,y,"  ")
  171.       end
  172.     end
  173.   end
  174. end
  175.  
  176. local time_start = computer.uptime()
  177. scan()
  178. status("выставляю схему в реакторе")
  179. for ind, d in ipairs(circuit) do
  180.   while ind ~= drop do
  181.     for slot, val in ipairs(scaninv) do
  182.       if scaninv[slot][2] == components[d] then
  183.         if r.count(scaninv[slot][1]) > 0 then
  184.           r.select(scaninv[slot][1])
  185.           r.drop(1)
  186.           drop = drop + 1
  187.           if r.count(scaninv[slot][1]) == 0 then
  188.             table.remove(scaninv,slot)
  189.           end
  190.         end
  191.         break
  192.       end
  193.     end
  194.     if ind ~= drop then
  195.       status("требуется - "..translate[d])
  196.       while true do
  197.         local e = {event.pull()}    
  198.         if e[1] == "inventory_changed" and r.count(e[2]) > 0 then
  199.           status("ожидаю компоненты")
  200.           os.sleep(5)
  201.           scan()
  202.           break
  203.         elseif e[1] == "key_down" and e[4] == 29 or e[4] == 157 then
  204.           os.execute("cls")
  205.           os.exit()
  206.         end
  207.       end
  208.     end
  209.   end
  210. end
  211. os.execute("cls")
  212. print("готово "..os.date("%M:%S",computer.uptime()-time_start))
  213.  
  214. for i = 1, invsize do
  215.   if r.count(i) == 0 then
  216.     for j = invsize, 1, -1 do
  217.       if r.count(j) > 0 then
  218.         if j < i then
  219.           break
  220.         end
  221.         r.select(j)
  222.         r.transferTo(i)
  223.         break
  224.       end
  225.     end
  226.   end
  227. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement