local steamstorageamount = 38600

--local steamstorageamount = 50000

local monitor , reactor

function setupPeripherals ( )

local isWarned , ok

while true do

monitor = nil

reactor = nil

monitor = peripheral . find ( "monitor" , function ( name , object ) return object . isColour ( ) end )

reactor = peripheral . find ( "BigReactors-Reactor" )

if monitor and reactor and reactor . getConnected ( ) then

if not ok then

ok = true

term . setCursorPos ( 1 , 1 )

term . clear ( )

term . setTextColor ( colors . lime )

print ( 'Running. Look at the Monitor.' )

term . setTextColor ( colors . white )

monitor . setTextScale ( 1 )

monitor . setCursorBlink ( false )

end

break

else if monitor and not reactor then

ok = false

term . setCursorPos ( 1 , 1 )

term . clear ( )

term . setTextColor ( colors . red )

print ( 'This program requires a connection to a valid multiblock reactor.' )

term . setTextColor ( colors . white )

local x , y = monitor . getSize ( )

local b = string.len ( 'Reactor Disconnected' ) / 2

local mY = y / 2

local mX = ( x / 2 ) - b + 1

monitor . setCursorPos ( mX , mY )

monitor . setTextColor ( colors . red )

monitor . setTextScale ( 2 )

monitor . setCursorBlink ( true )

monitor . clear ( )

monitor . write ( 'Reactor Disconnected' )

monitor . setTextColor ( colors . white )

else

if not isWarned then

ok = false

isWarned = true

term . setCursorPos ( 1 , 1 )

term . clear ( )

term . setTextColor ( colors . red )

print ( 'This program requires an advanced monitor to function.' )

term . setTextColor ( colors . white )

end

end

end

sleep ( 1 )

end

end

function mainLoop ( )

while true do

setupPeripherals ( )

sleep ( 0.1 )

monitor . clear ( )

if reactor . isActivelyCooled ( ) then

reactor . setAllControlRodLevels ( math.floor ( ( 100 / steamstorageamount ) * reactor . getHotFluidAmount ( ) ) )

else

reactor . setAllControlRodLevels ( math.floor ( ( 100 / 10000000 ) * reactor . getEnergyStored ( ) ) )

--[[

if reactor.getEnergyStored() == 10000000 then

reactor.setAllControlRodLevels(100)

else

reactor.setAllControlRodLevels(0)

end

]] --

end

monitor . setCursorPos ( 1 , 1 )

monitor . setTextColor ( colors . white )

monitor . write ( 'Status:' )

if reactor . getActive ( ) then

monitor . setCursorPos ( 9 , 1 )

monitor . setTextColor ( colors . lime )

monitor . write ( 'Online' )

monitor . setCursorPos ( 16 , 1 )

monitor . setTextColor ( colors . lightGray )

monitor . write ( '&' )

monitor . setCursorPos ( 18 , 1 )

if reactor . isActivelyCooled ( ) then

monitor . setTextColor ( colors . cyan )

monitor . write ( 'Actively Cooled' )

else

monitor . setTextColor ( colors . orange )

monitor . write ( 'Passively Cooled' )

end

else

monitor . setCursorPos ( 9 , 1 )

monitor . setTextColor ( colors . red )

monitor . write ( 'Offline' )

end

monitor . setCursorPos ( 1 , 3 )

monitor . setTextColor ( colors . white )

monitor . write ( 'Fuel Level:' )

monitor . setCursorPos ( 13 , 3 )

monitor . setTextColor ( colors . yellow )

monitor . write ( math.floor ( ( ( reactor . getFuelAmount ( ) / reactor . getFuelAmountMax ( ) ) * 100 ) + 0.5 ) .. '% Fuel ' )

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 ( 'Rod Level: ' )

monitor . setTextColor ( colors . lightGray )

monitor . write ( ( reactor . getControlRodLevel ( math.random ( 0 , reactor . getNumberOfControlRods ( ) - 1 ) ) ) .. '% Depth' )

monitor . setCursorPos ( 1 , 7 )

monitor . setTextColor ( colors . white )

monitor . write ( 'Temperature:' )

monitor . setCursorPos ( 1 , 8 )

monitor . setTextColor ( colors . yellow )

monitor . write ( 'Fuel: ' )

if reactor . getFuelTemperature ( ) >= 1000 then

monitor . setTextColor ( colors . red )

else if reactor . getFuelTemperature ( ) >= 650 then

monitor . setTextColor ( colors . orange )

else

monitor . setTextColor ( colors . green )

end

end

monitor . write ( math.floor ( reactor . getFuelTemperature ( ) ) .. ' Celsius' )

monitor . setCursorPos ( 1 , 9 )

monitor . setTextColor ( colors . lightGray )

monitor . write ( 'Casing: ' )

if reactor . getCasingTemperature ( ) >= 1000 then

monitor . setTextColor ( colors . red )

else if reactor . getCasingTemperature ( ) >= 650 then

monitor . setTextColor ( colors . orange )

else

monitor . setTextColor ( colors . green )

end

end

monitor . write ( math.floor ( reactor . getCasingTemperature ( ) ) .. ' Celsius' )

monitor . setCursorPos ( 1 , 11 )

monitor . setTextColor ( colors . white )

if reactor . isActivelyCooled ( ) then

monitor . write ( 'Buffer:' )

monitor . setCursorPos ( 10 , 11 )

if reactor . getHotFluidAmount ( ) > 48000 then

monitor . setTextColor ( colors . red )

else if reactor . getHotFluidAmount ( ) >= 25000 then

monitor . setTextColor ( colors . orange )

else

monitor . setTextColor ( colors . lightGray )

end

end

monitor . write ( 'Steam: ' .. ( reactor . getHotFluidAmount ( ) ) .. 'mB ' )

monitor . setTextColor ( colors . cyan )

monitor . write ( 'Coolant: ' .. ( reactor . getCoolantAmount ( ) ) .. 'mB' )

else

monitor . write ( 'Flux:' )

monitor . setCursorPos ( 7 , 11 )

monitor . write ( tostring ( reactor . getEnergyStored ( ) ) : gsub ( "%.%d+" , "" ) )

monitor . setTextColor ( colors . red )

monitor . write ( 'RF ' )

monitor . setTextColor ( colors . lightGray )

monitor . write ( '@ ' )

monitor . setTextColor ( colors . white )

monitor . write ( tostring ( reactor . getEnergyProducedLastTick ( ) ) : gsub ( "%.%d+" , "" ) )

monitor . setTextColor ( colors . red )

monitor . write ( 'RF/t' )

end

end

end

while true do

pcall ( mainLoop )