bobmarley12345

Untitled

Mar 16th, 2022 (edited)
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.51 KB | None | 0 0
  1. -- BigReactor Control
  2. -- by jaranvil aka jared314, and carrot :)
  3. --
  4. -- feel free to use and/or modify this code
  5. --
  6. -----------------------------------------------
  7. -- Reactor Control - Version History
  8. --
  9. -- Version 3.0 - March 04/03/2022
  10. -- fixed the infinite parallel threads bug,
  11. -- because jaranvil though it was a great idea
  12. -- to call a parallel method, which calls itself :-)
  13. -- recursive parallel = bad
  14. -----------------------------------------------
  15. local version = 2.3
  16. -- is auto power enabled
  17. local auto_string = false
  18. -- auto on value
  19. local on = 0
  20. -- auto off value
  21. local off = 99
  22. -- is auto control rods enabled
  23. local auto_rods = false
  24. -- control rod auto value
  25. local auto_rf = 0
  26.  
  27. -- peripherals
  28. local reactor
  29. local mon
  30.  
  31. -- monitor size
  32. local monX
  33. local monY
  34.  
  35. term.clear()
  36. -------------------FORMATTING-------------------------------
  37. function cls()
  38. mon.setBackgroundColor(colors.black)
  39. mon.clear()
  40. mon.setCursorPos(1, 1)
  41. end
  42.  
  43. -- display text on computer's terminal screen
  44. function gfxprint_term(x, y, text, text_color, bg_color)
  45. term.setTextColor(text_color)
  46. term.setBackgroundColor(bg_color)
  47. term.setCursorPos(x, y)
  48. write(text)
  49. end
  50.  
  51. -- display text text on monitor, "mon" peripheral
  52. function gfxprint(x, y, text, text_color, bg_color)
  53. mon.setBackgroundColor(bg_color)
  54. mon.setTextColor(text_color)
  55. mon.setCursorPos(x, y)
  56. mon.write(text)
  57. end
  58.  
  59. -- draw line on computer terminal
  60. function gfxline(x, y, length, color)
  61. mon.setBackgroundColor(color)
  62. mon.setCursorPos(x, y)
  63. mon.write(string.rep(" ", length))
  64. end
  65.  
  66. -- draw line on computer terminal
  67. function gfxline_term(x, y, length, color)
  68. term.setBackgroundColor(color)
  69. term.setCursorPos(x, y)
  70. term.write(string.rep(" ", length))
  71. end
  72.  
  73. -- create progress bar
  74. -- draws two overlapping lines
  75. -- background line of bg_color
  76. -- main line of bar_color as a percentage of minVal/maxVal
  77. function gfx_progbar(x, y, length, minVal, maxVal, bar_color, bg_color)
  78. gfxline(x, y, length, bg_color) -- backgoround bar
  79. local barSize = math.floor((minVal / maxVal) * length)
  80. gfxline(x, y, barSize, bar_color) -- progress so far
  81. end
  82.  
  83. -- same as above but on the computer terminal
  84. function gfx_progbar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
  85. gfxline_term(x, y, length, bg_color) -- backgoround bar
  86. local barSize = math.floor((minVal / maxVal) * length)
  87. gfxline_term(x, y, barSize, bar_color) -- progress so far
  88. end
  89.  
  90. -- create button on monitor
  91. function gfxbtn(x, y, length, text, txt_color, bg_color)
  92. gfxline(x, y, length, bg_color)
  93. gfxprint((x + 2), y, text, txt_color, bg_color)
  94. end
  95.  
  96. -- header and footer bars on monitor
  97. function menubar()
  98. gfxline(1, 1, monX, colors.blue)
  99. gfxprint(2, 1, "Power Tools Settings", colors.white, colors.blue)
  100. gfxline(1, 19, monX, colors.blue)
  101. gfxprint(2, 19, " Reactor Control", colors.white, colors.blue)
  102. end
  103.  
  104. -- dropdown menu for power options
  105. function pwrmenu()
  106. gfxline(1, 2, 9, colors.gray)
  107. gfxline(1, 3, 9, colors.gray)
  108. gfxline(1, 4, 9, colors.gray)
  109. if active then
  110. gfxprint(2, 2, "ON", colors.lightGray, colors.gray)
  111. gfxprint(2, 3, "OFF", colors.white, colors.gray)
  112. else
  113. gfxprint(2, 2, "ON", colors.white, colors.gray)
  114. gfxprint(2, 3, "OFF", colors.lightGray, colors.gray)
  115. end
  116. gfxprint(2, 4, "Auto", colors.white, colors.gray)
  117. end
  118.  
  119. -- dropbox menu for tools
  120. function toolmenu()
  121. gfxline(10, 2, 14, colors.gray)
  122. gfxline(10, 3, 14, colors.gray)
  123. gfxline(10, 4, 14, colors.gray)
  124. gfxline(10, 5, 14, colors.gray)
  125. gfxprint(11, 2, "Control Rods", colors.white, colors.gray)
  126. gfxprint(11, 3, "Efficiency", colors.white, colors.gray)
  127. gfxprint(11, 4, "Fuel", colors.white, colors.gray)
  128. gfxprint(11, 5, "Waste", colors.white, colors.gray)
  129. end
  130.  
  131. -- dropdown menu for settings
  132. function settingsmenu()
  133. gfxline(12, 2, 18, colors.gray)
  134. gfxline(12, 3, 18, colors.gray)
  135. gfxprint(13, 2, "Check for Updates", colors.white, colors.gray)
  136. gfxprint(13, 3, "Reset peripherals", colors.white, colors.gray)
  137. end
  138.  
  139. -- basic popup screen with title bar and exit button
  140. function popupscreen(y, title, height)
  141. cls()
  142. menubar()
  143.  
  144. gfxline(4, y, 22, colors.blue)
  145. gfxline(25, y, 1, colors.red)
  146.  
  147. for counter = y + 1, height + y do
  148. gfxline(4, counter, 22, colors.white)
  149. end
  150.  
  151. gfxprint(25, y, "X", colors.white, colors.red)
  152. gfxprint(5, y, title, colors.white, colors.blue)
  153. end
  154.  
  155. -- write settings to config file
  156. function save_conf()
  157. sw = fs.open("config.txt", "w")
  158. sw.writeLine(version)
  159. sw.writeLine(auto_string)
  160. sw.writeLine(on)
  161. sw.writeLine(off)
  162. sw.writeLine(auto_rods)
  163. sw.writeLine(auto_rf)
  164. sw.close()
  165. end
  166.  
  167. -- read settings from file
  168. function load_conf()
  169. sr = fs.open("config.txt", "r")
  170. version = tonumber(sr.readLine())
  171. auto_string = sr.readLine()
  172. on = tonumber(sr.readLine())
  173. off = tonumber(sr.readLine())
  174. auto_rods = sr.readLine()
  175. auto_rf = tonumber(sr.readLine())
  176. sr.close()
  177. end
  178.  
  179. ------------------------END FORMATTING--------------------------
  180.  
  181. --
  182. function homepage()
  183. while true do
  184. cls()
  185. menubar()
  186. terminfo()
  187.  
  188. energy_stored = reactor.getEnergyStored()
  189.  
  190. --------POWER STAT--------------
  191. gfxprint(2, 3, "Power:", colors.yellow, colors.black)
  192. active = reactor.getActive()
  193. if active then
  194. gfxprint(10, 3, "ONLINE", colors.lime, colors.black)
  195. else
  196. gfxprint(10, 3, "OFFLINE", colors.red, colors.black)
  197. end
  198.  
  199. -----------FUEL---------------------
  200. gfxprint(2, 5, "Fuel Level:", colors.yellow, colors.black)
  201. local maxVal = reactor.getFuelAmountMax()
  202. local minVal = reactor.getFuelAmount()
  203. local percent = math.floor((minVal / maxVal) * 100)
  204. gfxprint(15, 5, percent .. "%", colors.white, colors.black)
  205.  
  206. if percent < 25 then
  207. gfx_progbar(2, 6, monX - 2, minVal, maxVal, colors.red, colors.gray)
  208. else
  209. if percent < 50 then
  210. gfx_progbar(2, 6, monX - 2, minVal, maxVal, colors.orange, colors.gray)
  211. else
  212. if percent < 75 then
  213. gfx_progbar(2, 6, monX - 2, minVal, maxVal, colors.yellow, colors.gray)
  214. else
  215. if percent <= 100 then
  216. gfx_progbar(2, 6, monX - 2, minVal, maxVal, colors.lime, colors.gray)
  217. end
  218. end
  219. end
  220. end
  221.  
  222. -----------ROD HEAT---------------
  223. gfxprint(2, 8, "Fuel Temp:", colors.yellow, colors.black)
  224. local maxVal = 2000
  225. local minVal = math.floor(reactor.getFuelTemperature())
  226.  
  227. if minVal < 500 then
  228. gfx_progbar(2, 9, monX - 2, minVal, maxVal, colors.lime, colors.gray)
  229. else
  230. if minVal < 1000 then
  231. gfx_progbar(2, 9, monX - 2, minVal, maxVal, colors.yellow, colors.gray)
  232. else
  233. if minVal < 1500 then
  234. gfx_progbar(2, 9, monX - 2, minVal, maxVal, colors.orange, colors.gray)
  235. else
  236. if minVal < 2000 then
  237. gfx_progbar(2, 9, monX - 2, minVal, maxVal, colors.red, colors.gray)
  238. else
  239. if minVal >= 2000 then
  240. gfx_progbar(2, 9, monX - 2, 2000, maxVal, colors.red, colors.gray)
  241. end
  242. end
  243. end
  244. end
  245. end
  246.  
  247. gfxprint(15, 8, math.floor(minVal) .. "/" .. maxVal, colors.white, colors.black)
  248.  
  249. -----------CASING HEAT---------------
  250. gfxprint(2, 11, "Casing Temp:", colors.yellow, colors.black)
  251. local maxVal = 2000
  252. local minVal = math.floor(reactor.getCasingTemperature())
  253. if minVal < 500 then
  254. gfx_progbar(2, 12, monX - 2, minVal, maxVal, colors.lime, colors.gray)
  255. else
  256. if minVal < 1000 then
  257. gfx_progbar(2, 12, monX - 2, minVal, maxVal, colors.yellow, colors.gray)
  258. else
  259. if minVal < 1500 then
  260. gfx_progbar(2, 12, monX - 2, minVal, maxVal, colors.orange, colors.gray)
  261. else
  262. if minVal < 2000 then
  263. gfx_progbar(2, 12, monX - 2, minVal, maxVal, colors.red, colors.gray)
  264. else
  265. if minVal >= 2000 then
  266. gfx_progbar(2, 12, monX - 2, 2000, maxVal, colors.red, colors.gray)
  267. end
  268. end
  269. end
  270. end
  271. end
  272. gfxprint(15, 11, math.floor(minVal) .. "/" .. maxVal, colors.white, colors.black)
  273.  
  274. -------------OUTPUT-------------------
  275. if reactor.isActivelyCooled() then
  276.  
  277. gfxprint(2, 14, "mB/tick:", colors.yellow, colors.black)
  278. mbt = math.floor(reactor.getHotFluidProducedLastTick())
  279. gfxprint(13, 14, mbt .. " mB/t", colors.white, colors.black)
  280.  
  281. else
  282.  
  283. gfxprint(2, 14, "RF/tick:", colors.yellow, colors.black)
  284. rft = math.floor(reactor.getEnergyProducedLastTick())
  285. gfxprint(13, 14, rft .. " RF/T", colors.white, colors.black)
  286.  
  287. end
  288.  
  289. ------------STORAGE------------
  290. if reactor.isActivelyCooled() then
  291.  
  292. gfxprint(2, 15, "mB Stored:", colors.yellow, colors.black)
  293. fluid_stored = reactor.getHotFluidAmount()
  294. fluid_max = reactor.getHotFluidAmountMax()
  295. fluid_stored_percent = math.floor((fluid_stored / fluid_max) * 100)
  296. gfxprint(13, 15, fluid_stored_percent .. "% (" .. fluid_stored .. " mB)", colors.white, colors.black)
  297.  
  298. else
  299.  
  300. gfxprint(2, 15, "RF Stored:", colors.yellow, colors.black)
  301. energy_stored_percent = math.floor((energy_stored / 10000000) * 100)
  302. gfxprint(13, 15, energy_stored_percent .. "% (" .. energy_stored .. " RF)", colors.white, colors.black)
  303.  
  304. end
  305.  
  306. -------------AUTO CONTROL RODS-----------------------
  307. auto_rods_bool = auto_rods == "true"
  308. insertion_percent = reactor.getControlRodLevel(0)
  309.  
  310. if reactor.isActivelyCooled() then
  311. gfxprint(2, 16, "Control Rods:", colors.yellow, colors.black)
  312. gfxprint(16, 16, insertion_percent .. "%", colors.white, colors.black)
  313. else
  314.  
  315. if auto_rods_bool then
  316. if active then
  317. if rft > auto_rf + 50 then
  318. reactor.setAllControlRodLevels(insertion_percent + 1)
  319. else
  320. if rft < auto_rf - 50 then
  321. reactor.setAllControlRodLevels(insertion_percent - 1)
  322. end
  323. end
  324. end
  325.  
  326. gfxprint(2, 16, "Control Rods:", colors.yellow, colors.black)
  327. gfxprint(16, 16, insertion_percent .. "%", colors.white, colors.black)
  328. gfxprint(21, 16, "(Auto)", colors.red, colors.black)
  329.  
  330. else
  331. gfxprint(2, 16, "Control Rods:", colors.yellow, colors.black)
  332. gfxprint(16, 16, insertion_percent .. "%", colors.white, colors.black)
  333. end
  334. end
  335.  
  336. -------------AUTO SHUTOFF--------------------------
  337. if reactor.isActivelyCooled() then
  338.  
  339. -- i dont know what I should do here
  340.  
  341. else
  342. auto = auto_string == "true"
  343. if auto then
  344. if active then
  345. gfxprint(2, 17, "Auto off:", colors.yellow, colors.black)
  346. gfxprint(13, 17, off .. "% RF Stored", colors.white, colors.black)
  347. if energy_stored_percent >= off then
  348. reactor.setActive(false)
  349. stop_function = "recursive"
  350. return
  351. end
  352. else
  353. gfxprint(2, 17, "Auto on:", colors.yellow, colors.black)
  354. gfxprint(13, 17, on .. "% RF Stored", colors.white, colors.black)
  355. if energy_stored_percent <= on then
  356. reactor.setActive(true)
  357. stop_function = "recursive"
  358. return
  359. end
  360. end
  361. else
  362. gfxprint(2, 17, "Auto power:", colors.yellow, colors.black)
  363. gfxprint(14, 17, "disabled", colors.red, colors.black)
  364. end
  365. end
  366.  
  367. sleep(0.5)
  368. end
  369. end
  370.  
  371. --------------MENU SCREENS--------------
  372.  
  373. -- auto power menu
  374. function auto_off()
  375.  
  376. auto = auto_string == "true"
  377. if auto then -- auto power enabled
  378.  
  379. popupscreen(3, "Auto Power", 11)
  380. gfxprint(5, 5, "Enabled", colors.lime, colors.white)
  381. gfxprint(15, 5, " disable ", colors.white, colors.black)
  382.  
  383. gfxprint(5, 7, "ON when storage =", colors.gray, colors.white)
  384. gfxprint(5, 8, " - ", colors.white, colors.black)
  385. gfxprint(13, 8, on .. "% RF", colors.black, colors.white)
  386. gfxprint(22, 8, " + ", colors.white, colors.black)
  387.  
  388. gfxprint(5, 10, "OFF when storage =", colors.gray, colors.white)
  389. gfxprint(5, 11, " - ", colors.white, colors.black)
  390. gfxprint(13, 11, off .. "% RF", colors.black, colors.white)
  391. gfxprint(22, 11, " + ", colors.white, colors.black)
  392.  
  393. gfxprint(11, 13, " Save ", colors.white, colors.black)
  394.  
  395. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  396.  
  397. -- disable auto
  398. if yPos == 5 then
  399. if xPos >= 15 and xPos <= 21 then
  400. auto_string = "false"
  401. save_conf()
  402. auto_off()
  403. else
  404. auto_off()
  405. end
  406. end
  407.  
  408. -- increase/decrease auto on %
  409. if yPos == 8 then
  410. if xPos >= 5 and xPos <= 8 then
  411. previous_on = on
  412. on = on - 1
  413. end
  414. if xPos >= 22 and xPos <= 25 then
  415. previous_on = on
  416. on = on + 1
  417. end
  418. end
  419.  
  420. -- increase/decrease auto off %
  421. if yPos == 11 then
  422. if xPos >= 5 and xPos <= 8 then
  423. previous_off = off
  424. off = off - 1
  425. end
  426. if xPos >= 22 and xPos <= 25 then
  427. previous_off = off
  428. off = off + 1
  429. end
  430. end
  431.  
  432. if on < 0 then
  433. on = 0
  434. end
  435. if off > 99 then
  436. off = 99
  437. end
  438.  
  439. if on == off or on > off then
  440. on = previous_on
  441. off = previous_off
  442. popupscreen(5, "Error", 6)
  443. gfxprint(5, 7, "Auto On value must be", colors.black, colors.white)
  444. gfxprint(5, 8, "lower then auto off", colors.black, colors.white)
  445. gfxprint(11, 10, "Okay", colors.white, colors.black)
  446. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  447.  
  448. auto_off()
  449. end
  450.  
  451. -- Okay button
  452. if yPos == 13 and xPos >= 11 and xPos <= 17 then
  453. save_conf()
  454. do_home()
  455. end
  456.  
  457. -- Exit button
  458. if yPos == 3 and xPos == 25 then
  459. do_home()
  460. end
  461.  
  462. auto_off()
  463. else
  464. popupscreen(3, "Auto Power", 5)
  465. gfxprint(5, 5, "Disabled", colors.red, colors.white)
  466. gfxprint(15, 5, " enable ", colors.white, colors.gray)
  467. gfxprint(11, 7, "Okay", colors.white, colors.black)
  468.  
  469. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  470.  
  471. -- Okay button
  472. if yPos == 7 and xPos >= 11 and xPos <= 17 then
  473. do_home()
  474. end
  475.  
  476. if yPos == 5 then
  477. if xPos >= 15 and xPos <= 21 then
  478. auto_string = "true"
  479. save_conf()
  480. auto_off()
  481. else
  482. auto_off()
  483. end
  484. else
  485. auto_off()
  486. end
  487. end
  488. end
  489.  
  490. -- efficiency menu
  491. function efficiency()
  492. popupscreen(3, "Efficiency", 12)
  493. fuel_usage = reactor.getFuelConsumedLastTick()
  494. rft = math.floor(reactor.getEnergyProducedLastTick())
  495.  
  496. rfmb = rft / fuel_usage
  497.  
  498. gfxprint(5, 5, "Fuel Consumption: ", colors.lime, colors.white)
  499. gfxprint(5, 6, fuel_usage .. " mB/t", colors.black, colors.white)
  500. gfxprint(5, 8, "Energy per mB: ", colors.lime, colors.white)
  501. gfxprint(5, 9, rfmb .. " RF/mB", colors.black, colors.white)
  502.  
  503. gfxprint(5, 11, "RF/tick:", colors.lime, colors.white)
  504. gfxprint(5, 12, rft .. " RF/T", colors.black, colors.white)
  505.  
  506. gfxprint(11, 14, " Okay ", colors.white, colors.black)
  507.  
  508. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  509.  
  510. -- Okay button
  511. if yPos == 14 and xPos >= 11 and xPos <= 17 then
  512. do_home()
  513. end
  514.  
  515. -- Exit button
  516. if yPos == 3 and xPos == 25 then
  517. do_home()
  518. end
  519.  
  520. efficiency()
  521. end
  522.  
  523. function fuel()
  524. popupscreen(3, "Fuel", 9)
  525.  
  526. fuel_max = reactor.getFuelAmountMax()
  527. fuel_level = reactor.getFuelAmount()
  528. fuel_reactivity = math.floor(reactor.getFuelReactivity())
  529.  
  530. gfxprint(5, 5, "Fuel Level: ", colors.lime, colors.white)
  531. gfxprint(5, 6, fuel_level .. "/" .. fuel_max, colors.black, colors.white)
  532.  
  533. gfxprint(5, 8, "Reactivity: ", colors.lime, colors.white)
  534. gfxprint(5, 9, fuel_reactivity .. "%", colors.black, colors.white)
  535.  
  536. gfxprint(11, 11, " Okay ", colors.white, colors.black)
  537.  
  538. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  539.  
  540. -- Okay button
  541. if yPos == 11 and xPos >= 11 and xPos <= 17 then
  542. do_home()
  543. end
  544.  
  545. -- Exit button
  546. if yPos == 3 and xPos == 25 then
  547. do_home()
  548. end
  549.  
  550. fuel()
  551. end
  552.  
  553. function waste()
  554. popupscreen(3, "Waste", 8)
  555.  
  556. waste_amount = reactor.getWasteAmount()
  557. gfxprint(5, 5, "Waste Amount: ", colors.lime, colors.white)
  558. gfxprint(5, 6, waste_amount .. " mB", colors.black, colors.white)
  559. gfxprint(8, 8, " Eject Waste ", colors.white, colors.red)
  560. gfxprint(11, 10, " Close ", colors.white, colors.black)
  561.  
  562. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  563.  
  564. -- eject button
  565. if yPos == 8 and xPos >= 8 and xPos <= 21 then
  566. reactor.doEjectWaste()
  567. popupscreen(5, "Waste Eject", 5)
  568. gfxprint(5, 7, "Waste Ejeceted.", colors.black, colors.white)
  569. gfxprint(11, 9, " Close ", colors.white, colors.black)
  570. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  571. -- Okay button
  572. if yPos == 7 and xPos >= 11 and xPos <= 17 then
  573. do_home()
  574. end
  575.  
  576. -- Exit button
  577. if yPos == 3 and xPos == 25 then
  578. do_home()
  579. end
  580. end
  581.  
  582. -- Okay button
  583. if yPos == 10 and xPos >= 11 and xPos <= 17 then
  584. do_home()
  585. end
  586.  
  587. -- Exit button
  588. if yPos == 3 and xPos == 25 then
  589. do_home()
  590. end
  591. waste()
  592. end
  593.  
  594. function set_auto_rf()
  595. popupscreen(5, "Auto Adjust", 11)
  596. gfxprint(5, 7, "Try to maintain:", colors.black, colors.white)
  597.  
  598. gfxprint(13, 9, " ^ ", colors.white, colors.gray)
  599. gfxprint(10, 11, auto_rf .. " RF/t", colors.black, colors.white)
  600. gfxprint(13, 13, " v ", colors.white, colors.gray)
  601. gfxprint(11, 15, " Okay ", colors.white, colors.gray)
  602.  
  603. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  604.  
  605. -- increase button
  606. if yPos == 9 then
  607. auto_rf = auto_rf + 100
  608. save_conf()
  609. set_auto_rf()
  610. end
  611.  
  612. -- decrease button
  613. if yPos == 13 then
  614. auto_rf = auto_rf - 100
  615. if auto_rf < 0 then
  616. auto_rf = 0
  617. end
  618. save_conf()
  619. set_auto_rf()
  620. end
  621.  
  622. if yPos == 15 then
  623. control_rods()
  624. end
  625.  
  626. set_auto_rf()
  627. end
  628.  
  629. function control_rods()
  630.  
  631. if reactor.isActivelyCooled() then
  632.  
  633. popupscreen(3, "Control Rods", 13)
  634. insertion_percent = reactor.getControlRodLevel(0)
  635.  
  636. gfxprint(5, 5, "Inserted: " .. insertion_percent .. "%", colors.black, colors.white)
  637. gfx_progbar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
  638.  
  639. gfxprint(5, 9, " << ", colors.white, colors.black)
  640. gfxprint(10, 9, " < ", colors.white, colors.black)
  641. gfxprint(17, 9, " > ", colors.white, colors.black)
  642. gfxprint(21, 9, " >> ", colors.white, colors.black)
  643.  
  644. gfxprint(5, 11, "Auto:", colors.black, colors.white)
  645. gfxprint(5, 13, "unavilable for", colors.red, colors.white)
  646. gfxprint(5, 14, "active cooling", colors.red, colors.white)
  647.  
  648. gfxprint(11, 16, " Close ", colors.white, colors.gray)
  649.  
  650. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  651.  
  652. if yPos == 9 and xPos >= 5 and xPos <= 15 then
  653. reactor.setAllControlRodLevels(insertion_percent - 10)
  654. end
  655.  
  656. if yPos == 9 and xPos >= 10 and xPos <= 13 then
  657. reactor.setAllControlRodLevels(insertion_percent - 1)
  658. end
  659.  
  660. if yPos == 9 and xPos >= 17 and xPos <= 20 then
  661. reactor.setAllControlRodLevels(insertion_percent + 1)
  662. end
  663.  
  664. if yPos == 9 and xPos >= 21 and xPos <= 25 then
  665. reactor.setAllControlRodLevels(insertion_percent + 10)
  666. end
  667.  
  668. ------Close button-------
  669. if yPos == 16 and xPos >= 11 and xPos <= 17 then
  670. do_home()
  671. end
  672.  
  673. ------Exit button------------
  674. if yPos == 5 and xPos == 25 then
  675. do_home()
  676. end
  677. control_rods()
  678.  
  679. else
  680.  
  681. popupscreen(3, "Control Rods", 13)
  682. insertion_percent = reactor.getControlRodLevel(0)
  683.  
  684. gfxprint(5, 5, "Inserted: " .. insertion_percent .. "%", colors.black, colors.white)
  685. gfx_progbar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
  686.  
  687. gfxprint(5, 9, " << ", colors.white, colors.black)
  688. gfxprint(10, 9, " < ", colors.white, colors.black)
  689. gfxprint(17, 9, " > ", colors.white, colors.black)
  690. gfxprint(21, 9, " >> ", colors.white, colors.black)
  691.  
  692. gfxprint(5, 11, "Auto:", colors.black, colors.white)
  693. gfxprint(16, 11, " disable ", colors.white, colors.black)
  694.  
  695. auto_rods_bool = auto_rods == "true"
  696. if auto_rods_bool then
  697.  
  698. gfxprint(5, 13, "RF/t: " .. auto_rf, colors.black, colors.white)
  699. gfxprint(18, 13, " set ", colors.white, colors.black)
  700. else
  701. gfxprint(16, 11, " enable ", colors.white, colors.black)
  702. gfxprint(5, 13, "disabled", colors.red, colors.white)
  703. end
  704.  
  705. gfxprint(11, 15, " Close ", colors.white, colors.gray)
  706.  
  707. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  708.  
  709. -----manual adjust buttons------------
  710. if yPos == 9 and xPos >= 5 and xPos <= 15 then
  711. reactor.setAllControlRodLevels(insertion_percent - 10)
  712. end
  713.  
  714. if yPos == 9 and xPos >= 10 and xPos <= 13 then
  715. reactor.setAllControlRodLevels(insertion_percent - 1)
  716. end
  717.  
  718. if yPos == 9 and xPos >= 17 and xPos <= 20 then
  719. reactor.setAllControlRodLevels(insertion_percent + 1)
  720. end
  721.  
  722. if yPos == 9 and xPos >= 21 and xPos <= 25 then
  723. reactor.setAllControlRodLevels(insertion_percent + 10)
  724. end
  725.  
  726. ------auto buttons-----------------
  727. if yPos == 11 and xPos >= 16 then
  728. if auto_rods_bool then
  729. auto_rods = "false"
  730. save_conf()
  731. control_rods()
  732. else
  733. auto_rods = "true"
  734. save_conf()
  735. control_rods()
  736. end
  737. end
  738.  
  739. if yPos == 13 and xPos >= 18 then
  740. set_auto_rf()
  741. end
  742.  
  743. ------Close button-------
  744. if yPos == 15 and xPos >= 11 and xPos <= 17 then
  745. do_home()
  746. end
  747.  
  748. ------Exit button------------
  749. if yPos == 5 and xPos == 25 then
  750. do_home()
  751. end
  752. control_rods()
  753.  
  754. end
  755. end
  756.  
  757. -----------------------Settings--------------------------------
  758.  
  759. function rf_mode()
  760. wait = read()
  761. end
  762.  
  763. function steam_mode()
  764. wait = read()
  765. end
  766.  
  767. function install_update(program, pastebin)
  768. cls()
  769. gfxline(4, 5, 22, colors.blue)
  770.  
  771. for counter = 6, 10 do
  772. gfxline(4, counter, 22, colors.white)
  773. end
  774.  
  775. gfxprint(5, 5, "Updating...", colors.white, colors.blue)
  776. gfxprint(5, 7, "Open computer", colors.black, colors.white)
  777. gfxprint(5, 8, "terminal.", colors.black, colors.white)
  778.  
  779. if fs.exists("install") then
  780. fs.delete("install")
  781. end
  782. shell.run("pastebin get p4zeq7Ma install")
  783. shell.run("install")
  784. end
  785.  
  786. function update()
  787. popupscreen(5, "Updates", 4)
  788. gfxprint(5, 7, "Connecting to", colors.black, colors.white)
  789. gfxprint(5, 8, "pastebin...", colors.black, colors.white)
  790.  
  791. sleep(0.5)
  792.  
  793. shell.run("pastebin get MkF2QQjH current_version.txt")
  794. sr = fs.open("current_version.txt", "r")
  795. current_version = tonumber(sr.readLine())
  796. sr.close()
  797. fs.delete("current_version.txt")
  798. terminfo()
  799.  
  800. if current_version > version then
  801.  
  802. popupscreen(5, "Updates", 7)
  803. gfxprint(5, 7, "Update Available!", colors.black, colors.white)
  804. gfxprint(11, 9, " Install ", colors.white, colors.black)
  805. gfxprint(11, 11, " Ignore ", colors.white, colors.black)
  806.  
  807. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  808.  
  809. -- Instatll button
  810. if yPos == 9 and xPos >= 11 and xPos <= 17 then
  811. install_update()
  812. end
  813.  
  814. -- Exit button
  815. if yPos == 5 and xPos == 25 then
  816. do_home()
  817. end
  818. do_home()
  819.  
  820. else
  821. popupscreen(5, "Updates", 5)
  822. gfxprint(5, 7, "You are up to date!", colors.black, colors.white)
  823. gfxprint(11, 9, " Okay ", colors.white, colors.black)
  824.  
  825. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  826.  
  827. -- Okay button
  828. if yPos == 9 and xPos >= 11 and xPos <= 17 then
  829. do_home()
  830. end
  831.  
  832. -- Exit button
  833. if yPos == 5 and xPos == 25 then
  834. do_home()
  835. end
  836. do_home()
  837. end
  838.  
  839. end
  840.  
  841. function reset_peripherals()
  842. cls()
  843. gfxline(4, 5, 22, colors.blue)
  844.  
  845. for counter = 6, 10 do
  846. gfxline(4, counter, 22, colors.white)
  847. end
  848.  
  849. gfxprint(5, 5, "Reset Peripherals", colors.white, colors.blue)
  850. gfxprint(5, 7, "Open computer", colors.black, colors.white)
  851. gfxprint(5, 8, "terminal.", colors.black, colors.white)
  852. setup_wizard()
  853.  
  854. end
  855.  
  856. -- stop running status screen if monitors was touched
  857. function stop()
  858. while true do
  859. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  860. x = xPos
  861. y = yPos
  862. stop_function = "monitor_touch"
  863. return
  864. end
  865. end
  866.  
  867. function mon_touch()
  868. -- when the monitor is touch on the homepage
  869. if y == 1 then
  870. if x < monX / 3 then
  871. pwrmenu()
  872. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  873. if xPos < 9 then
  874. if yPos == 2 then
  875. reactor.setActive(true)
  876. timer = 0 -- reset anytime the reactor is turned on/off
  877. do_home()
  878. else
  879. if yPos == 3 then
  880. reactor.setActive(false)
  881. timer = 0 -- reset anytime the reactor is turned on/off
  882. do_home()
  883. else
  884. if yPos == 4 then
  885. auto_off()
  886. else
  887. do_home()
  888. end
  889. end
  890. end
  891. else
  892. do_home()
  893. end
  894.  
  895. else
  896. if x < 20 then
  897. toolmenu()
  898. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  899. if xPos < 25 and xPos > 10 then
  900. if yPos == 2 then
  901. control_rods()
  902. else
  903. if yPos == 3 then
  904. efficiency()
  905. else
  906. if yPos == 4 then
  907. fuel()
  908. else
  909. if yPos == 5 then
  910. waste()
  911. else
  912. do_home()
  913. end
  914. end
  915. end
  916. end
  917. else
  918. do_home()
  919. end
  920. else
  921. if x < monX then
  922. settingsmenu()
  923. local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  924. if xPos > 13 then
  925. if yPos == 2 then
  926. update()
  927. else
  928. if yPos == 3 then
  929. reset_peripherals()
  930. else
  931. do_home()
  932. end
  933. end
  934. else
  935. do_home()
  936. end
  937. end
  938. end
  939. end
  940. else
  941. do_home()
  942. end
  943. end
  944.  
  945. function terminfo()
  946. term.clear()
  947. gfxline_term(1, 1, 55, colors.blue)
  948. gfxprint_term(13, 1, "BigReactor Controls", colors.white, colors.blue)
  949. gfxline_term(1, 19, 55, colors.blue)
  950. gfxprint_term(6, 19, "by jaranvil aka jared314, and carrot :)", colors.white, colors.blue)
  951.  
  952. gfxprint_term(1, 3, "Current program:", colors.white, colors.black)
  953. gfxprint_term(1, 4, "Reactor Control v3.0", colors.blue, colors.black)
  954.  
  955. gfxprint_term(1, 6, "Please give me your feedback, suggestions,", colors.white, colors.black)
  956. gfxprint_term(1, 7, "and errors!", colors.white, colors.black)
  957. end
  958.  
  959. -- run both homepage() and stop() until one returns
  960. function do_home()
  961. cls()
  962. parallel.waitForAny(homepage, stop)
  963.  
  964. if stop_function == "terminal_screen" then
  965. stop_function = "nothing"
  966. setup_wizard()
  967. elseif stop_function == "monitor_touch" then
  968. stop_function = "nothing"
  969. mon_touch()
  970. elseif stop_function == "recursive" then
  971. stop_function = "nothing"
  972. do_home()
  973. end
  974. end
  975.  
  976. -- test if the entered monitor and reactor can be wrapped
  977. function do_setup()
  978. term.clear()
  979.  
  980. gfxline_term(1, 1, 55, colors.blue)
  981. gfxprint_term(10, 1, "BigReactors Controls", colors.white, colors.blue)
  982.  
  983. gfxline_term(1, 19, 55, colors.blue)
  984. gfxprint_term(3, 19, "by jaranvil aka jared314, and carrot :)", colors.white, colors.blue)
  985.  
  986.  
  987. gfxprint_term(1, 3, "Searching for a peripherals...", colors.white, colors.black)
  988. reactor = find_reactor()
  989. mon = find_mon()
  990. gfxprint_term(2, 5, "Connecting to reactor...", colors.white, colors.black)
  991. if reactor == nil then
  992. gfxprint_term(1, 8, "Error:", colors.red, colors.black)
  993. gfxprint_term(1, 9, "Could not connect to reactor", colors.red, colors.black)
  994. gfxprint_term(1, 10, "Reactor must be connected with networking cable", colors.white, colors.black)
  995. gfxprint_term(1, 11, "and modems or the computer is directly beside", colors.white, colors.black)
  996. gfxprint_term(1, 12, "the reactors computer port.", colors.white, colors.black)
  997. gfxprint_term(1, 14, "Press Enter to continue...", colors.gray, colors.black)
  998. wait = read()
  999. setup_wizard()
  1000. else
  1001. gfxprint_term(27, 5, "success", colors.lime, colors.black)
  1002. sleep(0.5)
  1003. end
  1004.  
  1005. gfxprint_term(2, 6, "Connecting to monitor...", colors.white, colors.black)
  1006. sleep(0.5)
  1007. if mon == nil then
  1008. gfxprint_term(1, 7, "Error:", colors.red, colors.black)
  1009. gfxprint_term(1, 8, "Could not connect to a monitor. Place a 3x3 advanced monitor", colors.red, colors.black)
  1010. gfxprint_term(1, 11, "Press Enter to continue...", colors.gray, colors.black)
  1011. wait = read()
  1012. setup_wizard()
  1013. else
  1014. monX, monY = mon.getSize()
  1015. gfxprint_term(27, 6, "success", colors.lime, colors.black)
  1016. sleep(0.5)
  1017. end
  1018. gfxprint_term(2, 7, "saving configuration...", colors.white, colors.black)
  1019.  
  1020. save_conf()
  1021.  
  1022. sleep(0.1)
  1023. gfxprint_term(1, 9, "Setup Complete!", colors.lime, colors.black)
  1024. sleep(1)
  1025.  
  1026. auto = auto_string == "true"
  1027. do_home()
  1028. end
  1029. ----------------SETUP-------------------------------
  1030.  
  1031. function setup_wizard()
  1032. term.clear()
  1033.  
  1034. gfxprint_term(1, 1, "BigReactor Controls v" .. version, colors.lime, colors.black)
  1035. gfxprint_term(1, 2, "Peripheral setup", colors.white, colors.black)
  1036. gfxprint_term(1, 4, "Step 1:", colors.lime, colors.black)
  1037. gfxprint_term(1, 5, "-Place 3x3 advanced monitors next to computer.", colors.white, colors.black)
  1038. gfxprint_term(1, 7, "Step 2:", colors.lime, colors.black)
  1039. gfxprint_term(1, 8, "-Place a wired modem on this computer and on the ", colors.white, colors.black)
  1040. gfxprint_term(1, 9, " computer port of the reactor.", colors.white, colors.black)
  1041. gfxprint_term(1, 10, "-connect modems with network cable.", colors.white, colors.black)
  1042. gfxprint_term(1, 11, "-right click modems to activate.", colors.white, colors.black)
  1043. gfxprint_term(1, 13, "Press Enter when ready...", colors.gray, colors.black)
  1044.  
  1045. wait = read()
  1046. do_setup()
  1047. end
  1048.  
  1049. function find_reactor()
  1050. local names = peripheral.getNames()
  1051. local i, name
  1052. for i, name in pairs(names) do
  1053. if peripheral.getType(name) == "BigReactors-Reactor" then
  1054. return peripheral.wrap(name)
  1055. else
  1056. -- return nil
  1057. end
  1058. end
  1059. end
  1060.  
  1061. function find_mon()
  1062. local names = peripheral.getNames()
  1063. local i, name
  1064. for i, name in pairs(names) do
  1065. if peripheral.getType(name) == "monitor" then
  1066. test = name
  1067. return peripheral.wrap(name)
  1068. else
  1069. -- return nil
  1070. end
  1071. end
  1072. end
  1073.  
  1074. function start()
  1075. -- if configs exists, load values and test
  1076. if fs.exists("config.txt") then
  1077. load_conf()
  1078. do_setup()
  1079. else
  1080. setup_wizard()
  1081. end
  1082. end
  1083.  
  1084. start()
Add Comment
Please, Sign In to add comment