Advertisement
Guest User

pm2.lua

a guest
Jun 3rd, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.10 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local ser = require("serialization")
  4. local shell = require("shell")
  5. local term = require("term")
  6. local colors = require("colors")
  7. local sides = require("sides")
  8. local gpu = component.gpu
  9.  
  10. rebuffer = 10000000
  11. tebuffer = 1000000
  12.  
  13. reactors = {}
  14. turbines = {}
  15. tanks = {}
  16. numtanks = 0
  17. numreactors = 0
  18. numturbines = 0
  19. steamreq = 0
  20. bufferlevel = 0
  21. buffercapacity = 0
  22.  
  23. function findReactors()
  24.     for add, _ in component.list("br_reactor") do
  25.         reactors[add] = component.proxy(add)
  26.         numreactors = numreactors + 1
  27.     end
  28.     print("Found " .. numreactors .. " reactors at:")
  29.     for add, _ in pairs(reactors) do
  30.         print(add)
  31.     end
  32.     os.sleep(2)
  33. end
  34.  
  35. function findTurbines()
  36.     for add, _ in component.list("br_turbine") do
  37.         turbines[add] = component.proxy(add)
  38.         numturbines = numturbines + 1
  39.     end
  40.     print("Found " .. numturbines .. " turbines at:")
  41.     for add, _ in pairs(turbines) do
  42.         print(add)
  43.     end
  44.     os.sleep(2)
  45. end
  46.  
  47. function findTanks()
  48.     for add, _ in component.list("tank_controller") do
  49.     tanks[add] = component.proxy(add)
  50.     numtanks = numtanks + 1
  51.     end
  52.     print("Found " .. numtanks .. " tanks at:")
  53.     for add, proxy in pairs(tanks) do
  54.         print(add)
  55.         buffercapacity = buffercapacity + proxy.getTankCapacity(sides.up)
  56.     end
  57.     print("Total Buffer Capacity =  " .. buffercapacity .. " mb")
  58.     os.sleep(2)
  59. end
  60.  
  61. function fillBuffer()
  62.     for add, proxy in pairs(reactors) do
  63.         proxy.setAllControlRodLevels(100)
  64.         while proxy.getHotFluidAmount() < proxy.getHotFluidAmountMax() do
  65.             for i = 0, (proxy.getNumberOfControlRods() - 1) do
  66.                 if ((proxy.getCoolantAmount() / proxy.getCoolantAmountMax()) * 100) >= 50 then
  67.                     if proxy.getControlRodLevel(i) > 0 then
  68.                         proxy.setControlRodLevel(i, proxy.getControlRodLevel(i) - 1)
  69.                         os.sleep(0.5)
  70.                     end
  71.                 else
  72.                     break
  73.                 end
  74.             end
  75.         end
  76.     end
  77. end
  78.  
  79. findReactors()
  80. findTurbines()
  81. findTanks()
  82. --fillBuffer()
  83.  
  84. function displayStatus()
  85.     term.clear()
  86.     for add, _ in pairs(reactors) do
  87.         --print("Reactor Load:  " .. reactors[add].load .. "%")
  88.     end
  89.     for add, _ in pairs(turbines) do
  90.         print("Turbine Rotor Speed:  " .. turbines[add].rpm .. "  RPM")
  91.     end
  92.     print("Buffer Tank Level:  " .. math.floor(((bufferlevel / buffercapacity) * 100)) .. "%")
  93.     print("Turbine Steam Requirements:  " .. steamreq .. " mb/t")
  94. end
  95.  
  96. print("setup complete!")
  97.  
  98. while true do
  99.     steamreq = 0
  100.     bufferlevel = 0
  101.     for add, proxy in pairs(turbines) do
  102.         if proxy.getActive() then
  103.             if proxy.getRotorSpeed() < 1775 then
  104.                 proxy.setFluidFlowRateMax(proxy.getFluidFlowRateMaxMax())
  105.                 proxy.setInductorEngaged(false)
  106.             elseif proxy.getRotorSpeed() > 1825 then
  107.                 proxy.setFluidFlowRateMax(0)
  108.             end
  109.             if ((proxy.getEnergyStored() / tebuffer) * 100) < 10 and proxy.getRotorSpeed() > 1775 then
  110.                 proxy.setInductorEngaged(true)
  111.             elseif ((proxy.getEnergyStored() / tebuffer) * 100) > 90 then
  112.                 proxy.setInductorEngaged(false)
  113.             end
  114.             turbines[add].rpm = math.floor(proxy.getRotorSpeed())
  115.             steamreq = steamreq + proxy.getFluidFlowRateMax()
  116.         end
  117.     end
  118.     for add, proxy in pairs(tanks) do
  119.         bufferlevel = bufferlevel + proxy.getTankLevel(sides.up)
  120.     end
  121.     for add, proxy in pairs(reactors) do
  122.         for i = 0, (proxy.getNumberOfControlRods() - 1) do
  123.             proxy.setControlRodLevel(i, (bufferlevel / buffercapacity) * 100)
  124.         end
  125. --        if proxy.getActive() then
  126. --            proxy.setAllControlRodLevels(100 - (steamreq / proxy.getHotFluidAmountMax()) * 100)
  127. --        end
  128.     end
  129.     displayStatus()
  130.     os.sleep(0.5)
  131. end                
  132.  
  133. --[[
  134. file = io.open("reactorstatus", "w")
  135. file:write(ser.serialize(reactors))
  136. file:close()
  137. os.exit()
  138.  
  139. file = io.open("reactorstatus", "r")
  140. reactors = ser.unserialize(file:read("*all"))
  141. file:close()
  142. ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement