Advertisement
costantino03

new reactor control 2025

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