Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Big Reactor Monitor Program Written By: 0_Mr_Redstone_0 AKA MoJoCreatior
- This code is considered free for use both commercial and private and can be redistributed so long as it meats following criteria:
- 1: 0_Mr_Redstone_0 and MoJoCreatior are credited as the original authors
- 2: You do not try to take full ownership of the code/written program
- 3: If you modify the code for re-upload you must provide it under the same conditions. as in- Open Source, and credit me as original author]]
- program = "Big Reactor Monitor Program V:1.3"
- --Functions
- function intro()
- term.setBackgroundColour(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColour(colors.green)
- print(program.." -Written By: 0_Mr_Redstone_0 AKA MoJoCreatior")
- print(" ")
- end
- function centerText(text,line)
- length = string.len(text)
- minus = math.floor(monX-length)
- x = math.floor(minus/2)
- mon.setCursorPos(x+1,line)
- mon.write(text)
- end
- function centerTextC(text,line,colorB,colorT)
- mon.setBackgroundColour(colorB)
- mon.setTextColour(colorT)
- length = string.len(text)
- minus = math.floor(monX-length)
- x = math.floor(minus/2)
- mon.setCursorPos(x+1,line)
- mon.write(text)
- end
- function clearScreen()
- mon.setBackgroundColour(colors.white)
- mon.clear()
- end
- function textScale()
- mon.setTextScale(0.5)
- monX,monY = mon.getSize()
- if monX <= 16 or monY <= 11 then mon.setTextScale(0.5) elseif
- monX <= 37 or monY <= 25 then mon.setTextScale(1) elseif
- monX <= 58 or monY <= 39 then mon.setTextScale(1.5) elseif
- monX <= 80 or monY <= 53 then mon.setTextScale(2) elseif
- monX <= 101 or monY <= 68 then mon.setTextScale(2.5) else
- mon.setTextScale(3)
- end
- end
- function config(name)
- cfg = fs.open("config/"..name,"r")
- name = cfg.readAll()
- cfg.close()
- return name
- end
- function statBar(fillColor,emptyColor,line,percent,pColor)
- monX,monY = mon.getSize()
- barEmpty = monX-5
- if percent == 100 then length = 2 elseif percent == 0 then length = 4 else length = 3 end
- barFill = percent/100
- barFill = math.floor((barFill*barEmpty)+0.5)
- mon.setCursorPos(2,line)
- mon.setBackgroundColour(emptyColor)
- mon.write(string.rep(" ",barEmpty))
- mon.setCursorPos(2,line)
- mon.setBackgroundColour(fillColor)
- mon.write(string.rep(" ",barFill))
- mon.setCursorPos(barEmpty+length,line)
- mon.setBackgroundColour(colors.white)
- mon.setTextColour(pColor)
- mon.write(percent)
- mon.setCursorPos(monX,line)
- mon.write("%")
- end
- function percent(current,total)
- return math.floor((current/total*100)+0.5)
- end
- function header(colorB,colorT)
- clearScreen()
- mon.setBackgroundColour(colorB)
- mon.setTextColour(colorT)
- mon.setCursorPos(1,1)
- if string.len(title)+2 <= monX-3 then
- centerText(string.rep(" ",string.len(title)+2),1) else
- mon.clearLine() end
- centerText(title,1)
- end
- --Loads Config Files
- title = config("title")
- rate = config("rate")
- dynamic = config("dynamic")
- --Shows Settings inside control computer
- intro()
- term.setTextColour(colors.red)
- print("Final Settings\n")
- term.setTextColour(colors.blue)
- print("Title: "..title)
- if rate == "s" then print("Update Rate: slow") else print("Update Rate: fast") end
- if dynamic == "y" then print("Dynamic Scaling: enabled") else print("Dynamic Scaling: disabled") end
- term.setTextColour(colors.red)
- print("\nIf settings are incorrect. Run setup again")
- term.setTextColour(colors.blue)
- print("Hold CTRL+T to stop program")
- --Wraps the Reactor and monitor as peripherals
- mon = peripheral.find("monitor")
- reactor = peripheral.find("BigReactors-Reactor")
- --Text Scaling
- textScale()
- while true do
- --Main Program Loop
- --Dynamic Scaling Conditional
- if dynamic == "y" then textScale() end
- --Basic Variables & Calculations
- monX,monY = mon.getSize()
- controlRod = reactor.getControlRodLevel(0)
- reactorRF = reactor.getEnergyStored()
- percentRF = percent(reactorRF,10000000)
- reactor.setAllControlRodLevels((percentRF*2)-50)
- RFt = math.floor(reactor.getEnergyProducedLastTick()+.05)
- RFs = reactor.getEnergyStored()
- mbC = reactor.getFuelAmount() or 1
- mbM = reactor.getFuelAmountMax() or 1
- fuelPercent = percent(mbC,mbM)
- mbT = (math.floor((reactor.getFuelConsumedLastTick()*1000)+0.05))/1000
- if percentRF <= 40 then reactor.setAllControlRodLevels(0) end
- if percentRF == 100 then reactor.setAllControlRodLevels(100) end
- --Render Code
- header(colors.black,colors.white)
- centerTextC(RFt..":RF/t",monY-4,colors.white,colors.green)
- centerTextC(RFs..":RF",monY-3,colors.white,colors.red)
- centerTextC(mbT..":mb/t",3,colors.white,colors.purple)
- statBar(colors.yellow,colors.lightGray,4,fuelPercent,colors.purple)
- statBar(colors.gray,colors.lightGray,monY-1,controlRod,colors.gray)
- statBar(colors.red,colors.lightGray,monY-2,percentRF,colors.red)
- --Update Rate
- if rate == "f"
- then os.sleep(1)
- elseif rate == "s"
- then os.sleep(5)
- else os.sleep(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment