mrkarp

rc2c2

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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×