Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local reactor = peripheral.find("fissionReactorLogicAdapter")
- local turbine = peripheral.find("turbineValve")
- local induction_matrix = peripheral.find("inductionPort")
- local coolant_reserve = peripheral.wrap("right")
- peripheral.find("modem", rednet.open)
- local function clear()
- term.setBackgroundColor(colours.black) -- Set the background colour to black.
- term.clear() -- Paint the entire display with the current background colour.
- term.setCursorPos(1,1) -- Move the cursor to the top left position.
- end
- local function enableReserveCoolant()
- redstone.setOutput("back", false)
- end
- local function disableReserveCoolant()
- redstone.setOutput("back", true)
- end
- local function checkCoolantLevels(output)
- if reactor.getCoolantFilledPercentage() < 0.65 then
- if output == true then
- print("Alert, Coolant Low! (" .. reactor.getCoolantFilledPercentage() * 100 .. "%)")
- end
- return false
- elseif reactor.getCoolantFilledPercentage() < 0.95 then
- if output == true then
- print("Warning, Coolant below 95% (" .. reactor.getCoolantFilledPercentage() * 100 .. "%), injecting coolant from reserve ...")
- end
- enableReserveCoolant()
- return true
- else
- if output == true then
- print("Coolant levels normal (" .. reactor.getCoolantFilledPercentage() * 100 .. "%)")
- end
- disableReserveCoolant()
- return true
- end
- end
- local function checkHeatedCoolantLevels(output)
- if reactor.getHeatedCoolantFilledPercentage() > 0.65 then
- if output == true then
- print("Alert, Heated Coolant High! (" .. reactor.getHeatedCoolantFilledPercentage() * 100 .. "%)")
- end
- return false
- else
- if output == true then
- print("Heated Coolant levels normal (" .. reactor.getHeatedCoolantFilledPercentage() * 100 .. "%)")
- end
- return true
- end
- end
- local function checkTurbinePower(output)
- if turbine.getEnergyFilledPercentage() > 0.50 then
- if output == true then
- print("Turbine Power OK. (" .. turbine.getEnergyFilledPercentage() * 100 .. "%)")
- end
- return false
- elseif turbine.getEnergyFilledPercentage() > 0.75 then
- if output == true then
- print("Turbine Power High! Consider venting. (" .. turbine.getEnergyFilledPercentage() * 100 .. "%)")
- end
- return false
- else
- if output == true then
- print("Turbine Power levels normal (" .. turbine.getEnergyFilledPercentage() * 100 .. "%)")
- end
- return true
- end
- end
- local function checkInductionMatrixPower(output)
- if induction_matrix.getEnergyFilledPercentage() > 0.75 then
- if output == true then
- print("Induction Matrix power OK. (" .. induction_matrix.getEnergyFilledPercentage() * 100 .. "%)")
- end
- return false
- elseif induction_matrix.getEnergyFilledPercentage() > 0.90 then
- if output == true then
- print("Induction Matrix Power High! Consider venting. (" .. induction_matrix.getEnergyFilledPercentage() * 100 .. "%)")
- end
- return false
- else
- if output == true then
- print("Induction Matrix Power levels normal (" .. induction_matrix.getEnergyFilledPercentage() * 100 .. "%)")
- end
- return true
- end
- end
- local function checkFuelLevels(output)
- if reactor.getFuelFilledPercentage() < 0.25 then
- if output == true then
- print("Alert, Reactor Fuel Low! (" .. reactor.getFuelFilledPercentage() * 100 .. "%)")
- end
- return false
- else
- if output == true then
- print("Fuel levels normal (" .. reactor.getFuelFilledPercentage() * 100 .. "%)")
- end
- return true
- end
- end
- local function checkDamageLevels(output)
- if reactor.getDamagePercent() > 0 then
- if output == true then
- print("Alert, Reactor Damaged! (" .. reactor.getDamagePercent() * 100 .. "%)")
- end
- return false
- else
- if output == true then
- print("Damage levels normal (" .. reactor.getDamagePercent() * 100 .. "%)")
- end
- return true
- end
- end
- local function checkWasteLevels(output)
- if reactor.getWasteFilledPercentage() > 0.75 then
- if output == true then
- print("Alert, Reactor Waste High! (" .. reactor.getWasteFilledPercentage() * 100 .. "%)")
- end
- return false
- else
- if output == true then
- print("Waste levels normal (" .. reactor.getWasteFilledPercentage() * 100 .. "%)")
- end
- return true
- end
- end
- local function checkReserveCoolantEnabled()
- if redstone.getOutput("back") == true then
- return false
- else
- return true
- end
- end
- local function checkReserveCoolantLevels(output)
- if coolant_reserve.getFilledPercentage() < 0.25 then
- if output == true then
- print("Alert, Reserve Coolant Low! (" .. coolant_reserve.getFilledPercentage() * 100 .. "%)")
- end
- return false
- else
- if output == true then
- print("Reserve Coolant levels normal (" .. coolant_reserve.getFilledPercentage() * 100 .. "%)")
- end
- return true
- end
- end
- local function checkCoolantOrScram(output)
- if checkCoolantLevels() == false and checkReserveCoolantEnabled() == false then
- if output == true then
- print("Coolant levels too low, enabling reserve coolant!")
- end
- enableReserveCoolant()
- elseif checkCoolantLevels() == false and checkReserveCoolantEnabled() == true then
- if output == true then
- print("Coolant levels too low, SCRAM! ...")
- end
- reactor.scram()
- end
- end
- local function checkDamageOrScram(output)
- if checkDamageLevels() == false then
- if output == true then
- print("Damage levels too high, SCRAM!")
- end
- reactor.scram()
- end
- end
- local function checkReactorCritical()
- if checkCoolantLevels(false) == false or checkFuelLevels(false) == false or checkDamageLevels(false) == false or checkWasteLevels(false) == false or checkHeatedCoolantLevels(false) == false then
- return true
- else
- return false
- end
- end
- local function autoStart()
- local coolant_levels = checkCoolantLevels(true)
- if coolant_levels == true and checkFuelLevels(true) == true and checkDamageLevels(true) == true and checkWasteLevels(true) == true and checkHeatedCoolantLevels(true) == true and checkTurbinePower(true) == true and checkInductionMatrixPower(true) == true then
- print("Reactor is ready, starting...")
- reactor.activate()
- elseif coolant_levels == false then
- if checkReserveCoolantEnabled() == false then
- if checkReserveCoolantLevels() == false then
- print("Coolant levels too low to start reactor, waiting for reserves ...")
- else
- print("Coolant levels too low, enabling reserve coolant!")
- enableReserveCoolant()
- end
- else
- if checkCoolantLevels() == false then
- print("Coolant levels too low to start reactor, waiting for reserves ...")
- end
- end
- end
- end
- local function autoStop()
- local coolant_levels = checkCoolantLevels(true)
- if coolant_levels == false or checkFuelLevels(true) == false or checkDamageLevels(true) == false or checkWasteLevels(true) == false or checkHeatedCoolantLevels(true) == false then
- print("Reactor critical! Scramming reactor!")
- if coolant_levels == false and checkReserveCoolantEnabled() == false then
- print("Coolant levels too low, enabling reserve coolant!")
- enableReserveCoolant()
- end
- reactor.scram()
- elseif checkTurbinePower() == false or checkInductionMatrixPower() == false then
- if reactor.getStatus() == true then
- print("Power levels OK, stopping reactor.")
- reactor.scram()
- else
- print("Power levels OK, not starting reactor.")
- reactor.scram()
- end
- else
- checkTurbinePower(true)
- checkInductionMatrixPower(true)
- end
- end
- local function autoMonitor()
- while true do
- clear()
- if checkReactorCritical() == true then
- rednet.broadcast("alarm", "alarm_listener")
- else
- rednet.broadcast("ok", "alarm_listener")
- end
- if reactor.getStatus() == true then
- autoStop()
- else
- autoStart()
- end
- sleep(5)
- end
- end
- autoMonitor()
Advertisement
Add Comment
Please, Sign In to add comment