Advertisement
neuroticfox

DC14 Retest

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