Compare commits

...
8 Commits
2 changed files with 58 additions and 17 deletions
+55 -14
View File
@@ -14,6 +14,7 @@ local version = 0.3
local autoInputGate = 1 local autoInputGate = 1
local curInputGate = 222000 local curInputGate = 222000
local targetOutput local targetOutput
local autoOutputGate = 0
local mon, monitor, monX, monY local mon, monitor, monX, monY
@@ -153,26 +154,31 @@ function save_config()
sw.writeLine(autoInputGate) sw.writeLine(autoInputGate)
sw.writeLine(curInputGate) sw.writeLine(curInputGate)
sw.writeLine(targetOutput or 0) sw.writeLine(targetOutput or 0)
sw.writeLine(autoOutputGate or 0)
sw.close() sw.close()
end end
function load_config() function load_config()
sr = fs.open("reactorconfig.txt", "r") sr = fs.open("reactorconfig.txt", "r")
autoInputGate = tonumber(sr.readLine()) autoInputGate = tonumber(sr.readLine() or 1)
curInputGate = tonumber(sr.readLine()) curInputGate = tonumber(sr.readLine() or 222000)
targetOutput = tonumber(sr.readLine()) targetOutput = tonumber(sr.readLine() or 0)
autoOutputGate = tonumber(sr.readLine() or 0)
sr.close() sr.close()
end end
if fs.exists("reactorconfig.txt") == false then if fs.exists("reactorconfig.txt") then
save_config()
else
load_config() load_config()
end end
if not targetOutput then if not targetOutput or targetOutput == 0 then
targetOutput = fluxgate.getSignalLowFlow() targetOutput = fluxgate.getSignalLowFlow()
end end
if not autoOutputGate then
autoOutputGate = 0
end
save_config()
function reset() function reset()
term.clear() term.clear()
@@ -227,6 +233,10 @@ function reactorControl()
drawTerminalText(1, i, "Output Gate", fluxgate.getSignalLowFlow()) drawTerminalText(1, i, "Output Gate", fluxgate.getSignalLowFlow())
i = i + 1 i = i + 1
drawTerminalText(1, i, "Input Gate", inputFluxgate.getSignalLowFlow()) drawTerminalText(1, i, "Input Gate", inputFluxgate.getSignalLowFlow())
i = i + 1
drawTerminalText(1, i, "Target Output", targetOutput)
i = i + 1
drawTerminalText(1, i, "Auto Output", autoOutputGate == 1 and "ON" or "OFF")
-- Reactor Control Logic -- Reactor Control Logic
if emergencyCharge then if emergencyCharge then
@@ -260,7 +270,7 @@ function reactorControl()
if currentFlow ~= targetOutput then if currentFlow ~= targetOutput then
local diff = targetOutput - currentFlow local diff = targetOutput - currentFlow
local absDiff = math.abs(diff) local absDiff = math.abs(diff)
local step = math.min(absDiff, math.max(5000, absDiff / 20)) local step = math.min(absDiff, math.max(1000, absDiff / 60))
if diff > 0 then if diff > 0 then
local fieldPercent = math.ceil(ri.fieldStrength / ri.maxFieldStrength * 10000) * 0.01 local fieldPercent = math.ceil(ri.fieldStrength / ri.maxFieldStrength * 10000) * 0.01
if fieldPercent >= 20 then if fieldPercent >= 20 then
@@ -361,18 +371,35 @@ function buttonControls()
local sLength2 = (sLength+12+(string.len("Reboot"))+1) local sLength2 = (sLength+12+(string.len("Reboot"))+1)
button.setButton("reboot", "Reboot", rebootSystem, sLength+12, 28, sLength2, 30, 0, 0, colors.blue) button.setButton("reboot", "Reboot", rebootSystem, sLength+12, 28, sLength2, 30, 0, 0, colors.blue)
local sLength3 = 4+(string.len("Back")+1) local autoLabel = autoOutputGate == 1 and "Auto Out:ON" or "Auto Out:OFF"
button.setButton("back", "Back", buttonMain, 4, 32, sLength3, 34, 0, 0, colors.blue) local sLength3 = sLength2 + 11 + string.len(autoLabel)
button.setButton("autoOut", autoLabel, toggleAutoOutput, sLength2+11, 28, sLength3, 30, 0, 0, autoOutputGate == 1 and colors.green or colors.red)
local sLength4 = 4+(string.len("Back")+1)
button.setButton("back", "Back", buttonMain, 4, 32, sLength4, 34, 0, 0, colors.blue)
button.screen() button.screen()
end end
function changeOutputValue(num, val) function changeOutputValue(num, val)
autoOutputGate = 0
if val == 1 then if val == 1 then
targetOutput = math.min(targetOutput + num, 2000000000) targetOutput = math.min(targetOutput + num, 2000000000)
else else
targetOutput = math.max(targetOutput - num, 0) targetOutput = math.max(targetOutput - num, 0)
end end
local ri_local = reactor.getReactorInfo()
if not ri_local or ri_local.status ~= "running" then
fluxgate.setSignalLowFlow(targetOutput)
end
updateReactorInfo()
save_config()
end
function toggleAutoOutput()
autoOutputGate = autoOutputGate == 1 and 0 or 1
updateReactorInfo() updateReactorInfo()
save_config() save_config()
end end
@@ -473,6 +500,19 @@ function updateReactorInfo()
if not ri then return end if not ri then return end
if ri.status == "running" and autoOutputGate == 1 then
local satPercent = getPercentage(ri.energySaturation, ri.maxEnergySaturation)
local currentOutput = fluxgate.getSignalLowFlow()
if satPercent > 95 then
local boost = math.max(10000, math.floor(currentOutput * 0.05))
targetOutput = math.min(targetOutput + boost, 2000000000)
elseif satPercent > 90 then
local boost = math.max(5000, math.floor(currentOutput * 0.02))
targetOutput = math.min(targetOutput + boost, 2000000000)
end
end
drawUpdatedText(4, 4, "Status:", reactorStatus(ri.status)[1], reactorStatus(ri.status)[2], colors.white) drawUpdatedText(4, 4, "Status:", reactorStatus(ri.status)[1], reactorStatus(ri.status)[2], colors.white)
drawUpdatedText(4, 5, "Generation:", f.format_int(ri.generationRate).." rf/t", colors.lime, colors.yellow) drawUpdatedText(4, 5, "Generation:", f.format_int(ri.generationRate).." rf/t", colors.lime, colors.yellow)
@@ -480,12 +520,13 @@ function updateReactorInfo()
drawUpdatedText(4, 7, "Temperature:", f.format_int(ri.temperature).."C", tempColor, colors.lightGray) drawUpdatedText(4, 7, "Temperature:", f.format_int(ri.temperature).."C", tempColor, colors.lightGray)
local currentFlow = fluxgate.getSignalLowFlow() local currentFlow = fluxgate.getSignalLowFlow()
local autoTag = autoOutputGate == 1 and " [AUTO]" or " [MAN]"
local outputText local outputText
if currentFlow ~= targetOutput then if currentFlow ~= targetOutput then
local arrow = currentFlow < targetOutput and " " or " " local dir = currentFlow < targetOutput and " +" or " -"
outputText = f.format_int(currentFlow).." "..f.format_int(targetOutput).." rf/t"..arrow outputText = f.format_int(currentFlow).." > "..f.format_int(targetOutput).." rf/t"..dir..autoTag
else else
outputText = f.format_int(currentFlow).." rf/t" outputText = f.format_int(currentFlow).." rf/t"..autoTag
end end
drawUpdatedText(4, 9, "Output:", outputText, colors.lightBlue, colors.cyan) drawUpdatedText(4, 9, "Output:", outputText, colors.lightBlue, colors.cyan)
drawUpdatedText(4, 10, "Input:", f.format_int(inputFluxgate.getSignalLowFlow()).." rf/t", colors.lightBlue, colors.cyan) drawUpdatedText(4, 10, "Input:", f.format_int(inputFluxgate.getSignalLowFlow()).." rf/t", colors.lightBlue, colors.cyan)
@@ -509,7 +550,7 @@ function drawUpdatedText(x, y, label, value, color, labelColor)
local key = label local key = label
if lastValues[key] ~= value then if lastValues[key] ~= value then
labelColor = labelColor or colors.white labelColor = labelColor or colors.white
f.draw_text_lr(mon, x, y, 3, " ", " ", colors.white, color, colors.black) f.draw_line(mon, x, y, monX - x, colors.black)
f.draw_text_lr(mon, x, y, 3, label, value, labelColor, color, colors.black) f.draw_text_lr(mon, x, y, 3, label, value, labelColor, color, colors.black)
lastValues[key] = value lastValues[key] = value
end end
+3 -3
View File
@@ -1,6 +1,6 @@
local libURL = "https://raw.githubusercontent.com/StormFusions/Draconic-ComputerCraft-Program/main/lib/f.lua" local libURL = "https://git.ipost.rocks/code002lover/Draconic-ComputerCraft-Program/raw/branch/main/lib/f.lua"
local libURL2 = "https://raw.githubusercontent.com/StormFusions/Draconic-ComputerCraft-Program/main/lib/button.lua" local libURL2 = "https://git.ipost.rocks/code002lover/Draconic-ComputerCraft-Program/raw/branch/main/lib/button.lua"
local startupURL = "https://raw.githubusercontent.com/StormFusions/Draconic-ComputerCraft-Program/main/reactor.lua" local startupURL = "https://git.ipost.rocks/code002lover/Draconic-ComputerCraft-Program/raw/branch/main/reactor.lua"
local lib, lib2, startup local lib, lib2, startup
local libFile, lib2File, startupFile local libFile, lib2File, startupFile