Advertisement
Sparkybearbomb

Reactor Controler - ERRORED

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