Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require "component"
- local keyboard = require "keyboard"
- local term = require "term"
- local os = require "os"
- local event = require "event"
- local gpu = component.gpu
- local turbine = {}
- local turbineAvailable
- local w, h = gpu.getResolution()
- defaultBgColour = gpu.getBackground()
- defaultFgColour = gpu.getForeground()
- local running = true
- local refreshRate = .8
- local thTable = {"STEAM IN", "COOLANT OUT", "ROTOR SPEED", "ROTOR MASS", "EFFICIENCY", "INDUCTOR STATE", "RF OUT", "STORED RF"}
- local turbineMaxSteamIn = 0
- local powerON = 975001 -- Set here where the turbines should reactivate after a shutdown
- local powerOFF = 1000000 -- Turbine max energy buffer. Turbines will shutdown
- --CLEAR THE SCREEN
- gpu.fill(1, 1, w, h, " ")
- -- COLOURS
- local colours = {}
- colours.white = 0xFFFFFF
- colours.orange = 0xFFA500
- colours.magenta = 0xFF00FF
- colours.lightblue = 0x00AEEF
- colours.yellow = 0xFFFF00
- colours.lime = 0x00FF00
- colours.pink = 0xFFC0CB
- colours.gray = 0x555555
- colours.grey = 0x555555
- colours.silver = 0xAAAAAA
- colours.cyan = 0x00FFFF
- colours.purple = 0x800080
- colours.blue = 0x0000FF
- colours.brown = 0x603913
- colours.green = 0x008000
- colours.red = 0xFF0000
- colours.black = 0x000000
- local interfaceColour = colours.gray
- if component.isAvailable("br_turbine") then
- turbineAvailable = true
- else
- turbineAvailable = false
- end
- if 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
- function label(x, y, message, colour, ...)
- local colour = colour or gpu.getForeground()
- local oldColour = gpu.getForeground()
- end
- --Turbines
- if turbineAvailable then
- local i = 1
- for address, type in component.list("br_turbine") do
- turbine[i] = component.proxy(address)
- i = i + 1
- end
- else
- label(1, 29, "%s", colours.red, "[ ! ] NO TURBINES CONNECTED [ ! ]")
- end
- function drawInterface(colour)
- gpu.setBackground(colour)
- 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(defaultBgColour)
- 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", colours.lime, "ENGAGED")
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- else
- label(startColumn, row, "%s", colours.red, "DISENGAGED")
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- end
- elseif
- thTable[i] == "RF OUT" then
- label(startColumn, row, "%d", colours.lime, tostring(turbineCurrentEnergyOutput))
- startColumn = (startColumn + string.len(thTable[i])) + spaces
- elseif
- thTable[i] == "STORED RF" then
- label(startColumn, row, "%d", colours.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(colours.lime)
- gpu.fill(149, 29, 10, 3, " ")
- label(153, 30, "ON", colours.white)
- gpu.setBackground(defaultBgColour)
- gpu.set(149, 28, "Efficiency")
- else
- gpu.setBackground(colours.red)
- gpu.fill(149, 29, 10, 3, " ")
- label(152, 30, "OFF", colours.pink)
- gpu.setBackground(defaultBgColour)
- 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(colours.lime)
- gpu.fill(120, 29, 10, 3, " ")
- label(124, 30, "ON", colours.white)
- gpu.setBackground(defaultBgColour)
- gpu.set(120, 28, "Auto Power")
- else
- gpu.setBackground(colours.red)
- gpu.fill(120, 29, 10, 3, " ")
- label(124, 30, "OFF", colours.pink)
- gpu.setBackground(defaultBgColour)
- 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 percent(curValue, maxValue)
- return (curValue / maxValue) * 100
- 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 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", colours.red)
- label(startColumn, startRow + 16, "All Stored Energy: " .. reactorTotalEnergyStored + turbineTotalEnergyStored .. " RF", colours.lime)
- label(startColumn, startRow + 11, "[While Auto Power Mode Is Active]", nil)
- label(startColumn, startRow + 12, "Auto Power Off: 1000000 Stored RF", colours.red)
- label(startColumn, startRow + 13, "Auto Power On: 975000 Stored RF", colours.lime)
- total_r_RfOutput = 0
- for i = 1, #turbine do
- total_t_RfOutput = total_t_RfOutput + turbine[i].getEnergyProducedLastTick()
- i = i + 1
- end
- totalRfOutput = math.floor(total_t_RfOutput)
- label(startColumn, startRow + 17, "Total RF Output: " .. totalRfOutput .. " RF/t", colours.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 --", colours.orange)
- for i = 1, #ckList do
- label(keyCol, keyRow + 1, ckList[i], colours.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
- -- START COLLECTING DATA IN REALTIME
- while running do
- drawInterface(interfaceColour)
- 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, colours.white) --Turbine Steam Meter
- fillMeters(56, 43, 7, t_coolantAmount, t_coolantAmountMax, colours.lightblue) --Turbine Coolant Out Meter
- fillMeters(109, 43, 7, t_rfStored, t_rfMax, colours.green) --Turbine RF Meter
- end
- end
- os.sleep(refreshRate)
- term.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement