Advertisement
neuroticfox

DC 11.0 [Recommended]

Dec 29th, 2022 (edited)
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.54 KB | None | 0 0
  1.  :: start ::
  2.  -- Locals & Requirements
  3.     local component = require("component")
  4.     local event = require("event")
  5.     local term = require("term")
  6.     local gpu = component.gpu
  7.     local screen = component.screen
  8.     local unicode= require("unicode")
  9.     local idealField = 25
  10.     local idealTemp = 8000
  11.     local cutoffTemp = 9005
  12.     local chaosMode = 0
  13.     local tempDrop = 0
  14.     local cVar = "Do not use Chaos Mode with less than one block of fuel"
  15.     local tArgs = {...}
  16.     local reactorOutputMultiplier = tonumber(tArgs[1]) or 1
  17.     local ratioX, ratioY = screen.getAspectRatio()
  18.     local maxX, maxY = gpu.maxResolution()
  19.     gpu.setResolution(math.min(ratioX*55, maxX), math.min(ratioY*25,maxY))
  20. term.clear()
  21. term.setCursor(0, 0)
  22. os.sleep(0.5)
  23.  -- Components
  24.     if not component.isAvailable("draconic_reactor") then
  25.         print("Reactor not connected. Please connect computer to reactor with an Adapter block.")
  26.         os.exit()
  27.     end
  28.     local reactor = component.draconic_reactor
  29.     local info = reactor.getReactorInfo()
  30.     local flux_gates = {}
  31.     for x,y in pairs(component.list("flux_gate")) do
  32.         flux_gates[#flux_gates+1] = x
  33.     end
  34.     if #flux_gates < 2 then
  35.         print("Not enough flux gates connected; please connect inflow and outflow flux gates with Adapter blocks.")
  36.         os.exit()
  37.     end
  38.     local inputFlux = component.proxy(flux_gates[1])
  39.     local outputFlux = component.proxy(flux_gates[2])
  40.     if not inputFlux or not outputFlux then
  41.         print("Not enough flux gates connected; please connect inflow and outflow flux gates with Adapter blocks.")
  42.         os.exit()
  43.     end
  44.  -- First Cycle
  45.     reactor.chargeReactor()
  46.     os.sleep(0.1)
  47.     reactor.stopReactor()
  48.  -- Functions
  49. function exit_msg(msg)
  50.     term.clear()
  51.     print(msg)
  52.     os.exit()
  53. end
  54. function modifyTemp(offset)
  55.     local newTemp = idealTemp + offset
  56.     if newTemp > 8000 then
  57.         newTemp = 8000
  58.     elseif newTemp < 2000 then
  59.         newTemp = 2000
  60.     end
  61.         idealTemp = newTemp
  62.     end
  63. function modifyField(offset)
  64.     local newField = idealField + offset
  65.     if newField > 99 then
  66.         newField = 99
  67.     elseif newField < 99 and chaosMode == 1 then
  68.         newField = 99
  69.     elseif newField < 0.5 then
  70.         newField = 0.5
  71.     end
  72.         idealField = newField
  73.     end
  74.  -- Buttons
  75.     local adj_button_width = 19
  76.     local tempOffsetX = 62
  77.     local tempOffsetY = 2
  78.     local fieldOffsetX = tempOffsetX + adj_button_width + 2
  79.     local fieldOffsetY = 2
  80.     local cutoffField = 0.75
  81.     highest_use = 0.1
  82.     local buttons = {
  83.     startButton={
  84.     x=2,
  85.     y=20,
  86.     width=18,
  87.     height=1,
  88.     text="Start",
  89.     textcolor = 0x0000AA,
  90.     action=function()
  91.       if info.status == "cooling" or info.status == "cold" then
  92.             chaosMode = 0
  93.             idealField = 25
  94.             cutoffField = 0.4
  95.             idealTemp = 8000
  96.             cVar = "Do not use Chaos Mode with less than one block of fuel"
  97.         reactor.chargeReactor()
  98.       elseif info.status == "stopping" then
  99.             chaosMode = 0
  100.             idealField = 25
  101.             cutoffField = 0.4
  102.             idealTemp = 8000
  103.             cVar = "Do not use Chaos Mode with less than one block of fuel"
  104.         reactor.activateReactor()
  105.       end
  106.     end,
  107.     condition=function() return info.status ~= "running" and info.status ~= "warming_up" end
  108.   },
  109.   shutdownButton={
  110.     x=2,
  111.     y=20,
  112.     width=18,
  113.     height=1,
  114.     text="Shutdown",
  115.     textcolor = 0xAA0000,
  116.     action=function()
  117.     cutoffTemp = 9000
  118.     idealTemp = 8000
  119.     idealField = 25
  120.     cutoffField = 0.4
  121.     chaosMode = 0
  122.     cVar = "Do not use Chaos Mode with less than one block of fuel"
  123.       state = "MASD"
  124.       reactor.stopReactor()
  125.     end,
  126.     condition=function() return info.status == "running" or info.status == "warming_up" end
  127.   },
  128.   chaosMode={
  129.     x=2,
  130.     y=22,
  131.     width=18,
  132.     height=1,
  133.     text=" Chaos Mode",
  134.     textcolor = 0x800080,
  135.     action=function()
  136.         if chaosMode == 0 then
  137.             chaosMode = 1
  138.             cutoffTemp = 19750
  139.             idealField = 99
  140.             cutoffField = 5
  141.             idealTemp = 55537.78
  142.         elseif chaosMode == 1 then
  143.             chaosMode = 0
  144.             idealField = 25
  145.             cutoffField = 0.4
  146.             idealTemp = 8000
  147.         end
  148.     end,
  149.     condition=function() return info.status == "running" or info.status == "warming_up" end
  150.   },
  151.   forceExit={
  152.     x=158,
  153.     y=1,
  154.     width=3,
  155.     height=1,
  156.     text=" X ",
  157.     textcolor = 0xB00000,
  158.     action=function()
  159.         chaosMode = 0
  160.         idealField = 99
  161.         cutoffField = 0.4
  162.         idealTemp = 8000
  163.       reactor.stopReactor()
  164.       gpu.setResolution(gpu.maxResolution())
  165.       event_loop = false
  166.       os.execute("cls")
  167.     end,
  168. --    condition=function() return running or shutting_down end
  169.   },
  170.   Update={
  171.     x=22,
  172.     y=22,
  173.     width=18,
  174.     height=1,
  175.     text="Update",
  176.     action=function()
  177.         reactor.stopReactor()
  178.         os.execute("pastebin get -f xQUeKash dc11; cls; dc11")
  179.     end,
  180.     condition=function() return info.status ~= "running" and info.status ~= "warming_up" end
  181.   },
  182.   switchGates={
  183.     x=2,
  184.     y=22,
  185.     width=18,
  186.     height=1,
  187.     text="Swap Flux Gates",
  188.     action=function()
  189.       cutoffTemp = 10500
  190.       local old_addr = inputFlux.address
  191.       inputFlux = component.proxy(outputFlux.address)
  192.       outputFlux = component.proxy(old_addr)
  193.     end,
  194.     condition=function() return info.status == "cooling" or info.status == "cold" or info.status == "stopping" end
  195.   },
  196.   tempMax={
  197.     x=tempOffsetX,
  198.     y=tempOffsetY,
  199.     width=adj_button_width,
  200.     height=1,
  201.     text="Maximum",
  202.     textcolor = 0x552222,
  203.     action=function()
  204.       idealTemp = 8000
  205.     end
  206.   },
  207.   tempPThousand={
  208.     x=tempOffsetX,
  209.     y=tempOffsetY+2,
  210.     width=adj_button_width,
  211.     height=1,
  212.     text="+1000",
  213.     textcolor = 0x552222,
  214.     action=function() modifyTemp(1000) end
  215.   },
  216.   tempPHundred={
  217.     x=tempOffsetX,
  218.     y=tempOffsetY+4,
  219.     width=adj_button_width,
  220.     height=1,
  221.     text="+100",
  222.     textcolor = 0x552222,
  223.     action=function() modifyTemp(100) end
  224.   },
  225.   tempPTen={
  226.     x=tempOffsetX,
  227.     y=tempOffsetY+6,
  228.     width=adj_button_width,
  229.     height=1,
  230.     text="+10",
  231.     textcolor = 0x552222,
  232.     action=function() modifyTemp(10) end
  233.   },
  234.   tempPOne={
  235.     x=tempOffsetX,
  236.     y=tempOffsetY+8,
  237.     width=adj_button_width,
  238.     height=1,
  239.     text="+1",
  240.     textcolor = 0x552222,
  241.     action=function() modifyTemp(1) end
  242.   },
  243.   tempMin={
  244.     x=tempOffsetX,
  245.     y=tempOffsetY+20,
  246.     width=adj_button_width,
  247.     height=1,
  248.     text="Minimum",
  249.     textcolor = 0x552222,
  250.     action=function() modifyTemp(-20000) end
  251.   },
  252.   tempMThousand={
  253.     x=tempOffsetX,
  254.     y=tempOffsetY+18,
  255.     width=adj_button_width,
  256.     height=1,
  257.     text="-1000",
  258.     textcolor = 0x552222,
  259.     action=function() modifyTemp(-1000) end
  260.   },
  261.   tempMHundred={
  262.     x=tempOffsetX,
  263.     y=tempOffsetY+16,
  264.     width=adj_button_width,
  265.     height=1,
  266.     text="-100",
  267.     textcolor = 0x552222,
  268.     action=function() modifyTemp(-100) end
  269.   },
  270.   tempMTen={
  271.     x=tempOffsetX,
  272.     y=tempOffsetY+14,
  273.     width=adj_button_width,
  274.     height=1,
  275.     text="-10",
  276.     textcolor = 0x552222,
  277.     action=function() modifyTemp(-10) end
  278.   },
  279.   tempMOne={
  280.     x=tempOffsetX,
  281.     y=tempOffsetY+12,
  282.     width=adj_button_width,
  283.     height=1,
  284.     text="-1",
  285.     textcolor = 0x552222,
  286.     action=function() modifyTemp(-1) end
  287.   },
  288.   fieldPTen={
  289.     x=fieldOffsetX,
  290.     y=fieldOffsetY+3,
  291.     width=adj_button_width,
  292.     height=1,
  293.     text="+10",
  294.     textcolor = 0x222299,
  295.     action=function() modifyField(10) end
  296.   },
  297.     fieldPOne={
  298.     x=fieldOffsetX,
  299.     y=fieldOffsetY+5,
  300.     width=adj_button_width,
  301.     height=1,
  302.     text="+1",
  303.     textcolor = 0x222299,
  304.     action=function() modifyField(1) end
  305.   },
  306.   fieldPTenth={
  307.     x=fieldOffsetX,
  308.     y=fieldOffsetY+7,
  309.     width=adj_button_width,
  310.     height=1,
  311.     text="+0.1",
  312.     textcolor = 0x222299,
  313.     action=function() modifyField(0.1) end
  314.   },
  315.   fieldMTen={
  316.     x=fieldOffsetX,
  317.     y=fieldOffsetY+17,
  318.     width=adj_button_width,
  319.     height=1,
  320.     text="-10",
  321.     textcolor = 0x222299,
  322.     action=function() modifyField(-10) end
  323.   },
  324.     fieldMOne={
  325.     x=fieldOffsetX,
  326.     y=fieldOffsetY+15,
  327.     width=adj_button_width,
  328.     height=1,
  329.     text="-1",
  330.     textcolor = 0x222299,
  331.     action=function() modifyField(-1) end
  332.   },
  333.   fieldMTenth={
  334.     x=fieldOffsetX,
  335.     y=fieldOffsetY+13,
  336.     width=adj_button_width,
  337.     height=1,
  338.     text="-0.1",
  339.     textcolor = 0x222299,
  340.     action=function() modifyField(-0.1) end
  341.    }
  342. }
  343.  -- Control Loop
  344. event_loop = true
  345. while event_loop do
  346.         info = reactor.getReactorInfo()
  347.     if not info or info.maxFuelConversion < 0.001 then
  348.     cutoffTemp = 9000
  349.     idealTemp = 8000
  350.     chaosMode = 0
  351.     gpu.setBackground(0x000000)
  352.     gpu.setForeground(0xFF0000)
  353.     term.setCursor(55, 1)
  354.     print "Please verify that your reactor is refueled."
  355.     term.setCursor(55, 2)
  356.     print "Please verify the integrity of your reactor."
  357.     os.sleep(0.5)
  358.     goto start
  359.     gpu.setForeground(0x000000)
  360.     end
  361.     if info.temperature >= 2000 and info.status ~= "stopping"  then
  362.         reactor.activateReactor()
  363.     end
  364.  -- Chaos Mode Safe Shutdown
  365.     if info.temperature > 18000 and tempDrop == 0 then
  366.         idealTemp = 16000
  367.         tempDrop = 1
  368.         cVar = "Cooling For Shutdown"
  369.     elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) < 8 and tempDrop == 1 then
  370.         idealTemp = 14000
  371.         tempDrop = 2
  372.     elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) < 15 and info.maxFuelConversion < 1297 then
  373.         idealTemp = 8000
  374.         idealField = 50
  375.     elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) < 1.3 and tempDrop == 2 and info.maxFuelConversion < 5185 and info.maxFuelConversion > 144 then
  376.         idealTemp = 8000
  377.         idealField = 25
  378.     elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) < 0.75 and tempDrop == 2 then
  379.         idealTemp = 8000
  380.         idealField = 25
  381.     end
  382.     local targetShieldPercent = idealField or 15 -- Desired shield strength
  383.     local targetShield = (targetShieldPercent / 100)
  384.  -- Reactor equation variables
  385.     local targetTemp50  = math.min((idealTemp / 10000) * 50, 99)
  386.     local coreSat       = info.energySaturation / info.maxEnergySaturation
  387.     local convLVL       = (info.fuelConversion / info.maxFuelConversion * 1.3) - 0.3
  388.  -- Calculate the temperature rise resistance for the reactor at the desired temperature.
  389.     local targetTempResist = ((targetTemp50^4) / (100 - targetTemp50))
  390.  -- Calculate the temperature rise exponential needed to reach the desired temperature
  391.     local targetTempExpo = -(targetTempResist*convLVL) - 1000*convLVL + targetTempResist
  392.  -- Calculate the saturation level needed to produce the required tempRiseExpo
  393.     local term1 = 1334.1-(3*targetTempExpo)
  394.     local term2 = (1200690-(2700*targetTempExpo))^2
  395.     local term3 = ((-1350*targetTempExpo)+(((-4*term1^3+term2)^(1/2))/2)+600345)^(1/3)
  396.     local targetNegCSat = -(term1/(3*term3))-(term3/3)
  397.  -- Saturation received from above equation needs to be reformatted to a more useful form
  398.     local targetCoreSat = 1 - (targetNegCSat/99)
  399.     local targetSat = targetCoreSat * info.maxEnergySaturation
  400.  -- Calculate the difference between where saturation is and where it needs to be
  401.     local saturationError = info.energySaturation - targetSat
  402.  -- Calculate field drain
  403.     local tempDrainFactor = 0
  404.     if info.temperature > 8000 then
  405.         tempDrainFactor = 1 + ((info.temperature-8000)^2 * 0.0000025)
  406.     elseif info.temperature > 2000 then
  407.         tempDrainFactor = 1
  408.     elseif info.temperature > 1000 then
  409.         tempDrainFactor = (info.temperature-1000)/1000
  410.     end
  411.     local baseMaxRFt = (info.maxEnergySaturation / 1000) * reactorOutputMultiplier * 1.5
  412.     local fieldDrain = math.min(tempDrainFactor * math.max(0.01, (1-coreSat)) * (baseMaxRFt / 10.923556), 2147000000)
  413.     local fieldNegPercent = 1 - targetShield
  414.  --local fieldInputRate = fieldDrain / fieldNegPercent
  415.     local fieldStrengthError = (info.maxFieldStrength * targetShield) - info.fieldStrength
  416.     local requiredInput = math.min((info.maxFieldStrength * info.fieldDrainRate) / (info.maxFieldStrength - info.fieldStrength), info.maxFieldStrength - info.fieldStrength)
  417.  --Automations
  418.    if info.status == "running" then
  419.     local outputNeeded = math.min(saturationError, (info.maxEnergySaturation/40))-- + info.generationRate
  420.         outputFlux.setFlowOverride(outputNeeded)
  421.         inputFlux.setFlowOverride(math.min(fieldStrengthError + requiredInput, info.maxFieldStrength) - info.fieldDrainRate + 1)
  422.     elseif info.status == "warming_up" then
  423.         outputFlux.setFlowOverride(0)
  424.         inputFlux.setFlowOverride(500000000)
  425.     elseif info.status == "stopping" then
  426.         outputFlux.setFlowOverride(0)
  427.         inputFlux.setFlowOverride(requiredInput)
  428.     if info.temperature > cutoffTemp then
  429.         print("Reactor Too Hot, shutting down")
  430.         reactor.stopReactor()
  431.     end
  432.     if ((info.fieldStrength / info.maxFieldStrength) * 100) < cutoffField then
  433.         print("Reactor Field Has Failed, Failsafe Activated, Shutting Down")
  434.         reactor.stopReactor()
  435.     end
  436.     if ((1 - info.fuelConversion / info.maxFuelConversion) * 100) < 0.2 then
  437.         print("Reactor Fuel Low, Shutting Down")
  438.         reactor.stopReactor()
  439.     end
  440.    end
  441.     -- Get Temp Rise
  442.         oldTemp = currentTemp or info.temperature
  443.         currentTemp = info.temperature
  444.         oldTempRate = tempChangeRate or currentTemp - oldTemp
  445.         tempChangeRate = currentTemp - oldTemp
  446.         tempAccel = tempChangeRate - oldTempRate
  447.     if tempAccel == 0 then
  448.         tempAccel = 0.001
  449.     end
  450.     -- Get Fuel Use Rate
  451.         oldFuel = currentFuel or (info.maxFuelConversion - info.fuelConversion)
  452.         currentFuel = (info.maxFuelConversion - info.fuelConversion)
  453.         oldUseRate = fuelUseRate or math.max(info.fuelConversionRate*20, 0.1)
  454.         fuelUseRate = math.max(info.fuelConversionRate*20, 0.1)
  455.         fuelAccel = math.max(fuelUseRate - oldUseRate, 0.1)
  456.  -- Fuel Conversion Rate
  457.     if info.fuelConversionRate > 249999 then
  458.         fuelConversionRate = ((info.fuelConversionRate / (info.maxFuelConversion * 1000000)) * 2000)
  459.         fuelMeasure = "  %%/s"
  460.     elseif info.fuelConversionRate > 999 then
  461.         fuelConversionRate = (info.fuelConversionRate / 1000)
  462.         fuelMeasure = " "..(unicode.char(956)).."b/t"
  463.     elseif info.fuelConversionRate > 999999 then
  464.         fuelConversionRate = (info.fuelConversionRate / 1000000)
  465.         fuelMeasure = " mb/t"
  466.     else
  467.         fuelConversionRate = info.fuelConversionRate
  468.         fuelMeasure = " nb/t"
  469.     end
  470.  --Burn Stage
  471.     if ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 20 then burnStage = "H"
  472.     elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 15 then burnStage = "He"
  473.     elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 10 then burnStage = "C"
  474.     elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 8 then burnStage = "Ne"
  475.     elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 6.75 then burnStage = "O"
  476.     elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 5.5 then burnStage = "Si"
  477.     elseif ((1 - info.fuelConversion / info.maxFuelConversion) * 100) > 5 then burnStage = "Fe"
  478.     end
  479.  -- DrawData
  480.     local secondsToExpire = (info.maxFuelConversion - info.fuelConversion) / math.max(info.fuelConversionRate*0.00002, 0.00001)
  481.  -- GUI
  482.     if term.isAvailable() then
  483.         function modify_eff(offset)
  484.             local eff = ((outputFlux / inputFlux) * 100)
  485.             if eff > 100000 then
  486.             eff = 1
  487.         end
  488.     end
  489.     local left_margin = 2
  490.     local spacing = 1
  491.     local values = {
  492.                 "Draconomometer™  [v11.1-xQUeKash]",
  493.                 " ",
  494.                 "                   Reactor Statistics",
  495.                 "┌───────────────────────────┬────────────────────────────┐",
  496. string.format("│Time Until Refuel:         │  %5dd, %2dh, %2dm, %2ds     │", secondsToExpire/86400, secondsToExpire   /3600 % 24, secondsToExpire/60 % 60, secondsToExpire % 60),
  497. string.format("│Ideal Field:               │           %5.1f%%           │", idealField),
  498. string.format("│Current Field:             │           %5.1f%%           │", ((info.fieldStrength / info.maxFieldStrength) * 100)+0.1),
  499.                 "├───────────────────────────┼────────────────────────────┤",
  500. string.format("│Fuel Remaining:            │           %7.3f%%         │", ((1 - info.fuelConversion / info.maxFuelConversion) * 100)),
  501. string.format("│Fuel Use Rate:             │           %7.3f" .. fuelMeasure .. "     │", fuelConversionRate),
  502.                 "├───────────────────────────┼────────────────────────────┤",
  503. string.format("│Temperature                │   %7.1f°c [%8.1f°f]   │", info.temperature, ((info.temperature * 1.8) + 32)),
  504. string.format("│Ideal Temperature:         │   %7.1f°c [%8.1f°f]   │", idealTemp, ((idealTemp * 1.8) + 32)),
  505.                 "├───────────────────────────┼────────────────────────────┤",
  506. string.format("│Energy Input:              │   %12.1f RF/t        │", requiredInput),
  507. string.format("│Energy Output:             │   %12.1f RF/t        │", outputFlux.getFlow()),
  508.                 "└───────────────────────────┴────────────────────────────┘",
  509.                 " " .. cVar,
  510.                 " ",
  511.                 " ",
  512.                 " ",
  513.                 " ",
  514.                 " ",
  515.                 " ",
  516.                 " ",
  517.                 " ",
  518.                 " ",
  519.                 " ",
  520.                 " ",
  521.                 " ",
  522.                 " ",
  523.                 " ",
  524.                 " ",
  525.                 "             [Debug Values]",
  526.               "┌─────────────┬─────────────┬─────────────┐          Eq. Fusion Stage     " .. burnStage,
  527. string.format("│ Temperature │  Remaining  │ Consumption │          Max Fuel [nb]:       %4.3f", (info.maxFuelConversion * 1000000)),
  528. string.format("├─────────────┼─────────────┼─────────────┤          Fuel Remaining [nb]: %4.3f", ((info.maxFuelConversion - info.fuelConversion) * 1000000)),
  529. string.format("│    14000    │    93.27    │    91.90    │          Temperature Rise: %4.3f", tempAccel),
  530. string.format("├─────────────┼─────────────┼─────────────┤          Temp Resist for target temp %d (%d): %.2f", idealTemp, targetTemp50, targetTempResist),
  531. string.format("│    15000    │    59.00    │    123.5    │          Temp expo for convLVL %.2f: %.2f", convLVL, targetTempExpo),
  532. string.format("├─────────────┼─────────────┼─────────────┤          Saturation needed for zero rise: %d (%3.2f%%)", targetSat, targetCoreSat*100),
  533. string.format("│    16000    │    36.45    │     161     │          Error between current saturation and target saturation: %d\n", saturationError),
  534. string.format("├─────────────┼─────────────┼─────────────┤          Current field drain is %d RF/t", info.fieldDrainRate),
  535. string.format("│    17000    │    21.40    │     204     │          Current temp drain factor for temp %d is %1.2f", info.temperature, tempDrainFactor),
  536. string.format("├─────────────┼─────────────┼─────────────┤          fieldNegPercent is %d", fieldNegPercent),
  537. string.format("│    18000    │    11.80    │     251     │          Error between current field strength and target strength: %d", fieldStrengthError),
  538. string.format("├─────────────┼─────────────┼─────────────┤          Required input to counter field drain: %d RF/t\n", requiredInput),
  539. string.format("│    19000    │    03.89    │     303     │          Setting input flux gate to %d RF/t", requiredInput),
  540. string.format("└─────────────┴─────────────┴─────────────┘          Setting output flux gate to %d RF/t", outputFlux.getFlow())
  541. }
  542. term.clear()
  543.     for i, v in ipairs(values) do
  544.         term.setCursor(left_margin, i * spacing)
  545.         term.write(v)
  546.     end
  547.  -- Draw Buttons
  548.         term.setCursor(tempOffsetX, tempOffsetY+10)
  549.         term.write("Reactor Temperature")
  550.         term.setCursor(fieldOffsetX+1, fieldOffsetY+10)
  551.         term.write("  Field Strength")
  552.         gpu.setForeground(0xFFFFFF)
  553.     for bname, button in pairs(buttons) do
  554.         gpu.setForeground(0x000000)
  555.         if button.depressed then
  556.             button.depressed = button.depressed - 1
  557.             if button.depressed == 0 then
  558.                 button.depressed = nil
  559.             end
  560.         end
  561.     if button.condition == nil or button.condition() then
  562.         local centerColor = 0xBBBBBB
  563.         local highlightColor = 0xCCCCCC
  564.         local lowlightColor = 0x808080
  565.     if button.depressed then
  566.         centerColor = 0xAAAAAA
  567.         highlightColor = 0x707070
  568.         lowlightColor = 0xBBBBBB
  569.     end
  570.         gpu.setBackground(centerColor)
  571.         gpu.fill(button.x, button.y, button.width, button.height, " ")
  572.     if button.width > 1 and button.height > 1 then
  573.         gpu.setBackground(lowlightColor)
  574.         gpu.fill(button.x+1, button.y+button.height-1, button.width-1, 1, " ")
  575.         gpu.fill(button.x+button.width-1, button.y, 1, button.height, " ")
  576.         gpu.setBackground(highlightColor)
  577.         gpu.fill(button.x, button.y, 1, button.height, " ")
  578.         gpu.fill(button.x, button.y, button.width, 1, " ")
  579.     end
  580.         gpu.setBackground(centerColor)
  581.     if button.textcolor then gpu.setForeground(button.textcolor) end
  582.         term.setCursor(button.x + math.floor(button.width / 2 - #button.text / 2), button.y + math.floor(button.height / 2))
  583.         term.write(button.text)
  584.     end
  585.     end
  586.     gpu.setBackground(0x777777)
  587.     gpu.setForeground(0x000000)
  588.     end
  589.  -- Wait for next tick, or manual shutdown
  590.     local event, id, op1, op2 = event.pull(0.05)
  591.     if event == "interrupted" then
  592.         if safe then
  593.         break
  594.         end
  595.     elseif event == "touch" then
  596.  -- Handle Button Presses
  597.         local x = op1
  598.         local y = op2
  599.         for bname, button in pairs(buttons) do
  600.             if (button.condition == nil or button.condition()) and x >= button.x and x <= button.x + button.width and y >= button.y and y <= button.y + button.height then
  601.                 button.action()
  602.                 button.depressed = 3
  603.             end
  604.         end
  605.     end
  606.     os.sleep()
  607.         if info.fuelConversionRate == 0 and info.temperature > 8000 then
  608.         reactor.stopReactor()
  609.         cutoffTemp = 9000
  610.         idealTemp = 8000
  611.         chaosMode = 0
  612.     end
  613. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement