mrWhiskasss

Контроль реактора на конденсаторах [Industrialcraft +OpenComputers]

Dec 14th, 2021 (edited)
1,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[opencomputers контроль реактора IC2(1.7.10) на конденсаторах
  2.     pastebin.com/kxgfyM9                         update 26.10.21
  3.  
  4. использовать только вместе с модом OpenPeripheral
  5. pastebin run YidCrWCG
  6. для проекта computercraft.ru
  7. https://computercraft.ru/topic/2604-programma-ochen-mnogo-elektrichestva
  8. авторы: Asior, serafim
  9.  
  10. требования:
  11. монитор и видеокарта 2-го уровня,
  12. адаптер, транспозер, контроллер красного камня.
  13.  
  14. пример сборки:
  15. https://i.imgur.com/eRb0iAx.png
  16. https://i.imgur.com/UqrFVkC.png
  17. https://i.imgur.com/y42OiO7.png
  18.  
  19. схема реактора:
  20. https://i.imgur.com/SXbeOu8.png
  21. https://i.imgur.com/OW27suK.png
  22.  
  23. использование:
  24. собрать установку, для плутония нагреть реактор до 8400 градусов,
  25. в сундук положить запасные конденсаторы и стержни,
  26. желательно обеспечить автокрафт перезарядки конденсаторов
  27. https://pastebin.com/WgcCKBFn
  28. ]]--
  29.  
  30. local offReac = 8500 --температура перегрева реактора до отключения
  31. local perDamage = 80 --процент износа конденсатора при котором он меняется
  32.  
  33. local com = require("component")
  34. local computer = require("computer")
  35. local event = require("event")
  36. local gpu = com.gpu
  37. local w,h = gpu.getResolution()
  38. local per,noFuel,lowEu,toReac,run = 0,0,0,1,true
  39. local sideReac,sideInv,sideRed,OutputEUt,StartEUt
  40. local slotReac,Reflector = {},{}
  41.  
  42. if not com.isAvailable("inventory") then
  43.     print("нет сундука")
  44.     print("использовать только вместе с модом OpenPeripheral")
  45.     os.exit()
  46. end
  47. if not com.isAvailable("me_interface") then
  48.     print("нет interface")
  49.     print("использовать только вместе с модом OpenPeripheral")
  50.     os.exit()
  51. end
  52. local chest = com.inventory
  53. local slotsInv = chest.getSize()
  54.  
  55. local interface = com.me_interface
  56.  
  57. if not com.isAvailable("redstone") then
  58.     print("нет контроллера красного камня")
  59.     os.exit()
  60. end
  61. local red = com.redstone
  62.  
  63. if not com.isAvailable("reactor_chamber") then
  64.     print("камера реактора не найдена")
  65.     os.exit()
  66. end
  67. local reactor = com.reactor_chamber
  68.  
  69. if reactor.producesEnergy() then
  70.     print("\n".."остановите реактор !")
  71.     for i = 0,5 do
  72.         if red.getOutput(i) > 0 then
  73.             red.setOutput(i, 0)
  74.         end
  75.     end
  76.     os.exit()
  77. end
  78.  
  79. if reactor.getHeat() > offReac then
  80.     print("\n".."перегрев реактора !")
  81.     os.exit()
  82. end
  83.  
  84. os.execute("cls")
  85. print("сохранение конденсаторов")
  86. local data = reactor.getAllStacks(0)
  87. for i = 0,54 do
  88.     if data[i] and data[i].name then
  89.         if string.find(data[i].name,"ondensator") then
  90.             local per = math.ceil(100*data[i].dmg/data[i].max_dmg)
  91.             print("слот: "..(i).."  износ: "..per.." %")
  92.             if per >= perDamage then
  93.                 print("\n".."замените конденсатор в слоте: "..(i))
  94.                 os.exit()
  95.             end
  96.             table.insert(slotReac, i)
  97.         end
  98.     end
  99. end
  100. print("сохранение отражателей")
  101. for i = 0,54 do
  102.     if data[i] and data[i].name then
  103.         if string.find(data[i].name,"eflector") then
  104.             print("слот: "..(i))
  105.             table.insert(Reflector, i)
  106.         end
  107.     end
  108. end
  109.  
  110. print("пробный запуск")
  111. for k,n in pairs({3,2,4,5,0,1}) do
  112.     red.setOutput(n, 15)
  113.     if reactor.producesEnergy() then
  114.         os.sleep(1)
  115.         StartEUt = math.ceil(reactor.getReactorEUOutput())
  116.         print("StartEUt = "..StartEUt)
  117.         sideRed = n
  118.         red.setOutput(n, 0)
  119.         print("редстоун в стороне: "..sideRed)
  120.         break
  121.     else
  122.         red.setOutput(n, 0)
  123.     end
  124.     if k == 6 then
  125.         print("\n".."реактор не запускается")
  126.         os.exit()
  127.     end
  128. end
  129.  
  130. print("настройка завершена".."\n".."старт...")
  131. os.sleep(2)
  132. -- ▀ ▄ █
  133. local function gui()
  134.     gpu.setResolution(28,15)
  135.     gpu.setBackground(0x696969)
  136.     gpu.fill(1,1,28,15," ")
  137.     gpu.setForeground(0x3C3C3C)
  138.     gpu.set(1,1,"████████████████████████████")
  139.     gpu.set(1,2,"█  █  █  █  █  █  █  █  █  █")
  140.     gpu.setForeground(0x008000)
  141.     gpu.set(2,2,"█")
  142.     gpu.set(5,2,"█")
  143.     gpu.set(8,2,"█")
  144.     gpu.set(11,2,"█")
  145.     gpu.set(14,2,"█")
  146.     gpu.set(17,2,"█")
  147.     gpu.set(20,2,"█")
  148.     gpu.set(23,2,"█")
  149.     gpu.set(26,2,"█")
  150.     --
  151.     gpu.setForeground(0x00ff00)
  152.     gpu.set(3,2,"█")
  153.     gpu.set(6,2,"█")
  154.     gpu.set(9,2,"█")
  155.     gpu.set(12,2,"█")
  156.     gpu.set(15,2,"█")
  157.     gpu.set(18,2,"█")
  158.     gpu.set(21,2,"█")
  159.     gpu.set(24,2,"█")
  160.     gpu.set(27,2,"█")
  161.     gpu.setForeground(0x3C3C3C)
  162.     gpu.set(1,3,"████████████████████████████")
  163.     gpu.set(1,4,"█  █  █  █  █  █  █  █  █  █")
  164.     gpu.setForeground(0x008000)
  165.     gpu.set(2,4,"█")
  166.     gpu.set(5,4,"█")
  167.     gpu.set(8,4,"█")
  168.     gpu.set(11,4,"█")
  169.     gpu.set(14,4,"█")
  170.     gpu.set(17,4,"█")
  171.     gpu.set(20,4,"█")
  172.     gpu.set(23,4,"█")
  173.     gpu.set(26,4,"█")
  174.     --
  175.     gpu.setForeground(0x00ff00)
  176.     gpu.set(3,4,"█")
  177.     gpu.set(6,4,"█")
  178.     gpu.set(9,4,"█")
  179.     gpu.set(12,4,"█")
  180.     gpu.set(15,4,"█")
  181.     gpu.set(18,4,"█")
  182.     gpu.set(21,4,"█")
  183.     gpu.set(24,4,"█")
  184.     gpu.set(27,4,"█")
  185.     gpu.setForeground(0x3C3C3C)
  186.     gpu.set(1,5,"████████████████████████████")
  187.     gpu.set(1,6,"█  █  █  █  █  █  █  █  █  █")
  188.     gpu.setForeground(0x008000)
  189.     gpu.set(2,6,"█")
  190.     gpu.set(5,6,"█")
  191.     gpu.set(8,6,"█")
  192.     gpu.set(11,6,"█")
  193.     gpu.set(14,6,"█")
  194.     gpu.set(17,6,"█")
  195.     gpu.set(20,6,"█")
  196.     gpu.set(23,6,"█")
  197.     gpu.set(26,6,"█")
  198.     --
  199.     gpu.setForeground(0x00ff00)
  200.     gpu.set(3,6,"█")
  201.     gpu.set(6,6,"█")
  202.     gpu.set(9,6,"█")
  203.     gpu.set(12,6,"█")
  204.     gpu.set(15,6,"█")
  205.     gpu.set(18,6,"█")
  206.     gpu.set(21,6,"█")
  207.     gpu.set(24,6,"█")
  208.     gpu.set(27,6,"█")
  209.     gpu.setForeground(0x3C3C3C)
  210.     gpu.set(1,7,"████████████████████████████")
  211.     gpu.set(1,8,"█  █  █  █  █  █  █  █  █  █")
  212.     gpu.setForeground(0x008000)
  213.     gpu.set(2,8,"█")
  214.     gpu.set(5,8,"█")
  215.     gpu.set(8,8,"█")
  216.     gpu.set(11,8,"█")
  217.     gpu.set(14,8,"█")
  218.     gpu.set(17,8,"█")
  219.     gpu.set(20,8,"█")
  220.     gpu.set(23,8,"█")
  221.     gpu.set(26,8,"█")
  222.     --
  223.     gpu.setForeground(0x00ff00)
  224.     gpu.set(3,8,"█")
  225.     gpu.set(6,8,"█")
  226.     gpu.set(9,8,"█")
  227.     gpu.set(12,8,"█")
  228.     gpu.set(15,8,"█")
  229.     gpu.set(18,8,"█")
  230.     gpu.set(21,8,"█")
  231.     gpu.set(24,8,"█")
  232.     gpu.set(27,8,"█")
  233.     gpu.setForeground(0x3C3C3C)
  234.     gpu.set(1,9,"████████████████████████████")
  235.     gpu.set(1,10,"█  █  █  █  █  █  █  █  █  █")
  236.     gpu.setForeground(0x008000)
  237.     gpu.set(2,10,"█")
  238.     gpu.set(5,10,"█")
  239.     gpu.set(8,10,"█")
  240.     gpu.set(11,10,"█")
  241.     gpu.set(14,10,"█")
  242.     gpu.set(17,10,"█")
  243.     gpu.set(20,10,"█")
  244.     gpu.set(23,10,"█")
  245.     gpu.set(26,10,"█")
  246.     --
  247.     gpu.setForeground(0x00ff00)
  248.     gpu.set(3,10,"█")
  249.     gpu.set(6,10,"█")
  250.     gpu.set(9,10,"█")
  251.     gpu.set(12,10,"█")
  252.     gpu.set(15,10,"█")
  253.     gpu.set(18,10,"█")
  254.     gpu.set(21,10,"█")
  255.     gpu.set(24,10,"█")
  256.     gpu.set(27,10,"█")
  257.     gpu.setForeground(0x3C3C3C)
  258.     gpu.set(1,11,"████████████████████████████")
  259.     gpu.set(1,12,"█  █  █  █  █  █  █  █  █  █")
  260.     gpu.setForeground(0x008000)
  261.     gpu.set(2,12,"█")
  262.     gpu.set(5,12,"█")
  263.     gpu.set(8,12,"█")
  264.     gpu.set(11,12,"█")
  265.     gpu.set(14,12,"█")
  266.     gpu.set(17,12,"█")
  267.     gpu.set(20,12,"█")
  268.     gpu.set(23,12,"█")
  269.     gpu.set(26,12,"█")
  270.     --
  271.     gpu.setForeground(0x00ff00)
  272.     gpu.set(3,12,"█")
  273.     gpu.set(6,12,"█")
  274.     gpu.set(9,12,"█")
  275.     gpu.set(12,12,"█")
  276.     gpu.set(15,12,"█")
  277.     gpu.set(18,12,"█")
  278.     gpu.set(21,12,"█")
  279.     gpu.set(24,12,"█")
  280.     gpu.set(27,12,"█")
  281.     gpu.setForeground(0x3C3C3C)
  282.     gpu.set(1,13,"████████████████████████████")
  283. end
  284.  
  285. local xy = {
  286.     {"2","2"},{"5","2"},{"8","2"},{"11","2"},{"14","2"},{"17","2"},{"20","2"},{"23","2"},{"26","2"},
  287.     {"2","4"},{"5","4"},{"8","4"},{"11","4"},{"14","4"},{"17","4"},{"20","4"},{"23","4"},{"26","4"},
  288.     {"2","6"},{"5","6"},{"8","6"},{"11","6"},{"14","6"},{"17","6"},{"20","6"},{"23","6"},{"26","6"},
  289.     {"2","8"},{"5","8"},{"8","8"},{"11","8"},{"14","8"},{"17","8"},{"20","8"},{"23","8"},{"26","8"},
  290.     {"2","10"},{"5","10"},{"8","10"},{"11","10"},{"14","10"},{"17","10"},{"20","10"},{"23","10"},{"26","10"},
  291.     {"2","12"},{"5","12"},{"8","12"},{"11","12"},{"14","12"},{"17","12"},{"20","12"},{"23","12"},{"26","12"},
  292. }
  293.  
  294. local function stop(wait)
  295.     gpu.setBackground(0x000000)
  296.     local e = ({event.pull(wait,"key_down")})[4]
  297.     if e == 18 or e == 20 then
  298.         red.setOutput(sideRed, 0)
  299.         gpu.setResolution(w, h)
  300.         gpu.setBackground(0x000000)
  301.         gpu.setForeground(0xFFFFFF)
  302.         gpu.fill(1, 1, w, h, " ")
  303.         print("программа завершена")
  304.         os.sleep(1)
  305.         if reactor.producesEnergy() then
  306.             print("ВНИМАНИЕ реактор по прежнему активен !!!")
  307.         else
  308.             print("реактор остановлен")
  309.         end
  310.         run = false
  311.     end
  312.     gpu.setBackground(0x696969)
  313. end
  314.  
  315. local function alert(message)
  316.     gpu.setBackground(0x000000)
  317.     gpu.setForeground(0xFF9900)
  318.     gpu.set(1,14,"  для завершения нажмите E  ")
  319.     gpu.setForeground(0xFF0000)
  320.     gpu.set(1,15,message)
  321.     computer.beep(500, 1)
  322.     stop(3)
  323.     gpu.setBackground(0x696969)
  324. end
  325.  
  326. local function ReactorControl()
  327.     local function redstone(state)
  328.         if state then
  329.             red.setOutput(sideRed, 15)
  330.         else
  331.             while red.getOutput(sideRed) > 0 or reactor.getReactorEUOutput() > 0 do
  332.                 red.setOutput(sideRed, 0)
  333.                 os.sleep(0.2)
  334.             end
  335.             gpu.setBackground(0x000000)
  336.             gpu.setForeground(0x00FF00)
  337.             gpu.set(1,14,"      eu/t =  0           ")
  338.             gpu.setBackground(0x696969)
  339.         end
  340.     end
  341.     local data = reactor.getAllStacks(0)
  342.     for i = 1,#slotReac do
  343.         if data[slotReac[i]] then
  344.             per = math.ceil(100*data[slotReac[i]].dmg/data[slotReac[i]].max_dmg)
  345.             gpu.setForeground(0xFF9900)
  346.             gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),tostring(per))
  347.         else
  348.             per = 0
  349.         end
  350.         if per == 100 then
  351.             gpu.setBackground(0x000000)
  352.             redstone(false)
  353.             alert(" снизте % замены конденсат. ")
  354.             while run do
  355.                 computer.beep(500, 1)
  356.                 stop(3)
  357.                 gpu.setBackground(0x696969)
  358.             end
  359.             os.exit()
  360.         end
  361.         if per >= perDamage or per == 0 then
  362.             gpu.setBackground(0x000000)
  363.             gpu.setForeground(0xFF9900)
  364.             gpu.set(1,15,"    замена конденсаторов    ")
  365.             gpu.setBackground(0x696969)
  366.             redstone(false)
  367.             interface.pullItem("DOWN",slotReac[i])
  368.             gpu.setForeground(0xFF0000)
  369.             gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██")
  370.             local data1 = chest.getAllStacks(0)
  371.             for i1 = 1,slotsInv do
  372.                 if data1[i1] and data1[i1].name then
  373.                     local per = math.ceil(100*data1[i1].dmg/data1[i1].max_dmg)
  374.                     if string.find(data1[i1].name,"ondensator") and per < 90 then
  375.                         toReac = chest.pushItemIntoSlot("DOWN",i1,1,slotReac[i])
  376.                         if toReac then
  377.                             gpu.setForeground(0x696969)
  378.                             gpu.setBackground(0x696969)
  379.                             gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██")
  380.                         end
  381.                         break
  382.                     else
  383.                         toReac = 0
  384.                     end
  385.                 end
  386.             end
  387.         end
  388.     end
  389.     local function circuitCheck()
  390.  
  391.         local data = reactor.getAllStacks(0)
  392.         local sh = 0
  393.         for i = 1,#slotReac do
  394.             if data[slotReac[i]] then
  395.                 sh = sh + 1
  396.             end
  397.         end
  398.         if sh == #slotReac then
  399.             return true
  400.         else
  401.             return false
  402.         end
  403.     end
  404.     gpu.setBackground(0x000000)
  405.     if reactor.getHeat() > offReac then
  406.         redstone(false)
  407.         alert("     перегрев реактора !    ")
  408.     elseif not circuitCheck() then
  409.         alert(" нет целых конденсаторов !  ")
  410.     elseif toReac == 0 then
  411.         alert("    в сундуке нет места !   ")
  412.     elseif noFuel >= 5 then
  413.         alert("       нет топлива !        ")
  414.     else
  415.         redstone(true)
  416.         if not reactor.producesEnergy() then
  417.             alert("  реактор не запускается !  ")
  418.         else
  419.             OutputEUt = math.ceil(reactor.getReactorEUOutput())
  420.  
  421.             gpu.set(1,14,"      eu/t =  "..OutputEUt.."            ")
  422.             gpu.set(1,15,"      реактор активен       ")
  423.         end
  424.     end
  425.     stop(0.7)
  426.     gpu.setBackground(0x696969)
  427.     if reactor.producesEnergy() and reactor.getReactorEUOutput() == 0 then
  428.         noFuel = noFuel + 1
  429.     else
  430.         noFuel = 0
  431.         if OutputEUt and OutputEUt < StartEUt then
  432.             lowEu = lowEu + 1
  433.         else
  434.             lowEu = 0
  435.         end
  436.     end
  437.     gpu.setBackground(0x000000)
  438.     if noFuel == 3 or lowEu == 3 then
  439.         local data2 = reactor.getAllStacks(0)
  440.         local data3 = chest.getAllStacks(0)
  441.         for i2 = 1,54 do
  442.             if data2[i2] and data2[i2].name then
  443.                 if string.find(data2[i2].name,"depleted") then
  444.                     redstone(false)
  445.                     gpu.setForeground(0xFF9900)
  446.                     gpu.set(1,15,"      замена стержней       ")
  447.                     interface.pullItem("DOWN",i2)
  448.                     for i3 = 0,slotsInv do
  449.                         if data3[i3] and data3[i3].name then
  450.                             if string.find(data3[i3].name,"MOX") or string.find(data3[i3].name,"Uran") then
  451.                                 if not string.find(data3[i3].name,"depleted") then
  452.                                     chest.pushItemIntoSlot("DOWN",i3,1,i2)
  453.                                     break
  454.                                 end
  455.                             end
  456.                         end
  457.                     end
  458.                 end
  459.             end
  460.         end
  461.         StartEUt = 0
  462.         lowEu = 0
  463.         for i4 = 1,#Reflector do
  464.             if not data2[Reflector[i4]] then
  465.                 for i5 = 0,slotsInv do
  466.                     if data3[i5] and data3[i5].name then
  467.                         if string.find(data3[i5].name,"eflector") then
  468.                             redstone(false)
  469.                             gpu.setForeground(0xFF9900)
  470.                             gpu.set(1,15,"      замена отражателя     ")
  471.                             chest.pushItemIntoSlot("DOWN",i5,1,Reflector[i4])
  472.                         end
  473.                     end
  474.                 end
  475.             end
  476.         end
  477.     end
  478.     gpu.setBackground(0x696969)
  479.     if OutputEUt and OutputEUt > StartEUt then
  480.         StartEUt = math.ceil(reactor.getReactorEUOutput())
  481.     end
  482. end
  483.  
  484. gui()
  485. gpu.setBackground(0x000000)
  486. gpu.setForeground(0xFF9900)
  487. gpu.set(1,14,"  для завершения нажмите E  ")
  488. gpu.setBackground(0x696969)
  489. os.sleep(1)
  490. while run do
  491.     local ok,err = pcall(ReactorControl)
  492.     if not ok then
  493.         red.setOutput(sideRed, 0)
  494.         gpu.setResolution(w, h)
  495.         gpu.setBackground(0x000000)
  496.         gpu.setForeground(0xFFFFFF)
  497.         os.execute("cls")
  498.         print("программа аварийно завершена")
  499.         if type(err) == "table" then
  500.             io.stderr:write(table.unpack(err))
  501.         else
  502.             io.stderr:write(err)
  503.         end
  504.         run = false
  505.     end
  506. end
Advertisement
Add Comment
Please, Sign In to add comment