Advertisement
neuroticfox

DC 12.0

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