Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local t = peripheral.find("turbine")
- local r = peripheral.find("fissionReactor")
- local i = peripheral.find("inductionMatrix")
- local m = peripheral.find("monitor")
- local w, h = m.getSize()
- local onCooldown = false
- local energyFull = false
- local buttons = {}
- buttons[1] = {"Auto burnrate", true, colors.white}
- local function formatNumber(count, aNumber)
- return ("%0." .. count .. "f"):format(aNumber)
- end
- local function formatBigNumber(work, append, sizes)
- if (work == 0) then return work .. append end
- local i = math.floor(math.log(work) / math.log(1000)) + 1
- return tostring(string.format("%0.2f", (work / 1000 ^ (i - 1)))) .. sizes[i] .. append
- end
- local function formatEnergy(num)
- return formatBigNumber(num, "fe", {"","K","M","G","T"})
- end
- local function formatLiquid(num)
- return formatBigNumber(num, "B", {"m","","K","M","G"})
- end
- function printCenter(msg, line)
- local x = (w + 1) / 2 - #msg / 2
- m.setCursorPos(x, line)
- m.write(msg)
- end
- -- 0.1 burn = 3.3kFE
- local function calculateBurnRate()
- local inductionEnergyOut = i.getLastOutput()
- local outRate = inductionEnergyOut / 10000 / 3
- if outRate > r.getMaxBurnRate() then outRate = r.getMaxBurnRate() end
- return outRate
- end
- m.setTextScale(0.5)
- local function getCurrentStats()
- return {
- inductionEnergyPct = i.getEnergyFilledPercentage(),
- inductionEnergy = i.getEnergy(),
- inductionEnergyMax = i.getMaxEnergy(),
- inductionEnergyIn = i.getLastInput(),
- inductionEnergyOut = i.getLastOutput(),
- inductionEnergyRatio = i.getLastInput() / i.getLastOutput(),
- reactorSteamPct = r.getHeatedCoolantFilledPercentage(),
- reactorSteam = r.getHeatedCoolant().amount,
- reactorCoolantPct = r.getCoolantFilledPercentage(),
- reactorCoolant = r.getCoolant().amount,
- reactorTemp = r.getTemperature(),
- reactorBurnRate = r.getBurnRate(),
- reactorStatus = r.getStatus(),
- turbineSteamPct = t.getSteamFilledPercentage(),
- turbineSteam = t.getSteam(),
- turbineEnergyProd = t.getProductionRate(),
- }
- end
- local function checkReactor()
- local stats = getCurrentStats()
- local desiredAction = r.activate -- r.activate, r.scram, nothing, makeMeASandwitch
- if (stats.inductionEnergyPct > 0.95 and not energyFull)
- then
- desiredAction = r.scram
- energyFull = true
- end
- if (stats.inductionEnergyPct < 0.1 and energyFull)
- then
- desiredAction = r.activate
- energyFull = false
- end
- if (stats.reactorSteamPct > 0.9 or stats.reactorCoolantPct < 0.1 and not onCooldown)
- then
- desiredAction = r.scram
- onCooldown = true
- end
- if (stats.reactorSteamPct < 0.9 and stats.reactorCoolantPct > 0.9 and onCooldown)
- then
- desiredAction = r.activate
- onCooldown = false
- end
- if buttons[1][2] then
- r.setBurnRate(calculateBurnRate())
- end
- desiredAction()
- end
- local function updateMonitor()
- local stats = getCurrentStats()
- m.clear()
- m.setCursorPos(1, 1)
- m.write("Energy stored: " .. formatNumber(2, stats.inductionEnergyPct * 100) .. "%")
- m.setCursorPos(1, 2)
- m.write(" " .. formatEnergy(stats.inductionEnergy) .. " / " .. formatEnergy(stats.inductionEnergyMax))
- m.setCursorPos(1, 3)
- m.write(" " .. formatEnergy(stats.inductionEnergyIn) .. " in / " .. formatEnergy(stats.inductionEnergyOut) .. " out")
- m.setCursorPos(1, 4)
- m.write("Energy ratio: " .. stats.inductionEnergyRatio)
- m.setCursorPos(1, 6)
- m.write("Reactor burnrate:" .. stats.reactorBurnRate .. "mB/t")
- m.setCursorPos(1, 7)
- m.write("Reactor coolant: " .. formatNumber(2, stats.reactorCoolantPct * 100) .. "% (" .. formatLiquid(stats.reactorCoolant) .. ")")
- m.setCursorPos(1, 8)
- m.write("Reactor steam: " .. formatNumber(2, stats.reactorSteamPct * 100) .. "% (" .. formatLiquid(stats.reactorSteam) .. ")")
- m.setCursorPos(1, 9)
- m.write("Reactor temp: " .. formatNumber(2, stats.reactorTemp) .. "K")
- m.setCursorPos(1, 11)
- m.write("Turbine prod: " .. formatEnergy(stats.turbineEnergyProd) .. "")
- m.setCursorPos(1, 12)
- m.write("Turbine steam: " .. formatNumber(2, stats.turbineSteamPct * 100) .. "% (" .. formatLiquid(stats.turbineSteam) .. ")")
- height = 15
- for i = 1, #buttons do
- if buttons[i][2] == true then
- m.setBackgroundColor(colors.green)
- elseif buttons[i][2] == false then
- m.setBackgroundColor(colors.red)
- else
- m.setBackgroundColor(colors.lightGray)
- end
- printCenter("* *", i + height)
- printCenter(buttons[i][1], i+height)
- m.setBackgroundColor(colors.black)
- end
- end
- -- event, peripheral_name, x, y
- local function processButtons(event)
- height = 15
- for i = 1, #buttons do
- if event[4] == height + i then
- buttons[i][2] = not buttons[i][2]
- print(buttons[i][2])
- end
- end
- end
- local checkTimer = os.startTimer(0.5) --queue first timer in 1 second
- while true do
- local event = {os.pullEvent()}
- if event[1] == "monitor_touch" then
- processButtons(event)
- elseif event[1] == "timer" then
- if event[2] == checkTimer then --our check timer
- checkReactor()
- updateMonitor()
- checkTimer = os.startTimer(0.5) --start next timer for checks function in 1 second.
- end
- end
- end
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement