You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

107 lines
2.8 KiB

-- Reactor Control v0.2.4 (C) WarrickSothr
local component = require("component")
local term = require("term")
local event = require("event")
local keyboard = require("keyboard")
local side = require("sides")
local gpu = component.gpu
local br = component.br_reactor
local transposer = component.transposer
local tickCount = 0
local tickMinuteDivisor = 20
local minute = 0
local hour = 0
local fuelInputSide = side.left
local currentEnergyStorageTrendState = ""
local currentEnergyStorageTrend = 0
local currentEnergyStored = 9999999
local maxEnergyStored = 9990000
local running = true
local maxScreenWidth, maxScreenHeight = gpu.maxResolution()
local displayDivisor = 2
gpu.setResolution(maxScreenWidth/displayDivisor, maxScreenHeight/displayDivisor)
term.clear()
term.setCursorBlink(false)
local function keepTime()
tickCount = tickCount + 1
if tickCount >= tickMinuteDivisor then
minute = minute + 1
tickCount = 0
end
if minute >= 60 then
hour = hour + 1
minute = 0
end
end
local function populateLoopVariables()
local energyStorageTrend = br.getEnergyStored() - currentEnergyStored
if energyStorageTrend == 0 or currentEnergyStored >= maxEnergyStored then
currentEnergyStorageTrend = 0
currentEnergyStorageTrendState = "Stable"
elseif energyStorageTrend > 0 then
currentEnergyStorageTrend = 1
currentEnergyStorageTrendState = "Filling"
elseif energyStorageTrend < 0 then
currentEnergyStorageTrend = -1
currentEnergyStorageTrendState = "Draining"
else
currentEnergyStorageTrend = 0
currentEnergyStorageTrendState = "UNKNOWN"
end
currentEnergyStored = br.getEnergyStored()
end
local function printLine(s, ...)
term.clearLine()
term.write(s:format(...))
term.write("\n")
end
local function drawScreen()
term.setCursor(1,1)
printLine("Current Runtime: %d:%d", hour, minute)
printLine("Current Energy Output: %04.2f RF", br.getEnergyProducedLastTick())
printLine("Current Fuel Level: %d mB", br.getFuelAmount())
printLine("Total Energy Stored: %d RF", currentEnergyStored)
printLine("Current Energy Storage Trend: %s", currentEnergyStorageTrendState)
term.clearLine()
print()
end
local function onKeyDown(key)
if key == keyboard.keys.q then
running = false
end
end
while running do
keepTime()
populateLoopVariables()
drawScreen()
if tickCount %5 == 0 and currentEnergyStorageTrend < 0 then
transposer.transferItem(fuelInputSide, side.down, 1, 1)
end
local event, address, arg1, arg2, arg3 = event.pull(1)
if event== "key_down" then
onKeyDown(arg2)
end
end
term.clear()
term.setCursorBlink(true)
gpu.setResolution(maxScreenWidth, maxScreenHeight)