Advertisement
Tacnuke

Reactor Control Program ver.2.4 for opencomputers

Sep 16th, 2016
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.81 KB | None | 0 0
  1. --[[Reactors Control Program for Opencomputers
  2.     requires tier 3 computer, graphics card and screens.
  3.  
  4.     mekanism support includes induction matrix, industrial turbine, laser amplifier, and fusion reactor. currently supports only 1
  5.     industrial turbine. redstone I/O needs to be below the laser amplifier with a redstone sensitive energy cable below it.
  6.  
  7.  big reactors support is only for passive cooled reactors currently. turbine support is planned in the near future.
  8.  
  9.  multi turbine support is planned for both big reactors and mekanism. should be implemented soon-ish.
  10. By Tacnuke2011
  11. Thx to MalkContent for helping figure out my recursive nightmare!]]
  12.  
  13. --libs
  14.  
  15. local component = require("component")
  16. local term = require("term")
  17. local event = require("event")
  18. local seri = require("serialization")
  19. local colors = require("colors")
  20. local sides = require("sides")
  21.  
  22. --vars
  23.  
  24. local listen = true
  25. local br = component.getPrimary("br_reactor")
  26. local ec = component.getPrimary("elite_energy_cube")
  27. --local iT = component.industrial_turbine
  28. --local lasAmp = component.laser_amplifier
  29. --local rla = component.reactor_logic_adapter
  30. --local rs = component.redstone
  31. local gpu = component.getPrimary("gpu")
  32. local w, h = gpu.getResolution()
  33. local run = true
  34. local enCap = br.getEnergyCapacity()
  35. local enStor = "..."
  36. local storDev = "..."
  37. local on = .2 -- lower limit i.e. .2 is 20%
  38. local off = .85 -- upper limit i.e. .85 is 85%
  39. local enProd = ""
  40. local enGen = ""
  41. --local im = component.getPrimary("induction_matrix")
  42.  
  43.  
  44. --energy check
  45.  
  46. local function power()
  47.  
  48.   local temEn = ""
  49.   local maxEn = ""
  50.  
  51.   if ec then
  52.     maxEn = ec.getMaxEnergy()
  53.     temEn = ec.getEnergyStored()
  54.   elseif im then
  55.     maxEn = im.getMaxEnergy()
  56.     temEn = im.getEnergyStored()
  57.   elseif not ec and not im then
  58.     maxEn = br.getEnergyCapacity()
  59.     temEn = br.getEnergyStored()
  60.   end
  61.  
  62. --  if lasAmp.getEnergy() == lasAmp.getMaxEnergy() then
  63. --    rs.setOutput(sides.bottom, 15)
  64. --  elseif lasAmp.getEnergy() ~= lasAmp.getMaxEnergy() then
  65.   --  rs.setOutput(sides.bottom, 0)
  66.  -- end
  67.  
  68.   if rla then
  69.       gpu.set(1, 1, "Fusion Reactor detected")
  70.       os.sleep(.5)
  71.     if rla.getWater() and rla.hasFuel() then
  72.       if rla.getInjectionRate() ~= 4 then
  73.         rla.setInjectionRate(4)
  74.       end
  75.      elseif not rla.getWater() then
  76.       rla.setInectionRate(2)
  77.        end
  78.   elseif not rla then
  79.    gpu.set(1, 1, "Big Reactor detected")
  80.    --os.sleep(.5)
  81.   end
  82.  
  83.  if not ec then
  84.     temEn = im.getEnergyStored()
  85.     enMin = (maxEn*on)
  86.     enMax = (maxEn*off)
  87.     enStor= math.floor((temEn/maxEn)*100)
  88.     storDev = "Induction Matrix: "
  89.  
  90.      if iT then
  91.       turSt = iT.getSteam()
  92.       turPow = iT.getEnergyStored()
  93.       enProd = math.floor(im.getInput()/2.5)
  94.       enGen = "Indutrial Turbine "
  95.      end
  96.    
  97.      elseif br and not ec then
  98.      
  99.       enGen = "Big Reactor "
  100.       enProd = math.floor(br.getEnergyProducedLastTick())
  101.       temEn = br.getEnergyStored()
  102.       enMin = (br.getEnergyCapacity()*on)
  103.       enMax = (br.getEnergyCapacity()*off)
  104.       enStor= math.floor((temEn/enCap)*100)
  105.       storDev = "Reactor: "
  106.       enGen = "Big Reactor"
  107.       enProd = math.floor(br.getEnergyProducedLastTick())
  108.  
  109.      elseif ec then
  110.       temEn = ec.getEnergyStored()
  111.       storDev = "Energy Cube: "
  112.       enGen = "Big Reactor"
  113.       enProd = math.floor(br.getEnergyProducedLastTick())
  114.       enStor = (temEn/ec.getMaxEnergyStored()*100)
  115.       enMin = (ec.getMaxEnergy()*on)
  116.       enMax = (ec.getMaxEnergy()*off)
  117.    
  118.   end
  119.  
  120.     if temEn <= enMin then br.setActive(true)
  121.       elseif temEn >= enMax then br.setActive(false)    
  122.     end
  123.  
  124.   end
  125.  
  126. --display settings and output
  127.  
  128. local function heading(text)
  129.    w, h = gpu.getResolution()
  130.    term.setCursor((w-string.len(text))/2+4, 2)
  131.    term.write(text)
  132. end
  133.  
  134. local function display()  
  135.   gpu.setBackground(0x000000)
  136.   gpu.setResolution(140, 40)
  137.   gpu.setForeground(0x0040ff)
  138.   gpu.fill(1, 1, 40, h," ")
  139.  
  140.   power()  
  141. end
  142.  
  143. local function stat()
  144.  
  145.  if br.getActive() then
  146.      
  147.       gpu.setForeground(0x000000)
  148.       gpu.setBackground(0x00a500)
  149.       gpu.fill(83, 10, 7, 1, "online")
  150.       gpu.set(83, 10, "Online")
  151.       gpu.setBackground(0xff0000)
  152.       gpu.fill(75, 10, 7, 1, "offline")
  153.       gpu.set(75, 10, "Offline")
  154.      
  155.  
  156.     elseif not br.getActive() then
  157.      
  158.       gpu.setForeground(0x000000)
  159.       gpu.setBackground(0xff0000)
  160.       gpu.fill(83, 10, 7, 1, "online")
  161.       gpu.set(83, 10, "Online")
  162.       gpu.setBackground(0x00a500)
  163.       gpu.fill(75, 10, 7, 1, "offline")
  164.       gpu.set(75, 10, "Offline")
  165.      
  166.  
  167.     end
  168. end
  169.  
  170. local function info()
  171.  
  172. gpu.setForeground(0x0040ff)
  173. gpu.setBackground(0x000000)
  174. gpu.set(((w-string.len("Reactor Status:"))/2-2), 10, "Reactor Status:")
  175. gpu.fill(1, 11, w, 1, " ")
  176. gpu.set(((w-string.len("Fuel Consumption:"))/2-3), 11, "Fuel Consumption: "..tonumber(string.format("%.3f", br.getFuelConsumedLastTick())).." mB/t")
  177. gpu.fill(w, 12, w, 1, " ")
  178. gpu.set(((w-string.len("Fuel Amount"))/2-1), 12, "Fuel Amount: "..br.getFuelAmount().." mB")
  179. gpu.fill(1, 13, w, 1, " ")
  180. gpu.set(((w-string.len("Waste Amount: "))/2-1), 13, "Waste Amount: "..br.getWasteAmount().." mB")
  181. gpu.fill(1, 14, w, 1, " ")
  182. gpu.set(((w-string.len(storDev))/2.0125), 14, storDev..enStor.." %")
  183. gpu.fill(1, 15, w, 1, " ")
  184. gpu.set(((w-string.len("RF Output: "))/2+1), 15, "RF Output: "..(ec.getEnergy()/ec.getEnergyStored()).." kRF/t")
  185. gpu.fill(1, 16, w, 1, " ")
  186. gpu.set(((w-string.len("RF Production: "))/2-1), 16, "RF Production: "..enGen..": "..enProd.." RF/t")
  187. gpu.fill(1, 17, w, 1, " ")
  188. gpu.set(((w-string.len("Casing Temp.: "))/2-1), 17, "Casing Temp.: "..math.floor(br.getCasingTemperature()).." C")
  189. gpu.fill(1, 18, w, 1, " ")
  190. gpu.set(((w-string.len("Fuel Temp.: "))/2), 18, "Fuel Temp.: "..math.floor(br.getFuelTemperature()).." C")
  191. gpu.set(((w-string.len("Fuel Reactivity: "))/2-2), 19, "Fuel Reactivity: "..math.floor(br.getFuelReactivity()).." %")
  192. gpu.setBackground(0x00a500)
  193. gpu.setForeground(0x000000)
  194. gpu.set(((w-string.len("Exit"))/2+1), 21, "Exit")
  195. gpu.setBackground(0x000000)
  196. gpu.setForeground(0x0040ff)
  197. os.sleep(3)
  198. display()
  199.  
  200. end
  201.  
  202. --event listener
  203. --exit button
  204.  
  205. function listen(name, address, x, y, button, player)
  206.  
  207.   if x <=74 and x >= 69  and y == 21 then
  208.     term.setCursor(1, 1)
  209.     term.clear()
  210.     br.setActive(false)
  211.     run = false
  212.     term.write("Closing")
  213.     os.sleep(.5)
  214.     gpu.setBackground(0x000000)
  215.     term.setCursor(1,1)
  216.     term.clear()
  217.  
  218.   elseif x >= 82 and x <= 91 and y == 10 then
  219.     br.setActive(true)
  220.  
  221.   elseif x >= 74 and x <= 82 and y == 10 then
  222.     br.setActive(false)
  223.   end
  224.  
  225. end
  226.  
  227. event.listen("touch", listen)
  228.  
  229. --main loop
  230.  
  231. while run do
  232.    
  233.     heading("Reactor Control")
  234.     stat()
  235.     info()
  236.     os.sleep(1)
  237. end
  238.  
  239. event.ignore("touch", listen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement