Advertisement
troty

Draconic Core Mananger

May 5th, 2023 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.34 KB | None | 0 0
  1. --modpack configs
  2. reactorOutputMultiplier = 1.0
  3. reactorFuelUsageMultiplier = 1.0
  4.  
  5. --program configs (multiplied by the reactor output multiplier and divided by core volume)
  6. maxIOsmoothing = 888 * reactorOutputMultiplier
  7. IOlimitingMaxOUT = 5200000 * reactorOutputMultiplier
  8. IOlimitingMinIN = 1500000 * reactorOutputMultiplier
  9.  
  10. --Do not change anything below!!!!!!!
  11.  
  12. --Functions
  13. function toggle(boolean)
  14. if boolean == 1 then
  15. return 0
  16. else
  17. return 1
  18. end
  19. end
  20.  
  21. function energyCoreFullWarning()
  22. gWrite("! ATTENTION !", corePosX-5, corePosY-1, colors.white, coreColor)
  23. gWrite("ENERGY CORE FULL!", corePosX-7, corePosY, colors.white, coreColor)
  24. gWrite("LOCKING IO SMOOTH", corePosX-7, corePosY+1, colors.white, coreColor)
  25. gWrite("TO AVOID OVERLOAD", corePosX-7, corePosY+2, colors.white, coreColor)
  26. end
  27. function fuelConversionWarning()
  28. gWrite("! ATTENTION !", corePosX-5, corePosY-1, colors.white, coreColor)
  29. gWrite("FUEL CONVERSION", corePosX-7, corePosY, colors.white, coreColor)
  30. gWrite("ABOVE SET LIMITS!", corePosX-7, corePosY+1, colors.white, coreColor)
  31. gWrite("SHUTTING DOWN...", corePosX-7, corePosY+2, colors.white, coreColor)
  32. end
  33. function powerOutputWarning()
  34. gWrite("!! WARNING !!", corePosX-5, corePosY-1, colors.white, coreColor)
  35. gWrite("INSUFFICIENT", corePosX-7, corePosY, colors.white, coreColor)
  36. gWrite("OUTPUT FOR SELF-", corePosX-7, corePosY+1, colors.white, coreColor)
  37. gWrite("SUSTAINABILITY", corePosX-7, corePosY+2, colors.white, coreColor)
  38. end
  39. function reactorBoomWarning()
  40. gWrite("!! DANGER !!", corePosX-5, corePosY-1, colors.white, coreColor)
  41. gWrite("CORE DESTABILIZED", corePosX-7, corePosY, colors.white, coreColor)
  42. gWrite("!! EXPLOSION !!", corePosX-7, corePosY+1, colors.white, coreColor)
  43. gWrite("!! IMMINENT !!", corePosX-7, corePosY+2, colors.white, coreColor)
  44. end
  45.  
  46. --chatgeepeetee moment
  47. function secondsToTimeString(seconds)
  48. local days = math.floor(seconds / (24 * 3600))
  49. local hours = math.floor((seconds % (24 * 3600)) / 3600)
  50. local minutes = math.floor((seconds % 3600) / 60)
  51. local remainingSeconds = math.floor(seconds % 60)
  52.  
  53. local formattedTime = string.format("%sd %sh %sm %ss", days, hours, minutes, remainingSeconds)
  54.  
  55. return formattedTime
  56. end
  57. function secondsToTimeStringExtended(seconds)
  58. local years = math.floor(seconds / (365 * 24 * 3600))
  59. local days = math.floor((seconds % (365 * 24 * 3600)) / (24 * 3600))
  60. local hours = math.floor((seconds % (24 * 3600)) / 3600)
  61. local minutes = math.floor((seconds % 3600) / 60)
  62. local remainingSeconds = math.floor(seconds % 60)
  63.  
  64. local formattedTime = string.format("%sy %sd %sh %sm %ss", years, days, hours, minutes, remainingSeconds)
  65.  
  66. return formattedTime
  67. end
  68.  
  69. --save/load config functions
  70. function saveConfig()
  71. config = fs.open("config.txt", "w")
  72. config.writeLine(tempTarget)
  73. config.writeLine(fieldTarget)
  74. config.writeLine(saturationTarget)
  75. config.writeLine(fuelUseRateTarget)
  76. config.writeLine(conversionTarget)
  77. config.writeLine(targetPowerOutput)
  78. config.writeLine(fastStartup)
  79. config.writeLine(safetySystems)
  80. config.writeLine(onePointTwelveMode)
  81. config.writeLine(controlSelected)
  82. config.writeLine(saturationSafetyOverride)
  83. config.writeLine(scriptInitialized)
  84. config.writeLine(controlsLocked)
  85. config.writeLine(ioLocked)
  86. config.writeLine(powerOutputUpdated)
  87. config.writeLine(powerInputUpdated)
  88. config.writeLine(ioSmoothing)
  89. config.writeLine(IOlimiting)
  90. config.close()
  91. end
  92.  
  93. function loadConfig()
  94. config = fs.open("config.txt", "r")
  95. tempTarget = tonumber(config.readLine())
  96. fieldTarget = tonumber(config.readLine())
  97. saturationTarget = tonumber(config.readLine())
  98. fuelUseRateTarget = tonumber(config.readLine())
  99. conversionTarget = tonumber(config.readLine())
  100. targetPowerOutput = tonumber(config.readLine())
  101. fastStartup = tonumber(config.readLine())
  102. safetySystems = tonumber(config.readLine())
  103. onePointTwelveMode = tonumber(config.readLine())
  104. controlSelected = tonumber(config.readLine())
  105. saturationSafetyOverride = tonumber(config.readLine())
  106. scriptInitialized = tonumber(config.readLine())
  107. controlsLocked = tonumber(config.readLine())
  108. ioLocked = tonumber(config.readLine())
  109. powerOutputUpdated = tonumber(config.readLine())
  110. powerInputUpdated = tonumber(config.readLine())
  111. ioSmoothing = tonumber(config.readLine())
  112. IOlimiting = tonumber(config.readLine())
  113. config.close()
  114. end
  115.  
  116. --periphSearch function by https://github.com/acidjazz/drmon/blob/master/drmon.lua
  117. function periphSearch(type)
  118. local names = peripheral.getNames()
  119. local i, name
  120. for i, name in pairs(names) do
  121. if peripheral.getType(name) == type then
  122. return peripheral.wrap(name)
  123. end
  124. end
  125. return null
  126. end
  127.  
  128. --graphics functions
  129. function gWrite(text, x, y, cl, clBg)
  130. mon.monitor.setCursorPos(x, y)
  131. mon.monitor.setTextColor(cl)
  132. mon.monitor.setBackgroundColor(clBg)
  133. mon.monitor.write(text)
  134. end
  135.  
  136. function gWriteTextOnly(text, x, y, cl, lmt)
  137. mon.monitor.setCursorPos(x, y)
  138. mon.monitor.setTextColor(cl)
  139. for tl = 0,string.len(text),1 do
  140. letter = string.sub(text,tl,tl)
  141. clBg = mon.monitor.getBackgroundColor()
  142. if tl > lmt then
  143. clBg = colors.gray
  144. end
  145. mon.monitor.setBackgroundColor(clBg)
  146. mon.monitor.write(letter)
  147. end
  148. end
  149.  
  150. function gWriteR(text, x, y, cl, clBg)
  151. gWrite(text, mon.x - string.len(tostring(text)) - x, y, cl, clBg)
  152. end
  153.  
  154. function gClear()
  155. mon.monitor.setBackgroundColor(colors.black)
  156. mon.monitor.clear()
  157. mon.monitor.setCursorPos(1,1)
  158. end
  159.  
  160. function gWriteLR(textL, textR, xL, xR, y, clL, clR, clBg)
  161. gWrite(textL, xL, y, clL, clBg)
  162. gWriteR(textR, xR, y, clR, clBg)
  163. end
  164.  
  165. function gDrawLine(x, y, length, cl)
  166. if length < 0 then
  167. return
  168. end
  169. mon.monitor.setCursorPos(x, y)
  170. if cl ~= nil then
  171. mon.monitor.setBackgroundColor(cl)
  172. end
  173. mon.monitor.write(string.rep(" ", length))
  174. end
  175.  
  176. function gDrawProgressBar(x, y, length, proportion, cl, clBg)
  177. if proportion < 0.0 or proportion > 1.0 then
  178. gDrawLine(x, y, length, cl)
  179. else
  180. gDrawLine(x, y, length, clBg)
  181. gDrawLine(x, y, math.floor(proportion*length), cl)
  182. end
  183. end
  184.  
  185. function gDrawStandardProgressBar(y, proportion, cl)
  186. gDrawProgressBar(2, y, mon.x-2, proportion, cl, colors.gray)
  187. end
  188.  
  189. --initialization function
  190. function initialize()
  191. --connect machines
  192. energy_core = periphSearch("draconic_rf_storage")
  193. reactor = periphSearch("draconic_reactor")
  194. inputGate = periphSearch("flow_gate")
  195. outputGate = peripheral.wrap("top")
  196.  
  197. --detect if they are null and give a valid error message
  198. if reactor == null then
  199. error("No valid reactor was found!")
  200. end
  201. if inputGate == null then
  202. error("No input flux gate was found!")
  203. end
  204. if outputGate == null then
  205. error("No output flux gate was found!")
  206. end
  207. if energy_core == null then
  208. print("No energy core was found. Skipping.")
  209. end
  210.  
  211. inputGate.setOverrideEnabled(true)
  212. outputGate.setOverrideEnabled(true)
  213. end
  214.  
  215. function temperatureControlSelected()
  216. targetTemp50 = math.min((tempTarget / 10000) * 50, 99)
  217. convLVL = (info.fuelConversion / info.maxFuelConversion * 1.3) - 0.3
  218. targetTempResist = ((targetTemp50^4) / (100 - targetTemp50))
  219. targetTempExpo = -(targetTempResist*convLVL) - 1000*convLVL + targetTempResist
  220. term1 = 1334.1-(3*targetTempExpo)
  221. term2 = (1200690-(2700*targetTempExpo))^2
  222. term3 = ((-1350*targetTempExpo)+(((-4*term1^3+term2)^(1/2))/2)+600345)^(1/3)
  223. targetNegCSat = -(term1/(3*term3))-(term3/3)
  224. targetCoreSat = 1 - (targetNegCSat/99)
  225. targetSat = targetCoreSat * info.maxEnergySaturation
  226. if controlSelected == 2 then
  227. targetSat = saturationTarget
  228. end
  229. saturationError = info.energySaturation - targetSat
  230. powerOutput = (math.min(saturationError, (info.maxEnergySaturation/40)) + info.generationRate)
  231. if powerOutput < 0 then
  232. powerOutput = 0
  233. end
  234. targetPowerOutput = powerOutput
  235.  
  236. tempDrainFactor = 0
  237. if tempTarget > 8000 then
  238. tempDrainFactor = 1 + ((tempTarget-8000)^2 * 0.0000025)
  239. elseif tempTarget> 2000 then
  240. tempDrainFactor = 1
  241. elseif tempTarget > 1000 then
  242. tempDrainFactor = (tempTarget-1000)/1000
  243. end
  244.  
  245. fuelUseRateTarget = (tempDrainFactor*(1D-targetSat/info.maxEnergySaturation)*(0.005)*1000000)*reactorFuelUsageMultiplier
  246. saturationTarget = targetSat
  247. end
  248.  
  249. function saturationControlSelected()
  250. coreSat = saturationTarget / info.maxEnergySaturation
  251. fuelUseRateTarget = (tempDrainFactor*(1D-coreSat)*(0.005)*1000000)*reactorFuelUsageMultiplier
  252.  
  253. saturationError = info.energySaturation - saturationTarget
  254. powerOutput = (math.min(saturationError, (info.maxEnergySaturation/40)) + info.generationRate)
  255. if powerOutput < 0 then
  256. powerOutput = 0
  257. end
  258. targetPowerOutput = powerOutput
  259. tempTarget = info.temperature
  260. end
  261.  
  262. function conversionRateControlSelected()
  263.  
  264. end
  265.  
  266. function powerOutputControlSelected()
  267. powerOutput = targetPowerOutput
  268. fuelUseRateTarget = fuelUseRate
  269. saturationTarget = info.energySaturation
  270. tempTarget = info.temperature
  271. end
  272.  
  273. --Always runs every time when the script starts
  274. if fs.exists("config.txt") then
  275. print("Loading config...")
  276. loadConfig()
  277. print("Done!")
  278. else
  279. print("Creating config...")
  280. tempTarget = 8000
  281. fieldTarget = 20
  282. fastStartup = 0
  283. safetySystems = 1
  284. onePointTwelveMode = 0
  285. saturationTarget = 11.33
  286. fuelUseRateTarget = 4433
  287. conversionTarget = 85
  288. targetPowerOutput = 3797871
  289. controlSelected = 0
  290. saturationSafetyOverride = 0
  291. scriptInitialized = 0
  292. controlsLocked = 0
  293. ioLocked = 0
  294. powerOutputUpdated = 0
  295. powerInputUpdated = 0
  296. ioSmoothing = 0
  297. IOlimiting = 0
  298. scriptFPS = 0
  299. saveConfig()
  300. print("Done!")
  301. end
  302.  
  303. explosionTextState = 0
  304. configScreenSelected = false
  305. prevSat = 69420
  306. prevTime = os.epoch("utc")
  307. fpscooldown = 10
  308. messageCooldown = 0
  309. currentTableValue = 1
  310. energyStored = 6942069420
  311. prevEnergyStored = 0
  312.  
  313. --initial monitor setup
  314. tmpMon = periphSearch("monitor")
  315. if tmpMon == null then
  316. error("No monitor was found")
  317. end
  318.  
  319. if scriptInitialized == 1 then
  320. initialize()
  321. end
  322.  
  323. --Runs every tick no matter what
  324. function update()
  325. while true do
  326. monX, monY = tmpMon.getSize()
  327. mon = {}
  328. mon.monitor, mon.x, mon.y = tmpMon, monX, monY
  329.  
  330. fpscooldown = fpscooldown + 1
  331. if fpscooldown >= 10 then
  332. currentTime = os.epoch("utc")
  333. scriptFPS = 10000/(currentTime - prevTime)
  334. fpscooldown = 0
  335. end
  336. if scriptFPS == nil then
  337. scriptFPS = 0
  338. end
  339. prevTime = currentTime
  340.  
  341. if scriptFPS > 15 then
  342. fpsColor = colors.lime
  343. elseif scriptFPS > 13 then
  344. fpsColor = colors.yellow
  345. elseif scriptFPS > 8 then
  346. fpsColor = colors.orange
  347. else
  348. fpsColor = colors.red
  349. end
  350.  
  351. if controlsLocked ~= 1 then
  352. bottomBarColor = colors.lightGray
  353. else
  354. bottomBarColor = colors.gray
  355. end
  356.  
  357. if scriptInitialized == 1 then
  358. main()
  359. if configScreenSelected == true then
  360. configScreen()
  361. else
  362. controlScreen()
  363. end
  364. else
  365. configScreenSelected = true
  366. configScreen()
  367. gWrite("INITIALIZE SCRIPT", 8, 17, colors.white, colors.purple)
  368. end
  369.  
  370. if powerOutput ~= powerOutput then
  371. powerOutput = 0
  372. end
  373. saveConfig()
  374.  
  375. sleep()
  376. end
  377. end
  378.  
  379. --The function that detects if the monitor has been touched and then runs
  380. function updateMon()
  381. while true do
  382. event, side, xPos, yPos = os.pullEvent("monitor_touch")
  383. if configScreenSelected == true then
  384. --runs if config screen is selected and the monitor has been touched
  385. if yPos == 2 and xPos >= 15 and xPos <= 16 then
  386. onePointTwelveMode = toggle(onePointTwelveMode)
  387. elseif yPos == 3 and xPos >= 16 and xPos <= 17 then
  388. fastStartup = toggle(fastStartup)
  389. elseif yPos == 4 and xPos >= 18 and xPos <= 19 then
  390. safetySystems = toggle(safetySystems)
  391. elseif yPos == 5 and xPos >= 24 and xPos <= 25 then
  392. saturationSafetyOverride = toggle(saturationSafetyOverride)
  393. elseif yPos == 6 and xPos >= 16 and xPos <= 17 then
  394. IOlimiting = toggle(IOlimiting)
  395. end
  396.  
  397.  
  398. if scriptInitialized == 1 then
  399. if yPos == 17 and xPos >= 8 and xPos <= 13 then
  400. configScreenSelected = false
  401. end
  402. else
  403. if yPos == 17 and xPos >= 8 and xPos <= 24 then
  404. scriptInitialized = 1
  405. configScreenSelected = false
  406. initialize()
  407. end
  408. end
  409. else
  410. --runs if config screen is NOT selected and the monitor has been touched
  411. if yPos == 17 and xPos == 1 then
  412. controlsLocked = toggle(controlsLocked)
  413. end
  414. if controlsLocked ~= 1 then
  415. if yPos == 4 and xPos == 2 then
  416. tempTarget = tempTarget - 1.0
  417. controlSelected = 0
  418. prevLowestSatSubtractor = 20000
  419. elseif yPos == 4 and xPos >= 4 and xPos <= 5 then
  420. tempTarget = tempTarget - 10.0
  421. controlSelected = 0
  422. prevLowestSatSubtractor = 200000
  423. elseif yPos == 4 and xPos >= 7 and xPos <= 9 then
  424. tempTarget = tempTarget - 100.0
  425. controlSelected = 0
  426. prevLowestSatSubtractor = 2000000
  427. elseif yPos == 4 and xPos >= 11 and xPos <= 13 then
  428. tempTarget = tempTarget + 100.0
  429. controlSelected = 0
  430. prevLowestSatSubtractor = 20000
  431. elseif yPos == 4 and xPos >= 15 and xPos <= 16 then
  432. tempTarget = tempTarget + 10.0
  433. controlSelected = 0
  434. prevLowestSatSubtractor = 20000
  435. elseif yPos == 4 and xPos == 18 then
  436. tempTarget = tempTarget + 1.0
  437. controlSelected = 0
  438. prevLowestSatSubtractor = 20000
  439. end
  440. if controlSelected == 0 then
  441. tempTarget = math.floor(tempTarget*1.0)/1.0
  442.  
  443. if tempTarget < 2000 then
  444. tempTarget = 2000
  445. end
  446. end
  447.  
  448. if fieldTarget <= 10 then
  449. fieldTargetSetDivider = 10
  450. else
  451. fieldTargetSetDivider = 1
  452. end
  453. if fieldTarget <= 9.999 then
  454. fieldTargetSetDivider2 = 10
  455. else
  456. fieldTargetSetDivider2 = 1
  457. end
  458. if yPos == 9 and xPos == 2 then
  459. fieldTarget = fieldTarget - 0.099/fieldTargetSetDivider
  460. elseif yPos == 9 and xPos >= 4 and xPos <= 5 then
  461. fieldTarget = fieldTarget - 0.999/fieldTargetSetDivider
  462. elseif yPos == 9 and xPos >= 7 and xPos <= 9 then
  463. fieldTarget = fieldTarget - 9.999/fieldTargetSetDivider
  464. elseif yPos == 9 and xPos >= 11 and xPos <= 13 then
  465. fieldTarget = fieldTarget + 10.001/fieldTargetSetDivider2
  466. elseif yPos == 9 and xPos >= 15 and xPos <= 16 then
  467. fieldTarget = fieldTarget + 1.001/fieldTargetSetDivider2
  468. elseif yPos == 9 and xPos == 18 then
  469. fieldTarget = fieldTarget + 0.101/fieldTargetSetDivider2
  470. end
  471.  
  472. if fieldTarget <= 10 and fieldTargetSetDivider == 1 then
  473. fieldTarget = 10
  474. end
  475.  
  476. if yPos == 14 and xPos == 2 then
  477. saturationTarget = saturationTarget - 100000
  478. prevLowestSatSubtractor = 20000
  479. controlSelected = 2
  480. elseif yPos == 14 and xPos >= 4 and xPos <= 5 then
  481. saturationTarget = saturationTarget - 1000000.0
  482. prevLowestSatSubtractor = 20000
  483. controlSelected = 2
  484. elseif yPos == 14 and xPos >= 7 and xPos <= 9 then
  485. saturationTarget = saturationTarget - 10000000.0
  486. prevLowestSatSubtractor = 20000
  487. controlSelected = 2
  488. elseif yPos == 14 and xPos >= 11 and xPos <= 13 then
  489. saturationTarget = saturationTarget + 10000000.0
  490. prevLowestSatSubtractor = 2000000
  491. controlSelected = 2
  492. elseif yPos == 14 and xPos >= 15 and xPos <= 16 then
  493. saturationTarget = saturationTarget + 1000000.0
  494. prevLowestSatSubtractor = 200000
  495. controlSelected = 2
  496. elseif yPos == 14 and xPos == 18 then
  497. saturationTarget = saturationTarget + 100000
  498. prevLowestSatSubtractor = 20000
  499. controlSelected = 2
  500. end
  501.  
  502. if controlSelected == 2 then
  503. if saturationTarget > 1000000000 then
  504. saturationTarget = 1000000000
  505. end
  506.  
  507. if saturationTarget < 0 then
  508. saturationTarget = 0
  509. end
  510.  
  511. end
  512. if fuelUseRateTarget >= 10000 then
  513. fuelUseRateTargetMultiplier = 10
  514. else
  515. fuelUseRateTargetMultiplier = 1
  516. end
  517.  
  518. --if yPos == 4 and xPos == monX-17 then
  519. -- fuelUseRateTarget = fuelUseRateTarget - 1*fuelUseRateTargetMultiplier
  520. -- controlSelected = 3
  521. -- prevLowestSatSubtractor = 20000
  522. --elseif yPos == 4 and xPos >= monX-15 and xPos <= monX-14 then
  523. -- fuelUseRateTarget = fuelUseRateTarget - 10.0*fuelUseRateTargetMultiplier
  524. -- controlSelected = 3
  525. -- prevLowestSatSubtractor = 200000
  526. --elseif yPos == 4 and xPos >= monX-12 and xPos <= monX-10 then
  527. -- fuelUseRateTarget = fuelUseRateTarget - 100.0*fuelUseRateTargetMultiplier
  528. -- controlSelected = 3
  529. -- prevLowestSatSubtractor = 2000000
  530. --elseif yPos == 4 and xPos >= monX-8 and xPos <= monX-6 then
  531. -- fuelUseRateTarget = fuelUseRateTarget + 100.0*fuelUseRateTargetMultiplier
  532. -- controlSelected = 3
  533. -- prevLowestSatSubtractor = 20000
  534. --elseif yPos == 4 and xPos >= monX-4 and xPos <= monX-3 then
  535. -- fuelUseRateTarget = fuelUseRateTarget + 10.0*fuelUseRateTargetMultiplier
  536. -- controlSelected = 3
  537. -- prevLowestSatSubtractor = 20000
  538. --elseif yPos == 4 and xPos == monX-1 then
  539. -- fuelUseRateTarget = fuelUseRateTarget + 1*fuelUseRateTargetMultiplier
  540. -- controlSelected = 3
  541. -- prevLowestSatSubtractor = 20000
  542. --end
  543.  
  544. if controlSelected == 3 then
  545. if fuelUseRateTarget < 500 then
  546. fuelUseRateTarget = 500.5
  547. end
  548. end
  549.  
  550. if yPos == 9 and xPos == monX-17 then
  551. conversionTarget = conversionTarget - 0.1
  552. elseif yPos == 9 and xPos >= monX-15 and xPos <= monX-14 then
  553. conversionTarget = conversionTarget - 1.0
  554. elseif yPos == 9 and xPos >= monX-12 and xPos <= monX-10 then
  555. conversionTarget = conversionTarget - 10.0
  556. elseif yPos == 9 and xPos >= monX-8 and xPos <= monX-6 then
  557. conversionTarget = conversionTarget + 10.0
  558. elseif yPos == 9 and xPos >= monX-4 and xPos <= monX-3 then
  559. conversionTarget = conversionTarget + 1.0
  560. elseif yPos == 9 and xPos == monX-1 then
  561. conversionTarget = conversionTarget + 0.1
  562. end
  563.  
  564. if conversionTarget > 100 then
  565. conversionTarget = 100
  566. end
  567.  
  568. if conversionTarget < 0 then
  569. conversionTarget = 0
  570. end
  571.  
  572. if yPos == 14 and xPos == monX-17 then
  573. targetPowerOutput = targetPowerOutput - 1000.0
  574. controlSelected = 5
  575. elseif yPos == 14 and xPos >= monX-15 and xPos <= monX-14 then
  576. targetPowerOutput = targetPowerOutput - 10000.0
  577. controlSelected = 5
  578. elseif yPos == 14 and xPos >= monX-12 and xPos <= monX-10 then
  579. targetPowerOutput = targetPowerOutput - 100000.0
  580. controlSelected = 5
  581. elseif yPos == 14 and xPos >= monX-8 and xPos <= monX-6 then
  582. targetPowerOutput = targetPowerOutput + 100000.0
  583. controlSelected = 5
  584. elseif yPos == 14 and xPos >= monX-4 and xPos <= monX-3 then
  585. targetPowerOutput = targetPowerOutput + 10000.0
  586. controlSelected = 5
  587. elseif yPos == 14 and xPos == monX-1 then
  588. targetPowerOutput = targetPowerOutput + 1000.0
  589. controlSelected = 5
  590. end
  591.  
  592. if targetPowerOutput < 0*reactorOutputMultiplier then
  593. targetPowerOutput = 0*reactorOutputMultiplier
  594. end
  595.  
  596. if fieldTarget <= 10 then
  597. fieldTarget = math.floor(fieldTarget*10.0*10.0)/100.0
  598. else
  599. fieldTarget = math.floor(fieldTarget*10.0)/10.0
  600. end
  601.  
  602. if fieldTarget < 0.00001 then
  603. fieldTarget = 0.00001
  604. elseif fieldTarget > 100 then
  605. fieldTarget = 100
  606. end
  607.  
  608. if safetySystems == 1 then
  609. if tempTarget > 10000 then
  610. tempTarget = 10000
  611. end
  612. if targetPowerOutput > 25000000*reactorOutputMultiplier then
  613. targetPowerOutput = 25000000*reactorOutputMultiplier
  614. end
  615. if conversionTarget > 90 then
  616. conversionTarget = 90
  617. end
  618. if fuelUseRateTarget > 51000.5 then
  619. fuelUseRateTarget = 51000.5
  620. end
  621. if saturationTarget < 85000000 then
  622. saturationTarget = 85000000
  623. end
  624. if fieldTarget <= 5 and safetySystems == 1 then
  625. fieldTarget = 5
  626. end
  627. end
  628.  
  629. if yPos == 17 and xPos >= 2 and xPos <= 5 then
  630. if info.status == "cold" or info.status == "cooling" or info.status == "stopping" then
  631. reactor.chargeReactor()
  632. reactor.activateReactor()
  633. else
  634. reactor.stopReactor()
  635. end
  636. end
  637.  
  638. if yPos == 17 and xPos >= 15 and xPos <= 21 then
  639. ioLocked = toggle(ioLocked)
  640. end
  641.  
  642. if yPos == 17 and xPos >= 23 and xPos <= 31 then
  643. ioSmoothing = toggle(ioSmoothing)
  644. end
  645.  
  646. if yPos == 17 and xPos >= 8 and xPos <= 13 then
  647. configScreenSelected = true
  648. end
  649. end
  650. end
  651. end
  652. end
  653.  
  654. --The main function that runs calculations and stuff every tick after the program has been initialized
  655. function main()
  656. if reactor ~= reactor then
  657. print ("a minor reactor disconnection error has been prevented! DE please fix your reactor disconnecting from cc randomly!")
  658. else
  659. info = reactor.getReactorInfo()
  660. end
  661. energyCoreExists = false
  662. energyCoreFull = false
  663. if energy_core ~= null then
  664. energyStored = energy_core.getEnergyStored()
  665. if energyStored ~= nil then
  666. energyCoreExists = true
  667. energyTransfer = energyStored - prevEnergyStored
  668. prevEnergyStored = energyStored
  669. end
  670. end
  671. if energyCoreExists and energyStored > energy_core.getMaxEnergyStored()-100000 and ioSmoothing == 1 then
  672. energyCoreFull = true
  673. end
  674.  
  675. if info == nil then
  676. print ("a MAJOR reactor disconnection error has been prevented! DE please fix your reactor disconnecting from cc randomly!")
  677. info = prevInfo
  678. end
  679.  
  680. prevInfo = info
  681.  
  682. coreSat = info.energySaturation / info.maxEnergySaturation
  683. fuelConversion = info.fuelConversion / info.maxFuelConversion * 100
  684. avaliableFuelDivider = 10368 / info.maxFuelConversion
  685. maxSmoothing = maxIOsmoothing / avaliableFuelDivider
  686.  
  687. tempDrainFactor = 0
  688. if info.temperature > 8000 then
  689. tempDrainFactor = 1 + ((info.temperature-8000)^2 * 0.0000025)
  690. elseif info.temperature > 2000 then
  691. tempDrainFactor = 1
  692. elseif info.temperature > 1000 then
  693. tempDrainFactor = (info.temperature-1000)/1000
  694. end
  695.  
  696. fieldPercentage = (info.fieldStrength/info.maxFieldStrength)*100
  697. saturationPercentage = (info.energySaturation/info.maxEnergySaturation)*100
  698.  
  699. fieldStrengthError = (info.maxFieldStrength * fieldTarget/100) - info.fieldStrength
  700. requiredInput = math.min((info.maxFieldStrength * info.fieldDrainRate) / (info.maxFieldStrength - info.fieldStrength), info.maxFieldStrength - info.fieldStrength)
  701. if requiredInput ~= requiredInput then
  702. requiredInput = 0
  703. end
  704. powerInput = ((math.min(fieldStrengthError + requiredInput, info.maxFieldStrength))+1)*reactorOutputMultiplier
  705.  
  706. fuelUseRate = (tempDrainFactor*(1D-coreSat)*(0.005)*1000000)*reactorFuelUsageMultiplier
  707.  
  708. if controlSelected == 0 then
  709. temperatureControlSelected()
  710. elseif controlSelected == 2 then
  711. saturationControlSelected()
  712. elseif controlSelected == 3 then
  713. conversionRateControlSelected()
  714. elseif controlSelected == 5 then
  715. powerOutputControlSelected()
  716. end
  717.  
  718. if info.status == "running" and fuelConversion >= conversionTarget then
  719. reactor.stopReactor()
  720. print("Fuel conversion levels above set target. Stopping reactor!")
  721. end
  722.  
  723. if info.status == "warming_up" then
  724. if fieldPercentage >= 10 or fastStartup == 1 then
  725. if saturationPercentage >= 50 and fastStartup == 0 then
  726. powerInput = 500000*reactorOutputMultiplier/avaliableFuelDivider
  727. else
  728. powerInput = 100000000*reactorOutputMultiplier/avaliableFuelDivider
  729. end
  730. else
  731. powerInput = 10000*reactorOutputMultiplier/avaliableFuelDivider
  732. end
  733. if info.temperature >= 2000 then
  734. reactor.activateReactor()
  735. end
  736. end
  737.  
  738. if powerOutput ~= powerOutput then
  739. powerOutput = 0
  740. end
  741.  
  742. if powerInput ~= powerInput then
  743. powerInput = 0
  744. end
  745.  
  746. if ioLocked ~= 1 and energyCoreFull == false then
  747. if ioSmoothing ~= 1 then
  748. powerInputUpdated = powerInput
  749. powerOutputUpdated = powerOutput
  750. else
  751.  
  752. inputSmoothingError = powerInput - powerInputUpdated
  753. outputSmoothingError = powerOutput - powerOutputUpdated
  754.  
  755. if inputSmoothingError > maxSmoothing then
  756. inputSmoothingError = maxSmoothing
  757. elseif inputSmoothingError < -maxSmoothing then
  758. inputSmoothingError = -maxSmoothing
  759. end
  760.  
  761. if outputSmoothingError > maxSmoothing then
  762. outputSmoothingError = maxSmoothing
  763. elseif outputSmoothingError < -maxSmoothing then
  764. outputSmoothingError = -maxSmoothing
  765. end
  766.  
  767. powerInputUpdated = powerInputUpdated + inputSmoothingError
  768. powerOutputUpdated = powerOutputUpdated + outputSmoothingError
  769. end
  770.  
  771. if powerOutputUpdated <= 0 then
  772. powerOutputUpdated = 0
  773. end
  774.  
  775. if powerInputUpdated <= 0 then
  776. powerInputUpdated = 0
  777. end
  778.  
  779. if info.status == "cold" then
  780. powerInputUpdated = 0
  781. powerOutputUpdated = 0
  782. end
  783.  
  784. if IOlimiting == 1 then
  785. convLVL = ((info.fuelConversion / info.maxFuelConversion * 1.3)*5.2)^0.83 + 1
  786.  
  787. if powerInputUpdated < IOlimitingMinIN/avaliableFuelDivider then
  788. if info.status == "stopping" or info.status == "running" then
  789. powerInputUpdated = IOlimitingMinIN/avaliableFuelDivider
  790. end
  791. end
  792.  
  793. if powerOutputUpdated > IOlimitingMaxOUT/avaliableFuelDivider*convLVL then
  794. powerOutputUpdated = IOlimitingMaxOUT/avaliableFuelDivider*convLVL
  795. end
  796. end
  797.  
  798. inputGate.setFlowOverride(powerInputUpdated)
  799. outputGate.setFlowOverride(powerOutputUpdated)
  800. end
  801. end
  802.  
  803. --Displays controls, reactor temperature and stuff
  804. function controlScreen()
  805. gClear()
  806. corePosX = monX/2
  807. corePosY = monY/2-2
  808. coreColor = colors.gray
  809.  
  810. remainingFuel = (info.maxFuelConversion - info.fuelConversion) * 1000
  811. fuelTargetRemove = (info.maxFuelConversion * 1000 * ((100 - conversionTarget)/100))
  812. reactableFuel = remainingFuel - fuelTargetRemove
  813. fuelETA = (reactableFuel / fuelUseRate) * 1000 / 20
  814. if fuelETA < 0 then
  815. fuelETA = 0
  816. end
  817.  
  818. gDrawProgressBar(2, 19, mon.x, 10, bottomBarColor, bottomBarColor)
  819. gWrite("FPS: " .. math.floor(scriptFPS*10)/10, 2, 19, fpsColor, bottomBarColor)
  820. if energyCoreExists then
  821. gWrite("E.S: " .. energyStored, 12, 19, colors.white, bottomBarColor)
  822. if energyTransfer < 0 and powerOutputUpdated < powerInputUpdated then
  823. explosionETA = math.max(0,(energyStored / -energyTransfer)/20)
  824. gWrite("Explosion In: " .. secondsToTimeStringExtended(explosionETA), corePosX-13, 18, colors.yellow, colors.red)
  825. end
  826. end
  827.  
  828. if scriptStatusDisplay ~= 0 then
  829. gWrite(" ", 1, 19, colors.white, colors.green)
  830. scriptStatusDisplay = 0
  831. else
  832. gWrite(" ", 1, 19, colors.white, colors.red)
  833. scriptStatusDisplay = 1
  834. end
  835.  
  836. gWrite("CONFIG", 8, 17, colors.white, colors.purple)
  837.  
  838. if ioLocked ~= 1 then
  839. gWrite("LOCK IO", 15, 17, colors.lightGray, colors.yellow)
  840. else
  841. gWrite("LOCK IO", 15, 17, colors.lightGray, colors.orange)
  842. end
  843.  
  844. if ioSmoothing ~= 1 then
  845. gWrite("IO SMOOTH", 23, 17, colors.gray, colors.lime)
  846. else
  847. gWrite("IO SMOOTH", 23, 17, colors.gray, colors.green)
  848. end
  849.  
  850. if info.status == "stopping" or info.status == "cold" or info.status == "cooling" then
  851. if info.maxFuelConversion ~= 0 then
  852. gWrite("START", 2, 17, colors.white, colors.green)
  853. end
  854. elseif info.status ~= "beyond_hope" then
  855. gWrite("STOP", 2, 17, colors.white, colors.red)
  856. else
  857. gWrite("RUN", 2, 17, colors.yellow, colors.red)
  858. end
  859.  
  860.  
  861. if info.status == "running" or info.status == "stopping" then
  862. if info.temperature > 10000 then
  863. coreColor = colors.white
  864. elseif info.temperature > 9000 then
  865. coreColor = colors.yellow
  866. elseif info.temperature > 5700 then
  867. coreColor = colors.orange
  868. else
  869. coreColor = colors.red
  870. end
  871. elseif info.status == "cold" then
  872. coreColor = colors.gray
  873. elseif info.status == "warming_up" then
  874. coreColor = colors.lightGray
  875. end
  876.  
  877. shieldColorTMP = colors.gray
  878. shieldColorTMP2 = colors.gray
  879.  
  880. if fieldPercentage> 50 then
  881. shieldColorTMP2 = colors.lightBlue
  882. elseif fieldPercentage > 25 then
  883. shieldColorTMP2 = colors.cyan
  884. else
  885. shieldColorTMP2 = colors.blue
  886. end
  887. if info.status == "beyond_hope" then
  888. shieldColorTMP = colors.magenta
  889. shieldColorTMP2 = colors.magenta
  890. coreColor = colors.pink
  891. if math.random(0,100) > 90 then
  892. coreColor = colors.white
  893. end
  894. end
  895.  
  896. if fieldPercentage > 9.13 then
  897. shieldColor = shieldColorTMP2
  898. else
  899. shieldColor = shieldColorTMP
  900. end
  901. gDrawProgressBar(corePosX-3, corePosY-5, 9, 1, shieldColor, colors.gray)
  902. if fieldPercentage > 8.3 then
  903. shieldColor = shieldColorTMP2
  904. else
  905. shieldColor = shieldColorTMP
  906. end
  907. gDrawProgressBar(corePosX-5, corePosY-4, 13, 1, shieldColor, colors.gray)
  908. if fieldPercentage > 7.47 then
  909. shieldColor = shieldColorTMP2
  910. else
  911. shieldColor = shieldColorTMP
  912. end
  913. gDrawProgressBar(corePosX-6, corePosY-3, 15, 1, shieldColor, colors.gray)
  914. if fieldPercentage > 6.64 then
  915. shieldColor = shieldColorTMP2
  916. else
  917. shieldColor = shieldColorTMP
  918. end
  919. gDrawProgressBar(corePosX-7, corePosY-2, 17, 1, shieldColor, colors.gray)
  920. if fieldPercentage > 5.81 then
  921. shieldColor = shieldColorTMP2
  922. else
  923. shieldColor = shieldColorTMP
  924. end
  925. gDrawProgressBar(corePosX-8, corePosY-1, 19, 1, shieldColor, colors.gray)
  926. if fieldPercentage > 4.98 then
  927. shieldColor = shieldColorTMP2
  928. else
  929. shieldColor = shieldColorTMP
  930. end
  931. gDrawProgressBar(corePosX-8, corePosY, 19, 1, shieldColor, colors.gray)
  932. if fieldPercentage > 4.15 then
  933. shieldColor = shieldColorTMP2
  934. else
  935. shieldColor = shieldColorTMP
  936. end
  937. gDrawProgressBar(corePosX-8, corePosY+1, 19, 1, shieldColor, colors.gray)
  938. if fieldPercentage > 3.32 then
  939. shieldColor = shieldColorTMP2
  940. else
  941. shieldColor = shieldColorTMP
  942. end
  943. gDrawProgressBar(corePosX-8, corePosY+2, 19, 1, shieldColor, colors.gray)
  944. if fieldPercentage > 2.49 then
  945. shieldColor = shieldColorTMP2
  946. else
  947. shieldColor = shieldColorTMP
  948. end
  949. gDrawProgressBar(corePosX-7, corePosY+3, 17, 1, shieldColor, colors.gray)
  950. if fieldPercentage > 1.66 then
  951. shieldColor = shieldColorTMP2
  952. else
  953. shieldColor = shieldColorTMP
  954. end
  955. gDrawProgressBar(corePosX-6, corePosY+4, 15, 1, shieldColor, colors.gray)
  956. if fieldPercentage > 0.83 then
  957. shieldColor = shieldColorTMP2
  958. else
  959. shieldColor = shieldColorTMP
  960. end
  961. gDrawProgressBar(corePosX-5, corePosY+5, 13, 1, shieldColor, colors.gray)
  962. if fieldPercentage > 0.01 then
  963. shieldColor = shieldColorTMP2
  964. else
  965. shieldColor = shieldColorTMP
  966. end
  967.  
  968. gDrawProgressBar(corePosX-3, corePosY+6, 9, 1, shieldColor, colors.gray)
  969.  
  970. gDrawProgressBar(corePosX-3, corePosY-4, 9, 1, coreColor, colors.gray)
  971. gDrawProgressBar(corePosX-5, corePosY-3, 13, 1, coreColor, colors.gray)
  972. gDrawProgressBar(corePosX-6, corePosY-2, 15, 1, coreColor, colors.gray)
  973. gDrawProgressBar(corePosX-7, corePosY-1, 17, 1, coreColor, colors.gray)
  974. gDrawProgressBar(corePosX-7, corePosY, 17, 1, coreColor, colors.gray)
  975. gDrawProgressBar(corePosX-7, corePosY+1, 17, 1, coreColor, colors.gray)
  976. gDrawProgressBar(corePosX-7, corePosY+2, 17, 1, coreColor, colors.gray)
  977. gDrawProgressBar(corePosX-6, corePosY+3, 15, 1, coreColor, colors.gray)
  978. gDrawProgressBar(corePosX-5, corePosY+4, 13, 1, coreColor, colors.gray)
  979. gDrawProgressBar(corePosX-3, corePosY+5, 9, 1, coreColor, colors.gray)
  980.  
  981. warnings = {}
  982. messageCooldown = messageCooldown + 1
  983. local tableValue = 0
  984.  
  985. if energyCoreFull then
  986. table.insert(warnings, tableValue, energyCoreFullWarning)
  987. tableValue = tableValue + 1
  988. end
  989. if fuelConversion >= conversionTarget then
  990. table.insert(warnings, tableValue, fuelConversionWarning)
  991. tableValue = tableValue + 1
  992. end
  993. if powerOutputUpdated < powerInputUpdated then
  994. table.insert(warnings, tableValue, powerOutputWarning)
  995. tableValue = tableValue + 1
  996. end
  997. if info.status == "beyond_hope" then
  998. table.insert(warnings, tableValue, reactorBoomWarning)
  999. tableValue = tableValue + 1
  1000. end
  1001.  
  1002. if messageCooldown > 20 then
  1003. currentTableValue = currentTableValue + 1
  1004. messageCooldown = 0
  1005. end
  1006. if currentTableValue > tableValue then
  1007. currentTableValue = 1
  1008. end
  1009. if warnings[currentTableValue] then
  1010. warnings[currentTableValue]()
  1011. end
  1012.  
  1013. if info.maxFuelConversion == 0 then
  1014. gWrite("Reactor Core Empty!", corePosX-8, 1, colors.orange, colors.black)
  1015. elseif info.status == "cold" then
  1016. gWrite("Reactor Offline", corePosX-6, 1, colors.lightGray, colors.black)
  1017. elseif info.status == "warming_up" then
  1018. gWrite("Charging Reactor...", corePosX-8, 1, colors.blue, colors.black)
  1019. elseif info.status == "running" then
  1020. gWrite("Reactor Online", corePosX-6, 1, colors.lime, colors.black)
  1021. elseif info.status == "stopping" then
  1022. gWrite("Shutting Down...", corePosX-6, 1, colors.yellow, colors.black)
  1023. elseif info.status == "cooling" then
  1024. gWrite("Cooling Down...", corePosX-6, 1, colors.cyan, colors.black)
  1025. elseif info.status == "beyond_hope" then
  1026. explosionTextState = explosionTextState + 1
  1027. if explosionTextState > 5 then
  1028. if explosionTextState > 10 then
  1029. explosionTextState = 0
  1030. end
  1031. gWrite(" !!!EXPLOSION IMMINENT!!! ", corePosX-29, 1, colors.orange, colors.red)
  1032. else
  1033. gWrite(" !!!EXPLOSION IMMINENT!!! ", corePosX-29, 1, colors.red, colors.orange)
  1034. end
  1035. end
  1036.  
  1037. if controlSelected == 0 then
  1038. coreTempSelectorColor = colors.cyan
  1039. else
  1040. coreTempSelectorColor = colors.blue
  1041. end
  1042.  
  1043. gWrite("Core Temp: " .. info.temperature .. "°C", 2, 2, colors.white, colors.black)
  1044. gWrite("Target: " .. math.floor(tempTarget*1000.0)/1000.0 .. "°C", 2, 3, colors.white, colors.black)
  1045. gWrite("<", 2, 4, colors.white, coreTempSelectorColor)
  1046. gWrite("<<", 4, 4, colors.white, coreTempSelectorColor)
  1047. gWrite("<<<", 7, 4, colors.white, coreTempSelectorColor)
  1048. gWrite(">>>", 11, 4, colors.white, coreTempSelectorColor)
  1049. gWrite(">>", 15, 4, colors.white, coreTempSelectorColor)
  1050. gWrite(">", 18, 4, colors.white, coreTempSelectorColor)
  1051.  
  1052. if math.floor(info.temperature*10.0)/10.0 > math.floor(tempTarget*10.0)/10.0 then
  1053. tempLineColor = colors.red
  1054. elseif math.floor(info.temperature*10.0)/10.0 < math.floor(tempTarget*10.0)/10.0 then
  1055. tempLineColor = colors.yellow
  1056. else
  1057. tempLineColor = colors.green
  1058. end
  1059.  
  1060. gDrawProgressBar(1, 5, 19, info.temperature/16000.0, tempLineColor, colors.gray)
  1061.  
  1062. gWrite("Field: " .. fieldPercentage .. "%", 2, 7, colors.white, colors.black)
  1063. gWrite("Target: " .. fieldTarget .. "%", 2, 8, colors.white, colors.black)
  1064. gWrite("<", 2, 9, colors.white, colors.blue)
  1065. gWrite("<<", 4, 9, colors.white, colors.blue)
  1066. gWrite("<<<", 7, 9, colors.white, colors.blue)
  1067. gWrite(">>>", 11, 9, colors.white, colors.blue)
  1068. gWrite(">>", 15, 9, colors.white, colors.blue)
  1069. gWrite(">", 18, 9, colors.white, colors.blue)
  1070.  
  1071. if math.floor(info.fieldStrength/info.maxFieldStrength*1000.0)/10.0 > fieldTarget then
  1072. fieldLineColor = colors.yellow
  1073. elseif math.floor((info.fieldStrength+1000)/info.maxFieldStrength*1000.0)/10.0 < fieldTarget then
  1074. fieldLineColor = colors.red
  1075. else
  1076. fieldLineColor = colors.green
  1077. end
  1078.  
  1079. if fieldStrength == 0 then
  1080. fieldAdder = 0.1
  1081. else
  1082. fieldAdder = 0
  1083. end
  1084.  
  1085. gDrawProgressBar(1, 10, 19, (math.floor((info.fieldStrength+1000)/info.maxFieldStrength*10*10)/100) + fieldAdder, fieldLineColor, colors.gray)
  1086.  
  1087. if controlSelected == 2 then
  1088. saturationSelectorColor = colors.cyan
  1089. else
  1090. saturationSelectorColor = colors.blue
  1091. end
  1092.  
  1093. gWrite("Saturation: " .. math.floor(saturationPercentage*100.0)/100.0 .. "%", 2, 12, colors.white, colors.black)
  1094. gWrite("Target: " .. math.min(100,math.floor(saturationTarget/info.maxEnergySaturation*10000)/100) .. "%", 2, 13, colors.white, colors.black)
  1095. gWrite("<", 2, 14, colors.white, saturationSelectorColor)
  1096. gWrite("<<", 4, 14, colors.white, saturationSelectorColor)
  1097. gWrite("<<<", 7, 14, colors.white, saturationSelectorColor)
  1098. gWrite(">>>", 11, 14, colors.white, saturationSelectorColor)
  1099. gWrite(">>", 15, 14, colors.white, saturationSelectorColor)
  1100. gWrite(">", 18, 14, colors.white, saturationSelectorColor)
  1101.  
  1102. if math.floor(info.energySaturation/10000000*100.0)/100.0 < math.floor(saturationTarget/10000000*10.0*10)/100.0 then
  1103. saturationLineColor = colors.red
  1104. elseif math.floor(info.energySaturation/10000000*100.0)/100.0 > math.floor(saturationTarget/10000000*10.0*10)/100.0 then
  1105. saturationLineColor = colors.yellow
  1106. else
  1107. saturationLineColor = colors.green
  1108. end
  1109.  
  1110. gDrawProgressBar(1, 15, 19, math.floor(info.energySaturation/info.maxEnergySaturation*1100.0*10)/10000.0, saturationLineColor, colors.gray)
  1111.  
  1112. --if controlSelected == 3 then
  1113. -- convrateSelectorColor = colors.cyan
  1114. --else
  1115. -- convrateSelectorColor = colors.blue
  1116. --end
  1117. convrateSelectorColor = colors.lightGray
  1118.  
  1119. gWriteR(math.floor(fuelUseRate*1)/1.0 .. "nb/t" .. " :Conv Rate", 0, 2, colors.white, colors.black)
  1120. gWriteR(math.floor(fuelUseRateTarget*1)/1.0 .. "nb/t " .. " :Target", 0, 3, colors.white, colors.black)
  1121. gWrite("<", monX-17, 4, colors.white, convrateSelectorColor)
  1122. gWrite("<<",monX-15, 4, colors.white, convrateSelectorColor)
  1123. gWrite("<<<", monX-12, 4, colors.white, convrateSelectorColor)
  1124. gWrite(">>>", monX-8, 4, colors.white, convrateSelectorColor)
  1125. gWrite(">>", monX-4, 4, colors.white, convrateSelectorColor)
  1126. gWrite(">", monX-1, 4, colors.white, convrateSelectorColor)
  1127.  
  1128. if math.floor(fuelUseRate*1)/1.0 < math.floor(fuelUseRateTarget*1)/1.0 then
  1129. fuelUseRateLineColor = colors.yellow
  1130. elseif math.floor(fuelUseRate*1)/1.0 > math.floor(fuelUseRateTarget*1)/1.0 then
  1131. fuelUseRateLineColor = colors.red
  1132. else
  1133. fuelUseRateLineColor = colors.green
  1134. end
  1135.  
  1136. gDrawProgressBar(monX-18, 5, 19, fuelUseRate/20000, fuelUseRateLineColor, colors.gray)
  1137.  
  1138. gWriteR(math.floor(fuelConversion*10)/10.0 .. "%" .. " :Conv Level", 0, 7, colors.white, colors.black)
  1139. gWriteR(conversionTarget .. "%" .. " :Stop at", 0, 8, colors.white, colors.black)
  1140. gWrite("<", monX-17, 9, colors.white, colors.blue)
  1141. gWrite("<<", monX-15, 9, colors.white, colors.blue)
  1142. gWrite("<<<", monX-12, 9, colors.white, colors.blue)
  1143. gWrite(">>>", monX-8, 9, colors.white, colors.blue)
  1144. gWrite(">>", monX-4, 9, colors.white, colors.blue)
  1145. gWrite(">", monX-1, 9, colors.white, colors.blue)
  1146.  
  1147. if fuelConversion > conversionTarget then
  1148. convLevelLineColor = colors.red
  1149. elseif fuelConversion > conversionTarget/1.1 then
  1150. convLevelLineColor = colors.orange
  1151. elseif fuelConversion > conversionTarget/1.25 then
  1152. convLevelLineColor = colors.yellow
  1153. else
  1154. convLevelLineColor = colors.green
  1155. end
  1156.  
  1157. local fuelBarFillage = fuelConversion/info.maxFuelConversion*19 / (conversionTarget/70)
  1158. gDrawProgressBar(monX-18, 10, 19, fuelBarFillage, convLevelLineColor, colors.gray)
  1159. if fuelUseRate > 1 then
  1160. gWriteTextOnly(secondsToTimeString(fuelETA), monX-18, 10, colors.white, fuelBarFillage*19)
  1161. else
  1162. gWriteTextOnly(("-:-d -:-h -:-m -:-s"), monX-18, 10, colors.white, fuelBarFillage*19)
  1163. end
  1164.  
  1165. if controlSelected == 5 then
  1166. outputSelectorColor = colors.cyan
  1167. else
  1168. outputSelectorColor = colors.blue
  1169. end
  1170.  
  1171. gWriteR(math.floor(info.generationRate-powerInput*1)/1.0 .. "OP/t" .. " :Total", 0, 12, colors.white, colors.black)
  1172. gWriteR(math.floor(targetPowerOutput*1)/1.0 .. "OP/t" .. " :Target", 0, 13, colors.white, colors.black)
  1173. gWrite("<", monX-17, 14, colors.white, outputSelectorColor)
  1174. gWrite("<<", monX-15, 14, colors.white, outputSelectorColor)
  1175. gWrite("<<<", monX-12, 14, colors.white, outputSelectorColor)
  1176. gWrite(">>>", monX-8, 14, colors.white, outputSelectorColor)
  1177. gWrite(">>", monX-4, 14, colors.white, outputSelectorColor)
  1178. gWrite(">", monX-1, 14, colors.white, outputSelectorColor)
  1179.  
  1180. if (powerOutput-powerInput)+1000*reactorOutputMultiplier < math.floor(targetPowerOutput*1)/1.0 then
  1181. outputLineColor = colors.red
  1182. elseif (powerOutput-powerInput)-1000*reactorOutputMultiplier > math.floor(targetPowerOutput*1)/1.0 then
  1183. outputLineColor = colors.yellow
  1184. else
  1185. outputLineColor = colors.green
  1186. end
  1187.  
  1188. gDrawProgressBar(monX-18, 15, 19, (info.generationRate-powerInput*1)/25000000/reactorOutputMultiplier, outputLineColor, colors.gray)
  1189.  
  1190. ioColor = colors.white
  1191. if IOlimiting == 1 and ioLocked ~= 1 and ioSmoothing ~= 1 then
  1192. ioColor = colors.cyan
  1193. gWrite("I/O LIMITED!", corePosX-5, corePosY+9, colors.cyan, colors.black)
  1194. end
  1195.  
  1196. if ioSmoothing == 1 and ioLocked ~= 1 then
  1197. ioColor = colors.lime
  1198. gWrite("I/O SMOOTHED!", corePosX-5, corePosY+9, colors.green, colors.black)
  1199. end
  1200.  
  1201. if ioLocked == 1 then
  1202. ioColor = colors.orange
  1203. gWrite("I/O LOCKED!", corePosX-4, corePosY+9, colors.yellow, colors.black)
  1204. end
  1205.  
  1206. if energyCoreFull then
  1207. gWrite("I/O FORCELOCKED!", corePosX-7, corePosY+9, colors.red, colors.black)
  1208. end
  1209.  
  1210. gWrite("IN: " .. math.floor(powerInputUpdated*1.0)/1.0 .. "OP/t", corePosX-6, corePosY+7, ioColor, colors.black)
  1211. gWrite("OUT: " .. math.floor(powerOutputUpdated*1.0)/1.0 .. "OP/t", corePosX-7, corePosY+8, ioColor, colors.black)
  1212. end
  1213.  
  1214. --Runs when the config screen is selected or when the program isnt initialized
  1215. function configScreen()
  1216. gClear()
  1217.  
  1218. gDrawProgressBar(2, 19, mon.x, 10, bottomBarColor, bottomBarColor)
  1219. gWrite("FPS: " .. math.floor(scriptFPS*10)/10, 2, 19, fpsColor, bottomBarColor)
  1220. if energyCoreExists then
  1221. gWrite("E.S: " .. energyStored, 12, 19, colors.white, bottomBarColor)
  1222. end
  1223.  
  1224. if scriptStatusDisplay ~= 0 then
  1225. gWrite(" ", 1, 19, colors.white, colors.green)
  1226. scriptStatusDisplay = 0
  1227. else
  1228. gWrite(" ", 1, 19, colors.white, colors.red)
  1229. scriptStatusDisplay = 1
  1230. end
  1231.  
  1232. gWrite("1.12.2 Mode:", 2, 2, colors.white, colors.black)
  1233. gWrite("Fast Startup:", 2, 3, colors.white, colors.black)
  1234. gWrite("Safety Systems:", 2, 4, colors.white, colors.black)
  1235. gWrite("Sat. Safety Override:", 2, 5, colors.white, colors.black)
  1236. gWrite("I/O limiting:", 2, 6, colors.white, colors.black)
  1237.  
  1238. if onePointTwelveMode == 1 then
  1239. gWrite("ON", 15, 2, colors.white, colors.green)
  1240. else
  1241. gWrite("OF", 15, 2, colors.white, colors.red)
  1242. end
  1243.  
  1244. if fastStartup == 1 then
  1245. gWrite("ON", 16, 3, colors.white, colors.green)
  1246. else
  1247. gWrite("OF", 16, 3, colors.white, colors.red)
  1248. end
  1249.  
  1250. if safetySystems == 1 then
  1251. gWrite("ON", 18, 4, colors.white, colors.green)
  1252. else
  1253. gWrite("OF", 18, 4, colors.white, colors.red)
  1254. end
  1255.  
  1256. if saturationSafetyOverride == 1 then
  1257. gWrite("ON", 24, 5, colors.white, colors.green)
  1258. else
  1259. gWrite("OF", 24, 5, colors.white, colors.red)
  1260. end
  1261.  
  1262. if IOlimiting == 1 then
  1263. gWrite("ON", 16, 6, colors.white, colors.green)
  1264. else
  1265. gWrite("OF", 16, 6, colors.white, colors.red)
  1266. end
  1267.  
  1268. gWrite("CONFIG", 8, 17, colors.white, colors.purple)
  1269. end
  1270.  
  1271. -- run the update function and the monitor function in parallel so the entire program dosent only tick when someone clicks the monitor
  1272. parallel.waitForAny(update, updateMon)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement