Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Draconic Control v16.0f [xSMT] [T3 autoflux | slice probe]
- -- Based on vpLUH33Y / v16.0a and the v16.0b test build.
- -- This build controls against the same shield-charge basis shown by the DE GUI.
- --
- -- Changes:
- -- * Full DE-required field input; no "- info.fieldDrainRate" on input command.
- -- * Current Field is calculated on the same shield-charge basis used by the DE GUI.
- -- * Flux gate autodetect is restored to the T3Zucygs/v15.2 startup behavior.
- -- * Control loop is read -> calculate -> write gates -> optional slice record -> short yield.
- -- * Grab Slice no longer calls getReactorInfo() or sleeps from the button thread.
- -- It asks the primary control loop to record four consecutive control-pass samples.
- -- * Main control buttons are on the right side so they do not overlap the table.
- local component = require("component")
- local event = require("event")
- local term = require("term")
- local thread = require("thread")
- local unicode = require("unicode")
- local gpu = component.gpu
- local screen = component.screen
- local function clamp(v, lo, hi)
- if v ~= v then return lo end
- if v < lo then return lo end
- if v > hi then return hi end
- return v
- end
- local function pct_to_frac(pct)
- return (tonumber(pct) or 0) / 100
- end
- local function safe_div(a, b, fallback)
- if not b or b == 0 then return fallback or 0 end
- return a / b
- end
- local function fmt_rf(v)
- v = tonumber(v) or 0
- if math.abs(v) >= 1000000000 then
- return string.format("%.3f GRF/t", v / 1000000000)
- elseif math.abs(v) >= 1000000 then
- return string.format("%.3f MRF/t", v / 1000000)
- elseif math.abs(v) >= 1000 then
- return string.format("%.3f kRF/t", v / 1000)
- else
- return string.format("%.1f RF/t", v)
- end
- end
- local function clear()
- term.clear()
- term.setCursor(1, 1)
- end
- local tArgs = {...}
- if tostring(tArgs[1]) == "-h" then
- clear()
- print("Draconic Control v16.0f [xSMT | T3 autoflux | slice probe]")
- print("dc16d [O] [T] [F] [M]")
- print()
- print("[O] Reactor Output Multiplier, usually 1")
- print("[T] Desired Temperature, usually 8000")
- print("[F] Desired Field Strength as displayed percent")
- print(" Example: 0.15 means 0.15%, internally 0.0015")
- print("[M] 1 = Simple GUI, 2 = Developer GUI, 3 = Text only")
- os.exit()
- end
- local reactorOutputMultiplier = tonumber(tArgs[1]) or 1
- local idealTemp = tonumber(tArgs[2]) or 8000
- local idealFieldPercent = tonumber(tArgs[3]) or 15
- local Mode = tonumber(tArgs[4]) or 1
- local chaosMode = 0
- local eventLoop = true
- local info = nil
- local statusLine = "T3-style flux autodetect active; use Swap Flux Gates if reversed."
- local coreSat = 0
- local convLVL = 0
- local targetTemp50 = 0
- local targetTempResist = 0
- local targetTempExpo = 0
- local targetNegCSat = 0
- local targetCoreSat = 0
- local targetSat = 0
- local saturationError = 0
- local outputNeeded = 0
- local tempDrainFactor = 0
- local baseMaxRFt = 0
- local calculatedFieldDrain = 0
- local fieldDrainUsed = 0
- local fieldNegPercent = 1
- local requiredInput = 0
- local fieldStrengthError = 0
- local inputCommand = 0
- local drainPercentThisTick = 0
- local currentFieldPercent = 0
- local postDrainFieldPercent = 0
- local deviation = 0
- local fuelConversionRate = 0
- local fuelMeasure = " nb/t"
- local fuelUseRate = 0
- local fuelAccel = 0
- local tempChangeRate = 0
- local tempAccel = 0
- local secondsToExpire = 0
- local tempDrain = 0
- local burnStage = "?"
- local cutoffTemp = 19500
- local cutoffFieldPercent = math.max(0.05, idealFieldPercent * 0.50)
- local lastSlice = {
- label = "none",
- a = nil, b = nil, c = nil, d = nil,
- drain = nil,
- max = nil,
- msg = "Slice: not grabbed yet"
- }
- -- Slice probe state. The button only sets sliceRequested.
- -- The primary control loop records samples immediately after gate writes, so the probe
- -- does not sleep/yield between reactor read and gate update.
- local sliceRequested = false
- local sliceActive = false
- local sliceIndex = 0
- local sliceSamples = {}
- local ratioX, ratioY = screen.getAspectRatio()
- local maxX, maxY = gpu.maxResolution()
- gpu.setResolution(math.min(ratioX * 55, maxX), math.min(ratioY * 25, maxY))
- clear()
- if not component.isAvailable("draconic_reactor") then
- print("Reactor not connected. Please connect computer to reactor with an Adapter block.")
- os.exit()
- end
- local reactor = component.draconic_reactor
- info = reactor.getReactorInfo()
- local fluxGates = {}
- for address in pairs(component.list("flux_gate")) do
- fluxGates[#fluxGates + 1] = address
- end
- if #fluxGates < 2 then
- print("Not enough flux gates connected; connect inflow and outflow flux gates with Adapter blocks.")
- os.exit()
- end
- local inputFlux = component.proxy(fluxGates[1])
- local outputFlux = component.proxy(fluxGates[2])
- if not inputFlux or not outputFlux then
- print("Could not proxy both flux gates.")
- os.exit()
- end
- inputFlux.setOverrideEnabled(true)
- outputFlux.setOverrideEnabled(true)
- print("Input and Output Flux Gates Available")
- local function autodetectFluxGatesT3()
- -- T3Zucygs/v15.2 style auto gate setup.
- -- This intentionally mirrors the older startup behavior instead of the
- -- inverted pulse detector from v16.0e.
- reactor.chargeReactor()
- local satOne = info.energySaturation
- local fieldOne = info.fieldStrength
- inputFlux.setFlowOverride(1.0)
- os.sleep(0.1)
- local satTwo = info.energySaturation
- local fieldTwo = info.fieldStrength
- inputFlux.setFlowOverride(0.0)
- reactor.stopReactor()
- if satTwo <= satOne or fieldTwo <= fieldOne then
- local oldAddr = inputFlux.address
- inputFlux = component.proxy(outputFlux.address)
- outputFlux = component.proxy(oldAddr)
- inputFlux.setOverrideEnabled(true)
- outputFlux.setOverrideEnabled(true)
- statusLine = "T3 autoflux swapped gates; use Swap Flux Gates if reversed."
- else
- statusLine = "T3 autoflux kept gates; use Swap Flux Gates if reversed."
- end
- end
- autodetectFluxGatesT3()
- print("Input and Output Flux Gates Set")
- local function resetNormalTargets()
- chaosMode = 0
- idealFieldPercent = tonumber(tArgs[3]) or idealFieldPercent
- idealTemp = tonumber(tArgs[2]) or idealTemp
- cutoffTemp = 19500
- cutoffFieldPercent = math.max(0.05, idealFieldPercent * 0.50)
- statusLine = "Normal raw OC field control active."
- end
- local function modifyTemp(offset)
- local newTemp = idealTemp + offset
- if newTemp > 8000 and Mode == 1 then
- newTemp = 8000
- elseif newTemp > 15000 then
- newTemp = 15000
- elseif newTemp < 2000 then
- newTemp = 2000
- end
- idealTemp = newTemp
- end
- local function modifyField(offset)
- local newField = idealFieldPercent + offset
- if chaosMode == 1 and newField < 99 then
- newField = 99
- elseif newField > 99 then
- newField = 99
- elseif Mode == 2 then
- newField = math.max(0.005, newField)
- else
- newField = math.max(0.05, newField)
- end
- idealFieldPercent = newField
- cutoffFieldPercent = math.max(0.025, idealFieldPercent * 0.50)
- end
- local function getIdealFieldFraction()
- return clamp(pct_to_frac(idealFieldPercent), 0.0000001, 0.99)
- end
- local function pctFromSnapshot(s)
- if not s then return 0 end
- return safe_div(s.fieldStrength or 0, s.maxFieldStrength or 0, 0) * 100
- end
- local function grabSlice()
- -- Do not call reactor.getReactorInfo() here. Do not sleep here.
- -- The primary control loop will record four consecutive post-write control-pass samples.
- sliceRequested = true
- statusLine = "Slice requested; primary loop will record A/B/C/D without blocking control."
- end
- local function recordSliceSample()
- if sliceRequested and not sliceActive then
- sliceRequested = false
- sliceActive = true
- sliceIndex = 0
- sliceSamples = {}
- statusLine = "Slice capture active; recording consecutive control-pass samples."
- end
- if sliceActive and info then
- sliceIndex = sliceIndex + 1
- sliceSamples[sliceIndex] = {
- raw = postDrainFieldPercent,
- drain = drainPercentThisTick,
- input = inputCommand,
- output = outputNeeded
- }
- if sliceIndex >= 4 then
- sliceActive = false
- lastSlice.a = sliceSamples[1] and sliceSamples[1].raw or 0
- lastSlice.b = sliceSamples[2] and sliceSamples[2].raw or 0
- lastSlice.c = sliceSamples[3] and sliceSamples[3].raw or 0
- lastSlice.d = sliceSamples[4] and sliceSamples[4].raw or 0
- lastSlice.drain = drainPercentThisTick
- lastSlice.max = info.maxFieldStrength or 0
- lastSlice.label = string.format("A %.6f B %.6f C %.6f D %.6f", lastSlice.a, lastSlice.b, lastSlice.c, lastSlice.d)
- lastSlice.msg = string.format("Slice A/B/C/D raw: %.6f / %.6f / %.6f / %.6f | drain %.6f%%", lastSlice.a, lastSlice.b, lastSlice.c, lastSlice.d, lastSlice.drain)
- statusLine = lastSlice.msg
- else
- statusLine = string.format("Slice capture active: %d/4 samples recorded.", sliceIndex)
- end
- end
- end
- local function updateReactorMath()
- info = reactor.getReactorInfo()
- targetTemp50 = math.min((idealTemp / 10000) * 50, 99)
- coreSat = safe_div(info.energySaturation, info.maxEnergySaturation, 0)
- convLVL = safe_div(info.fuelConversion, info.maxFuelConversion, 0) * 1.3 - 0.3
- targetTempResist = ((targetTemp50 ^ 4) / (100 - targetTemp50))
- targetTempExpo = -(targetTempResist * convLVL) - 1000 * convLVL + targetTempResist
- local term1 = 1334.1 - (3 * targetTempExpo)
- local term2 = (1200690 - (2700 * targetTempExpo)) ^ 2
- local term3Inner = (-1350 * targetTempExpo) + (((-4 * term1 ^ 3 + term2) ^ 0.5) / 2) + 600345
- if term3Inner < 0 then
- targetNegCSat = 1
- targetCoreSat = 0.99
- else
- local term3 = term3Inner ^ (1 / 3)
- if term3 == 0 then
- targetNegCSat = 1
- else
- targetNegCSat = -(term1 / (3 * term3)) - (term3 / 3)
- end
- targetCoreSat = clamp(1 - (targetNegCSat / 99), 0.01, 0.99)
- end
- targetSat = targetCoreSat * info.maxEnergySaturation
- saturationError = info.energySaturation - targetSat
- if info.temperature > 8000 then
- tempDrainFactor = 1 + ((info.temperature - 8000) ^ 2 * 0.0000025)
- elseif info.temperature > 2000 then
- tempDrainFactor = 1
- elseif info.temperature > 1000 then
- tempDrainFactor = (info.temperature - 1000) / 1000
- else
- tempDrainFactor = 0
- end
- baseMaxRFt = (info.maxEnergySaturation / 1000) * reactorOutputMultiplier * 1.5
- calculatedFieldDrain = math.min(
- tempDrainFactor * math.max(0.01, (1 - coreSat)) * (baseMaxRFt / 10.923556),
- 2147000000
- )
- fieldDrainUsed = tonumber(info.fieldDrainRate) or calculatedFieldDrain
- local idealField = getIdealFieldFraction()
- fieldNegPercent = math.max(0.0000001, 1 - idealField)
- requiredInput = math.min(fieldDrainUsed / fieldNegPercent, info.maxFieldStrength)
- drainPercentThisTick = safe_div(fieldDrainUsed, info.maxFieldStrength, 0) * 100
- postDrainFieldPercent = safe_div(info.fieldStrength, info.maxFieldStrength, 0) * 100
- currentFieldPercent = clamp(postDrainFieldPercent + drainPercentThisTick, 0, 100)
- local targetFieldStrength = math.max(0, (info.maxFieldStrength * idealField) - fieldDrainUsed)
- fieldStrengthError = targetFieldStrength - info.fieldStrength
- deviation = math.abs(currentFieldPercent - idealFieldPercent)
- outputNeeded = clamp(math.min(saturationError, info.maxEnergySaturation / 40), 0, info.maxEnergySaturation / 40)
- -- Full required input plus correction. Do not subtract fieldDrainRate.
- inputCommand = clamp(requiredInput + fieldStrengthError + 1, 0, info.maxFieldStrength)
- end
- local function primaryCalculations()
- while eventLoop do
- -- Critical path: read -> calculate -> write gates.
- -- No sleep/yield between getReactorInfo() and setFlowOverride().
- updateReactorMath()
- if info.status == "running" then
- outputFlux.setFlowOverride(outputNeeded)
- inputFlux.setFlowOverride(inputCommand)
- elseif info.status == "warming_up" then
- outputFlux.setFlowOverride(0)
- inputFlux.setFlowOverride(550000000)
- elseif info.status == "stopping" then
- outputFlux.setFlowOverride(0)
- inputFlux.setFlowOverride(requiredInput)
- else
- outputFlux.setFlowOverride(0)
- end
- -- Probe records after gate writes, from cached values, without extra reactor calls.
- recordSliceSample()
- -- Cooperative yield only after gates are already updated.
- -- Keep this small but nonzero so GUI/input threads do not get starved.
- os.sleep(0.05)
- end
- end
- local function secondaryCalculations()
- local oldTemp = nil
- local oldTempRate = nil
- local oldFuel = nil
- local oldUseRate = nil
- while eventLoop do
- if info and info.status == "running" then
- if info.temperature > cutoffTemp then
- print("Reactor Too Hot, shutting down")
- reactor.stopReactor()
- end
- if currentFieldPercent < cutoffFieldPercent then
- print("Reactor Field Below Cutoff, failsafe activated, shutting down")
- reactor.stopReactor()
- end
- if ((1 - info.fuelConversion / info.maxFuelConversion) * 100) < 0.2 then
- print("Reactor Fuel Low, Shutting Down")
- reactor.stopReactor()
- end
- end
- if info then
- oldTemp = oldTemp or info.temperature
- local currentTemp = info.temperature
- oldTempRate = oldTempRate or (currentTemp - oldTemp)
- tempChangeRate = currentTemp - oldTemp
- tempAccel = tempChangeRate - oldTempRate
- if tempAccel == 0 then tempAccel = 0.001 end
- oldTemp = currentTemp
- oldTempRate = tempChangeRate
- oldFuel = oldFuel or (info.maxFuelConversion - info.fuelConversion)
- local currentFuel = (info.maxFuelConversion - info.fuelConversion)
- oldUseRate = oldUseRate or math.max(info.fuelConversionRate * 20, 0.1)
- fuelUseRate = math.max(info.fuelConversionRate * 20, 0.1)
- fuelAccel = math.max(fuelUseRate - oldUseRate, 0.1)
- oldFuel = currentFuel
- oldUseRate = fuelUseRate
- if info.fuelConversionRate > 999999 then
- fuelConversionRate = info.fuelConversionRate / 1000000
- fuelMeasure = " mb/t"
- elseif info.fuelConversionRate > 249999 then
- fuelConversionRate = ((info.fuelConversionRate / (info.maxFuelConversion * 1000000)) * 2000)
- fuelMeasure = " %%/s"
- elseif info.fuelConversionRate > 999 then
- fuelConversionRate = info.fuelConversionRate / 1000
- fuelMeasure = " " .. unicode.char(956) .. "b/t"
- else
- fuelConversionRate = info.fuelConversionRate
- fuelMeasure = " nb/t"
- end
- if info.fuelConversionRate < 1 then
- tempDrain = math.max((info.temperature - 2000) / 0.4, 0)
- else
- tempDrain = 1
- end
- local fuelRemainPct = (1 - info.fuelConversion / info.maxFuelConversion) * 100
- if fuelRemainPct > 20 then burnStage = "H"
- elseif fuelRemainPct > 15 then burnStage = "He"
- elseif fuelRemainPct > 10 then burnStage = "C"
- elseif fuelRemainPct > 8 then burnStage = "Ne"
- elseif fuelRemainPct > 5.5 then burnStage = "O"
- elseif fuelRemainPct > 2.5 then burnStage = "Si"
- elseif fuelRemainPct > 1 then burnStage = "Fe"
- else burnStage = "Spent" end
- secondsToExpire = (info.maxFuelConversion - info.fuelConversion) / math.max(info.fuelConversionRate * 0.00002, 0.00001)
- end
- os.sleep(0.1)
- end
- end
- local adj_button_width = 19
- local tempOffsetX = 62
- local tempOffsetY = 2
- local fieldOffsetX = tempOffsetX + adj_button_width + 2
- local fieldOffsetY = 2
- local controlX = fieldOffsetX + adj_button_width + 3
- local buttons = {}
- local function buildButtons()
- buttons = {
- startButton = {
- x = controlX, y = 13, width = 18, height = 1, text = "Start", textcolor = 0x0000AA,
- action = function()
- if info.status == "cooling" or info.status == "cold" then
- resetNormalTargets()
- reactor.chargeReactor()
- elseif info.status == "stopping" then
- resetNormalTargets()
- reactor.activateReactor()
- end
- end,
- condition = function() return info.status ~= "running" and info.status ~= "warming_up" end
- },
- shutdownButton = {
- x = controlX, y = 13, width = 18, height = 1, text = "Shutdown", textcolor = 0xAA0000,
- action = function()
- resetNormalTargets()
- reactor.stopReactor()
- end,
- condition = function() return info.status == "running" or info.status == "warming_up" end
- },
- sliceButton = {
- x = controlX, y = 15, width = 18, height = 1, text = "Grab Slice", textcolor = 0x005555,
- action = function() grabSlice() end,
- condition = function() return info.status == "running" or info.status == "warming_up" or info.status == "stopping" end
- },
- switchGates = {
- x = controlX, y = 17, width = 18, height = 1, text = "Swap Flux Gates",
- action = function()
- local oldAddr = inputFlux.address
- inputFlux = component.proxy(outputFlux.address)
- outputFlux = component.proxy(oldAddr)
- inputFlux.setOverrideEnabled(true)
- outputFlux.setOverrideEnabled(true)
- statusLine = "Flux gates swapped manually."
- end
- },
- chaosMode = {
- x = controlX, y = 19, width = 18, height = 1, text = " Chaos Mode", textcolor = 0x800080,
- action = function()
- if chaosMode == 0 then
- chaosMode = 1
- cutoffTemp = 19750
- idealFieldPercent = 99
- cutoffFieldPercent = 5
- idealTemp = 55537.78
- statusLine = "Chaos Mode active. This is supposed to be cursed."
- else
- resetNormalTargets()
- end
- end,
- condition = function() return Mode == 2 and info.status == "running" end
- },
- forceExit = {
- x = 158, y = 1, width = 3, height = 1, text = " X ", textcolor = 0xB00000,
- action = function()
- inputFlux.setFlowOverride(250000)
- outputFlux.setFlowOverride(0)
- resetNormalTargets()
- reactor.stopReactor()
- eventLoop = false
- end
- },
- tempMax = {x=tempOffsetX, y=tempOffsetY, width=adj_button_width, height=1, text="Maximum", textcolor=0x552222, action=function() idealTemp = 8000 end},
- tempPThousand = {x=tempOffsetX, y=tempOffsetY+2, width=adj_button_width, height=1, text="+1000", textcolor=0x552222, action=function() modifyTemp(1000) end},
- tempPHundred = {x=tempOffsetX, y=tempOffsetY+4, width=adj_button_width, height=1, text="+100", textcolor=0x552222, action=function() modifyTemp(100) end},
- tempPTen = {x=tempOffsetX, y=tempOffsetY+6, width=adj_button_width, height=1, text="+10", textcolor=0x552222, action=function() modifyTemp(10) end},
- tempPOne = {x=tempOffsetX, y=tempOffsetY+8, width=adj_button_width, height=1, text="+1", textcolor=0x552222, action=function() modifyTemp(1) end},
- tempMOne = {x=tempOffsetX, y=tempOffsetY+12, width=adj_button_width, height=1, text="-1", textcolor=0x552222, action=function() modifyTemp(-1) end},
- tempMTen = {x=tempOffsetX, y=tempOffsetY+14, width=adj_button_width, height=1, text="-10", textcolor=0x552222, action=function() modifyTemp(-10) end},
- tempMHundred = {x=tempOffsetX, y=tempOffsetY+16, width=adj_button_width, height=1, text="-100", textcolor=0x552222, action=function() modifyTemp(-100) end},
- tempMThousand = {x=tempOffsetX, y=tempOffsetY+18, width=adj_button_width, height=1, text="-1000", textcolor=0x552222, action=function() modifyTemp(-1000) end},
- tempMin = {x=tempOffsetX, y=tempOffsetY+20, width=adj_button_width, height=1, text="Minimum", textcolor=0x552222, action=function() modifyTemp(-20000) end},
- fieldPTen = {x=fieldOffsetX, y=fieldOffsetY+1, width=adj_button_width, height=1, text="+10", textcolor=0x222299, action=function() modifyField(10) end},
- fieldPOne = {x=fieldOffsetX, y=fieldOffsetY+3, width=adj_button_width, height=1, text="+1", textcolor=0x222299, action=function() modifyField(1) end},
- fieldPTenth = {x=fieldOffsetX, y=fieldOffsetY+5, width=adj_button_width, height=1, text="+0.1", textcolor=0x222299, action=function() modifyField(0.1) end},
- fieldPThou = {x=fieldOffsetX, y=fieldOffsetY+7, width=adj_button_width, height=1, text="+0.005", textcolor=0x222299, action=function() modifyField(0.005) end},
- fieldMThou = {x=fieldOffsetX, y=fieldOffsetY+13, width=adj_button_width, height=1, text="-0.005", textcolor=0x222299, action=function() modifyField(-0.005) end},
- fieldMTenth = {x=fieldOffsetX, y=fieldOffsetY+15, width=adj_button_width, height=1, text="-0.1", textcolor=0x222299, action=function() modifyField(-0.1) end},
- fieldMOne = {x=fieldOffsetX, y=fieldOffsetY+17, width=adj_button_width, height=1, text="-1", textcolor=0x222299, action=function() modifyField(-1) end},
- fieldMTen = {x=fieldOffsetX, y=fieldOffsetY+19, width=adj_button_width, height=1, text="-10", textcolor=0x222299, action=function() modifyField(-10) end}
- }
- end
- buildButtons()
- local function writeRows(rows, left, spacing)
- for i, v in ipairs(rows) do
- term.setCursor(left, i * spacing)
- term.write(v)
- end
- end
- local function drawButton(button)
- if button.condition and not button.condition() then return end
- local centerColor = 0xBBBBBB
- local highlightColor = 0xCCCCCC
- local lowlightColor = 0x808080
- if button.depressed then
- centerColor = 0xAAAAAA
- highlightColor = 0x707070
- lowlightColor = 0xBBBBBB
- button.depressed = button.depressed - 1
- if button.depressed <= 0 then button.depressed = nil end
- end
- gpu.setForeground(0x000000)
- gpu.setBackground(centerColor)
- gpu.fill(button.x, button.y, button.width, button.height, " ")
- if button.width > 1 and button.height > 1 then
- gpu.setBackground(lowlightColor)
- gpu.fill(button.x + 1, button.y + button.height - 1, button.width - 1, 1, " ")
- gpu.fill(button.x + button.width - 1, button.y, 1, button.height, " ")
- gpu.setBackground(highlightColor)
- gpu.fill(button.x, button.y, 1, button.height, " ")
- gpu.fill(button.x, button.y, button.width, 1, " ")
- end
- gpu.setBackground(centerColor)
- if button.textcolor then gpu.setForeground(button.textcolor) end
- term.setCursor(button.x + math.floor(button.width / 2 - #button.text / 2), button.y + math.floor(button.height / 2))
- term.write(button.text)
- end
- local function drawGUI()
- os.sleep(1)
- while eventLoop do
- if term.isAvailable() and Mode ~= 3 and info then
- local left_margin = 2
- local spacing = 1
- local values = {
- "Draconic Control™ [v16.0f xSMT | gui-field-sync]",
- " ",
- "┌──────────────────Reactor Statistics────────────────────┐",
- string.format("│Status: │ %32s │", tostring(info.status)),
- string.format("│Time Until Refuel:│ %5.0fd, %2.0fh, %2.0fm, %2.0fs │", secondsToExpire/86400, secondsToExpire/3600 % 24, secondsToExpire/60 % 60, secondsToExpire % 60),
- string.format("│Time Until Cool: │ %5.0fd, %2.0fh, %2.0fm, %2.0fs │", tempDrain/86400, tempDrain/3600 % 24, tempDrain/60 % 60, tempDrain % 60),
- string.format("│Ideal Field: │ %26.2f%% │", idealFieldPercent),
- string.format("│Current Field: │ %26.2f%% │", currentFieldPercent),
- string.format("│Field Deviation: │ %26.3f%% │", deviation),
- "├──────────────────┼──────────────────────────────────┤",
- string.format("│Slice A Raw: │ %26.6f%% │", lastSlice.a or 0),
- string.format("│Slice B/C/D Raw: │ %8.6f / %8.6f / %8.6f │", lastSlice.b or 0, lastSlice.c or 0, lastSlice.d or 0),
- "├──────────────────┼──────────────────────────────────┤",
- string.format("│Fuel Remaining: │ %26.3f%% │", ((1 - info.fuelConversion / info.maxFuelConversion) * 100)),
- string.format("│Fuel Use Rate: │ %22.3f%s │", fuelConversionRate, fuelMeasure),
- "├──────────────────┼──────────────────────────────────┤",
- string.format("│Temperature: │ %10.1f°c [%10.1f°f] │", info.temperature, ((info.temperature * 1.8) + 32)),
- string.format("│Ideal Temp: │ %10.1f°c [%10.1f°f] │", idealTemp, ((idealTemp * 1.8) + 32)),
- string.format("│Cutoff Field: │ %26.3f%% │", cutoffFieldPercent),
- "├──────────────────┼──────────────────────────────────┤",
- string.format("│Field Input Need: │ %32s │", fmt_rf(requiredInput)),
- string.format("│Input Gate Set: │ %32s │", fmt_rf(inputCommand)),
- string.format("│Energy Output: │ %32s │", fmt_rf(outputFlux.getFlow())),
- "└──────────────────┴──────────────────────────────────┘",
- " " .. statusLine,
- " "
- }
- local values2 = {
- " ", " ", " ", " [Developer]",
- string.format("CoreSat: %.6f", coreSat),
- string.format("ConvLVL: %.6f", convLVL),
- string.format("TargetCoreSat: %.6f", targetCoreSat),
- string.format("TargetSat: %.0f", targetSat),
- string.format("SaturationError: %.0f", saturationError),
- string.format("FieldDrainReported: %.0f RF/t", tonumber(info.fieldDrainRate) or 0),
- string.format("FieldDrainCalculated: %.0f RF/t", calculatedFieldDrain),
- string.format("FieldDrainUsed: %.0f RF/t", fieldDrainUsed),
- string.format("TempDrainFactor: %.6f", tempDrainFactor),
- string.format("FieldNegPercent(gui target): %.9f", fieldNegPercent),
- string.format("RequiredInput(total): %.0f RF/t", requiredInput),
- string.format("FieldStrengthError: %.0f RF", fieldStrengthError),
- string.format("InputCommand: %.0f RF/t", inputCommand),
- string.format("PostDrainField: %.6f%%", postDrainFieldPercent),
- string.format("DrainThisTick: %.6f%%", drainPercentThisTick),
- string.format("Slice: %s", lastSlice.label or "none"),
- string.format("Burn Stage: %s", burnStage),
- "Input Gate: " .. tostring(inputFlux.address),
- "Output Gate: " .. tostring(outputFlux.address)
- }
- term.clear()
- if Mode == 2 then writeRows(values2, 100, spacing) end
- writeRows(values, left_margin, spacing)
- term.setCursor(tempOffsetX, tempOffsetY + 10)
- term.write("Reactor Temperature")
- term.setCursor(fieldOffsetX + 1, fieldOffsetY + 10)
- term.write(" Field Strength")
- for _, button in pairs(buttons) do drawButton(button) end
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFFFFFF)
- elseif term.isAvailable() and Mode == 3 and info then
- local rows = {
- string.format("Status: %s", tostring(info.status)),
- string.format("Ideal Field: %.2f%%", idealFieldPercent),
- string.format("Current Field: %.2f%%", currentFieldPercent),
- string.format("PostDrainField: %.6f%%", postDrainFieldPercent),
- string.format("DrainThisTick: %.6f%%", drainPercentThisTick),
- string.format("Slice A/B/C/D: %.6f / %.6f / %.6f / %.6f", lastSlice.a or 0, lastSlice.b or 0, lastSlice.c or 0, lastSlice.d or 0),
- string.format("Temp: %.1fC / Target %.1fC", info.temperature, idealTemp),
- string.format("FieldDrainUsed: %.0f RF/t", fieldDrainUsed),
- string.format("RequiredInput: %.0f RF/t", requiredInput),
- string.format("InputCommand: %.0f RF/t", inputCommand),
- string.format("OutputCommand: %.0f RF/t", outputNeeded),
- string.format("Fuel Remaining: %.3f%%", ((1 - info.fuelConversion / info.maxFuelConversion) * 100)),
- string.format("Eq. Fusion Stage: %s", burnStage)
- }
- term.clear()
- writeRows(rows, 2, 1)
- end
- os.sleep(0.1)
- end
- end
- local function parseInput()
- while eventLoop do
- local ev, _, x, y = event.pull()
- if ev == "interrupted" then
- eventLoop = false
- break
- elseif ev == "touch" then
- for _, button in pairs(buttons) do
- if (not button.condition or button.condition())
- and x >= button.x and x <= button.x + button.width
- and y >= button.y and y <= button.y + button.height then
- button.action()
- button.depressed = 3
- end
- end
- end
- end
- end
- local primaryThread = thread.create(primaryCalculations)
- local secondaryThread = thread.create(secondaryCalculations)
- local guiThread = thread.create(drawGUI)
- local inputThread = thread.create(parseInput)
- thread.waitForAny({primaryThread, secondaryThread, guiThread, inputThread})
- eventLoop = false
- pcall(function() outputFlux.setFlowOverride(0) end)
- pcall(function() inputFlux.setFlowOverride(250000) end)
- pcall(function() reactor.stopReactor() end)
- term.clear()
- term.setCursor(1, 1)
- local sx, sy = gpu.maxResolution()
- gpu.setResolution(sx, sy)
- print("Exited Draconic Control v16.0f T3 autoflux slice probe")
Advertisement
Add Comment
Please, Sign In to add comment