Advertisement
serafim7

reactor IC2 1.7.10 mfsu control [OpenComputers]

Jan 19th, 2020 (edited)
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.55 KB | None | 0 0
  1. --[[opencomputers reactor IC2 mfsu control by serafim
  2.     pastebin.com/Cd8yFFSw             update 05.07.21
  3.  
  4. управление реактором IC2(1.7.10) поддерживая
  5. заряд в энергохранилище на уровне 97-100 %
  6.  
  7. требования:
  8. компьютер 1-го уровня,
  9. адаптер, контроллер красного камня,
  10. реактор IC2, любая батарея IC2.
  11.  
  12. пример сборки:
  13. https://i.imgur.com/xc8hrvH.png
  14. ]]--
  15.  
  16. local heat = 130 --температура перегрева реактора до отключения
  17.  
  18. local batlist = {
  19.   "batbox",
  20.   "cesu",
  21.   "mfe",
  22.   "mfsu",
  23.   "chargepad_batbox",
  24.   "chargepad_cesu",
  25.   "chargepad_mfe",
  26.   "chargepad_mfsu"
  27. }
  28.  
  29. local com = require("component")
  30. local computer = require("computer")
  31. local event = require("event")
  32. local gpu = com.gpu
  33. local w, h = gpu.getResolution()
  34. local noFuel,sideRed,run,bat = 0,nil,true
  35.  
  36. if not com.isAvailable("redstone") then
  37.   print("нет контроллера красного камня")
  38.   os.exit()
  39. end
  40. local red = com.redstone
  41.  
  42. if com.isAvailable("reactor") then
  43.   reactor = com.reactor
  44. elseif com.isAvailable("reactor_chamber") then
  45.   reactor = com.reactor_chamber
  46. else
  47.   print("реактор не найден")
  48.   os.exit()
  49. end
  50.  
  51. if reactor.getHeat() > heat then
  52.   print("перегрев реактора")
  53.   os.exit()
  54. end
  55.  
  56. if reactor.producesEnergy() then
  57.   print("остановите реактор !")
  58.   for i = 0,5 do
  59.     if red.getOutput(i) > 0 then
  60.       red.setOutput(i, 0)
  61.     end
  62.   end
  63.   os.exit()
  64. end
  65.  
  66. for j, name in pairs(batlist) do
  67.   local adress = com.list(name)()
  68.   if adress then
  69.     bat = com.proxy(adress)
  70.     print("подключен "..name)
  71.     break
  72.   end
  73.   if j == #batlist then
  74.     print("батарея не найдена")
  75.     os.exit()
  76.   end
  77. end
  78. local capacity = math.floor(bat.getCapacity())
  79.  
  80. print("пробный запуск")
  81. for i, n in pairs({3,2,4,5,0,1}) do
  82.   red.setOutput(n, 15)
  83.   if reactor.producesEnergy() then
  84.     sideRed = n
  85.     red.setOutput(sideRed, 0)
  86.     print("реактор в стороне "..sideRed)
  87.     os.sleep(1)
  88.     break
  89.   else
  90.     red.setOutput(n, 0)
  91.   end
  92.   if i == 6 then
  93.     print("\n".."реактор не запускается")
  94.     os.exit()
  95.   end
  96. end
  97.  
  98. gpu.setResolution(18,6)
  99. gpu.setBackground(0x000000)
  100. gpu.fill(1,1,18,6," ")
  101. gpu.set(1,1,"всего   "..capacity)
  102. gpu.set(1,2,"энергии")
  103. gpu.set(1,3,"хранит")
  104. gpu.set(1,4,"eu/t")
  105. gpu.set(1,5,"нагрев")
  106. gpu.set(1,6,"реактор остановлен")
  107.  
  108. local function stop(wait)
  109.   if event.pull(wait,"key_down") then
  110.     red.setOutput(sideRed, 0)
  111.     gpu.setResolution(w,h)
  112.     gpu.fill(1,1,w,h," ")
  113.     print("программа завершена")
  114.     os.sleep(1)
  115.     if reactor.producesEnergy() then
  116.       print("ВНИМАНИЕ реактор по прежнему активен !!!")
  117.       computer.beep(500, 1)
  118.     else
  119.       print("реактор остановлен")
  120.     end
  121.     run = false
  122.   end
  123. end
  124.  
  125. local function ReactorControl()
  126.   local energy = math.floor(bat.getStored())
  127.   local percent = math.floor(energy/capacity*100)
  128.   local reactorHeat = math.floor(reactor.getHeat())
  129.   gpu.set(9,2,energy.."  ")
  130.   gpu.set(9,3,percent.." % ")
  131.   gpu.set(9,4,math.floor(reactor.getReactorEUOutput()).."  ")
  132.   if reactorHeat > heat then
  133.     red.setOutput(sideRed, 0)
  134.     gpu.set(1,6,"перегрев реактора")
  135.     computer.beep(500, 1)
  136.     stop(3)
  137.   else
  138.     gpu.set(9,5,reactorHeat.."  ")
  139.     if percent < 98 then
  140.       red.setOutput(sideRed, 15)
  141.       if not reactor.producesEnergy() then
  142.         gpu.set(1,6,"нет запуска реактора")
  143.       elseif reactor.getReactorEUOutput() == 0 then
  144.         noFuel = noFuel + 1
  145.       else
  146.         noFuel = 0
  147.       end
  148.       if noFuel >= 3 then
  149.         gpu.set(1,6,"нет топлива !     ")
  150.         computer.beep(500, 1)
  151.         stop(3)
  152.       else
  153.         gpu.set(1,6,"реактор активен   ")
  154.       end
  155.     elseif percent >= 100 then
  156.       red.setOutput(sideRed, 0)
  157.       gpu.set(1,6,"реактор остановлен")
  158.     end
  159.   end
  160. end
  161.  
  162. while run do
  163.   local ok,err = pcall(ReactorControl)
  164.   if not ok then
  165.     red.setOutput(sideRed, 0)
  166.     gpu.setResolution(w, h)
  167.     gpu.setBackground(0x000000)
  168.     gpu.setForeground(0xFFFFFF)
  169.     os.execute("cls")
  170.     print("программа аварийно завершена")
  171.     io.stderr:write(err)
  172.     run = false
  173.   end
  174.   stop(1)
  175. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement