Advertisement
neuroticfox

Draconic Control v15.0b [xMPD] [Lua 5.3 / 5.2]

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