Hastwell

Jaranvil Haxor'd Reactor Program

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