Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ "EBRM" stands for Efficiency Based Reactor Monitor, and it works
- only with Big Reactors reactors. It displays power levels, allows for
- easy on and off functionality, and the ability to change control rod
- levels with the click of a button.
- ]]--
- local component = require("component")
- local event = require("event")
- local reactor = component.br_reactor
- local gpu = component.gpu
- local screen = component.screen
- local term = require("term")
- --Display
- local oldBG = 0x000000
- local oldFG = 0xFFFFFF
- function gpuOldColors()
- gpu.setBackground(oldBG, false)
- gpu.setForeground(oldFG, false)
- end
- function clearScreen()
- local oldColor = gpu.getBackground(false)
- local w, h = gpu.getResolution()
- gpu.setBackground(0x000000, false)
- gpu.fill(1, 1, w, h, " ")
- gpu.setBackground( oldColor, false)
- term.setCursor(1, 1)
- end
- function checkAspectRatio()
- local w, h = screen.getAspectRatio()
- local neededWidth = 3
- local neededHeight = 3
- if (w == neededWidth and h == neededHeight) then
- return true
- else
- return false
- end
- end
- function checkComponents()
- if (component.isAvailable("br_reactor") == true and component.isAvailable("screen") == true) then
- return true
- else
- return false
- end
- end
- function generateDividers()
- gpu.setBackground(oldBG, false)
- gpu.setForeground(0x3a3a3a, false)
- gpu.fill(1, 1, 1, 25, "|")
- gpu.fill(50, 1, 1, 25, "|")
- gpu.fill(25, 1, 1, 25, "|")
- gpu.fill(26, 1, 1, 25, "|")
- gpu.fill(1, 1, 50, 1, "=")
- gpu.fill(1, 25, 50, 1, "=")
- gpu.fill(26, 4, 25, 1, "=")
- end
- function generateTitles()
- gpuOldColors()
- term.setCursor(27, 2)
- print(" EFFICIENCY BASED")
- term.setCursor(27, 3)
- print(" REACTOR MONITOR")
- term.setCursor(28, 6)
- print("Energy Stored:")
- term.setCursor(28, 8)
- print("RF/t:")
- term.setCursor(28, 10)
- print("Fuel Level:")
- term.setCursor(28, 12)
- print("Fuel MAX:")
- term.setCursor(28, 14)
- print("Control Rods:")
- term.setCursor(28, 16)
- print("Temperature:")
- end
- local grey = 0x3a3a3a
- local darkred = 0x660800
- local darkyellow = 0x66611f
- function generateBars()
- gpu.setBackground(grey, false)
- gpu.setForeground(oldFG, false)
- gpu.fill(3, 2, 5, 23, " ")
- gpu.setBackground(darkred, false)
- gpu.fill(4, 3, 3, 21, " ")
- gpu.setBackground(grey, false)
- gpu.fill(9, 2, 5, 23, " ")
- gpu.setBackground(darkyellow, false)
- gpu.fill(10, 3, 3, 21, " ")
- gpu.setBackground(grey, false)
- gpu.fill(15, 2, 5, 23, " ")
- gpu.setBackground(0x5e4a58, false)
- gpu.fill(16, 3, 3, 21, " ")
- gpu.setBackground(grey, false)
- gpu.fill(21, 21, 3, 3, " ")
- gpu.fill(21, 17, 3, 3, " ")
- term.setCursor(22, 18)
- print("+")
- term.setCursor(22, 22)
- print("-")
- gpuOldColors()
- end
- local green = 0x06e015
- local red = 0xd10300
- function buttonOnOff()
- if (reactor.getActive() == true) then
- gpu.setBackground(green, false)
- gpu.setForeground(0xFFFFFF, false)
- term.setCursor(41, 24)
- print(" DISABLE ")
- else
- gpu.setBackground(red, false)
- gpu.setForeground(0xFFFFFF, false)
- term.setCursor(41, 24)
- print(" ENABLE ")
- end
- gpu.setBackground(0x000000, false)
- end
- --Initialization
- clearScreen()
- checkComponents()
- if (checkComponents() == false) then
- print("You do not have all the required components for this program. Please restart your computer.")
- end
- checkAspectRatio()
- if (checkAspectRatio() == true) then
- gpu.setResolution(50, 25)
- clearScreen()
- print("Screen Resolution set to 50, 25.")
- os.sleep(1)
- clearScreen()
- else
- clearScreen()
- print("You must have a 3x3 screen to use EBRM! Please restart your computer.")
- end
- generateDividers()
- generateTitles()
- generateBars()
- buttonOnOff()
- --Reactor Stats and Functions
- local RF = math.floor(reactor.getEnergyProducedLastTick())
- ReactorStats = {}
- function reactorCheckStats()
- ReactorStats["EnergyAmt"] = reactor.getEnergyStored()
- ReactorStats["FuelAmt"] = reactor.getFuelAmount()
- ReactorStats["FuelMax"] = reactor.getFuelAmountMax()
- ReactorStats["FuelPercent"] = math.floor((ReactorStats["FuelMax"] / ReactorStats["FuelAmt"]) * 100)
- ReactorStats["ControlRodLvl"] = reactor.getControlRodLevel(1)
- ReactorStats["RF"] = math.floor(reactor.getEnergyProducedLastTick())
- ReactorStats["FuelTemp"] = reactor.getFuelTemperature()
- end
- local percentFuelLevel = math.floor((reactor.getFuelAmountMax() / reactor.getFuelAmount()) * 10)
- function reactorPrintStats()
- gpu.setBackground(oldBG, false)
- gpu.setForeground(green, false)
- term.setCursor(42, 6)
- print(" ")
- term.setCursor(42, 6)
- print(ReactorStats["EnergyAmt"])
- term.setCursor(42, 8)
- print(" ")
- term.setCursor(42, 8)
- print(ReactorStats["RF"])
- term.setCursor(42, 10)
- print(" ")
- term.setCursor(42, 10)
- print(ReactorStats["FuelPercent"] .. "%")
- term.setCursor(42, 12)
- print(ReactorStats["FuelMax"])
- term.setCursor(42, 14)
- print(" ")
- term.setCursor(42, 14)
- print(ReactorStats["ControlRodLvl"] .. "%")
- term.setCursor(42, 16)
- print(math.ceil(ReactorStats["FuelTemp"]) .. "C")
- gpuOldColors()
- end
- function reactorSetControlRodLvl(ControlButton)
- if ControlButton == 1 then
- if ReactorStats["ControlRodLvl"] <= 90 then
- reactor.setAllControlRodLevels(ReactorStats["ControlRodLvl"] + 10)
- end
- end
- if ControlButton == 2 then
- if ReactorStats["ControlRodLvl"] >= 10 then
- reactor.setAllControlRodLevels(ReactorStats["ControlRodLvl"] - 10)
- end
- end
- end
- --Bars
- local barHeightMax = 21
- local barY1 = 3
- local barY2 = 23
- function barsFuel(fuelCurrent)
- end
- function bars(val1, valMax, barX, color)
- gpu.setBackground(color, false)
- local barPercent = math.ceil((val1 / valMax) * 100)
- local barHeight = math.ceil(barHeightMax * (barPercent / 100))
- local barSub = barY2 - (barHeight - 1)
- for barY = 23, barSub, -1 do
- gpu.set(barX, barY, " ")
- end
- gpuOldColors()
- end
- function barsControl(controlrodsCurrent)
- end
- --Main Loop
- local ebrmStatus = true
- function buttonPress()
- if (reactor.getActive() == true) then
- reactor.setActive(false)
- buttonOnOff()
- else
- reactor.setActive(true)
- buttonOnOff()
- end
- end
- while ebrmStatus == true do
- local event, address, arg1, arg2, arg3 = event.pull(0.02)
- if (event == nil) then
- reactorCheckStats()
- reactorPrintStats()
- generateBars()
- bars(ReactorStats["EnergyAmt"], 10000000, 4, red)
- bars(ReactorStats["FuelAmt"], ReactorStats["FuelMax"], 10, 0xe4f248)
- bars(ReactorStats["FuelTemp"], 2000, 16, 0xd66e13)
- elseif event == "touch" and arg1 >= 41 and arg1 <= 49 and arg2 == 24 then
- buttonPress()
- elseif event == "touch" and arg1 >= 21 and arg1 <= 23 and arg2 >= 17 and arg2 <= 19 then
- reactorSetControlRodLvl(1)
- elseif event == "touch" and arg1 >= 21 and arg1 <= 23 and arg2 >= 21 and arg2 <= 23 then
- reactorSetControlRodLvl(2)
- end
- end
- --[[ TODO:
- -Spacers / dividers
- -energy level
- -fuel level
- -fuel rod percent level
- -reactor status
- -reactor on/off control
- -RF/t
- -Bar Graph
- -Control Rod Control
- Automatic Control Mode
- ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement