Suppenbiatch

reactor + energycell

Jan 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.51 KB | None | 0 0
  1. local component = require("component");
  2. local sides = require("sides");
  3. local term = require("term");
  4. local computer = require("computer");
  5.  
  6. local reactor = {}
  7. local cell = {}
  8. local i = 1
  9. local n = 1
  10.  
  11. for address, type in component.list("br_reactor") do
  12.     reactor[i] = component.proxy(address)
  13.     i = i + 1
  14. end
  15.  
  16. i = 1
  17. for address2, type in component.list("draconic_rf_storage") do
  18.     cell[i] = component.proxy(address2)
  19.     i = i + 1
  20. end
  21.  
  22.  
  23. local gpu = component.gpu;
  24. local red = component.redstone;
  25.  
  26. local w, h = gpu.getResolution();
  27. gpu.fill(1, 1, w, h, " ");
  28. term.setCursorBlink(false);
  29.  
  30. red.setOutput(sides.west, 0);
  31. red.setOutput(sides.east, 0);
  32. gpu.setResolution(80,20)
  33.  
  34. function round(num, idp)
  35.   local mult = 10^(idp or 0);
  36.   return math.floor(num * mult + 0.5) / mult;
  37. end
  38.  
  39. function formateNumber(n) --http://richard.warburton.it
  40.     n = string.format("%.f", tostring(n))
  41.     local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$');
  42.     return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right;
  43. end
  44.  
  45. function tablelength(T)
  46.     local count = 0
  47.     for _ in pairs(T) do count = count + 1 end
  48.     return count
  49. end
  50.  
  51. local fail = 0;
  52. local restartfluid = 0;
  53. local starttime = computer.uptime();
  54. local controlrodlvl = 69;
  55.  
  56. n = 1
  57. for _ in pairs(reactor) do
  58.     for i = 1 , reactor[n].getNumberOfControlRods()-1 do
  59.         reactor[n].setControlRodLevel(i, controlrodlvl);
  60.         i = i + 1;
  61.     end
  62.     n = n + 1;
  63. end
  64.  
  65. n = 1
  66. for _ in pairs(reactor) do
  67.     reactor[n].setActive(true);
  68.     n = n + 1
  69. end
  70.  
  71. while true do
  72.  
  73.     term.setCursor(1,1)
  74.     gpu.setForeground(0xFFFFFF);  
  75.     term.write("Number of Reactors: " .. tablelength(reactor))
  76.    
  77.     i = 1
  78.    
  79.     for _ in pairs(reactor) do
  80.    
  81.         local steamamount = reactor[i].getHotFluidProducedLastTick()
  82.         local casetemp = reactor[i].getCasingTemperature()
  83.         local fueltemp = reactor[i].getFuelTemperature()
  84.         local fuelcon = reactor[i].getFuelConsumedLastTick()
  85.         local coolantamount = reactor[i].getCoolantAmount()
  86.    
  87.         if steamamount < 2000 then
  88.             if fail == 0 then
  89.                 for n = 0, reactor[i].getNumberOfControlRods()-1 do
  90.                     reactor[i].setControlRodLevel(n, 100);
  91.                     n = n + 1;
  92.                 end
  93.                 fail = i    
  94.                 restartfluid = 1;
  95.                 starttime = computer.uptime();    
  96.                 term.setCursor(1,9);
  97.                 term.clearLine();
  98.                 gpu.setForeground(0xFF0000);
  99.                 term.write("FAILURE in Reactor " .. fail);
  100.                 if fail == 1 then
  101.                     red.setOutput(sides.west,15);
  102.                 elseif fail == 2 then
  103.                     red.setOutput(sides.north,15);
  104.                 end
  105.             end
  106.         end
  107.        
  108.         if fail ~= 0 then
  109.             if reactor[fail].getCoolantAmount() > 10000 then
  110.                 for n = 0, reactor[fail].getNumberOfControlRods()-1 do
  111.                     reactor[fail].setActive(true)
  112.                     reactor[fail].setControlRodLevel(n, controlrodlvl);
  113.                     n = n + 1;
  114.                 end
  115.                 term.setCursor(1,9);
  116.                 term.clearLine();
  117.                 gpu.setForeground(0x7CFC00);  
  118.                 term.write("SOLVED Reactor " .. fail);
  119.                 fail = 0;
  120.             end
  121.         end
  122.    
  123.         if restartfluid == 1 then
  124.             if starttime+2 < computer.uptime() then
  125.                 red.setOutput(sides.west,0);
  126.                 red.setOutput(sides.north,0);
  127.                 restartfluid = 0;
  128.             end
  129.         end
  130.  
  131.         gpu.setForeground(0xFF6347);
  132.         term.setCursor(1,2)
  133.         term.clearLine();
  134.         term.write("Reactor " .. i .. ":")
  135.         term.setCursor(1,3);
  136.         term.clearLine();
  137.         gpu.setForeground(0xFF0000);    
  138.         term.write("Casing Temperature: " .. round(casetemp,4) .. " °C");
  139.         term.setCursor(1,4);
  140.         term.clearLine();
  141.         term.write("Fuel   Temperature: " .. round(fueltemp,4) .. " °C");
  142.         term.setCursor(1,5);
  143.         term.clearLine();
  144.         gpu.setForeground(0xFFFFFF);    
  145.         term.write("Fuel Consumption per tick: " .. round(fuelcon,6) .. " mB/t");
  146.         term.setCursor(1,6);
  147.         term.clearLine();
  148.         gpu.setForeground(0x00BFFF);
  149.         term.write("Coolante Amount: " .. formateNumber(coolantamount) .. " mB");
  150.         term.setCursor(1,7);
  151.         term.clearLine();
  152.         term.write("Steam output per tick: " .. formateNumber(steamamount) .. " mB/t");
  153.        
  154.         local energy = 0
  155.         local maxEnergy = 0
  156.         local energypro = 0
  157.         local percentageStorage = 0
  158.         local c = 1
  159.        
  160.        
  161.         for _ in pairs(cell) do
  162.             energy = cell[c].getEnergyStored() + energy
  163.             maxEnergy = cell[c].getMaxEnergyStored() + maxEnergy
  164.             energypro = cell[c].getTransferPerTick() + energypro
  165.             c = c + 1
  166.         end
  167.        
  168.         percentageStorage = round((energy / maxEnergy * 100),5)
  169.        
  170.         term.setCursor(1,11)
  171.         term.clearLine()
  172.         term.setCursor(8,11)
  173.         gpu.setForeground(0x7FFF00)
  174.         term.write("Stored Energy: " .. formateNumber(energy) .. " RF")
  175.         term.setCursor(1,13)
  176.         term.clearLine()
  177.         term.write("Max storeable Energy: " .. formateNumber(maxEnergy) .. " RF")
  178.         term.setCursor(1,15)
  179.         term.clearLine()
  180.         term.write("The Cell is " .. percentageStorage .. " % charged")
  181.         if energypro > 0 then
  182.             gpu.setForeground(0x7FFF00)
  183.         else
  184.             gpu.setForeground(0xFF0000)
  185.         end
  186.         term.setCursor(1,16);
  187.         term.clearLine()
  188.         term.write("Charging with " .. formateNumber(energypro) .. " RF/t");
  189.        
  190. --BAR
  191.         local monitorX, monitorY = gpu.getResolution()
  192.         local bar = math.floor(((energy/maxEnergy) * (monitorX-2)) + 0.5)    
  193.        
  194.         term.setCursor(1,18)
  195.         gpu.setBackground(0xC0C0C0);
  196.         term.write(string.rep(" ", monitorX-2))
  197.         term.setCursor(1,18)
  198.         gpu.setBackground(0x7FFF00);
  199.         term.write(string.rep(" ", bar))
  200.        
  201.         term.setCursor(1,19)
  202.         gpu.setBackground(0xC0C0C0);
  203.         term.write(string.rep(" ", monitorX-2))
  204.         term.setCursor(1,19)
  205.         gpu.setBackground(0x7FFF00);
  206.         term.write(string.rep(" ", bar))
  207.        
  208.         gpu.setBackground(0x000000);
  209.         i = i + 1
  210.         os.sleep(0.2)
  211.        
  212.     end
  213. end
Add Comment
Please, Sign In to add comment