Wolf1596Games

BigReactors Control (modified for BiggerReactors)

Aug 4th, 2021 (edited)
496
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --  BigReactor Control
  2. --  by jaranvil aka jared314
  3. --
  4. --  feel free to use and/or modify this code
  5. --
  6. --  Modified by Wolf1596Games
  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 = 3.0
  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. function homepage()
  188.   while true do
  189.     clear()
  190.     menu_bar()
  191.     terminal_screen()
  192.  
  193.     energy_stored = reactor.battery().stored()
  194.    
  195.     --------POWER STAT--------------
  196.     draw_text(2, 3, "Power:", colors.yellow, colors.black)
  197.     active = reactor.active()
  198.     if active then
  199.       draw_text(10, 3, "ONLINE", colors.lime, colors.black)
  200.     else
  201.       draw_text(10, 3, "OFFLINE", colors.red, colors.black)
  202.     end
  203.  
  204.     -----------FUEL---------------------
  205.     draw_text(2, 5, "Fuel Level:", colors.yellow, colors.black)
  206.     local maxVal = reactor.fuelTank().capacity()
  207.     local minVal = reactor.fuelTank().fuel()
  208.     local percent = math.floor((minVal/maxVal)*100)
  209.     draw_text(15, 5, percent.."%", colors.white, colors.black)
  210.  
  211.     if percent < 25 then
  212.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.red, colors.gray)
  213.     else if percent < 50 then
  214.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.orange, colors.gray)
  215.     else if percent < 75 then
  216.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  217.     else if percent <= 100 then
  218.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.lime, colors.gray)
  219.     end
  220.     end
  221.     end
  222.     end
  223.  
  224.     -----------ROD HEAT---------------
  225.     draw_text(2, 8, "Fuel Temp:", colors.yellow, colors.black)
  226.     local maxVal = 2000
  227.     local minVal = math.floor(reactor.fuelTemperature())
  228.  
  229.     if minVal < 500 then
  230.     progress_bar(2, 9, monX-2, minVal, maxVal, colors.lime, colors.gray)
  231.     else if minVal < 1000 then
  232.     progress_bar(2, 9, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  233.     else if minVal < 1500 then  
  234.     progress_bar(2, 9, monX-2, minVal, maxVal, colors.orange, colors.gray)
  235.     else if minVal < 2000 then
  236.     progress_bar(2, 9, monX-2, minVal, maxVal, colors.red, colors.gray)
  237.     else if minVal >= 2000 then
  238.       progress_bar(2, 9, monX-2, 2000, maxVal, colors.red, colors.gray)
  239.     end
  240.     end
  241.     end
  242.     end
  243.     end
  244.  
  245.     draw_text(15, 8, math.floor(minVal).."/"..maxVal, colors.white, colors.black)
  246.  
  247.     -----------CASING HEAT---------------
  248.     draw_text(2, 11, "Casing Temp:", colors.yellow, colors.black)
  249.     local maxVal = 2000
  250.     local minVal = math.floor(reactor.casingTemperature())
  251.     if minVal < 500 then
  252.     progress_bar(2, 12, monX-2, minVal, maxVal, colors.lime, colors.gray)
  253.     else if minVal < 1000 then
  254.     progress_bar(2, 12, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  255.     else if minVal < 1500 then  
  256.     progress_bar(2, 12, monX-2, minVal, maxVal, colors.orange, colors.gray)
  257.     else if minVal < 2000 then
  258.     progress_bar(2, 12, monX-2, minVal, maxVal, colors.red, colors.gray)
  259.     else if minVal >= 2000 then
  260.       progress_bar(2, 12, monX-2, 2000, maxVal, colors.red, colors.gray)
  261.     end
  262.     end
  263.     end
  264.     end
  265.     end
  266.     draw_text(15, 11, math.floor(minVal).."/"..maxVal, colors.white, colors.black)
  267.  
  268.     -------------OUTPUT-------------------
  269.     if reactor.battery() == null then
  270.  
  271.       draw_text(2, 14, "mB/tick:", colors.yellow, colors.black)
  272.       mbt = math.floor(reactor.getHotFluidProducedLastTick())
  273.       draw_text(13, 14, mbt.." mB/t", colors.white, colors.black)
  274.  
  275.     else
  276.  
  277.       draw_text(2, 14, "FE/tick:", colors.yellow, colors.black)
  278.       rft = math.floor(reactor.battery().producedLastTick())
  279.       draw_text(13, 14, rft.." FE/T", colors.white, colors.black)
  280.  
  281.     end
  282.  
  283.     ------------STORAGE------------
  284.     if reactor.battery() == null then
  285.  
  286.       draw_text(2, 15, "mB Stored:", colors.yellow, colors.black)
  287.       fluid_stored = reactor.getHotFluidAmount()
  288.       fluid_max = reactor.getHotFluidAmountMax()
  289.       fluid_stored_percent = math.floor((fluid_stored/fluid_max)*100)
  290.       draw_text(13, 15, fluid_stored_percent.."% ("..fluid_stored.." mB)", colors.white, colors.black)
  291.  
  292.     else
  293.  
  294.     draw_text(2, 15, "FE Stored:", colors.yellow, colors.black)
  295.     energy_stored_percent = math.floor((energy_stored/reactor.battery().capacity())*100)
  296.     draw_text(13, 15, energy_stored_percent.."% ("..energy_stored.." FE)", colors.white, colors.black)
  297.  
  298.  
  299.     end
  300.  
  301.     -------------AUTO CONTROL RODS-----------------------
  302.     auto_rods_bool = auto_rods == "true"
  303.     insertion_percent = reactor.getControlRod(0).level()
  304.  
  305.     if reactor.battery() == null then
  306.       draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
  307.       draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  308.     else
  309.  
  310.       if auto_rods_bool then
  311.         if active then
  312.           if rft > auto_rf+50 then
  313.             reactor.setAllControlRodLevels(insertion_percent+1)
  314.           else if rft < auto_rf-50 then
  315.             reactor.setAllControlRodLevels(insertion_percent-1)
  316.           end
  317.           end
  318.         end
  319.  
  320.         draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
  321.         draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  322.         draw_text(21, 16, "(Auto)", colors.red, colors.black)
  323.      
  324.       else
  325.         draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
  326.         draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  327.       end
  328.     end
  329.  
  330.  
  331.     -------------AUTO SHUTOFF--------------------------
  332.     if reactor.battery() == null then
  333.  
  334.       --i dont know what I should do here
  335.  
  336.  
  337.     else
  338.       auto = auto_string == "true"
  339.       if auto then
  340.         if active then
  341.           draw_text(2, 17, "Auto off:", colors.yellow, colors.black)
  342.           draw_text(13, 17, off.."% FE Stored", colors.white, colors.black)
  343.           if energy_stored_percent >= off then
  344.             reactor.setActive(false)
  345.             call_homepage()
  346.           end
  347.         else
  348.           draw_text(2, 17, "Auto on:", colors.yellow, colors.black)
  349.           draw_text(13, 17, on.."% FE Stored", colors.white, colors.black)
  350.           if energy_stored_percent <= on then
  351.             reactor.setActive(true)
  352.             call_homepage()
  353.           end
  354.         end
  355.       else
  356.         draw_text(2, 17, "Auto power:", colors.yellow, colors.black)
  357.         draw_text(14, 17, "disabled", colors.red, colors.black)
  358.       end
  359.     end
  360.  
  361.     sleep(0.5)
  362.   end
  363. end
  364.  
  365.  
  366. --------------MENU SCREENS--------------
  367.  
  368. --auto power menu
  369. function auto_off()
  370.  
  371.   auto = auto_string == "true"
  372.   if auto then --auto power enabled
  373.  
  374.     popup_screen(3, "Auto Power", 11)
  375.     draw_text(5, 5, "Enabled", colors.lime, colors.white)
  376.     draw_text(15, 5, " disable ", colors.white, colors.black)
  377.    
  378.     draw_text(5, 7, "ON when storage =", colors.gray, colors.white)
  379.     draw_text(5, 8, " - ", colors.white, colors.black)
  380.     draw_text(13, 8, on.."% RF", colors.black, colors.white)
  381.     draw_text(22, 8, " + ", colors.white, colors.black)
  382.  
  383.     draw_text(5, 10, "OFF when storage =", colors.gray, colors.white)
  384.     draw_text(5, 11, " - ", colors.white, colors.black)
  385.     draw_text(13, 11, off.."% RF", colors.black, colors.white)
  386.     draw_text(22, 11, " + ", colors.white, colors.black)
  387.  
  388.     draw_text(11, 13, " Save ", colors.white, colors.black)
  389.  
  390.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  391.  
  392.     --disable auto
  393.     if yPos == 5 then
  394.       if xPos >= 15 and xPos <= 21 then
  395.         auto_string = "false"
  396.         save_config()
  397.         auto_off()
  398.       else
  399.         auto_off()
  400.       end
  401.     end
  402.  
  403.     --increase/decrease auto on %
  404.     if yPos == 8 then
  405.       if xPos >= 5 and xPos <= 8 then
  406.         previous_on = on
  407.         on = on-1
  408.       end
  409.       if xPos >= 22 and xPos <= 25 then
  410.         previous_on = on
  411.         on = on+1
  412.       end
  413.     end
  414.  
  415.     --increase/decrease auto off %
  416.     if yPos == 11 then
  417.       if xPos >= 5 and xPos <= 8 then
  418.         previous_off = off
  419.         off = off-1
  420.       end
  421.       if xPos >= 22 and xPos <= 25 then
  422.         previous_off = off
  423.         off = off+1
  424.       end
  425.     end
  426.  
  427.     if on < 0 then on = 0 end
  428.     if off >99 then off = 99 end
  429.  
  430.     if on == off or on > off then
  431.       on = previous_on
  432.       off = previous_off
  433.       popup_screen(5, "Error", 6)
  434.       draw_text(5, 7, "Auto On value must be", colors.black, colors.white)
  435.       draw_text(5, 8, "lower then auto off", colors.black, colors.white)
  436.       draw_text(11, 10, "Okay", colors.white, colors.black)
  437.       local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  438.  
  439.       auto_off()
  440.     end
  441.  
  442.     --Okay button
  443.     if yPos == 13 and xPos >= 11 and xPos <= 17 then
  444.       save_config()
  445.       call_homepage()
  446.     end
  447.  
  448.     --Exit button
  449.     if yPos == 3 and xPos == 25 then
  450.       call_homepage()
  451.     end
  452.  
  453.     auto_off()
  454.   else
  455.     popup_screen(3, "Auto Power", 5)
  456.     draw_text(5, 5, "Disabled", colors.red, colors.white)
  457.     draw_text(15, 5, " enable ", colors.white, colors.gray)
  458.     draw_text(11, 7, "Okay", colors.white, colors.black)
  459.  
  460.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  461.  
  462.     --Okay button
  463.     if yPos == 7 and xPos >= 11 and xPos <= 17 then
  464.       call_homepage()
  465.     end
  466.  
  467.     if yPos == 5 then
  468.       if xPos >= 15 and xPos <= 21 then
  469.         auto_string = "true"
  470.         save_config()
  471.         auto_off()
  472.       else
  473.         auto_off()
  474.       end
  475.     else
  476.       auto_off()
  477.     end
  478.   end
  479. end
  480.  
  481. --efficiency menu
  482. function efficiency()
  483.   popup_screen(3, "Efficiency", 12)
  484.   fuel_usage = reactor.fuelTank().burnedLastTick()
  485.   rft = math.floor(reactor.battery().producedLastTick())
  486.  
  487.   rfmb = rft / fuel_usage
  488.  
  489.   draw_text(5, 5, "Fuel Consumption: ", colors.lime, colors.white)
  490.   draw_text(5, 6, fuel_usage.." mB/t", colors.black, colors.white)
  491.   draw_text(5, 8, "Energy per mB: ", colors.lime, colors.white)
  492.   draw_text(5, 9, rfmb.." FE/mB", colors.black, colors.white)
  493.  
  494.   draw_text(5, 11, "RF/tick:", colors.lime, colors.white)
  495.   draw_text(5, 12, rft.." FE/T", colors.black, colors.white)
  496.  
  497.   draw_text(11, 14, " Okay ", colors.white, colors.black)
  498.  
  499.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  500.  
  501.   --Okay button
  502.   if yPos == 14 and xPos >= 11 and xPos <= 17 then
  503.     call_homepage()
  504.   end
  505.  
  506.   --Exit button
  507.   if yPos == 3 and xPos == 25 then
  508.     call_homepage()
  509.   end
  510.  
  511.   efficiency()
  512. end
  513.  
  514.  
  515. function fuel()
  516.   popup_screen(3, "Fuel", 9)
  517.  
  518.   fuel_max = reactor.fuelTank().capacity()
  519.   fuel_level = reactor.fuelTank().fuel()
  520.   fuel_reactivity = math.floor(reactor.fuelTank().fuelReactivity())
  521.  
  522.   draw_text(5, 5, "Fuel Level: ", colors.lime, colors.white)
  523.   draw_text(5, 6, fuel_level.."/"..fuel_max, colors.black, colors.white)
  524.  
  525.   draw_text(5, 8, "Reactivity: ", colors.lime, colors.white)
  526.   draw_text(5, 9, fuel_reactivity.."%", colors.black, colors.white)
  527.  
  528.   draw_text(11, 11, " Okay ", colors.white, colors.black)
  529.  
  530.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  531.  
  532.  
  533.   --Okay button
  534.   if yPos == 11 and xPos >= 11 and xPos <= 17 then
  535.     call_homepage()
  536.   end
  537.  
  538.   --Exit button
  539.   if yPos == 3 and xPos == 25 then
  540.     call_homepage()
  541.   end
  542.  
  543.   fuel()
  544. end
  545.  
  546. function waste()
  547.   popup_screen(3, "Waste", 8)
  548.  
  549.   waste_amount = reactor.fuelTank().waste()
  550.   draw_text(5, 5, "Waste Amount: ", colors.lime, colors.white)
  551.   draw_text(5, 6, waste_amount.." mB", colors.black, colors.white)
  552.   draw_text(8, 8, " Eject Waste ", colors.white, colors.red)
  553.   draw_text(11, 10, " Close ", colors.white, colors.black)
  554.  
  555.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  556.  
  557.   --eject button
  558.   if yPos == 8 and xPos >= 8 and xPos <= 21 then
  559.     reactor.fuelTank().ejectWaste()
  560.     popup_screen(5, "Waste Eject", 5)
  561.     draw_text(5, 7, "Waste Ejeceted.", colors.black, colors.white)
  562.     draw_text(11, 9, " Close ", colors.white, colors.black)
  563.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  564.     --Okay button
  565.     if yPos == 7 and xPos >= 11 and xPos <= 17 then
  566.       call_homepage()
  567.     end
  568.  
  569.     --Exit button
  570.     if yPos == 3 and xPos == 25 then
  571.       call_homepage()
  572.     end
  573.   end
  574.  
  575.   --Okay button
  576.   if yPos == 10 and xPos >= 11 and xPos <= 17 then
  577.     call_homepage()
  578.   end
  579.  
  580.   --Exit button
  581.   if yPos == 3 and xPos == 25 then
  582.     call_homepage()
  583.   end
  584.   waste()
  585. end
  586.  
  587. function set_auto_rf()
  588.   popup_screen(5, "Auto Adjust", 11)
  589.     draw_text(5, 7, "Try to maintain:", colors.black, colors.white)
  590.  
  591.     draw_text(13, 9, " ^ ", colors.white, colors.gray)
  592.     draw_text(10, 11, auto_rf.." FE/t", colors.black, colors.white)
  593.     draw_text(13, 13, " v ", colors.white, colors.gray)
  594.     draw_text(11, 15, " Okay ", colors.white, colors.gray)
  595.  
  596.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  597.  
  598.     --increase button
  599.     if yPos == 9 then
  600.       auto_rf = auto_rf + 100
  601.       save_config()
  602.       set_auto_rf()
  603.     end
  604.  
  605.     --decrease button
  606.     if yPos == 13 then
  607.       auto_rf = auto_rf - 100
  608.       if auto_rf < 0 then auto_rf = 0 end
  609.       save_config()
  610.       set_auto_rf()
  611.     end
  612.  
  613.     if yPos == 15 then
  614.       control_rods()
  615.     end
  616.  
  617.     set_auto_rf()
  618. end
  619.  
  620. function control_rods()
  621.  
  622.   if reactor.battery() == null then
  623.  
  624.     popup_screen(3, "Control Rods", 13)
  625.     insertion_percent = reactor.getControlRod(0).level()
  626.  
  627.     draw_text(5, 5, "Inserted: "..insertion_percent.."%", colors.black, colors.white)
  628.     progress_bar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
  629.  
  630.     draw_text(5, 9, " << ", colors.white, colors.black)
  631.     draw_text(10, 9, " < ", colors.white, colors.black)
  632.     draw_text(17, 9, " > ", colors.white, colors.black)
  633.     draw_text(21, 9, " >> ", colors.white, colors.black)
  634.  
  635.     draw_text(5, 11, "Auto:", colors.black, colors.white)
  636.     draw_text(5, 13, "unavilable for", colors.red, colors.white)
  637.     draw_text(5, 14, "active cooling", colors.red, colors.white)
  638.  
  639.     draw_text(11, 16, " Close ", colors.white, colors.gray)
  640.  
  641.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  642.  
  643.     if yPos == 9 and xPos >= 5 and xPos <= 15 then
  644.       reactor.setAllControlRodLevels(insertion_percent-10)
  645.     end
  646.  
  647.     if yPos == 9 and xPos >= 10 and xPos <= 13 then
  648.       reactor.setAllControlRodLevels(insertion_percent-1)
  649.     end
  650.  
  651.     if yPos == 9 and xPos >= 17 and xPos <= 20 then
  652.       reactor.setAllControlRodLevels(insertion_percent+1)
  653.     end
  654.  
  655.     if yPos == 9 and xPos >= 21 and xPos <= 25 then
  656.       reactor.setAllControlRodLevels(insertion_percent+10)
  657.     end
  658.  
  659.     ------Close button-------
  660.     if yPos == 16 and xPos >= 11 and xPos <= 17 then
  661.       call_homepage()
  662.     end
  663.  
  664.     ------Exit button------------
  665.     if yPos == 5 and xPos == 25 then
  666.       call_homepage()
  667.     end
  668.     control_rods()
  669.  
  670.   else
  671.  
  672.     popup_screen(3, "Control Rods", 13)
  673.     insertion_percent = reactor.getControlRod(0).level()
  674.  
  675.     draw_text(5, 5, "Inserted: "..insertion_percent.."%", colors.black, colors.white)
  676.     progress_bar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
  677.  
  678.     draw_text(5, 9, " << ", colors.white, colors.black)
  679.     draw_text(10, 9, " < ", colors.white, colors.black)
  680.     draw_text(17, 9, " > ", colors.white, colors.black)
  681.     draw_text(21, 9, " >> ", colors.white, colors.black)
  682.  
  683.     draw_text(5, 11, "Auto:", colors.black, colors.white)
  684.     draw_text(16, 11, " disable ", colors.white, colors.black)
  685.  
  686.     auto_rods_bool = auto_rods == "true"
  687.     if auto_rods_bool then
  688.      
  689.       draw_text(5, 13, "FE/t: "..auto_rf, colors.black, colors.white)
  690.       draw_text(18, 13, " set ", colors.white, colors.black)
  691.     else
  692.       draw_text(16, 11, " enable ", colors.white, colors.black)
  693.       draw_text(5, 13, "disabled", colors.red, colors.white)
  694.     end
  695.  
  696.     draw_text(11, 15, " Close ", colors.white, colors.gray)
  697.  
  698.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  699.  
  700.     -----manual adjust buttons------------
  701.     if yPos == 9 and xPos >= 5 and xPos <= 15 then
  702.       reactor.setAllControlRodLevels(insertion_percent-10)
  703.     end
  704.  
  705.     if yPos == 9 and xPos >= 10 and xPos <= 13 then
  706.       reactor.setAllControlRodLevels(insertion_percent-1)
  707.     end
  708.  
  709.     if yPos == 9 and xPos >= 17 and xPos <= 20 then
  710.       reactor.setAllControlRodLevels(insertion_percent+1)
  711.     end
  712.  
  713.     if yPos == 9 and xPos >= 21 and xPos <= 25 then
  714.       reactor.setAllControlRodLevels(insertion_percent+10)
  715.     end
  716.  
  717.  
  718.     ------auto buttons-----------------
  719.     if yPos == 11 and xPos >= 16 then
  720.       if auto_rods_bool then
  721.         auto_rods = "false"
  722.         save_config()
  723.         control_rods()
  724.       else
  725.         auto_rods = "true"
  726.         save_config()
  727.         control_rods()
  728.       end
  729.     end
  730.  
  731.     if yPos == 13 and xPos >= 18 then
  732.       set_auto_rf()
  733.     end
  734.  
  735.     ------Close button-------
  736.     if yPos == 15 and xPos >= 11 and xPos <= 17 then
  737.       call_homepage()
  738.     end
  739.  
  740.     ------Exit button------------
  741.     if yPos == 5 and xPos == 25 then
  742.       call_homepage()
  743.     end
  744.     control_rods()
  745.  
  746.   end
  747. end
  748.  
  749. -----------------------Settings--------------------------------
  750.  
  751.  
  752. function rf_mode()
  753.   wait = read()
  754. end
  755.  
  756. function steam_mode()
  757.   wait = read()
  758. end
  759.  
  760. function install_update(program, pastebin)
  761.     clear()
  762.     draw_line(4, 5, 22, colors.blue)
  763.  
  764.     for counter = 6, 10 do
  765.       draw_line(4, counter, 22, colors.white)
  766.     end
  767.  
  768.     draw_text(5, 5, "Updating...", colors.white, colors.blue)
  769.     draw_text(5, 7, "Open computer", colors.black, colors.white)
  770.     draw_text(5, 8, "terminal.", colors.black, colors.white)
  771.  
  772.     if fs.exists("install") then fs.delete("install") end
  773.     shell.run("pastebin get 2JU1k5vg install")
  774.     shell.run("install")
  775. end
  776.  
  777. function update()
  778.   popup_screen(5, "Updates", 4)
  779.   draw_text(5, 7, "Connecting to", colors.black, colors.white)
  780.   draw_text(5, 8, "pastebin...", colors.black, colors.white)
  781.  
  782.   sleep(0.5)
  783.  
  784.   shell.run("pastebin get Xmfy1Dfc current_version.txt")
  785.   sr = fs.open("current_version.txt", "r")
  786.   current_version = tonumber(sr.readLine())
  787.   sr.close()
  788.   fs.delete("current_version.txt")
  789.   terminal_screen()
  790.  
  791.   if current_version > version then
  792.  
  793.     popup_screen(5, "Updates", 7)
  794.     draw_text(5, 7, "Update Available!", colors.black, colors.white)
  795.     draw_text(11, 9, " Install ", colors.white, colors.black)
  796.     draw_text(11, 11, " Ignore ", colors.white, colors.black)
  797.  
  798.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  799.  
  800.     --Instatll button
  801.     if yPos == 9 and xPos >= 11 and xPos <= 17 then
  802.       install_update()
  803.     end
  804.  
  805.     --Exit button
  806.     if yPos == 5 and xPos == 25 then
  807.       call_homepage()
  808.     end
  809.     call_homepage()
  810.  
  811.   else
  812.     popup_screen(5, "Updates", 5)
  813.     draw_text(5, 7, "You are up to date!", colors.black, colors.white)
  814.     draw_text(11, 9, " Okay ", colors.white, colors.black)
  815.  
  816.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  817.  
  818.     --Okay button
  819.     if yPos == 9 and xPos >= 11 and xPos <= 17 then
  820.       call_homepage()
  821.     end
  822.  
  823.     --Exit button
  824.     if yPos == 5 and xPos == 25 then
  825.       call_homepage()
  826.     end
  827.     call_homepage()
  828.   end
  829.  
  830.  
  831.  
  832. end
  833.  
  834. function reset_peripherals()
  835.   clear()
  836.   draw_line(4, 5, 22, colors.blue)
  837.  
  838.   for counter = 6, 10 do
  839.     draw_line(4, counter, 22, colors.white)
  840.   end
  841.  
  842.   draw_text(5, 5, "Reset Peripherals", colors.white, colors.blue)
  843.   draw_text(5, 7, "Open computer", colors.black, colors.white)
  844.   draw_text(5, 8, "terminal.", colors.black, colors.white)
  845.   setup_wizard()
  846.  
  847. end
  848.  
  849. --stop running status screen if monitors was touched
  850. function stop()
  851.   while true do
  852.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  853.       x = xPos
  854.       y = yPos
  855.       stop_function = "monitor_touch"
  856.     return
  857.   end
  858. end
  859.  
  860. function mon_touch()
  861.   --when the monitor is touch on the homepage
  862.   if y == 1 then
  863.       if x < monX/3 then
  864.         power_menu()
  865.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  866.         if xPos < 9 then
  867.           if yPos == 2 then
  868.             reactor.setActive(true)
  869.             timer = 0 --reset anytime the reactor is turned on/off
  870.             call_homepage()
  871.           else if yPos == 3 then
  872.             reactor.setActive(false)
  873.             timer = 0 --reset anytime the reactor is turned on/off
  874.             call_homepage()
  875.           else if yPos == 4 then
  876.             auto_off()
  877.           else
  878.             call_homepage()
  879.           end
  880.           end
  881.           end
  882.         else
  883.           call_homepage()
  884.         end
  885.        
  886.       else if x < 20 then
  887.         tools_menu()
  888.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  889.         if xPos < 25 and xPos > 10 then
  890.           if yPos == 2 then
  891.             control_rods()
  892.           else if yPos == 3 then
  893.             efficiency()
  894.           else if yPos == 4 then
  895.             fuel()
  896.           else if yPos == 5 then
  897.             waste()
  898.           else
  899.             call_homepage()
  900.           end
  901.           end
  902.           end
  903.           end
  904.         else
  905.           call_homepage()
  906.         end
  907.       else if x < monX then
  908.         settings_menu()
  909.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  910.         if xPos > 13 then
  911.           if yPos == 2 then
  912.             update()
  913.           else if yPos == 3 then
  914.             reset_peripherals()
  915.           else
  916.             call_homepage()
  917.           end
  918.           end
  919.         else
  920.           call_homepage()
  921.         end
  922.       end
  923.       end
  924.       end
  925.     else
  926.       call_homepage()
  927.     end
  928. end
  929.  
  930. function terminal_screen()
  931.   term.clear()
  932.   draw_line_term(1, 1, 55, colors.blue)
  933.   draw_text_term(13, 1, "BigReactor Controls", colors.white, colors.blue)
  934.   draw_line_term(1, 19, 55, colors.blue)
  935.   draw_text_term(13, 19, "by jaranvil aka jared314", colors.white, colors.blue)
  936.  
  937.   draw_text_term(1, 3, "Current program:", colors.white, colors.black)
  938.   draw_text_term(1, 4, "Reactor Control v"..version, colors.blue, colors.black)
  939.  
  940.   draw_text_term(1, 6, "Installer:", colors.white, colors.black)
  941.   draw_text_term(1, 7, "pastebin.com/p4zeq7Ma", colors.blue, colors.black)
  942.  
  943.   draw_text_term(1, 9, "Please give me your feedback, suggestions,", colors.white, colors.black)
  944.   draw_text_term(1, 10, "and errors!", colors.white, colors.black)
  945.  
  946.   draw_text_term(1, 11, "reddit.com/r/br_controls", colors.blue, colors.black)
  947. end
  948.  
  949. --run both homepage() and stop() until one returns
  950. function call_homepage()
  951.   clear()
  952.   parallel.waitForAny(homepage, stop)
  953.  
  954.   if stop_function == "terminal_screen" then
  955.     stop_function = "nothing"
  956.     setup_wizard()
  957.   else if stop_function == "monitor_touch" then
  958.     stop_function = "nothing"
  959.     mon_touch()
  960.   end
  961.   end
  962. end
  963.  
  964. --test if the entered monitor and reactor can be wrapped
  965.   function test_configs()
  966.   term.clear()
  967.  
  968.   draw_line_term(1, 1, 55, colors.blue)
  969.   draw_text_term(10, 1, "BigReactors Controls", colors.white, colors.blue)
  970.  
  971.   draw_line_term(1, 19, 55, colors.blue)
  972.   draw_text_term(10, 19, "by jaranvil aka jared314", colors.white, colors.blue)
  973.  
  974.   draw_text_term(1, 3, "Searching for a peripherals...", colors.white, colors.black)
  975.   sleep(1)
  976.  
  977.   reactor = reactorSearch()
  978.   mon = monitorSearch()
  979.  
  980.  
  981.   draw_text_term(2, 5, "Connecting to reactor...", colors.white, colors.black)
  982.   sleep(0.5)
  983.   if reactor == null then
  984.       draw_text_term(1, 8, "Error:", colors.red, colors.black)
  985.       draw_text_term(1, 9, "Could not connect to reactor", colors.red, colors.black)
  986.       draw_text_term(1, 10, "Reactor must be connected with networking cable", colors.white, colors.black)
  987.       draw_text_term(1, 11, "and modems or the computer is directly beside", colors.white, colors.black)
  988.        draw_text_term(1, 12,"the reactors computer port.", colors.white, colors.black)
  989.       draw_text_term(1, 14, "Press Enter to continue...", colors.gray, colors.black)
  990.       wait = read()
  991.       setup_wizard()
  992.   else
  993.       draw_text_term(27, 5, "success", colors.lime, colors.black)
  994.       sleep(0.5)
  995.   end
  996.  
  997.   draw_text_term(2, 6, "Connecting to monitor...", colors.white, colors.black)
  998.   sleep(0.5)
  999.   if mon == null then
  1000.       draw_text_term(1, 7, "Error:", colors.red, colors.black)
  1001.       draw_text_term(1, 8, "Could not connect to a monitor. Place a 3x3 advanced monitor", colors.red, colors.black)
  1002.       draw_text_term(1, 11, "Press Enter to continue...", colors.gray, colors.black)
  1003.       wait = read()
  1004.       setup_wizard()
  1005.   else
  1006.       monX, monY = mon.getSize()
  1007.       draw_text_term(27, 6, "success", colors.lime, colors.black)
  1008.       sleep(0.5)
  1009.   end
  1010.     draw_text_term(2, 7, "saving configuration...", colors.white, colors.black)  
  1011.  
  1012.     save_config()
  1013.  
  1014.     sleep(0.1)
  1015.     draw_text_term(1, 9, "Setup Complete!", colors.lime, colors.black)
  1016.     sleep(1)
  1017.  
  1018.     auto = auto_string == "true"
  1019.     call_homepage()
  1020.  
  1021. end
  1022. ----------------SETUP-------------------------------
  1023.  
  1024. function setup_wizard()
  1025.  
  1026.   term.clear()
  1027.  
  1028.  
  1029.      draw_text_term(1, 1, "BigReactor Controls v"..version, colors.lime, colors.black)
  1030.      draw_text_term(1, 2, "Peripheral setup", colors.white, colors.black)
  1031.      draw_text_term(1, 4, "Step 1:", colors.lime, colors.black)
  1032.      draw_text_term(1, 5, "-Place 3x3 advanced monitors next to computer.", colors.white, colors.black)
  1033.      draw_text_term(1, 7, "Step 2:", colors.lime, colors.black)
  1034.      draw_text_term(1, 8, "-Place a wired modem on this computer and on the ", colors.white, colors.black)
  1035.      draw_text_term(1, 9, " computer port of the reactor.", colors.white, colors.black)
  1036.      draw_text_term(1, 10, "-connect modems with network cable.", colors.white, colors.black)
  1037.      draw_text_term(1, 11, "-right click modems to activate.", colors.white, colors.black)
  1038.      draw_text_term(1, 13, "Press Enter when ready...", colors.gray, colors.black)
  1039.    
  1040.      wait = read()
  1041.       test_configs()
  1042.  
  1043.    
  1044. end
  1045.  
  1046. -- peripheral searching thanks to /u/kla_sch
  1047. -- http://pastebin.com/gTEBHv3D
  1048. function reactorSearch()
  1049.    local names = peripheral.getNames()
  1050.    local i, name
  1051.    for i, name in pairs(names) do
  1052.       if peripheral.getType(name) == "BiggerReactors_Reactor" then
  1053.          return peripheral.wrap(name)
  1054.       else
  1055.          --return null
  1056.       end
  1057.    end
  1058. end
  1059.  
  1060. function monitorSearch()
  1061.    local names = peripheral.getNames()
  1062.    local i, name
  1063.    for i, name in pairs(names) do
  1064.       if peripheral.getType(name) == "monitor" then
  1065.         test = name
  1066.          return peripheral.wrap(name)
  1067.       else
  1068.          --return null
  1069.       end
  1070.    end
  1071. end
  1072.  
  1073. function start()
  1074.   --if configs exists, load values and test
  1075.   if fs.exists("config.txt") then
  1076.       load_config()
  1077.       test_configs()
  1078.   else
  1079.     setup_wizard()
  1080.   end
  1081. end
  1082.  
  1083. start()
RAW Paste Data