Advertisement
Sparkybearbomb

Legacy Reactor Controler

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