Highbeam

reactorse1

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