Wolf1596Games

BigReactors Control (modified for BiggerReactors)

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