Advertisement
mrkarp

rc2rc

Feb 21st, 2021
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.85 KB | None | 0 0
  1. -- Get args
  2. local arg1, arg2, arg3 = ...
  3. -- Startup
  4. print('ReactorControl Engaged. View Monitor.\n')
  5. local w, h = term.getSize()
  6. -- Vars
  7. emptyflag = 0
  8. offlineflag = 0
  9. flashflag = 0
  10.  
  11. reactorNameInput = "BigReactors-Reactor_" .. arg1
  12. reactor = peripheral.wrap(reactorNameInput)
  13. if reactor == nil then
  14.    print("Reactor null")
  15. else
  16.     print("BigReactors-Reactor_"..arg1.." Found!\n")
  17.  
  18. end
  19.  
  20. monitorSideInput = arg2
  21. monitor = peripheral.wrap(monitorSideInput)
  22. if monitor == nil then
  23.    print("Monitor null")
  24. else
  25.     print("Monitor '"..monitorSideInput.."' Found!\n")
  26. end
  27.  
  28. controlRodNumber = arg3
  29. if controlRodNumber == nil then
  30.    print("ControlRodNumber null")
  31. else
  32.     print("Number Of Control Rods: "..arg3.."\n")
  33. end
  34.  
  35. -- Monitor Settings
  36. monitor.setTextScale(1)
  37. monitor.setBackgroundColor(colors.black)
  38.  
  39. if fs.exists("ProgressBar") then
  40.     print("You have the ProgressBar API")
  41.  else
  42.     print("Downloading API")
  43.     shell.run("pastebin get Rzxj0KKM ProgressBar")
  44.     print("Restarting Program")
  45.     restart()
  46. end
  47.  
  48. print("starting")
  49.  
  50. --Load ProgressBar API
  51. os.loadAPI('ProgressBar')
  52. ProgressBar.SetPeripheral(monitorSideInput)
  53.  
  54. function MakeFuelInfo ()
  55.     fuelMax = reactor.getFuelAmountMax()
  56.     fuelAmount = reactor.getFuelAmount()
  57.     fuelAmountText = math.floor(((reactor.getFuelAmount()/reactor.getFuelAmountMax())*100)+0.5)
  58.     ProgressBar.SetTable("Fuel", fuelMax, fuelAmount, 7, w - 7,2)
  59.     monitor.setCursorPos(w - 5, 2)
  60.     monitor.setTextColor(colors.yellow)
  61.     monitor.write(fuelAmountText..'%')
  62. end
  63.  
  64. function MakeWasteInfo()   
  65.     wasteMax = reactor.getFuelAmountMax()
  66.     wasteAmount = reactor.getWasteAmount()
  67.     wasteAmountText = math.floor(((reactor.getWasteAmount()/reactor.getFuelAmountMax())*100)+0.5)
  68.     ProgressBar.SetTable("Waste", wasteMax, wasteAmount, 7, w - 7, 3)
  69.     monitor.setCursorPos(w - 5, 3)
  70.     monitor.setTextColor(colors.cyan)
  71.     monitor.write(wasteAmountText..'%')
  72. end
  73.  
  74. function ControlRods(numberOfRods)
  75. local cursorPos = 6
  76. local rodLevelAvg = 0
  77.     --Run for each rod
  78.         for i=1, numberOfRods do   
  79.             rodLevelAvg = rodLevelAvg + (reactor.getControlRodLevel(0))
  80.         end
  81.         rodLevelAvg = rodLevelAvg / numberOfRods
  82.        
  83.         monitor.setTextColor(colors.green)
  84.         monitor.setCursorPos(1,cursorPos)
  85.         monitor.write('Rod Depths: ')
  86.         ProgressBar.SetTable("RODS", 100, rodLevelAvg, 12, w - 7, 6)
  87.         monitor.setCursorPos(w - 5,6)
  88.         monitor.write((100-(reactor.getControlRodLevel(0)))..'%')
  89. end
  90.  
  91. function GetCasingHeatinfo()
  92.        
  93.         if reactor.getCasingTemperature()>=650 then
  94.             monitor.setTextColor(colors.purple)
  95.             else if reactor.getCasingTemperature()>=950 then
  96.                 monitor.setTextColor(colors.red)
  97.             else
  98.             monitor.setTextColor(colors.green)
  99.             end
  100.         end
  101.         casingTemp = math.floor((reactor.getCasingTemperature())+0.5)
  102.         ProgressBar.SetTable("CasingTemp", 10000, casingTemp, 9, w - 7, 9)
  103.         monitor.setCursorPos(w - 5, 9)
  104.         monitor.setTextColor(colors.purple)
  105.         monitor.write(casingTemp..' C')
  106. end
  107.  
  108.  function GetFuelHeatInfo()
  109.  
  110.         if reactor.getFuelTemperature()>=650 then
  111.           monitor.setTextColor(colors.purple)
  112.           else if reactor.getFuelTemperature()>=950 then
  113.             monitor.setTextColor(colors.red)
  114.           else
  115.             monitor.setTextColor(colors.green)
  116.           end
  117.         end
  118.         fuelTemp = math.floor((reactor.getFuelTemperature())+0.5)
  119.         ProgressBar.SetTable("FuelTemp", 10000, fuelTemp, 9, w - 7, 10)
  120.         monitor.setCursorPos(w - 5,10)
  121.         monitor.write(fuelTemp..' C')
  122.  end
  123.  
  124.  function GetFluxInfo()
  125.         -- RF Stored
  126.         rfStored = reactor.getEnergyStored()
  127.         rfStoredFormat = rfStored / 1000000
  128.         ProgressBar.SetTable("RFStored", 8000000, rfStored, 8, w-10,13)
  129.         monitor.setCursorPos(w-7,13)
  130.         monitor.setTextColor(colors.orange)
  131.         monitor.write((math.floor(rfStoredFormat+0.5)..'Mil'))
  132.         --------------------------------------------------
  133.         -- RF Per Tick
  134.         monitor.setCursorPos(1,14)
  135.         monitor.setTextColor(colors.orange)
  136.         rfPerTick = reactor.getEnergyProducedLastTick()
  137.         --ProgressBar.SetTable("RFPerTick", 10000000, rfPerTick, 2,w-11,15)
  138.        
  139.         monitor.setCursorPos(1,14)
  140.         monitor.write('RF/t: '..(math.floor(reactor.getEnergyProducedLastTick()+0.5)))
  141.         --------------------------------------------------
  142.  
  143.  end
  144.  
  145. -- Main Function
  146. function main()
  147.     while true do
  148.     -- Initial Setup
  149.         monitor.clear()
  150.         monitor.setCursorPos(1,1)
  151.         monitor.setTextColor(colors.white)
  152.     -----------------------------------------------
  153.  
  154.     -- Make Fuel info
  155.         --Set POS, Color, Title
  156.         monitor.setCursorPos(1,2)
  157.         monitor.setTextColor(colors.yellow)
  158.         monitor.write('Fuel ')
  159.         MakeFuelInfo()
  160.     -----------------------------------------------
  161.  
  162.     -- Waste Bar
  163.         --Set POS, Color, Title
  164.         monitor.setCursorPos(1,3)
  165.         monitor.setTextColor(colors.lightBlue)
  166.         monitor.write('Waste ')
  167.         MakeWasteInfo()
  168.     -----------------------------------------------
  169.        
  170.     -- Control Rod
  171.         --Set POS, Color, Title
  172.         monitor.setCursorPos(1,5)
  173.         monitor.setTextColor(colors.white)
  174.         monitor.write('Control Rod Levels:')
  175.         ControlRods(controlRodNumber)
  176.     -----------------------------------------------
  177.        
  178.     -- Temps and Heat
  179.         monitor.setCursorPos(1,8)
  180.         monitor.setTextColor(colors.white)
  181.         monitor.write('Temperature:')
  182.    
  183.         monitor.setCursorPos(1,9)
  184.         monitor.setTextColor(colors.lightGray)
  185.         monitor.write('Casing: ')
  186.         GetCasingHeatinfo()
  187.         --------------------------------------------------
  188.         monitor.setCursorPos(1,10)
  189.         monitor.setTextColor(colors.yellow)
  190.         monitor.write('Fuel: ')
  191.         GetFuelHeatInfo()
  192.     --------------------------------------------------
  193.    
  194.     -- Flux Information
  195.         monitor.setCursorPos(1,12)
  196.         monitor.setTextColor(colors.white)
  197.         monitor.write('Fe/Rf:')
  198.        
  199.         monitor.setCursorPos(1,13)
  200.         monitor.setTextColor(colors.yellow)
  201.         monitor.write('Stored: ')
  202.        
  203.        
  204.         monitor.setCursorPos(1,13)
  205.         monitor.setTextColor(colors.green)
  206.         GetFluxInfo()
  207.     -------------------------------------------------- 
  208.        
  209.     ProgressBar.DrawToPeripheral()
  210.         monitor.setCursorPos(1,18)
  211.  
  212.         if flashflag==0 then
  213.           flashflag=1
  214.           if offlineflag==1 then
  215.             monitor.setCursorPos(1,17)
  216.             monitor.setTextColor(colors.lightGray)
  217.             monitor.write('OFFLINE - Manual Override')
  218.           end
  219.           if emptyflag==1 then
  220.             monitor.setCursorPos(1,17)
  221.             monitor.setTextColor(colors.pink)
  222.             monitor.write('OFFLINE - Fuel Exhausted')
  223.           end
  224.           if emptyflag==0 and offlineflag==0 and reactor.getControlRodLevel(0)>75 then
  225.             monitor.setCursorPos(1,17)
  226.             monitor.setTextColor(colors.yellow)
  227.             monitor.write('ONLINE - Low Power Mode')
  228.           end
  229.           if emptyflag==0 and offlineflag==0 and reactor.getControlRodLevel(0)<=75 then
  230.             monitor.setCursorPos(1,17)
  231.             monitor.setTextColor(colors.orange)
  232.             monitor.write('ONLINE - High Power Mode')
  233.           end
  234.         else
  235.           flashflag=0
  236.           monitor.setCursorPos(1,17)
  237.           monitor.clearLine()
  238.         end
  239.  
  240.         if reactor.getEnergyStored()<=8000000 and reactor.getEnergyStored()>100 then
  241.             reactor.setAllControlRodLevels(0+(math.floor(reactor.getEnergyStored()/80000)))
  242.         else
  243.             reactor.setAllControlRodLevels(0)
  244.         end
  245.          
  246.         if reactor.getFuelAmount()<=100 and offlineflag==0 then
  247.             reactor.setAllControlRodLevels(100)
  248.             reactor.setActive(false)
  249.             emptyflag=1
  250.         else
  251.             emptyflag=0
  252.         end
  253.              
  254.         if rs.getInput('bottom')==false and emptyflag==0 then
  255.             reactor.setActive(true)
  256.             offlineflag=0
  257.         end
  258.          
  259.         if rs.getInput('bottom')==true and emptyflag==0 then
  260.             reactor.setActive(false)
  261.             reactor.setAllControlRodLevels(100)
  262.             offlineflag=1
  263.         end    
  264.     sleep(1)
  265.     end
  266. end
  267.  
  268. function dump(o)
  269.    if type(o) == 'table' then
  270.       local s = '{ '
  271.       for k,v in pairs(o) do
  272.          if type(k) ~= 'number' then k = '"'..k..'"' end
  273.          s = s .. '['..k..'] = ' .. dump(v) .. ','
  274.       end
  275.       return s .. '} '
  276.    else
  277.       return tostring(o)
  278.    end
  279. end
  280.  
  281. function restart()
  282.     main()
  283. end
  284.  
  285. -- Reactor Connection Checl
  286. if reactor then
  287.     print("running main")
  288.  main()
  289. else
  290.     print("reactor not connected")
  291.     print(reactor.getNumberOfControlRods())
  292. end
  293.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement