Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[------------------------------------------------RECTOR / TURBINE MONITOR--------------------------------------------------------------
- Written by QuietStorm
- My first shot at lua and opencomputers
- Multiple reactor and turbine information and control panel. Use number pad 0-9 to change the color of the interface. Only tested with Opencomputers tier 3 hardware.
- Pros: Almost 100% working as I intended it to.
- Cons: Having to use term.clear() to update guages and remove unwanted text causes a flickering of the screen (afaik). Any help would be appreciated
- Features:
- -Interface color can be changed with number pad keys 0-9
- -Nearly every reactor & turbine methods used
- -Realtime guages
- -Automatically sets turbine flowrate according to the number of blades used. 100% Efficiency
- -Automatically shuts down turbines that have filled the energy buffer
- -Shutdown individual reactors and turbines
- -Insert or retract reactor control rods in multiples of 10
- -Can cycle through each reactor and turbine
- -Lots of machine info
- ]]--
- -- VARIABLES
- local com = require "component"
- local keyboard = require "keyboard"
- local term = require "term"
- local os = require "os"
- local event = require "event"
- local gpu = com.gpu
- local reactor = {}
- local turbine = {}
- local reactorAvailable
- local turbineAvailable
- local w, h = gpu.getResolution()
- defaultBgColor = gpu.getBackground()
- defaultFgColor = gpu.getForeground()
- local running = true
- local refreshRate = .8
- local rhTable = {"CASING TEMP", "FUEL TEMP", "WASTE", "CONTROL RODS", "STEAM OUT", "REACTIVITY", "RF OUT", "STORED RF"}
- local thTable = {"STEAM IN", "COOLANT OUT", "ROTOR SPEED", "ROTOR MASS", "EFFICIENCY", "INDUCTOR STATE", "RF OUT", "STORED RF"}
- local turbineMaxSteamIn = 0
- local controlRods = {}
- local powerON = 975001 -- Set here where the turbines should reactivate after a shutdown
- local powerOFF = 1000000 -- Turbine max energy buffer. Turbines will shutdown
- buttonInsertActive = false
- buttonRetractActive = false
- --CLEAR THE SCREEN
- gpu.fill(1, 1, w, h, " ")
- -- COLORS
- local colors = {}
- colors.white = 0xFFFFFF
- colors.orange = 0xFFA500
- colors.magenta = 0xFF00FF
- colors.lightblue = 0x00AEEF
- colors.yellow = 0xFFFF00
- colors.lime = 0x00FF00
- colors.pink = 0xFFC0CB
- colors.gray = 0x555555
- colors.grey = 0x555555
- colors.silver = 0xAAAAAA
- colors.cyan = 0x00FFFF
- colors.purple = 0x800080
- colors.blue = 0x0000FF
- colors.brown = 0x603913
- colors.green = 0x008000
- colors.red = 0xFF0000
- colors.black = 0x000000
- local interfaceColor = colors.gray
- -- CHECK FOR REACTOR & TURBINE COMPUTER PORTS
- if com.isAvailable("br_reactor") then
- reactorAvailable = true
- else
- reactorAvailable = false
- end
- if com.isAvailable("br_turbine") then
- turbineAvailable = true
- else
- turbineAvailable = false
- end
- if not reactorAvailable and not turbineAvailable then
- term.setCursor(1, 1)
- gpu.set(1, 1, "[ ! ] THIS PROGRAM REQUIRES AT LEAST (1) REACTOR OR (1) TURBINE TO RUN [ ! ]")
- os.sleep(7)
- captureKeys(q)
- end
- -- FETCH REACTOR AND TURBINE DATA
- --Reactors
- if reactorAvailable then
- local i = 1
- for address, type in com.list("br_reactor") do
- reactor[i] = com.proxy(address)
- i = i + 1
- end
- else
- label(1, 4, "%s", colors.red, "[ ! ] NO REACTORS CONNECTED [ ! ]")
- end
- --Turbines
- if turbineAvailable then
- local i = 1
- for address, type in com.list("br_turbine") do
- turbine[i] = com.proxy(address)
- i = i + 1
- end
- else
- label(1, 29, "%s", colors.red, "[ ! ] NO TURBINES CONNECTED [ ! ]")
- end
- --CHECK FOR A CURRENT REACTOR & TURBINE NUMBER
- if not reactorNum then
- reactorNum = 1
- end
- if not turbineNum then
- turbineNum = 1
- end
- -- FUNCTIONS
- function drawInterface(color)
- gpu.setBackground(color)
- gpu.fill(1, 1, w, 1, " ") --Top
- gpu.fill(1, h, w, 1, " ") --Bottom
- gpu.fill(1, 2, 1, h - 2, " ") --Left
- gpu.fill(w, 2, 1, h - 2, " ") --Right
- gpu.fill(2, 3, w - 2, 1, " ") --End Reactor heading
- gpu.fill(2, 8, w - 43, 1, " ") --End Reactor number stats
- gpu.fill(2, 23, w, 1, " ") --End Reactor Information
- gpu.fill(2, 25, w - 2, 1, " ") --End Turbine heading
- gpu.fill(2, 30, w - 43, 1, " ") --End Turbine number stats
- gpu.fill(2, 45, w, 1, " ") --End Turbine Information
- gpu.fill(w - 42, 4, 1, 19, " ") --Reactor side box
- gpu.fill(w - 42, 26, 1, 19, " ") --Turbine side box
- --Start reactor meters
- gpu.set(4, 10, "COOLANT")
- gpu.fill(3, 11, 1, 12, " ") --Coolant level left side
- gpu.fill(11, 11, 1, 12, " ") --Coolant level right side
- gpu.fill(4, 11, 7, 1, " ") --Coolant level top
- gpu.fill(4, 22, 7, 1, " ")--Coolant level bottom
- gpu.set(56, 10, " FUEL ")
- gpu.fill(55, 11, 1, 12, " ") --Fuel level left side
- gpu.fill(63, 11, 1, 12, " ") --Fuel level right side
- gpu.fill(56, 11, 7, 1, " ") --Fuel level top
- gpu.fill(56, 22, 7, 1, " ") --Fuel level bottom
- gpu.set(109, 10, " STEAM ")
- gpu.fill(108, 11, 1, 12, " ") --Steam level left side
- gpu.fill(116, 11, 1, 12, " ") --Steam level right side
- gpu.fill(109, 11, 7, 1, " ") --Steam level top
- gpu.fill(109, 22, 7, 1, " ") --Steam level bottom
- gpu.fill(119, 13, 2, 10, " ") --Control Rod level Left side
- gpu.fill(158, 13, 2, 10, " ") --Control Rod level Right side
- gpu.fill(119, 12, 41, 1, " ") --Control Rod level Top
- --Start turbine meters
- gpu.set(4, 32, " STEAM ")
- gpu.fill(3, 33, 1, 12, " ") --Steam level left side
- gpu.fill(11, 33, 1, 12, " ") --Steam level right side
- gpu.fill(4, 33, 7, 1, " ") --Steam level top
- gpu.fill(4, 44, 7, 1, " ")--Steam level bottom
- gpu.set(56, 32, " WATER ")
- gpu.fill(55, 33, 1, 12, " ") --Coolant level left side
- gpu.fill(63, 33, 1, 12, " ") --Coolant level right side
- gpu.fill(56, 33, 7, 1, " ") --Coolant level top
- gpu.fill(56, 44, 7, 1, " ")--Coolant level bottom
- gpu.set(109, 32, " RF ")
- gpu.fill(108, 33, 1, 12, " ") --RF level left side
- gpu.fill(116, 33, 1, 12, " ") --RF level right side
- gpu.fill(109, 33, 7, 1, " ") --RF level top
- gpu.fill(109, 44, 7, 1, " ")--RF level bottom
- gpu.setBackground(defaultBgColor)
- end
- function indicatorOn(col, row, text, color)
- gpu.setBackground(colors.lime)
- gpu.fill(col + 1, row, 8, 1, " ")
- gpu.fill(col, row + 1, 10, 1, " ")
- gpu.fill(col + 1, row + 2, 8, 1, " ")
- textLen = string.len(text)
- pos = math.floor(5 - (textLen / 2))
- label(col + pos, row + 1, text, color)
- gpu.setBackground(defaultBgColor)
- end
- function indicatorOff(col, row, text, color)
- gpu.setBackground(colors.red)
- gpu.fill(col + 1, row, 8, 1, " ")
- gpu.fill(col, row + 1, 10, 1, " ")
- gpu.fill(col + 1, row + 2, 8, 1, " ")
- textLen = string.len(text)
- pos = math.ceil(5 - (textLen / 2))
- label(col + pos, row + 1, text, color)
- gpu.setBackground(defaultBgColor)
- end
- function crButtons()
- label(133, 4, "CONTROL RODS", colors.yellow)
- label(120, 5, "Insert: [']", colors.orange)
- label(148, 5, "Retract [/]", colors.orange)
- if buttonInsertActive == false then
- indicatorOff(120, 7, "INSERT", colors.yellow)
- else
- indicatorOn(120, 7, "INSERT", colors.yellow)
- buttonInsertActive = false
- end
- if buttonRetractActive == false then
- indicatorOff(149, 7, "RETRACT", colors.yellow)
- else
- indicatorOn(149, 7, "RETRACT", colors.yellow)
- buttonRetractActive = false
- end
- end
- function percent(curValue, maxValue)
- return (curValue / maxValue) * 100
- end
- function fillMeters(col, row, width, Level, LevelMax, color)
- gpu.setBackground(color)
- gpu.setForeground(colors.purple)
- if math.floor(percent(Level, LevelMax)) >= 10 and math.floor(percent(Level, LevelMax)) <= 19 then
- gpu.fill(col, row, width, 1, " ")
- gpu.set(col + 2, row, "10%")
- end
- if math.floor(percent(Level, LevelMax)) >= 20 and math.floor(percent(Level, LevelMax)) <= 29 then
- currentRow = row - 1
- gpu.fill(col, currentRow, width, 2, " ")
- gpu.set(col + 2, currentRow, "20%")
- end
- if math.floor(percent(Level, LevelMax)) >= 30 and math.floor(percent(Level, LevelMax)) <= 39 then
- currentRow = row - 2
- gpu.fill(col, currentRow, width, 3, " ")
- gpu.set(col + 2, currentRow, "30%")
- end
- if math.floor(percent(Level, LevelMax)) >= 40 and math.floor(percent(Level, LevelMax)) <= 49 then
- currentRow = row - 3
- gpu.fill(col, currentRow, width, 4, " ")
- gpu.set(col + 2, currentRow, "40%")
- end
- if math.floor(percent(Level, LevelMax)) >= 50 and math.floor(percent(Level, LevelMax)) <= 59 then
- currentRow = row - 4
- gpu.fill(col, currentRow, width, 5, " ")
- gpu.set(col + 2, currentRow, "50%")
- end
- if math.floor(percent(Level, LevelMax)) >= 60 and math.floor(percent(Level, LevelMax)) <= 69 then
- currentRow = row - 5
- gpu.fill(col, currentRow, width, 6, " ")
- gpu.set(col + 2, currentRow, "60%")
- end
- if math.floor(percent(Level, LevelMax)) >= 70 and math.floor(percent(Level, LevelMax)) <= 79 then
- currentRow = row - 6
- gpu.fill(col, currentRow, width, 7, " ")
- gpu.set(col + 2, currentRow, "70%")
- end
- if math.floor(percent(Level, LevelMax)) >= 80 and math.floor(percent(Level, LevelMax)) <= 89 then
- currentRow = row - 7
- gpu.fill(col, currentRow, width, 8, " ")
- gpu.set(col + 2, currentRow, "80%")
- end
- if math.floor(percent(Level, LevelMax)) >= 90 and math.floor(percent(Level, LevelMax)) <= 99 then
- currentRow = row - 8
- gpu.fill(col, currentRow, width, 9, " ")
- gpu.set(col + 2, currentRow, "90%")
- end
- if percent(Level, LevelMax) == 100 then
- currentRow = row - 9
- gpu.fill(col, currentRow, width, 10, " ")
- gpu.set(col + 2, currentRow, "100%")
- end
- gpu.setBackground(defaultBgColor)
- gpu.setForeground(defaultFgColor)
- end
- function reactorMainHeader()
- reactorHeader = "REACTOR ["..reactorNum.." of "..#reactor.."] ID: ".. reactor[reactorNum].address .. ""
- gpu.set(2, 2, reactorHeader)
- label(string.len(reactorHeader) + 40, 2, "Fuel Burn Rate: %.3f mB/t", colors.yellow, fuelBurnRate)
- label(string.len(reactorHeader) + 80, 2, "Output Rating: %.0f%%", colors.green, outputRating)
- if reactor[reactorNum].getActive() then
- if reactor[reactorNum].isActivelyCooled() then
- label(string.len(reactorHeader) + 4, 2, "POWERED ON [ACTIVELY COOLED]", colors.lime)
- elseif not reactor[reactorNum].isActivelyCooled() then
- label(string.len(reactorHeader) + 4, 2, "POWERED ON [NOT ACTIVELY COOLED]", colors.lime)
- end
- else
- if reactor[reactorNum].isActivelyCooled() then
- label(string.len(reactorHeader) + 4, 2, "POWERED OFF [ACTIVELY COOLED]", colors.red)
- elseif not reactor[reactorNum].isActivelyCooled() then
- label(string.len(reactorHeader) + 4, 2, "POWERED OFF [NOT ACTIVELY COOLED]", colors.red)
- end
- end
- end
- function turbineMainHeader()
- turbineHeader = "TURBINE ["..turbineNum.." of "..#turbine.."] ID: "..turbine[turbineNum].address.. ""
- gpu.set(2, 24, turbineHeader)
- end
- function reactorPower()
- if reactor[reactorNum].getActive() then
- reactor[reactorNum].setActive(false)
- elseif not reactor[reactorNum].getActive() then
- reactor[reactorNum].setActive(true)
- end
- end
- function reactorLabels()
- startColumn = 2
- row = 5
- spaces = 6
- for i = 1, #rhTable do
- gpu.set(startColumn, row, rhTable[i])
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- end
- end
- function turbineLabels()
- startColumn = 2
- row = 27
- spaces = 5
- for i = 1, #thTable do
- gpu.set(startColumn, row, thTable[i])
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- i = i + 1
- end
- end
- function reactorDataTable()
- --REACTOR LABELS ROW 5
- startColumn = 2
- row = 5
- spaces = 6
- for i = 1, #rhTable do
- gpu.set(startColumn, row, rhTable[i])
- if rhTable[i] == "CASING TEMP" then
- label(startColumn, row + 1, "%d °C", colors.red, tostring(reactor[reactorNum].getCasingTemperature()))
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- elseif
- rhTable[i] == "FUEL TEMP" then
- label(startColumn, row + 1, "%d °C", colors.red, tostring(reactor[reactorNum].getFuelTemperature()))
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- elseif
- rhTable[i] == "FUEL CONSUMED" then
- label(startColumn, row + 1, "%d mB/t", nil, tostring(reactor[reactorNum].getFuelConsumedLastTick()))
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- elseif
- rhTable[i] == "WASTE" then
- label(startColumn, row + 1, "%d mB", nil, tostring(reactor[reactorNum].getWasteAmount()))
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- elseif
- rhTable[i] == "CONTROL RODS" then
- label(startColumn, row + 1, "%d Rods", nil, tostring(reactor[reactorNum].getNumberOfControlRods()))
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- elseif
- rhTable[i] == "STEAM OUT" then
- label(startColumn, row + 1, "%d mB/t", nil, tostring(reactor[reactorNum].getHotFluidProducedLastTick()))
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- elseif
- rhTable[i] == "REACTIVITY" then
- label(startColumn, row + 1, "%.0f%%", colors.yellow, tostring(reactor[reactorNum].getFuelReactivity()))
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- elseif
- rhTable[i] == "RF OUT" then
- if reactor[reactorNum].isActivelyCooled() then
- label(startColumn, row + 1, "%d RF/t", colors.red, "0")
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- else
- label(startColumn, row + 1, "%d RF/t", colors.green, tostring(reactor[reactorNum].getEnergyProducedLastTick()))
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- end
- elseif
- rhTable[i] == "STORED RF" then
- if reactor[reactorNum].isActivelyCooled() then
- label(startColumn, row + 1, "%d RF", colors.red, "0")
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- else
- label(startColumn, row + 1, "%d RF", colors.green, tostring(reactor[reactorNum].getEnergyStored()))
- startColumn = (startColumn + string.len(rhTable[i])) + spaces
- end
- end
- end
- end
- function turbineDataTable()
- for i = 1, #turbine do
- turbineSteamInput = turbine[turbineNum].getInputAmount()
- turbineCoolantOutput = turbine[turbineNum].getOutputAmount()
- turbineRotorSpeed = turbine[turbineNum].getRotorSpeed()
- turbineRotorMass = turbine[turbineNum].getRotorMass()
- turbineBladeEfficiency = turbine[turbineNum].getBladeEfficiency()
- turbineInductorState = turbine[turbineNum].getInductorEngaged()
- turbineCurrentEnergyOutput = turbine[turbineNum].getEnergyProducedLastTick()
- turbineEnergyStored = turbine[turbineNum].getEnergyStored()
- end
- startColumn = 2
- row = 28
- spaces = 5
- for i = 1, #thTable do
- if thTable[i] == "STEAM IN" then
- label(startColumn, row, "%d mB/t", nil, tostring(turbineSteamInput))
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- elseif
- thTable[i] == "COOLANT OUT" then
- label(startColumn, row, "%d mB/t", nil, tostring(turbineCoolantOutput))
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- elseif
- thTable[i] == "ROTOR SPEED" then
- label(startColumn, row, "%.1d RPM", nil, tostring(turbineRotorSpeed))
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- elseif
- thTable[i] == "ROTOR MASS" then
- label(startColumn, row, "%d", nil, tostring(turbineRotorMass))
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- elseif
- thTable[i] == "EFFICIENCY" then
- label(startColumn, row, "%.1d%%", nil, tostring(turbineBladeEfficiency))
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- elseif
- thTable[i] == "INDUCTOR STATE" then
- if turbineInductorState then
- label(startColumn, row, "%s", colors.lime, "ENGAGED")
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- else
- label(startColumn, row, "%s", colors.red, "DISENGAGED")
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- end
- elseif
- thTable[i] == "RF OUT" then
- label(startColumn, row, "%d", colors.lime, tostring(turbineCurrentEnergyOutput))
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- elseif
- thTable[i] == "STORED RF" then
- label(startColumn, row, "%d", colors.lime, tostring(turbineEnergyStored))
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- end
- end
- end
- --TURBINE AUTO EFFICIENCY MODE
- autoEfficiencyEnabled = false
- function autoEfficiency()
- if not autoEfficiencyEnabled then
- autoEfficiencyEnabled = false
- else
- autoEfficiencyEnabled = true
- for i = 1, #turbine do
- numBlades = turbine[i].getNumberOfBlades()
- flowRate = numBlades * 25
- turbine[i].setFluidFlowRateMax(flowRate)
- end
- end
- end
- function cycleEfficiencyMode()
- if autoEfficiencyEnabled then
- autoEfficiencyEnabled = false
- else
- if not autoEfficiencyEnabled then
- autoEfficiencyEnabled = true
- end
- end
- end
- function toggleAutoEfficiencyIndicator()
- if autoEfficiencyEnabled then
- gpu.setBackground(colors.lime)
- gpu.fill(149, 29, 10, 3, " ")
- label(153, 30, "ON", colors.white)
- gpu.setBackground(defaultBgColor)
- gpu.set(149, 28, "Efficiency")
- else
- gpu.setBackground(colors.red)
- gpu.fill(149, 29, 10, 3, " ")
- label(152, 30, "OFF", colors.pink)
- gpu.setBackground(defaultBgColor)
- gpu.set(149, 28, "Efficiency")
- end
- end
- function autoPowerCycle()
- if powerCycleActive then
- for i = 1, #turbine do
- if turbine[i].getEnergyStored() == powerOFF then
- turbine[i].setActive(false)
- end
- if turbine[i].getEnergyStored() < powerON then
- turbine[i].setActive(true)
- end
- end
- end
- end
- function autoPowerCycleControl()
- if powerCycleActive then
- powerCycleActive = false
- tpcStatus = false
- else
- powerCycleActive = true
- tpcStatus = true
- end
- end
- function toggleAutoPowerCycleIndicator()
- if powerCycleActive then
- gpu.setBackground(colors.lime)
- gpu.fill(120, 29, 10, 3, " ")
- label(124, 30, "ON", colors.white)
- gpu.setBackground(defaultBgColor)
- gpu.set(120, 28, "Auto Power")
- else
- gpu.setBackground(colors.red)
- gpu.fill(120, 29, 10, 3, " ")
- label(124, 30, "OFF", colors.pink)
- gpu.setBackground(defaultBgColor)
- gpu.set(120, 28, "Auto Power")
- end
- end
- function turbinePower()
- if turbine[turbineNum].getActive() then
- turbine[turbineNum].setActive(false)
- else
- turbine[turbineNum].setActive(true)
- end
- end
- function turbineStatus()
- if turbine[turbineNum].getActive() then
- gpu.set(119, 26, "Turbine Status: Active")
- else
- gpu.set(119, 26, "Turbine Status: Inactive")
- end
- end
- function totalReactorEnergyStored()
- rCap = 10000000
- reactorTotalEnergyStored = 0
- for i = 1, #reactor do
- reactorTotalEnergyStored = reactorTotalEnergyStored + reactor[i].getEnergyStored()
- end
- reactorEnergyPercentage = percent(reactorTotalEnergyStored, rCap * #reactor)
- end
- function totalTurbineEnergyStored()
- tCap = 1000000
- turbineTotalEnergyStored = 0
- for i = 1, #turbine do
- turbineTotalEnergyStored = turbineTotalEnergyStored + turbine[i].getEnergyStored()
- end
- turbineEnergyPercentage = percent(turbineTotalEnergyStored, tCap * #turbine)
- end
- function reactorSideBox() --Starts at column 119 & row 4
- colStart = 119
- rowStart = 4
- boxWidth = 159 - 119
- label(colStart + 4 , rowStart + 7, "REACTOR TOTAL CONTROL RODS LEVEL", colors.yellow)
- end
- function turbineSideBox() --Starts at column 119 & row 26
- startColumn = 119
- startRow = 27
- boxWidth = 159 - 119
- label(startColumn, startRow + 6, "[COMBINED TURBINE STORED ENERGY]", nil)
- totalTurbineEnergyStored()
- label(startColumn, startRow + 7, "Combined Energy: " .. turbineTotalEnergyStored .." RF", nil)
- label(startColumn, startRow + 8, "Maximum Storage: " .. 1000000 * #turbine .. " RF", nil)
- label(startColumn, startRow + 9, "To max capacity: " .. (1000000 * #turbine) - turbineTotalEnergyStored .. " RF", colors.red)
- label(startColumn, startRow + 16, "All Stored Energy: " .. reactorTotalEnergyStored + turbineTotalEnergyStored .. " RF", colors.lime)
- label(startColumn, startRow + 11, "[While Auto Power Mode Is Active]", nil)
- label(startColumn, startRow + 12, "Auto Power Off: 1000000 Stored RF", colors.red)
- label(startColumn, startRow + 13, "Auto Power On: 975000 Stored RF", colors.lime)
- total_r_RfOutput = 0
- for i = 1, #reactor - 1 do
- if not reactor[i].isActivelyCooled() then
- total_r_RfOutput = total_r_RfOutput + reactor[i].getEnergyProducedLastTick()
- end
- i = i + 1
- end
- total_t_RfOutput = 0
- for i = 1, #turbine do
- total_t_RfOutput = total_t_RfOutput + turbine[i].getEnergyProducedLastTick()
- i = i + 1
- end
- totalRfOutput = math.floor(total_r_RfOutput + total_t_RfOutput)
- label(startColumn, startRow + 17, "Total RF Output: " .. totalRfOutput .. " RF/t", colors.green)
- end
- function controlKeysTable()
- keyCol = 2
- keyRow = 46
- ckList = {"Exit", "Prev Reactor", "Next Reactor", "Prev Turbine", "Next Turbine", "Reactor Power", "Turbine Power", "Auto Power", "Auto Efficiency", "Eject Waste", "Eject Fuel", "Inductor"}
- label(keyCol, keyRow, "-- Program control keys --", colors.orange)
- for i = 1, #ckList do
- label(keyCol, keyRow + 1, ckList[i], colors.orange)
- keyCol = keyCol + string.len(ckList[i]) + 2
- end
- function half(value)
- return math.floor(value / 2)
- end
- keyVal = {"[q]", "[down]", "[up]", "[left]", "[right]", "[r]", "[t]", "[a]", "[e]", "[w]", "[f]", "[i]"}
- keyCol = 2
- keyRow = 46
- for x = 1, #keyVal do
- label((keyCol + half(string.len(ckList[x]))) - 2, keyRow + 2, keyVal[x], nil)
- keyCol = keyCol + string.len(ckList[x]) + 2
- end
- end
- function label(x, y, message, color, ...)
- local color = color or gpu.getForeground()
- local oldColor = gpu.getForeground()
- gpu.setForeground(color)
- term.setCursor(x, y)
- print(string.format(message, ...))
- gpu.setForeground(oldColor)
- end
- -- CONTROL RODS --
- function crWatchDog()
- rodLevel = 0
- local rods = {}
- local numRods = reactor[reactorNum].getNumberOfControlRods()
- for i = 1, numRods - 1 do
- rods[i] = reactor[reactorNum].getControlRodLevel(i)
- end
- for i = 1, #rods do
- rodLevel = rodLevel + rods[i]
- end
- rodLevel = rodLevel / #rods
- end
- function setControlRodLevel(operation, value)
- local setLevel = 0
- if operation == "addition" then
- if rodLevel < 100 then
- setLevel = rodLevel + value
- reactor[reactorNum].setAllControlRodLevels(0)
- reactor[reactorNum].setAllControlRodLevels(setLevel)
- end
- elseif
- operation == "subtraction" then
- if rodLevel > 0 then
- setLevel = rodLevel - value
- reactor[reactorNum].setAllControlRodLevels(0)
- reactor[reactorNum].setAllControlRodLevels(setLevel)
- end
- end
- end
- -- CAPTURE KEYBOARD EVENTS --
- function captureKeys(key)
- local event, address, _, key, _ = event.pull()
- if key == keyboard.keys.q then
- gpu.setBackground(defaultBgColor)
- term.setCursor(1,1)
- gpu.fill(1, 1, w, h, " ")
- running = false
- end
- if key == keyboard.keys.apostrophe then
- setControlRodLevel("addition", 10)
- buttonInsertActive = true
- end
- if key == keyboard.keys.slash then
- setControlRodLevel("subtraction", 10)
- buttonRetractActive = true
- end
- if key == keyboard.keys.up then
- place = reactorNum + 1
- if place > #reactor then
- reactorNum = 1
- else
- reactorNum = reactorNum + 1
- end
- end
- if key == keyboard.keys.down then
- place = reactorNum - 1
- if place < 1 then
- reactorNum = #reactor
- else
- reactorNum = reactorNum - 1
- end
- end
- if key == keyboard.keys.right then
- place = turbineNum + 1
- if place > #turbine then
- turbineNum = 1
- else
- turbineNum = turbineNum + 1
- end
- end
- if key == keyboard.keys.left then
- place = turbineNum - 1
- if place < 1 then
- turbineNum = #turbine
- else
- turbineNum = turbineNum - 1
- end
- end
- if key == keyboard.keys.a then
- autoPowerCycleControl()
- end
- if key == keyboard.keys.r then
- reactorPower()
- end
- if key == keyboard.keys.t then
- turbinePower()
- end
- if key == keyboard.keys.e then
- cycleEfficiencyMode()
- end
- if key == keyboard.keys.w then
- reactor[reactorNum].doEjectWaste()
- end
- if key == keyboard.keys.f then
- reactor[reactorNum].doEjectFuel()
- end
- if key == keyboard.keys.i then
- if turbine[turbineNum].getInductorEngaged() then
- turbine[turbineNum].setInductorEngaged(false)
- else
- turbine[turbineNum].setInductorEngaged(true)
- end
- end
- if key == keyboard.keys.numpad0 then
- interfaceColor = colors.orange
- elseif
- key == keyboard.keys.numpad1 then
- interfaceColor = colors.magenta
- elseif
- key == keyboard.keys.numpad2 then
- interfaceColor = colors.lightblue
- elseif
- key == keyboard.keys.numpad3 then
- interfaceColor = colors.silver
- elseif
- key == keyboard.keys.numpad4 then
- interfaceColor = colors.purple
- elseif
- key == keyboard.keys.numpad5 then
- interfaceColor = colors.pink
- elseif
- key == keyboard.keys.numpad6 then
- interfaceColor = colors.gray
- elseif
- key == keyboard.keys.numpad7 then
- interfaceColor = colors.lime
- elseif
- key == keyboard.keys.numpad8 then
- interfaceColor = colors.red
- elseif
- key == keyboard.keys.numpad9 then
- interfaceColor = colors.brown
- end
- end
- event.listen("key_down", captureKeys)
- -- START COLLECTING DATA IN REALTIME
- while running do
- drawInterface(interfaceColor)
- -- REACTOR & TURBINE VARIABLES FOR STATS
- if reactorAvailable then
- totalReactorEnergyStored()
- crWatchDog()
- outputRating = (100 - rodLevel)
- currentCoolantLevel = reactor[reactorNum].getCoolantAmount()
- coolantLevelMax = reactor[reactorNum].getCoolantAmountMax()
- curretFuelLevel = reactor[reactorNum].getFuelAmount()
- fuelLevelMax = reactor[reactorNum].getFuelAmountMax()
- fuelBurnRate = reactor[reactorNum].getFuelConsumedLastTick()
- currentSteamLevel = reactor[reactorNum].getHotFluidAmount()
- currentSteamLevelMax = reactor[reactorNum].getHotFluidAmountMax()
- currentSteamOutput = reactor[reactorNum].getHotFluidProducedLastTick()
- currentReactivity = reactor[reactorNum].getFuelReactivity()
- reactorEnergyStoredMax = 10000000
- currentEnergyStored = reactor[reactorNum].getEnergyStored()
- currentEnergyOutput = reactor[reactorNum].getEnergyProducedLastTick()
- reactorMainHeader()
- reactorLabels()
- reactorDataTable()
- reactorSideBox()
- crButtons()
- -- REACTOR METERS
- fillMeters(4, 21, 7, currentCoolantLevel, coolantLevelMax, colors.lightblue) --Reactor Coolant Meter
- fillMeters(56, 21, 7, curretFuelLevel, fuelLevelMax, colors.yellow) --Reactor Fuel Meter
- fillMeters(109, 21, 7, currentSteamLevel, currentSteamLevelMax, colors.white) --Reactor Steam Meter
- fillMeters(121, 22, 37, rodLevel, 100, colors.yellow) --Reactor Control Rod Meter
- end
- if turbineAvailable then
- totalTurbineEnergyStored()
- t_currentSteamLevel = turbine[turbineNum].getInputAmount()
- t_fluidAmountMax = turbine[turbineNum].getFluidAmountMax()
- t_coolantAmount = turbine[turbineNum].getOutputAmount()
- t_coolantAmountMax = 4000
- t_rfStored = turbineTotalEnergyStored
- t_rfMax = 1000000 * #turbine
- toggleAutoEfficiencyIndicator()
- toggleAutoPowerCycleIndicator()
- autoPowerCycle()
- turbineStatus()
- turbineMainHeader()
- turbineLabels()
- turbineDataTable()
- turbineSideBox()
- -- TURBINE AUTO EFFICIENCY MODE SETS THE TURBINE FLOW RATE FOR MAXIMUM EFFICIENCY
- autoEfficiency()
- -- TURBINE METERS
- fillMeters(4, 43, 7, t_currentSteamLevel, t_fluidAmountMax, colors.white) --Turbine Steam Meter
- fillMeters(56, 43, 7, t_coolantAmount, t_coolantAmountMax, colors.lightblue) --Turbine Coolant Out Meter
- fillMeters(109, 43, 7, t_rfStored, t_rfMax, colors.green) --Turbine RF Meter
- end
- controlKeysTable()
- os.sleep(refreshRate)
- term.clear()
- end
- event.ignore("key_down", captureKeys)
Add Comment
Please, Sign In to add comment