Advertisement
neuroticfox

Draconic Control v14.0 [xMAN] [Lua 5.3 / 5.2]

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