fishermedders

Untitled

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