Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Cosmetic settings for the monitor
- local textScale = 1 --Size of text
- local fuelDecimals = 3 --Decimals shown on fuel usage
- local doubleLineWarnings = true --Put warnings on two lines
- -- Settings for dealing with an overheating reactor
- local maxTemperature = 2200
- local tempWarningRatio = 0.75 --Ratio to change color for temp
- local failsafeMaxDraw = 20 --Max Percentage Draw
- local failsafeCooldown = 150 --Timer in Seconds
- local safeTemp = 1 --Temperature to resume normal operation at
- -- Increases cooldown timer if reactor stays above max temp, and
- -- goes to 0 draw if timer reaches double failsafeCooldown
- local handleBadSettings = true
- -- Use sides or modem names to connect the devices
- local monitorName = "right"
- local reactorName = "back"
- -- How long to wait before trying to connect if parts aren't ready
- -- Recommended values are 1 if next to computer, 5 if using modem.
- local monitorWait = 1
- local reactorWait = 1
- -- The first half of the warning messages
- local problemNotice = "OFFLINE"
- local workingNotice = "ONLINE"
- local failsafeNotice = "OVERHEATED"
- -- The string of characters (if any) that separates the two halves
- -- of the warning messages
- local noticeSeparator = " - "
- -- The second half of the warning messages
- local offlineWarning = "Manual Mode"
- local emptyWarning = "Out of Fuel"
- local noDrawWarning = "Standby Mode"
- local lightDrawWarning = "Low Power Mode"
- local mediumDrawWarning = "Moderate Power Mode"
- local highDrawWarning = "High Power Mode"
- local overheatWarning = "Safety Shutdown Cycle"
- -- Used Internally - changing will do nothing
- local rodLevels = 0
- local currentWarning = ""
- local cooldownTimer = 0
- local warningColor = colors.white
- local emptyflag = 0
- local offlineflag = 0
- local flashflag = 0
- local overheated = false
- local monitor = nil
- local reactor = nil
- while reactor == nil do
- reactor=peripheral.wrap(reactorName)
- if reactor == nil then
- print("Waiting for reactor peripheral")
- os.sleep(reactorWait)
- end
- end
- print("Found reactor. Looking for monitor.")
- while monitor == nil do
- monitor = peripheral.wrap(monitorName)
- if monitor == nil then
- print("Waiting for monitor to connect")
- os.sleep(monitorWait)
- end
- end
- print("Monitor found.")
- while not reactor.getConnected() do
- print("Waiting for reactor to connect.")
- os.sleep(reactorWait)
- end
- print("Program Initialized - View Monitor.")
- monitor.setTextScale(textScale)
- monitor.setBackgroundColor(colors.black)
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- while true do
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.setTextColor(colors.white)
- monitor.write('Fuel Level:')
- monitor.setCursorPos(1,2)
- monitor.setTextColor(colors.yellow)
- monitor.write(math.floor(((reactor.getFuelAmount()/reactor.getFuelAmountMax())*100)+0.5)..'% Fuel')
- monitor.setCursorPos(1,3)
- monitor.setTextColor(colors.lightBlue)
- monitor.write(math.floor(((reactor.getWasteAmount()/reactor.getFuelAmountMax())*100)+0.5)..'% Waste')
- monitor.setCursorPos(1,5)
- monitor.setTextColor(colors.white)
- monitor.write('Monitoring:')
- monitor.setTextColor(colors.green)
- monitor.setCursorPos(1,6)
- monitor.write('Rods: '..(100-(reactor.getControlRodLevel(0)))..'% Power')
- monitor.setCursorPos(1,7)
- monitor.write('Fuel: '..round(reactor.getFuelConsumedLastTick(),fuelDecimals)..' mB/t')
- monitor.setCursorPos(1,9)
- monitor.setTextColor(colors.white)
- monitor.write('Temperature:')
- monitor.setCursorPos(1,10)
- if reactor.getFuelTemperature()>=(maxTemperature*tempWarningRatio) then
- monitor.setTextColor(colors.purple)
- elseif reactor.getFuelTemperature()>=maxTemperature then
- monitor.setTextColor(colors.red)
- else
- monitor.setTextColor(colors.green)
- end
- monitor.write(math.floor(reactor.getFuelTemperature())..'C')
- monitor.setCursorPos(1,12)
- monitor.setTextColor(colors.white)
- monitor.write('Flux:')
- monitor.setCursorPos(1,13)
- monitor.setTextColor(colors.green)
- monitor.write(reactor.getEnergyStored()..' RF Stored ')
- if reactor.getEnergyProducedLastTick()>=500 and reactor.getEnergyProducedLastTick()<2000 then
- monitor.setTextColor(colors.orange)
- end
- if reactor.getEnergyProducedLastTick()>=2000 then
- monitor.setTextColor(colors.red)
- end
- monitor.setCursorPos(1,14)
- monitor.write((math.floor(reactor.getEnergyProducedLastTick()+0.5))..' RF/t')
- monitor.setCursorPos(1,16)
- monitor.setTextColor(colors.white)
- monitor.write('Warnings:')
- if flashflag==0 then
- flashflag=1
- currentWarning = ""
- currentWarning2 = ""
- if offlineflag==1 then
- warningColor = colors.lightGray
- currentWarning = problemNotice..noticeSeparator..offlineWarning
- elseif emptyflag==1 then
- warningColor = colors.pink
- currentWarning = problemNotice..noticeSeparator..emptyWarning
- elseif cooldownTimer > 0 then
- currentWarning = failsafeNotice..noticeSeparator
- if overheated then
- warningColor = colors.green
- currentWarning = currentWarning..overheatWarning..' ('..cooldownTimer..')'
- end
- else
- currentWarning = workingNotice..noticeSeparator
- end
- if emptyflag==0 and offlineflag==0 and not overheated then
- if reactor.getControlRodLevel(0)>99 then
- warningColor = colors.lightBlue
- currentWarning2 = noDrawWarning
- elseif reactor.getControlRodLevel(0)>75 then
- warningColor = colors.yellow
- currentWarning2 = lightDrawWarning
- elseif reactor.getControlRodLevel(0)>50 then
- warningColor = colors.orange
- currentWarning2 = mediumDrawWarning
- else
- warningColor = colors.red
- currentWarning2 = highDrawWarning
- end
- if not doubleLineWarnings then
- currentWarning = currentWarning..currentWarning2
- end
- if cooldownTimer > 0 then
- warningColor = colors.purple
- currentWarning = currentWarning..' ('..cooldownTimer..')'
- end
- end
- monitor.setCursorPos(1,17)
- monitor.setTextColor(warningColor)
- monitor.write(currentWarning)
- if doubleLineWarnings then
- monitor.setCursorPos(1,18)
- monitor.write(currentWarning2)
- end
- else
- flashflag=0
- monitor.setCursorPos(1,17)
- monitor.clearLine()
- if doubleLineWarnings then
- monitor.setCursorPos(1,18)
- monitor.clearLine()
- end
- end
- if emptyflag==0 and offlineflag==0 and not overheated then
- if reactor.getFuelTemperature() > maxTemperature and cooldownTimer == 0 then
- cooldownTimer = failsafeCooldown
- elseif reactor.getFuelTemperature() > maxTemperature and handleBadSettings then
- cooldownTimer = cooldownTimer + 1
- if cooldownTimer == failsafeCooldown * 2 then
- overheated = true
- end
- end
- if reactor.getEnergyStored()>= 1 then
- rodLevels = math.floor(reactor.getEnergyStored()/100000)
- else
- rodLevels = 0 --Full Draw
- end
- if cooldownTimer > 0 and rodLevels < (100 - failsafeMaxDraw) then
- rodLevels = (100 - failsafeMaxDraw)
- end
- reactor.setAllControlRodLevels(rodLevels)
- end
- if overheated then
- reactor.setAllControlRodLevels(100)
- end
- if reactor.getFuelAmount()<=100 and offlineflag==0 then
- reactor.setAllControlRodLevels(100)
- reactor.setActive(false)
- emptyflag=1
- else
- emptyflag=0
- end
- if rs.getInput('top')==false and emptyflag==0 then
- reactor.setActive(true)
- offlineflag=0
- end
- if rs.getInput('top')==true and emptyflag==0 then
- reactor.setActive(false)
- reactor.setAllControlRodLevels(100)
- offlineflag=1
- end
- if cooldownTimer > 0 and reactor.getFuelTemperature() <= maxTemperature then
- cooldownTimer = cooldownTimer - 1
- if overheated and (cooldownTimer == 0 or reactor.getFuelTemperature() <= safeTemp) then
- overheated = false
- cooldownTimer = 0
- end
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement