Advertisement
costantino03

new reactor control(2024)

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