Advertisement
neuroticfox

Draconic Control v15.2 [SMT] [Lua 5.3 / 5.2]

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