Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modemSide, reactorSide
- for _, side in ipairs(rs.getSides()) do
- if peripheral.getType(side) == "modem" then
- local wirelessMethod = false
- for i, method in ipairs(peripheral.getMethods(side)) do
- if method == "isWireless" then
- wirelessMethod = true
- if peripheral.call(side, "isWireless") then
- modemSide = side
- end
- break
- end
- end
- if not wirelessMethod then
- modemSide = side
- end
- elseif peripheral.getType(side) == "BigReactors-Reactor" then
- reactorSide = side
- end
- if modemSide and reactorSide then break end
- end
- local modem, reactor
- if modemSide then
- rednet.open(modemSide)
- modem = peripheral.wrap(modemSide)
- end
- if reactorSide then
- reactor = peripheral.wrap(reactorSide)
- else
- error("No Reactor Found")
- end
- local function sendUpdate(id, message)
- if modemSide then
- rednet.send(id, message)
- end
- end
- local function average(tab)
- local average = 0
- for i = 1, #tab do
- average = average + tab[i]
- end
- return average / #tab
- end
- local function pollInformation(reactor)
- local information = {}
- information.reactor = {}
- information.fuel = {}
- information.rods = {}
- information.cooling = {}
- information.power = {}
- do
- information.reactor.active = reactor.getActive()
- information.reactor.activeCooling = reactor.isActivelyCooled()
- information.reactor.temperature = reactor.getCasingTemperature()
- end
- do
- information.fuel.fuelAmount = reactor.getFuelAmount()
- information.fuel.wasteAmount = reactor.getWasteAmount()
- information.fuel.max = reactor.getFuelAmountMax()
- information.fuel.reactivity = reactor.getFuelReactivity()
- information.fuel.consumption = reactor.getFuelConsumedLastTick()
- information.fuel.temperature = reactor.getFuelTemperature()
- end
- do
- information.rods.count = reactor.getNumberOfControlRods()
- information.rods.levels = {}
- for i = 1, information.rods.count do
- information.rods.levels[i] = reactor.getControlRodLevel(i - 1)
- end
- information.rods.average = average(information.rods.levels)
- end
- if information.reactor.activeCooling then
- information.cooling.coldType = reactor.getCoolantType()
- information.cooling.coldAmount = reactor.getCoolantAmount()
- information.cooling.hotType = reactor.getHotFluidType()
- information.cooling.hotAmount = reactor.getHotFluidAmount()
- information.cooling.hotProduced = reactor.getHotFluidProducedLastTick()
- end
- if not information.reactor.activeCooling then
- information.power.produced = reactor.getEnergyProducedLastTick()
- information.power.stored = reactor.getEnergyStored()
- information.power.percentage = math.floor(information.power.stored / 100000)
- end
- return information
- end
- local settings = {
- rods = {
- setpoint = 0,
- maximum = 100,
- minimum = 0,
- mode = "auto",
- --values are auto, operator, startup.
- },
- reactor = {
- active = true,
- },
- general = {
- slowStartTickDelayCount = 4,
- slowStartSteamTickDelayCount = 20,
- }
- }
- local startupCount = 0
- local lastRodsSetting
- local function printCenter(text)
- text = tostring(text)
- local x, y = term.getSize()
- local xCur, yCur = term.getCursorPos()
- term.setCursorPos((x - #text) / 2 + 1, yCur)
- term.write(text)
- end
- local function displayScreen(info)
- local x, y = term.getSize()
- local column = math.ceil(x / 2)
- term.setBackgroundColor(term.isColor() and colors.gray or colors.black)
- term.setTextColor(colors.white)
- term.clear()
- do
- term.setCursorPos(2, 3)
- term.write("Temperature:")
- term.setCursorPos(2, 4)
- term.write("Core: "..info.fuel.temperature)
- term.setCursorPos(2, 5)
- term.write("Case: "..info.reactor.temperature)
- end
- do
- term.setCursorPos(2, 7)
- term.write("Fuel:")
- term.setCursorPos(2, 8)
- term.write("Fuel Level: "..tostring(info.fuel.fuelAmount).." mB")
- term.setCursorPos(2, 9)
- term.write("Waste Level: "..tostring(info.fuel.wasteAmount).." mB")
- term.setCursorPos(2, 10)
- term.write("Total: "..tostring(info.fuel.fuelAmount + info.fuel.wasteAmount).." mB")
- term.setCursorPos(2, 11)
- term.write("Capacity: "..tostring(info.fuel.max).." mB")
- term.setCursorPos(2, 12)
- term.write("Consumed: "..string.match(string.format("%f", info.fuel.consumption).."0000", "(%d+%.%d%d%d%d)").." mB/t")
- term.setCursorPos(2, 13)
- term.write("Reactivity: "..string.match(string.format("%f", info.fuel.reactivity).."00", "(%d+%.%d%d)").."%")
- end
- do
- term.setCursorPos(column, 3)
- term.write("Control Rods:")
- term.setCursorPos(column, 4)
- term.write("Actual: "..tostring(info.rods.average).."%")
- term.setCursorPos(column, 5)
- term.write("Setpoint: "..tostring(settings.rods.setpoint).."%")
- do
- if term.isColor() then term.setBackgroundColor(colors.red) end
- term.setCursorPos(column, 6)
- term.write("--")
- term.setCursorPos(column + 3, 6)
- term.write("-")
- if term.isColor() then term.setBackgroundColor(colors.yellow) end
- term.setCursorPos(column + 5, 6)
- term.write("=")
- if term.isColor() then term.setBackgroundColor(colors.lime) end
- term.setCursorPos(column + 7, 6)
- term.write("+")
- term.setCursorPos(column + 9, 6)
- term.write("++")
- if term.isColor() then term.setBackgroundColor(colors.blue) end
- term.setCursorPos(column + 12, 6)
- term.write("A")
- if term.isColor() then term.setBackgroundColor(colors.gray) end
- end
- end
- if info.reactor.activeCooling then
- --active cooling set
- term.setCursorPos(column, 8)
- term.write("Cooling:")
- term.setCursorPos(column, 9)
- term.write("Steam Output: "..tostring(info.cooling.hotProduced).." mB/t")
- term.setCursorPos(column, 10)
- term.write("Steam Level: "..tostring(info.cooling.hotAmount).." mB")
- term.setCursorPos(column, 11)
- term.write("Water Level: "..tostring(info.cooling.coldAmount).." mB")
- else
- --passive cooling set
- term.setCursorPos(column, 8)
- term.write("Power:")
- term.setCursorPos(column, 9)
- term.write("RF Output: "..tostring(math.floor(info.power.produced)).." RF/t")
- term.setCursorPos(column, 10)
- term.write("RF Stored: "..tostring(info.power.stored).." RF")
- term.setCursorPos(column, 11)
- term.write("RF % Full: "..tostring(info.power.percentage).."%")
- end
- end
- local function handleScreen(event)
- if event[1] == "mouse_click" then
- local x, y = term.getSize()
- local column = math.ceil(x / 2)
- if event[4] == 6 then
- if event[3] == column or event[3] == column + 1 then
- if event[2] == 1 then
- settings.rods.setpoint = math.max(0, settings.rods.setpoint - 10)
- settings.rods.mode = "operator"
- elseif event[2] == 2 then
- settings.rods.setpoint = 0
- settings.rods.mode = "operator"
- end
- elseif event[3] == column + 3 then
- settings.rods.setpoint = math.max(0, settings.rods.setpoint - 1)
- settings.rods.mode = "operator"
- elseif event[3] == column + 5 then
- settings.rods.setpoint = lastRodsSetting
- settings.rods.mode = "operator"
- elseif event[3] == column + 7 then
- settings.rods.setpoint = math.min(100, settings.rods.setpoint + 1)
- settings.rods.mode = "operator"
- elseif event[3] == column + 9 or event[3] == column + 10 then
- if event[2] == 1 then
- settings.rods.setpoint = math.min(100, settings.rods.setpoint + 10)
- settings.rods.mode = "operator"
- elseif event[2] == 2 then
- settings.rods.setpoint = 100
- settings.rods.mode = "operator"
- end
- elseif event[3] == column + 12 then
- settings.rods.mode = "auto"
- end
- end
- elseif event[1] == "char" then
- if event[2] == "-" then
- settings.rods.setpoint = math.max(0, settings.rods.setpoint - 1)
- settings.rods.mode = "operator"
- elseif event[2] == "=" then
- settings.rods.setpoint = lastRodsSetting
- settings.rods.mode = "operator"
- elseif event[2] == "+" then
- settings.rods.setpoint = math.min(100, settings.rods.setpoint + 1)
- settings.rods.mode = "operator"
- elseif string.lower(event[2]) == "a" then
- settings.rods.mode = "auto"
- end
- end
- end
- local function setRods(setpoint)
- if setpoint ~= lastRodsSetting then
- reactor.setAllControlRodLevels(math.max(settings.rods.minimum, math.min(settings.rods.maximum, setpoint)))
- sendUpdate(masterControl, "rods.actual:"..tostring(setpoint))
- lastRodsSetting = setpoint
- end
- end
- local tickRods = {
- operator = function(info)
- setRods(settings.rods.setpoint)
- end,
- startup = function(info)
- startupCount = startupCount + 1
- if info.power.percentage < info.rods.average then
- if startupCount >= settings.general.slowStartTickDelayCount then
- setRods(info.rods.average - 1)
- startupCount = 0
- end
- else
- setRods(info.power.percentage)
- settings.rods.mode = "auto"
- print("Reactor in AUTO mode")
- end
- end,
- auto = function(info)
- setRods(info.power.percentage)
- end,
- steamStartup = function(info)
- --
- end,
- }
- if fs.exists("reactorsettings") then
- dofile("reactorsettings")
- end
- local reactorTick = os.startTimer(0.5)
- print("Reactor Control Started")
- while true do
- local info = pollInformation(reactor)
- displayScreen(info)
- local event = {os.pullEvent()}
- if event[1] == "rednet_message" then
- if event[2] == masterControl then
- if event[3] == "stop" then
- print("Received STOP command")
- settings.reactor.active = false
- sendUpdate(masterControl, "reactor.active:false")
- reactor.setActive(false)
- elseif event[3] == "start" then
- print("Received START command")
- settings.reactor.active = true
- sendUpdate(masterControl, "reactor.active:true")
- reactor.setActive(true)
- reactor.setAllControlRodLevels(99)
- settings.rods.mode = "startup"
- sendUpdate(masterControl, "rods.mode:startup")
- print("Reactor in STARTUP mode")
- startupCount = 0
- reactorTick = os.startTimer(0.5)
- end
- end
- elseif event[1] == "timer" then
- if event[2] == reactorTick then
- if tickRods[settings.rods.mode] then
- tickRods[settings.rods.mode](info)
- end
- reactorTick = os.startTimer(0.5)
- end
- else
- handleScreen(event)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement