Advertisement
neuroticfox

DC 11.1

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