By Guest

MEK Fission Reactor Controller

Lua 1.84 KiB 41 2 months ago
local criticalTemperature = 600 local turbineEnergyTreshold = 0.8 local turbineEnergyMin = 0.2 local wasteThreshold = 0.8 local alarmSide = "top" local reactor = peripheral.find("fissionReactorLogicAdapter") local turbine = peripheral.find("turbineValve") _G.reactor = reactor; _G.turbine = turbine; assert(reactor, "Fission reactor not found") assert(turbine, "Turbine not found") print("Fission Controller enabled") print("Reactor is " .. (reactor.getStatus() and "online" or "offline")) local oldTemperature while true do local isEnabled = reactor.getStatus() local toScram = false local temperature = reactor.getTemperature() local coolantPc = reactor.getCoolantFilledPercentage() if oldTemperature ~= nil and temperature > oldTemperature then print("Temperature increased to " .. temperature) end if temperature > criticalTemperature then print("Critical temperature reached!") rs.setOutput(alarmSide, true) toScram = true break end oldTemperature = temperature if coolantPc < 0.2 then print("Coolant missing. Required: " .. coolantPc * 100 .. "%") toScram = true end if reactor.getWasteFilledPercentage() > wasteThreshold and isEnabled then print("Waste level too high!") toScram = true end if turbine.getEnergyFilledPercentage() > turbineEnergyTreshold and isEnabled then print("Energy level high. Disabling reactor.") toScram = true end if toScram and isEnabled then print("SCRAM activated") reactor.scram() else if not toScram and turbine.getEnergyFilledPercentage() < turbineEnergyMin then print("Energy level too low. Activating reactor.") reactor.activate() end end sleep(1) end