Advertisement
Temar

Extremereactors

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