GLaDOS446

DE-CONTROL V1

Jun 25th, 2026 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.08 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. -- =================================================================
  9.  
  10. local component = require("component")
  11. local event = require("event")
  12. local term = require("term")
  13. local colors = require("colors")
  14.  
  15. -- Komponenten binden
  16. local gpu = component.gpu
  17. local reactor = component.proxy(REACTOR_UUID)
  18. local input_gate = component.proxy(INPUT_GATE_UUID)
  19. local output_gate = component.proxy(OUTPUT_GATE_UUID)
  20.  
  21. if not reactor or not input_gate or not output_gate then
  22.     print("Fehler: Eine oder mehrere Komponenten wurden nicht gefunden!")
  23.     print("Bitte überprüfe die UUIDs in der Konfiguration.")
  24.     return
  25. end
  26.  
  27. -- Override-Modus auf den Flux Gates aktivieren
  28. input_gate.setOverrideEnabled(true)
  29. output_gate.setOverrideEnabled(true)
  30.  
  31. -- Bildschirm-Setup
  32. local screenW, screenH = 80, 25
  33. gpu.setResolution(screenW, screenH)
  34.  
  35. -- Globale Zustände
  36. local running = true
  37. local controlMode = "AUTO"
  38. local opMode = "SAFE"      
  39. local showWarning = false
  40. local failsafeEnabled = true
  41. local failsafeTriggered = false
  42.  
  43. -- PIN-Pad Zustände
  44. local showPinPad = false
  45. local pinBuffer = ""
  46.  
  47. -- Interne Fluss-Speicher
  48. local targetInput = input_gate.getFlow() or 100000
  49. local targetOutput = output_gate.getFlow() or 0
  50.  
  51. -- Betriebsmodi Parameter
  52. local profiles = {
  53.     SAFE       = { targetTemp = 2500, targetShield = 70, maxOutput = 100000 },
  54.     NORMAL     = { targetTemp = 4500, targetShield = 60, maxOutput = 500000 },
  55.     BOOST      = { targetTemp = 6500, targetShield = 55, maxOutput = 2000000 },
  56.     SUPERBOOST = { targetTemp = 7800, targetShield = 52, maxOutput = 8000000 }
  57. }
  58.  
  59. -- Helfer: Text formatieren
  60. local function formatNum(num)
  61.     if num >= 1000000 then return string.format("%.2fM", num / 1000000) end
  62.     if num >= 1000 then return string.format("%.1fk", num / 1000) end
  63.     return tostring(num)
  64. end
  65.  
  66. -- Helfer: Textausgabe
  67. local function drawText(x, y, text, fg, bg, width)
  68.     gpu.setForeground(fg or 0xFFFFFF)
  69.     gpu.setBackground(bg or 0x151515)
  70.     text = tostring(text)
  71.     if width then
  72.         if #text < width then
  73.             text = text .. string.rep(" ", width - #text)
  74.         elseif #text > width then
  75.             text = string.sub(text, 1, width)
  76.         end
  77.     end
  78.     gpu.set(x, y, text)
  79. end
  80.  
  81. -- Button-Klassenspeicher
  82. local buttons = {}
  83. local function registerButton(x1, y1, x2, y2, id)
  84.     table.insert(buttons, {x1=x1, y1=y1, x2=x2, y2=y2, id=id})
  85. end
  86.  
  87. -- GUI statischen Hintergrund zeichnen
  88. local function drawStaticGUI()
  89.     gpu.setBackground(0x151515)
  90.     gpu.fill(1, 1, screenW, screenH, " ")
  91.    
  92.     gpu.setForeground(0x00FFD5)
  93.     gpu.fill(1, 1, screenW, 1, "═")
  94.     gpu.fill(1, screenH, screenW, 1, "═")
  95.     gpu.set(4, 1, " DRACONIC REACTOR CONTROL SYSTEM [V2.2] ")
  96.    
  97.     for y = 3, 23 do gpu.set(42, y, "║") end
  98.  
  99.     drawText(4, 4, "REAKTOR STATUS:", 0xAAAAAA)
  100.     drawText(4, 6, "Kerntemperatur:", 0xAAAAAA)
  101.     drawText(4, 8, "Schildstärke  :", 0xAAAAAA)
  102.     drawText(4, 10, "Energie-Sätt. :", 0xAAAAAA)
  103.     drawText(4, 12, "Generierung   :", 0xAAAAAA)
  104.    
  105.     drawText(45, 4, "KONTROLLMODUS:", 0xAAAAAA)
  106.     drawText(45, 7, "BETRIEBSMODUS:", 0xAAAAAA)
  107.    
  108.     drawText(45, 13, "FLUX GATE MANAGEMENT", 0x00FFD5)
  109.     drawText(45, 15, "INPUT (Schild):", 0xAAAAAA)
  110.     drawText(45, 17, "OUTPUT (Netz):", 0xAAAAAA)
  111.  
  112.     drawText(75, 1, "[ X ]", 0xFF0000, 0x333333)
  113.     registerButton(75, 1, 79, 1, "EXIT")
  114. end
  115.  
  116. -- Grafisches PIN-Pad Overlay zeichnen
  117. local function drawPinPadGUI()
  118.     gpu.setBackground(0x222222)
  119.     gpu.fill(25, 4, 32, 17, " ")
  120.    
  121.     drawText(29, 5, "PIN-CODE ERFORDERLICH", 0xFFFF00, 0x222222)
  122.    
  123.     -- Displayzeile für Sterne
  124.     gpu.setBackground(0x111111)
  125.     gpu.fill(28, 7, 26, 1, " ")
  126.     local disp = string.rep("*", #pinBuffer)
  127.     if pinBuffer == "FALSCH" then
  128.         disp = "FALSCHER PIN!"
  129.         gpu.setForeground(0xFF0000)
  130.     else
  131.         gpu.setForeground(0xFFFFFF)
  132.     end
  133.     gpu.set(29, 7, disp)
  134.    
  135.     -- Tasten-Layout (Zeile 1-3)
  136.     drawText(29, 9, " [1] ", 0xFFFFFF, 0x333333) registerButton(29, 9, 33, 9, "PIN_1")
  137.     drawText(36, 9, " [2] ", 0xFFFFFF, 0x333333) registerButton(36, 9, 40, 9, "PIN_2")
  138.     drawText(43, 9, " [3] ", 0xFFFFFF, 0x333333) registerButton(43, 9, 47, 9, "PIN_3")
  139.    
  140.     drawText(29, 11, " [4] ", 0xFFFFFF, 0x333333) registerButton(29, 11, 33, 11, "PIN_4")
  141.     drawText(36, 11, " [5] ", 0xFFFFFF, 0x333333) registerButton(36, 11, 40, 11, "PIN_5")
  142.     drawText(43, 11, " [6] ", 0xFFFFFF, 0x333333) registerButton(43, 11, 47, 11, "PIN_6")
  143.    
  144.     drawText(29, 13, " [7] ", 0xFFFFFF, 0x333333) registerButton(29, 13, 33, 13, "PIN_7")
  145.     drawText(36, 13, " [8] ", 0xFFFFFF, 0x333333) registerButton(36, 13, 40, 13, "PIN_8")
  146.     drawText(43, 13, " [9] ", 0xFFFFFF, 0x333333) registerButton(43, 13, 47, 13, "PIN_9")
  147.    
  148.     -- Zeile 4 (Clear, 0, OK)
  149.     drawText(29, 15, " [C] ", 0xFF5555, 0x333333) registerButton(29, 15, 33, 15, "PIN_C")
  150.     drawText(36, 15, " [0] ", 0xFFFFFF, 0x333333) registerButton(36, 15, 40, 15, "PIN_0")
  151.     drawText(43, 15, " [OK] ", 0x00FF00, 0x333333) registerButton(43, 15, 47, 15, "PIN_OK")
  152.    
  153.     -- Abbrechen Button unten drunter
  154.     drawText(31, 18, " [ ABBRECHEN ] ", 0xFFFFFF, 0x444444) registerButton(31, 18, 45, 18, "PIN_CANCEL")
  155. end
  156.  
  157. -- Dynamische UI Elemente aktualisieren
  158. local function drawDynamicGUI(info, shieldPct)
  159.     if showPinPad then
  160.         drawPinPadGUI()
  161.         return
  162.     end
  163.  
  164.     if showWarning then
  165.         gpu.setBackground(0x330000)
  166.         gpu.fill(20, 8, 42, 9, " ")
  167.         drawText(22, 9, "!!! WARNUNG: UNSICHERER BETRIEB !!!", 0xFF0000, 0x330000)
  168.         drawText(22, 11, "Superboost kann den Reaktor zerstören.", 0xFFFFFF, 0x330000)
  169.         drawText(22, 12, "Failsafe wird zwingend vorausgesetzt.", 0xFFFFFF, 0x330000)
  170.        
  171.         drawText(26, 14, " [ BESTÄTIGEN ] ", 0x00FF00, 0x555555)
  172.         registerButton(26, 14, 41, 14, "CONFIRM_SUPER")
  173.         drawText(45, 14, " [ ABBRECHEN ] ", 0xFF0000, 0x555555)
  174.         registerButton(45, 14, 59, 14, "CANCEL_SUPER")
  175.         return
  176.     end
  177.  
  178.     local statusColor = 0x00FF00
  179.     if info.status == "offline" or info.status == "cold" then statusColor = 0x999999
  180.     elseif info.status == "charging" then statusColor = 0xFFFF00
  181.     elseif info.status == "stopping" then statusColor = 0xFF5500
  182.     end
  183.     drawText(21, 4, string.upper(info.status), statusColor, 0x151515, 15)
  184.    
  185.     local tempColor = 0x00FF00
  186.     if info.temperature > 5000 then tempColor = 0xFFFF00 end
  187.     if info.temperature > 7000 then tempColor = 0xFF0000 end
  188.     drawText(21, 6, string.format("%.1f °C", info.temperature), tempColor, 0x151515, 15)
  189.    
  190.     local shieldColor = 0x00FF00
  191.     if shieldPct < 60 then shieldColor = 0xFFFF00 end
  192.     if shieldPct < 51 then shieldColor = 0xFF0000 end
  193.     drawText(21, 8, string.format("%.2f %%", shieldPct), shieldColor, 0x151515, 15)
  194.    
  195.     local satPct = (info.energySaturation / info.maxEnergySaturation) * 100
  196.     drawText(21, 10, string.format("%.2f %%", satPct), 0x00AAFF, 0x151515, 15)
  197.     drawText(21, 12, formatNum(info.generationRate) .. " RF/t", 0x00FF00, 0x151515, 15)
  198.  
  199.     local btnAutoBG = (controlMode == "AUTO") and 0x0055FF or 0x333333
  200.     local btnManBG = (controlMode == "MANUELL") and 0x0055FF or 0x333333
  201.     drawText(61, 4, " AUTO ", 0xFFFFFF, btnAutoBG)
  202.     registerButton(61, 4, 66, 4, "MODE_AUTO")
  203.     drawText(69, 4, " MANUELL ", 0xFFFFFF, btnManBG)
  204.     registerButton(69, 4, 77, 4, "MODE_MANUAL")
  205.  
  206.     local mSafe = (opMode == "SAFE") and 0x00FF00 or 0x333333
  207.     local mNorm = (opMode == "NORMAL") and 0x0055FF or 0x333333
  208.     local mBoost = (opMode == "BOOST") and 0xFFFF00 or 0x333333
  209.     local mSBoost = (opMode == "SUPERBOOST") and 0xFF0000 or 0x333333
  210.    
  211.     drawText(45, 9, "  SAFE  ", 0xFFFFFF, mSafe)
  212.     registerButton(45, 9, 52, 9, "OP_SAFE")
  213.     drawText(54, 9, " NORMAL ", 0xFFFFFF, mNorm)
  214.     registerButton(54, 9, 61, 9, "OP_NORMAL")
  215.     drawText(63, 9, "  BOOST ", 0xFFFF00, mBoost)
  216.     registerButton(63, 9, 70, 9, "OP_BOOST")
  217.     drawText(72, 9, " S-BST  ", 0xFF0000, mSBoost)
  218.     registerButton(72, 9, 79, 9, "OP_SUPERBOOST")
  219.  
  220.     drawText(61, 15, string.format("%9s RF/t", formatNum(targetInput)), 0xFFFF00, 0x151515)
  221.     drawText(61, 17, string.format("%9s RF/t", formatNum(targetOutput)), 0x00FF00, 0x151515)
  222.    
  223.     if controlMode == "MANUELL" then
  224.         drawText(45, 19, " [IN -10k] ", 0xFFFFFF, 0x333333) registerButton(45, 19, 54, 19, "IN_-10K")
  225.         drawText(56, 19, " [IN +10k] ", 0xFFFFFF, 0x333333) registerButton(56, 19, 65, 19, "IN_+10K")
  226.         drawText(45, 21, " [OUT-10k] ", 0xFFFFFF, 0x333333) registerButton(45, 21, 54, 21, "OUT_-10K")
  227.         drawText(56, 21, " [OUT+10k] ", 0xFFFFFF, 0x333333) registerButton(56, 21, 65, 21, "OUT_+10K")
  228.     else
  229.         gpu.fill(45, 19, 25, 3, " ")
  230.     end
  231.  
  232.     local actColor = (info.status == "online") and 0x00FF00 or 0x333333
  233.     local chgColor = (info.status == "charging") and 0xFFFF00 or 0x333333
  234.    
  235.     drawText(4, 16, "┌────────────┐", 0xAAAAAA)
  236.     drawText(4, 17, "│   CHARGE   │", 0xFFFFFF, chgColor)
  237.     drawText(4, 18, "└────────────┘", 0xAAAAAA)
  238.     registerButton(4, 16, 17, 18, "ACT_CHARGE")
  239.  
  240.     drawText(20, 16, "┌────────────┐", 0xAAAAAA)
  241.     drawText(20, 17, "│  ACTIVATE  │", 0xFFFFFF, actColor)
  242.     drawText(20, 18, "└────────────┘", 0xAAAAAA)
  243.     registerButton(20, 16, 33, 18, "ACT_ACTIVATE")
  244.  
  245.     drawText(4, 20, "┌──────────────────────────────┐", 0xAAAAAA)
  246.     drawText(4, 21, "│         STOP REACTOR         │", 0xFFFFFF, 0x550000)
  247.     drawText(4, 22, "└──────────────────────────────┘", 0xAAAAAA)
  248.     registerButton(4, 20, 35, 22, "ACT_STOP")
  249.  
  250.     -- Interaktive Failsafe-Schaltfläche unten rechts
  251.     if failsafeTriggered then
  252.         drawText(45, 23, " FAILSAFE AUSGELÖST! SCHILD GEFALLEN ", 0xFFFFFF, 0xFF0000, 34)
  253.     else
  254.         if failsafeEnabled then
  255.             drawText(45, 23, " [ FAILSAFE MODE: AKTIV (ON) ]     ", 0x00FF00, 0x222222, 34)
  256.         else
  257.             drawText(45, 23, " [ FAILSAFE MODE: AUS (DEAKTIV) ]  ", 0xFF5555, 0x222222, 34)
  258.         end
  259.         registerButton(45, 23, 79, 23, "TOGGLE_FAILSAFE")
  260.     end
  261. end
  262.  
  263. -- Klick-Logik verarbeiten
  264. local function handleTouch(x, y)
  265.     for _, btn in ipairs(buttons) do
  266.         if x >= btn.x1 and x <= btn.x2 and y >= btn.y1 and y <= btn.y2 then
  267.            
  268.             -- PIN-Pad Logik abfangen
  269.             if showPinPad then
  270.                 if pinBuffer == "FALSCH" then pinBuffer = "" end
  271.                
  272.                 if btn.id == "PIN_CANCEL" then
  273.                     showPinPad = false
  274.                     pinBuffer = ""
  275.                 elseif btn.id == "PIN_C" then
  276.                     pinBuffer = ""
  277.                 elseif btn.id == "PIN_OK" then
  278.                     if pinBuffer == FAILSAFE_PIN then
  279.                         failsafeEnabled = not failsafeEnabled
  280.                         showPinPad = false
  281.                         pinBuffer = ""
  282.                     else
  283.                         pinBuffer = "FALSCH"
  284.                     end
  285.                 else
  286.                     local num = btn.id:sub(5)
  287.                     if #pinBuffer < 6 then pinBuffer = pinBuffer .. num end
  288.                 end
  289.                 buttons = {}
  290.                 drawStaticGUI()
  291.                 return
  292.             end
  293.  
  294.             if showWarning then
  295.                 if btn.id == "CONFIRM_SUPER" then opMode = "SUPERBOOST" showWarning = false
  296.                 elseif btn.id == "CANCEL_SUPER" then showWarning = false end
  297.                 buttons = {}
  298.                 drawStaticGUI()
  299.                 return
  300.             end
  301.  
  302.             -- Normale GUI Buttons
  303.             if btn.id == "EXIT" then running = false
  304.             elseif btn.id == "TOGGLE_FAILSAFE" then
  305.                 showPinPad = true
  306.                 pinBuffer = ""
  307.                 buttons = {}
  308.                 drawStaticGUI()
  309.                 return
  310.             elseif btn.id == "MODE_AUTO" then controlMode = "AUTO"
  311.             elseif btn.id == "MODE_MANUAL" then controlMode = "MANUELL"
  312.             elseif btn.id == "OP_SAFE" then opMode = "SAFE"
  313.             elseif btn.id == "OP_NORMAL" then opMode = "NORMAL"
  314.             elseif btn.id == "OP_BOOST" then opMode = "BOOST"
  315.             elseif btn.id == "OP_SUPERBOOST" then showWarning = true
  316.             elseif btn.id == "ACT_CHARGE" then reactor.chargeReactor()
  317.             elseif btn.id == "ACT_ACTIVATE" then reactor.activateReactor()
  318.             elseif btn.id == "ACT_STOP" then
  319.                 reactor.stopReactor()
  320.                 targetOutput = 0
  321.                 output_gate.setFlowOverride(0)
  322.             elseif btn.id == "IN_-10K" then targetInput = math.max(0, targetInput - 10000) input_gate.setFlowOverride(targetInput)
  323.             elseif btn.id == "IN_+10K" then targetInput = targetInput + 10000 input_gate.setFlowOverride(targetInput)
  324.             elseif btn.id == "OUT_-10K" then targetOutput = math.max(0, targetOutput - 10000) output_gate.setFlowOverride(targetOutput)
  325.             elseif btn.id == "OUT_+10K" then targetOutput = targetOutput + 10000 output_gate.setFlowOverride(targetOutput)
  326.             end
  327.            
  328.             buttons = {}
  329.             break
  330.         end
  331.     end
  332. end
  333.  
  334. -- Auto-Regelungs-Logik
  335. local function performAutoRegulation(info, shieldPct)
  336.     if controlMode ~= "AUTO" then return end
  337.    
  338.     local profile = profiles[opMode]
  339.    
  340.     -- 1. Schild-Regelung via Input Gate
  341.     if shieldPct < profile.targetShield then
  342.         targetInput = targetInput + 25000
  343.     elseif shieldPct > profile.targetShield + 2 then
  344.         targetInput = math.max(10000, targetInput - 10000)
  345.     end
  346.    
  347.     -- 2. Temperatur-Regelung via Output Gate
  348.     if info.status == "online" then
  349.         if info.temperature < profile.targetTemp then
  350.             targetOutput = targetOutput + 10000
  351.         elseif info.temperature > profile.targetTemp + 50 then
  352.             targetOutput = math.max(0, targetOutput - 20000)
  353.         end
  354.         targetOutput = math.min(targetOutput, profile.maxOutput)
  355.     else
  356.         targetOutput = 0
  357.     end
  358.    
  359.     input_gate.setFlowOverride(targetInput)
  360.     output_gate.setFlowOverride(targetOutput)
  361. end
  362.  
  363. -- Hauptschleife
  364. drawStaticGUI()
  365.  
  366. while running do
  367.     local info = reactor.getReactorInfo()
  368.    
  369.     if info then
  370.         local currentShield = info.fieldCharge or info.shieldCharge or 0
  371.         local maxShield = info.maxFieldCharge or info.maxShieldCharge or 1
  372.         local shieldPct = (currentShield / maxShield) * 100
  373.        
  374.         -- === CRITICAL FAILSAFE ===
  375.         -- Greift jetzt NUR, wenn der Reaktor wirklich "online" (aktiv am Laufen) ist!
  376.         if failsafeEnabled and info.status == "online" and shieldPct < 50.0 then
  377.             reactor.stopReactor()
  378.             targetOutput = 0
  379.             output_gate.setFlowOverride(0)        
  380.             targetInput = 2000000
  381.             input_gate.setFlowOverride(targetInput)    
  382.             failsafeTriggered = true
  383.             controlMode = "MANUELL"                
  384.         elseif shieldPct >= 70.0 then
  385.             failsafeTriggered = false
  386.         end
  387.        
  388.         if not failsafeTriggered then
  389.             performAutoRegulation(info, shieldPct)
  390.         end
  391.        
  392.         buttons = {}
  393.         registerButton(75, 1, 79, 1, "EXIT")
  394.         drawDynamicGUI(info, shieldPct)
  395.     end
  396.    
  397.     local id, _, x, y = event.pull(0.4, "touch")
  398.     if id == "touch" then
  399.         handleTouch(x, y)
  400.     end
  401. end
  402.  
  403. term.clear()
  404. print("Reaktor-Kontrollprogramm beendet.")
Advertisement
Add Comment
Please, Sign In to add comment