Advertisement
mrkarp

Untitled

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