supreamcallum45

reactor_control.lua

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