thelockj

reactor_control

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