GLaDOS446

DE-CONTROL V2

Jun 26th, 2026 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.44 KB | Source Code | 0 0
  1. -- =================================================================
  2. -- CONFIGURATION - BITTE HIER DEINE UUIDS EINTRAGEN!
  3. -- =================================================================
  4. local REACTOR_UUID     = "94b23646-6ef0-4a6c-8e3d-5319263d9175"
  5. local INPUT_GATE_UUID   = "8fb02e6f-8e47-4677-88ed-16a8b55f9c43"
  6. local OUTPUT_GATE_UUID  = "a656039b-a057-49e2-92b0-77f80fbf61d1"
  7. local FAILSAFE_PIN     = "1234" -- Dein Wunsch-PIN zum Umschalten
  8. local MIN_SHIELD_PERCENT = 50     -- Standard Mindest-Schildstärke für Failsafe (in %)
  9. -- =================================================================
  10.  
  11. local component = require("component")
  12. local event = require("event")
  13. local term = require("term")
  14. local colors = require("colors")
  15.  
  16. -- Komponenten binden
  17. local gpu = component.gpu
  18. local reactor = component.proxy(REACTOR_UUID)
  19. local input_gate = component.proxy(INPUT_GATE_UUID)
  20. local output_gate = component.proxy(OUTPUT_GATE_UUID)
  21.  
  22. if not reactor or not input_gate or not output_gate then
  23.     print("Fehler: Eine oder mehrere Komponenten wurden nicht gefunden!")
  24.     print("Bitte überprüfe die UUIDs in der Konfiguration.")
  25.     return
  26. end
  27.  
  28. -- Override-Modus auf den Flux Gates aktivieren
  29. input_gate.setOverrideEnabled(true)
  30. output_gate.setOverrideEnabled(true)
  31.  
  32. -- Bildschirm-Setup
  33. local screenW, screenH = 80, 25
  34. gpu.setResolution(screenW, screenH)
  35.  
  36. -- Globale Zustände
  37. local running = true
  38. local controlMode = "AUTO"
  39. local opMode = "SAFE"      
  40. local showWarning = false
  41. local failsafeEnabled = true
  42. local failsafeTriggered = false
  43. local panelLocked = false
  44.  
  45. -- PIN-Pad Zustände (Failsafe & Lock)
  46. local showPinPad = false
  47. local pinBuffer = ""
  48. local lockPinBuffer = ""
  49.  
  50. -- Interne Fluss-Speicher
  51. local targetInput = input_gate.getFlow() or 100000
  52. local targetOutput = output_gate.getFlow() or 0
  53.  
  54. -- Betriebsmodi Parameter
  55. local profiles = {
  56.     SAFE       = { targetTemp = 2500, targetShield = 70 },
  57.     NORMAL     = { targetTemp = 4500, targetShield = 60 },
  58.     BOOST      = { targetTemp = 6500, targetShield = 55 },
  59.     SUPERBOOST = { targetTemp = 7800, targetShield = 40 } -- 40% Ziel, damit 30% Failsafe nicht triggert
  60. }
  61.  
  62. -- Intelligenter Schild-Scanner
  63. local function calculateShieldPercent(info)
  64.     local current = info.fieldCharge or info.shieldCharge or info.FieldCharge or info.ShieldCharge or info.fieldContainment or info.shieldLevel
  65.     local max = info.maxFieldCharge or info.maxShieldCharge or info.MaxFieldCharge or info.MaxShieldCharge or info.maxFieldContainment or info.maxShieldLevel
  66.    
  67.     if not current or not max then
  68.         for k, v in pairs(info) do
  69.             if type(v) == "number" then
  70.                 local lk = string.lower(k)
  71.                 if (lk:find("field") or lk:find("shield") or lk:find("containment")) and not lk:find("gate") and not lk:find("in") and not lk:find("out") then
  72.                     if lk:find("max") then max = v else current = v end
  73.                 end
  74.             end
  75.         end
  76.     end
  77.    
  78.     current = current or 0
  79.     max = max or 1
  80.     if max <= 0 then max = 1 end
  81.     return (current / max) * 100
  82. end
  83.  
  84. -- Helfer: Text formatieren
  85. local function formatNum(num)
  86.     if num >= 1000000 then return string.format("%.2fM", num / 1000000) end
  87.     if num >= 1000 then return string.format("%.1fk", num / 1000) end
  88.     return tostring(num)
  89. end
  90.  
  91. -- Helfer: Textausgabe
  92. local function drawText(x, y, text, fg, bg, width)
  93.     gpu.setForeground(fg or 0xFFFFFF)
  94.     gpu.setBackground(bg or 0x151515)
  95.     text = tostring(text)
  96.     if width then
  97.         if #text < width then
  98.             text = text .. string.rep(" ", width - #text)
  99.         elseif #text > width then
  100.             text = string.sub(text, 1, width)
  101.         end
  102.     end
  103.     gpu.set(x, y, text)
  104. end
  105.  
  106. -- Button-Klassenspeicher
  107. local buttons = {}
  108. local function registerButton(x1, y1, x2, y2, id)
  109.     table.insert(buttons, {x1=x1, y1=y1, x2=x2, y2=y2, id=id})
  110. end
  111.  
  112. -- GUI statischen Hintergrund zeichnen
  113. local function drawStaticGUI()
  114.     gpu.setBackground(0x151515)
  115.     gpu.fill(1, 1, screenW, screenH, " ")
  116.    
  117.     if panelLocked then return end -- Statische GUI überspringen falls gesperrt
  118.  
  119.     gpu.setForeground(0x00FFD5)
  120.     gpu.fill(1, 1, screenW, 1, "═")
  121.     gpu.fill(1, screenH, screenW, 1, "═")
  122.     gpu.set(4, 1, " DRACONIC REACTOR CONTROL SYSTEM [V2.5] ")
  123.    
  124.     for y = 3, 22 do gpu.set(42, y, "║") end
  125.  
  126.     drawText(4, 4, "REAKTOR STATUS:", 0xAAAAAA)
  127.     drawText(4, 6, "Kerntemperatur:", 0xAAAAAA)
  128.     drawText(4, 8, "Schildstärke  :", 0xAAAAAA)
  129.     drawText(4, 10, "Energie-Sätt. :", 0xAAAAAA)
  130.     drawText(4, 12, "Generierung   :", 0xAAAAAA)
  131.    
  132.     drawText(45, 4, "KONTROLLMODUS:", 0xAAAAAA)
  133.     drawText(45, 7, "BETRIEBSMODUS:", 0xAAAAAA)
  134.    
  135.     drawText(45, 13, "FLUX GATE MANAGEMENT", 0x00FFD5)
  136.     drawText(45, 15, "INPUT (Schild):", 0xAAAAAA)
  137.     drawText(45, 17, "OUTPUT (Netz):", 0xAAAAAA)
  138.  
  139.     drawText(75, 1, "[ X ]", 0xFF0000, 0x333333)
  140.     registerButton(75, 1, 79, 1, "EXIT")
  141. end
  142.  
  143. -- Grafisches PIN-Pad für Failsafe-Modus zeichnen
  144. local function drawPinPadGUI()
  145.     gpu.setBackground(0x222222)
  146.     gpu.fill(25, 4, 32, 17, " ")
  147.     drawText(29, 5, "PIN-CODE ERFORDERLICH", 0xFFFF00, 0x222222)
  148.    
  149.     gpu.setBackground(0x111111)
  150.     gpu.fill(28, 7, 26, 1, " ")
  151.     local disp = string.rep("*", #pinBuffer)
  152.     if pinBuffer == "FALSCH" then disp = "FALSCHER PIN!" gpu.setForeground(0xFF0000) else gpu.setForeground(0xFFFFFF) end
  153.     gpu.set(29, 7, disp)
  154.    
  155.     drawText(29, 9, " [1] ", 0xFFFFFF, 0x333333) registerButton(29, 9, 33, 9, "PIN_1")
  156.     drawText(36, 9, " [2] ", 0xFFFFFF, 0x333333) registerButton(36, 9, 40, 9, "PIN_2")
  157.     drawText(43, 9, " [3] ", 0xFFFFFF, 0x333333) registerButton(43, 9, 47, 9, "PIN_3")
  158.     drawText(29, 11, " [4] ", 0xFFFFFF, 0x333333) registerButton(29, 11, 33, 11, "PIN_4")
  159.     drawText(36, 11, " [5] ", 0xFFFFFF, 0x333333) registerButton(36, 11, 40, 11, "PIN_5")
  160.     drawText(43, 11, " [6] ", 0xFFFFFF, 0x333333) registerButton(43, 11, 47, 11, "PIN_6")
  161.     drawText(29, 13, " [7] ", 0xFFFFFF, 0x333333) registerButton(29, 13, 33, 13, "PIN_7")
  162.     drawText(36, 13, " [8] ", 0xFFFFFF, 0x333333) registerButton(36, 13, 40, 13, "PIN_8")
  163.     drawText(43, 13, " [9] ", 0xFFFFFF, 0x333333) registerButton(43, 13, 47, 13, "PIN_9")
  164.     drawText(29, 15, " [C] ", 0xFF5555, 0x333333) registerButton(29, 15, 33, 15, "PIN_C")
  165.     drawText(36, 15, " [0] ", 0xFFFFFF, 0x333333) registerButton(36, 15, 40, 15, "PIN_0")
  166.     drawText(43, 15, " [OK] ", 0x00FF00, 0x333333) registerButton(43, 15, 47, 15, "PIN_OK")
  167.     drawText(31, 18, " [ ABBRECHEN ] ", 0xFFFFFF, 0x444444) registerButton(31, 18, 45, 18, "PIN_CANCEL")
  168. end
  169.  
  170. -- Fullscreen Lock-Screen zeichnen
  171. local function drawLockScreenGUI()
  172.     gpu.setBackground(0x151515)
  173.     gpu.fill(1, 1, screenW, screenH, " ")
  174.    
  175.     drawText(28, 2, "🔒 BEDIENFELD GESPERRT", 0xFF3333, 0x151515)
  176.    
  177.     gpu.setBackground(0x222222)
  178.     gpu.fill(25, 5, 32, 16, " ")
  179.     drawText(28, 6, "PIN EINGEBEN ZUM ENTSPERREN", 0xFFFF00, 0x222222)
  180.    
  181.     gpu.setBackground(0x111111)
  182.     gpu.fill(28, 8, 26, 1, " ")
  183.     local disp = string.rep("*", #lockPinBuffer)
  184.     if lockPinBuffer == "FALSCH" then disp = "FALSCHER PIN!" gpu.setForeground(0xFF0000) else gpu.setForeground(0xFFFFFF) end
  185.     gpu.set(29, 8, disp)
  186.    
  187.     drawText(29, 10, " [1] ", 0xFFFFFF, 0x333333) registerButton(29, 10, 33, 10, "LPIN_1")
  188.     drawText(36, 10, " [2] ", 0xFFFFFF, 0x333333) registerButton(36, 10, 40, 10, "LPIN_2")
  189.     drawText(43, 10, " [3] ", 0xFFFFFF, 0x333333) registerButton(43, 10, 47, 10, "LPIN_3")
  190.     drawText(29, 12, " [4] ", 0xFFFFFF, 0x333333) registerButton(29, 12, 33, 12, "LPIN_4")
  191.     drawText(36, 12, " [5] ", 0xFFFFFF, 0x333333) registerButton(36, 12, 40, 12, "LPIN_5")
  192.     drawText(43, 12, " [6] ", 0xFFFFFF, 0x333333) registerButton(43, 12, 47, 12, "LPIN_6")
  193.     drawText(29, 14, " [7] ", 0xFFFFFF, 0x333333) registerButton(29, 14, 33, 14, "LPIN_7")
  194.     drawText(36, 14, " [8] ", 0xFFFFFF, 0x333333) registerButton(36, 14, 40, 14, "LPIN_8")
  195.     drawText(43, 14, " [9] ", 0xFFFFFF, 0x333333) registerButton(43, 14, 47, 14, "LPIN_9")
  196.     drawText(29, 16, " [C] ", 0xFF5555, 0x333333) registerButton(29, 16, 33, 16, "LPIN_C")
  197.     drawText(36, 16, " [0] ", 0xFFFFFF, 0x333333) registerButton(36, 16, 40, 16, "LPIN_0")
  198.     drawText(43, 16, " [OK] ", 0x00FF00, 0x333333) registerButton(43, 16, 47, 16, "LPIN_OK")
  199. end
  200.  
  201. -- Dynamische UI Elemente aktualisieren
  202. local function drawDynamicGUI(info, shieldPct)
  203.     if panelLocked then
  204.         drawLockScreenGUI()
  205.         return
  206.     end
  207.  
  208.     if showPinPad then
  209.         drawPinPadGUI()
  210.         return
  211.     end
  212.  
  213.     if showWarning then
  214.         gpu.setBackground(0x330000)
  215.         gpu.fill(20, 8, 42, 9, " ")
  216.         drawText(22, 9, "!!! WARNUNG: UNSICHERER BETRIEB !!!", 0xFF0000, 0x330000)
  217.         drawText(22, 11, "Superboost senkt Failsafe auf 30%!", 0xFFFFFF, 0x330000)
  218.         drawText(22, 12, "Explosionsgefahr extrem erhöht.", 0xFFFFFF, 0x330000)
  219.        
  220.         drawText(26, 14, " [ BESTÄTIGEN ] ", 0x00FF00, 0x555555) registerButton(26, 14, 41, 14, "CONFIRM_SUPER")
  221.         drawText(45, 14, " [ ABBRECHEN ] ", 0xFF0000, 0x555555) registerButton(45, 14, 59, 14, "CANCEL_SUPER")
  222.         return
  223.     end
  224.  
  225.     local statusStr = string.lower(info.status or "")
  226.     local statusColor = 0x00FF00
  227.     if statusStr == "cold" or statusStr == "offline" then statusColor = 0x999999
  228.     elseif statusStr == "charging" or statusStr == "warmup" then statusColor = 0xFFFF00
  229.     elseif statusStr == "stopping" then statusColor = 0xFF5500
  230.     end
  231.     drawText(21, 4, string.upper(info.status), statusColor, 0x151515, 15)
  232.    
  233.     local tempColor = 0x00FF00
  234.     if info.temperature > 5000 then tempColor = 0xFFFF00 end
  235.     if info.temperature > 7000 then tempColor = 0xFF0000 end
  236.     drawText(21, 6, string.format("%.1f °C", info.temperature), tempColor, 0x151515, 15)
  237.    
  238.     local shieldColor = 0x00FF00
  239.     if shieldPct < 60 then shieldColor = 0xFFFF00 end
  240.     if shieldPct < 41 then shieldColor = 0xFF0000 end
  241.     drawText(21, 8, string.format("%.2f %%", shieldPct), shieldColor, 0x151515, 15)
  242.    
  243.     local satPct = (info.energySaturation / info.maxEnergySaturation) * 100
  244.     drawText(21, 10, string.format("%.2f %%", satPct), 0x00AAFF, 0x151515, 15)
  245.     drawText(21, 12, formatNum(info.generationRate) .. " RF/t", 0x00FF00, 0x151515, 15)
  246.  
  247.     local btnAutoBG = (controlMode == "AUTO") and 0x0055FF or 0x333333
  248.     local btnManBG = (controlMode == "MANUELL") and 0x0055FF or 0x333333
  249.     drawText(61, 4, " AUTO ", 0xFFFFFF, btnAutoBG) registerButton(61, 4, 66, 4, "MODE_AUTO")
  250.     drawText(69, 4, " MANUELL ", 0xFFFFFF, btnManBG) registerButton(69, 4, 77, 4, "MODE_MANUAL")
  251.  
  252.     local mSafe = (opMode == "SAFE") and 0x00FF00 or 0x333333
  253.     local mNorm = (opMode == "NORMAL") and 0x0055FF or 0x333333
  254.     local mBoost = (opMode == "BOOST") and 0xFFFF00 or 0x333333
  255.     local mSBoost = (opMode == "SUPERBOOST") and 0xFF0000 or 0x333333
  256.    
  257.     drawText(45, 9, "  SAFE  ", 0xFFFFFF, mSafe) registerButton(45, 9, 52, 9, "OP_SAFE")
  258.     drawText(54, 9, " NORMAL ", 0xFFFFFF, mNorm) registerButton(54, 9, 61, 9, "OP_NORMAL")
  259.     drawText(63, 9, "  BOOST ", 0xFFFF00, mBoost) registerButton(63, 9, 70, 9, "OP_BOOST")
  260.     drawText(72, 9, " S-BST  ", 0xFF0000, mSBoost) registerButton(72, 9, 79, 9, "OP_SUPERBOOST")
  261.  
  262.     drawText(61, 15, string.format("%9s RF/t", formatNum(targetInput)), 0xFFFF00, 0x151515)
  263.     drawText(61, 17, string.format("%9s RF/t", formatNum(targetOutput)), 0x00FF00, 0x151515)
  264.    
  265.     if controlMode == "MANUELL" then
  266.         drawText(45, 19, " [IN -10k] ", 0xFFFFFF, 0x333333) registerButton(45, 19, 54, 19, "IN_-10K")
  267.         drawText(56, 19, " [IN +10k] ", 0xFFFFFF, 0x333333) registerButton(56, 19, 65, 19, "IN_+10K")
  268.         drawText(45, 21, " [OUT-10k] ", 0xFFFFFF, 0x333333) registerButton(45, 21, 54, 21, "OUT_-10K")
  269.         drawText(56, 21, " [OUT+10k] ", 0xFFFFFF, 0x333333) registerButton(56, 21, 65, 21, "OUT_+10K")
  270.     else
  271.         gpu.fill(45, 19, 34, 3, " ")
  272.     end
  273.  
  274.     drawText(4, 16, "┌────────────┐", 0xAAAAAA)
  275.     drawText(4, 17, "│   CHARGE   │", 0xFFFFFF, (statusStr == "charging" or statusStr == "warmup") and 0xFFFF00 or 0x333333)
  276.     drawText(4, 18, "└────────────┘", 0xAAAAAA) registerButton(4, 16, 17, 18, "ACT_CHARGE")
  277.  
  278.     drawText(20, 16, "┌────────────┐", 0xAAAAAA)
  279.     drawText(20, 17, "│  ACTIVATE  │", 0xFFFFFF, (statusStr == "running" or statusStr == "online") and 0x00FF00 or 0x333333)
  280.     drawText(20, 18, "└────────────┘", 0xAAAAAA) registerButton(20, 16, 33, 18, "ACT_ACTIVATE")
  281.  
  282.     drawText(4, 20, "┌──────────────────────────────┐", 0xAAAAAA)
  283.     drawText(4, 21, "│         STOP REACTOR         │", 0xFFFFFF, 0x550000)
  284.     drawText(4, 22, "└──────────────────────────────┘", 0xAAAAAA) registerButton(4, 20, 35, 22, "ACT_STOP")
  285.  
  286.     -- Untere Statusleiste mit Failsafe & Sperren
  287.     if failsafeTriggered then
  288.         drawText(4, 24, " FAILSAFE AUSGELÖST! REAKTOR NOTABSCHALTUNG ", 0xFFFFFF, 0xFF0000, 44)
  289.     else
  290.         gpu.fill(4, 24, 44, 1, " ")
  291.     end
  292.  
  293.     if failsafeEnabled then
  294.         drawText(45, 24, "[FAILSAFE: AN]", 0x00FF00, 0x222222)
  295.     else
  296.         drawText(45, 24, "[FAILSAFE: AUS]", 0xFF5555, 0x222222)
  297.     end
  298.     registerButton(45, 24, 59, 24, "TOGGLE_FAILSAFE")
  299.  
  300.     drawText(62, 24, " [ PANEEL SPERREN ] ", 0xFFFF00, 0x333333)
  301.     registerButton(62, 24, 79, 24, "LOCK_PANEL")
  302. end
  303.  
  304. -- Klick-Logik verarbeiten
  305. local function handleTouch(x, y)
  306.     for _, btn in ipairs(buttons) do
  307.         if x >= btn.x1 and x <= btn.x2 and y >= btn.y1 and y <= btn.y2 then
  308.            
  309.             -- Lockscreen PIN Logik
  310.             if panelLocked then
  311.                 if lockPinBuffer == "FALSCH" then lockPinBuffer = "" end
  312.                 if btn.id == "LPIN_C" then lockPinBuffer = ""
  313.                 elseif btn.id == "LPIN_OK" then
  314.                     if lockPinBuffer == FAILSAFE_PIN then
  315.                         panelLocked = false
  316.                         lockPinBuffer = ""
  317.                         buttons = {}
  318.                         drawStaticGUI()
  319.                     else
  320.                         lockPinBuffer = "FALSCH"
  321.                     end
  322.                 elseif btn.id:sub(1, 5) == "LPIN_" then
  323.                     local num = btn.id:sub(6)
  324.                     if #lockPinBuffer < 6 then lockPinBuffer = lockPinBuffer .. num end
  325.                 end
  326.                 buttons = {}
  327.                 return
  328.             end
  329.  
  330.             -- Normaler Failsafe-PIN Pad
  331.             if showPinPad then
  332.                 if pinBuffer == "FALSCH" then pinBuffer = "" end
  333.                 if btn.id == "PIN_CANCEL" then showPinPad = false pinBuffer = ""
  334.                 elseif btn.id == "PIN_C" then pinBuffer = ""
  335.                 elseif btn.id == "PIN_OK" then
  336.                     if pinBuffer == FAILSAFE_PIN then
  337.                         failsafeEnabled = not failsafeEnabled
  338.                         showPinPad = false
  339.                         pinBuffer = ""
  340.                     else
  341.                         pinBuffer = "FALSCH"
  342.                     end
  343.                 else
  344.                     local num = btn.id:sub(5)
  345.                     if #pinBuffer < 6 then pinBuffer = pinBuffer .. num end
  346.                 end
  347.                 buttons = {}
  348.                 drawStaticGUI()
  349.                 return
  350.             end
  351.  
  352.             if showWarning then
  353.                 if btn.id == "CONFIRM_SUPER" then opMode = "SUPERBOOST" showWarning = false
  354.                 elseif btn.id == "CANCEL_SUPER" then showWarning = false end
  355.                 buttons = {}
  356.                 drawStaticGUI()
  357.                 return
  358.             end
  359.  
  360.             if btn.id == "EXIT" then running = false
  361.             elseif btn.id == "LOCK_PANEL" then
  362.                 panelLocked = true
  363.                 buttons = {}
  364.                 drawStaticGUI()
  365.                 return
  366.             elseif btn.id == "TOGGLE_FAILSAFE" then
  367.                 showPinPad = true
  368.                 pinBuffer = ""
  369.                 buttons = {}
  370.                 drawStaticGUI()
  371.                 return
  372.             elseif btn.id == "MODE_AUTO" then controlMode = "AUTO"
  373.             elseif btn.id == "MODE_MANUAL" then controlMode = "MANUELL"
  374.             elseif btn.id == "OP_SAFE" then opMode = "SAFE"
  375.             elseif btn.id == "OP_NORMAL" then opMode = "NORMAL"
  376.             elseif btn.id == "OP_BOOST" then opMode = "BOOST"
  377.             elseif btn.id == "OP_SUPERBOOST" then showWarning = true
  378.             elseif btn.id == "ACT_CHARGE" then reactor.chargeReactor()
  379.             elseif btn.id == "ACT_ACTIVATE" then reactor.activateReactor()
  380.             elseif btn.id == "ACT_STOP" then
  381.                 reactor.stopReactor()
  382.                 targetOutput = 0
  383.                 output_gate.setFlowOverride(0)
  384.             elseif btn.id == "IN_-10K" then targetInput = math.max(0, targetInput - 10000) input_gate.setFlowOverride(targetInput)
  385.             elseif btn.id == "IN_+10K" then targetInput = targetInput + 10000 input_gate.setFlowOverride(targetInput)
  386.             elseif btn.id == "OUT_-10K" then targetOutput = math.max(0, targetOutput - 10000) output_gate.setFlowOverride(targetOutput)
  387.             elseif btn.id == "OUT_+10K" then targetOutput = targetOutput + 10000 output_gate.setFlowOverride(targetOutput)
  388.             end
  389.            
  390.             buttons = {}
  391.             break
  392.         end
  393.     end
  394. end
  395.  
  396. -- Auto-Regelungs-Logik
  397. local function performAutoRegulation(info, shieldPct)
  398.     if controlMode ~= "AUTO" then return end
  399.    
  400.     local profile = profiles[opMode]
  401.     local statusStr = string.lower(info.status or "")
  402.     local isRunning = (statusStr == "running" or statusStr == "online" or statusStr == "active")
  403.    
  404.     -- 1. Schild-Regelung via Input Gate (Massive Einspeisung falls Schild zu schwach)
  405.     local baseDrain = info.fieldDrainRate or 40000
  406.     if shieldPct < profile.targetShield then
  407.         targetInput = baseDrain + 60000 -- Drückt das Schild mit ordentlich Puffer nach oben
  408.     elseif shieldPct > profile.targetShield + 1 then
  409.         targetInput = math.max(20000, baseDrain + 10000)
  410.     end
  411.    
  412.     -- 2. Temperatur- & Erzeugungsregelung via Output Gate
  413.     if isRunning then
  414.         local tempDiff = profile.targetTemp - info.temperature
  415.        
  416.         -- Überlast-/Unterlast-Mechanismus, um die Temperatur aktiv zu verändern:
  417.         -- Wenn zu kalt -> Ziehe MEHR als erzeugt wird (senkt Sättigung -> Kern heizt auf)
  418.         -- Wenn zu heiß -> Ziehe WENIGER als erzeugt wird (erhöht Sättigung -> Kern kühlt ab)
  419.         local adjustment = tempDiff * 60
  420.        
  421.         -- Schutz-Limitierungen für extreme Sprünge
  422.         if adjustment > 800000 then adjustment = 800000 end
  423.         if adjustment < -800000 then adjustment = -800000 end
  424.        
  425.         targetOutput = (info.generationRate or 0) + adjustment
  426.        
  427.         -- === NETZ- & SÄTTIGUNGS-PROTEKTOR ===
  428.         local satPct = 50
  429.         if info.maxEnergySaturation and info.maxEnergySaturation > 0 then
  430.             satPct = (info.energySaturation / info.maxEnergySaturation) * 100
  431.         end
  432.        
  433.         -- Falls die Sättigung einbricht (Gefahr!), drosseln wir den Strombezug radikal
  434.         if satPct < 40 then
  435.             targetOutput = math.min(targetOutput, info.generationRate * 0.7)
  436.         end
  437.         if satPct < 25 then
  438.             targetOutput = math.min(targetOutput, info.generationRate * 0.2)
  439.         end
  440.         if satPct < 15 then
  441.             targetOutput = 0 -- Komplette Netztrennung im Notfall
  442.         end
  443.        
  444.         if targetOutput < 0 then targetOutput = 0 end
  445.     else
  446.         targetOutput = 0
  447.     end
  448.    
  449.     input_gate.setFlowOverride(targetInput)
  450.     output_gate.setFlowOverride(targetOutput)
  451. end
  452.  
  453. -- Hauptschleife
  454. drawStaticGUI()
  455.  
  456. while running do
  457.     local info = reactor.getReactorInfo()
  458.    
  459.     if info then
  460.         local shieldPct = calculateShieldPercent(info)
  461.         local statusStr = string.lower(info.status or "")
  462.         local isRunning = (statusStr == "running" or statusStr == "online" or statusStr == "active")
  463.        
  464.         -- === DYNAMISCHER CRITICAL FAILSAFE ===
  465.         local currentFailsafeLimit = MIN_SHIELD_PERCENT
  466.         if opMode == "SUPERBOOST" then
  467.             currentFailsafeLimit = 30 -- Im Superboost darf das Schild bis auf 30% absinken
  468.         end
  469.        
  470.         if failsafeEnabled and isRunning and shieldPct < currentFailsafeLimit then
  471.             reactor.stopReactor()
  472.             targetOutput = 0
  473.             output_gate.setFlowOverride(0)        
  474.             targetInput = 3000000 -- Maximaler Schildschutz-Strom
  475.             input_gate.setFlowOverride(targetInput)    
  476.             failsafeTriggered = true
  477.             controlMode = "MANUELL"                
  478.         elseif shieldPct >= (currentFailsafeLimit + 15) then
  479.             failsafeTriggered = false
  480.         end
  481.        
  482.         if not failsafeTriggered then
  483.             performAutoRegulation(info, shieldPct)
  484.         end
  485.        
  486.         buttons = {}
  487.         if not panelLocked then
  488.             registerButton(75, 1, 79, 1, "EXIT")
  489.         end
  490.         drawDynamicGUI(info, shieldPct)
  491.     end
  492.    
  493.     local id, _, x, y = event.pull(0.4, "touch")
  494.     if id == "touch" then
  495.         handleTouch(x, y)
  496.     end
  497. end
  498.  
  499. term.clear()
  500. print("Reaktor-Kontrollprogramm beendet.")
Advertisement
Add Comment
Please, Sign In to add comment