Skip to content

Instantly share code, notes, and snippets.

@TehNut
Last active August 29, 2015 13:59
Show Gist options
  • Save TehNut/10575476 to your computer and use it in GitHub Desktop.
Save TehNut/10575476 to your computer and use it in GitHub Desktop.
print('Program initialized - View Monitor.')
--Settings for dealing with an overheating reactor
local maxTemperature = 1500
local tempWarningRatio = 0.75 --Ratio to change color for temp
local failsafeMaxDraw = 20 --Max Percentage Draw
local failsafeCooldown = 150 --Timer in Seconds
--Increases cooldown timer if reactor stays above max temp, and
--goes to 0 draw if timer reaches double failsafeCooldown
local handleBadSettings = true
local MONITOR_NAME="back"
local REACTOR_NAME="BigReactors-Reactor_4"
--The first half of the warning messages
local problemNotice = "OH NO!"
local workingNotice = "AW YEAH!"
local failsafeNotice = "TOO MUCH!"
--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 = "Winging It"
local emptyWarning = "Zero Stamina"
local noDrawWarning = "Heavy Petting"
local lightDrawWarning = "Light Penetration"
local mediumDrawWarning = "Decent Penetration"
local highDrawWarning = "BALLS DEEP!"
local overheatWarning = "Need A Rest!"
--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
reactor =nil
while reactor == nil do
reactor=peripheral.wrap(REACTOR_NAME)
if reactor == nil then
print("Waiting for reactor peripheral")
os.sleep(1)
end
end
monitor = nil
while monitor == nil do
monitor = peripheral.wrap(MONITOR_NAME)
if monitor == nil then
print("Waiting for monitor to connect")
os.sleep(5)
end
end
while not reactor.getConnected() do
print("Waiting for reactor to connect")
os.sleep(5)
end
monitor.setTextScale(1.5)
monitor.setBackgroundColor(colors.black)
while true do
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.orange)
monitor.write('Program has been initialized')
monitor.setCursorPos(1,2)
monitor.setTextColor(colors.white)
monitor.write('Fuel Level - ')
monitor.setTextColor(colors.yellow)
monitor.write(math.floor(((reactor.getFuelAmount()/reactor.getFuelAmountMax())*100)+0.5)..'% Fuel')
monitor.setCursorPos(1,3)
monitor.setTextColor(colors.white)
monitor.write('Waste Level - ')
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('Control Rod Levels - ')
monitor.setTextColor(colors.green)
monitor.setCursorPos(1,6)
monitor.write('Rod 1: '..(100-(reactor.getControlRodLevel(0)))..'% Depth')
monitor.setCursorPos(25,6)
monitor.write('Rod 2: '..(100-(reactor.getControlRodLevel(1)))..'% Depth')
monitor.setCursorPos(1,7)
monitor.write('Rod 3: '..(100-(reactor.getControlRodLevel(2)))..'% Depth')
monitor.setCursorPos(25,7)
monitor.write('Rod 4: '..(100-(reactor.getControlRodLevel(3)))..'% Depth')
monitor.setCursorPos(1,8)
monitor.write('Rod 5: '..(100-(reactor.getControlRodLevel(4)))..'% Depth')
monitor.setCursorPos(25,8)
monitor.write('Rod 6: '..(100-(reactor.getControlRodLevel(5)))..'% Depth')
monitor.setCursorPos(1,9)
monitor.write('Rod 7: '..(100-(reactor.getControlRodLevel(6)))..'% Depth')
monitor.setCursorPos(25,9)
monitor.write('Rod 8: '..(100-(reactor.getControlRodLevel(7)))..'% Depth')
monitor.setCursorPos(1,10)
monitor.write('Rod 9: '..(100-(reactor.getControlRodLevel(8)))..'% Depth')
monitor.setCursorPos(25,10)
monitor.write('Rod 10: '..(100-(reactor.getControlRodLevel(9)))..'% Depth')
monitor.setCursorPos(1,11)
monitor.write('Rod 11: '..(100-(reactor.getControlRodLevel(10)))..'% Depth')
monitor.setCursorPos(25,11)
monitor.write('Rod 12: '..(100-(reactor.getControlRodLevel(11)))..'% Depth')
monitor.setCursorPos(1,12)
monitor.write('Rod 13: '..(100-(reactor.getControlRodLevel(12)))..'% Depth')
monitor.setCursorPos(25,12)
monitor.write('Rod 14: '..(100-(reactor.getControlRodLevel(13)))..'% Depth')
monitor.setCursorPos(1,13)
monitor.write('Rod 15: '..(100-(reactor.getControlRodLevel(14)))..'% Depth')
monitor.setCursorPos(1,15)
monitor.setTextColor(colors.white)
monitor.write('Temperature')
monitor.setCursorPos(25,15)
monitor.write('Fuel Usage')
monitor.setCursorPos(1,16)
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(reactor.getFuelTemperature()..'C')
monitor.setCursorPos(25,16)
monitor.write(reactor.getFuelConsumedLastTick())
monitor.setCursorPos(1,18)
monitor.setTextColor(colors.white)
monitor.write('Flux')
monitor.setCursorPos(1,19)
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.write((math.floor(reactor.getEnergyProducedLastTick()+0.5))..'RF/t')
monitor.setCursorPos(1,21)
monitor.setTextColor(colors.orange)
monitor.write('Warnings:')
if flashflag==0 then
flashflag=1
currentWarning = ""
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
currentWarning = currentWarning..noDrawWarning
elseif reactor.getControlRodLevel(0)>75 then
warningColor = colors.yellow
currentWarning = currentWarning..lightDrawWarning
elseif reactor.getControlRodLevel(0)>50 then
warningColor = colors.orange
currentWarning = currentWarning..mediumDrawWarning
else
warningColor = colors.red
currentWarning = currentWarning..highDrawWarning
end
if cooldownTimer > 0 then
warningColor = colors.green
currentWarning = currentWarning..' ('..cooldownTimer..')'
end
end
monitor.setCursorPos(1,22)
monitor.setTextColor(warningColor)
monitor.write(currentWarning)
else
flashflag=0
monitor.setCursorPos(1,22)
monitor.clearLine()
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() == 0) then
overheated = false
cooldownTimer = 0
end
end
sleep(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment