neuroticfox

DC13 [Final Draconic Control Release]

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