Guest User

turbine

a guest
Aug 14th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.35 KB | None | 0 0
  1. function getDevices(deviceType)
  2.   local deviceName = nil
  3.   local deviceIndex = 1
  4.   local deviceList, deviceNames = {}, {}
  5.   local peripheralList = peripheral.getNames()
  6.  
  7.   deviceType = deviceType:lower()
  8.  
  9.   for peripheralIndex = 1, #peripheralList do
  10.     if (string.lower(peripheral.getType(peripheralList[peripheralIndex])) == deviceType) then
  11. --      write("Found "..peripheral.getType(peripheralList[peripheralIndex]).."["..peripheralIndex.."] as index \"["..deviceIndex.."]\" attached as \""..peripheralList[peripheralIndex].."\".\n")
  12.       deviceNames[deviceIndex] = peripheralList[peripheralIndex]
  13.       deviceList[deviceIndex] = peripheral.wrap(peripheralList[peripheralIndex])
  14.       deviceIndex = deviceIndex + 1
  15.      end
  16.   end
  17.   return deviceList, deviceNames
  18. end
  19. function energyStorage(numCapacitors)
  20.   energyBank, energyNames = getDevices("tile_blockcapacitorbank_name")
  21.   for bankIndex = 1, #energyBank do
  22.     capacitor = energyBank[bankIndex]
  23.     if not capacitor then
  24.       table.remove(energyBank, bankIndex)
  25.       if bankIndex ~= #energyBank then
  26.         bankIndex = bankIndex - 1
  27.       end
  28.       return math.floor((capacitor.getEnergyStored()/capacitor.getMaxEnergyStored()) * 100)
  29.     end
  30.     print("Capacitor Bank "..bankIndex)
  31.     print("Current RF: "..capacitor.getEnergyStored() * numCapacitors)
  32.     print("Max RF    : "..capacitor.getMaxEnergyStored() * numCapacitors)
  33.     print("Percentage: "..math.floor((capacitor.getEnergyStored()/capacitor.getMaxEnergyStored()) * 100).."%")
  34.   end
  35.   return math.floor((capacitor.getEnergyStored()/capacitor.getMaxEnergyStored()) * 100)
  36. end
  37. function turbines(engPct)
  38.   turbineBank, turbineNames = getDevices("BigReactors-Turbine")
  39.   for bankIndex = 1, #turbineBank do
  40.     turbine = turbineBank[bankIndex]
  41.     if not turbine then
  42.       table.remove(turbineBank, bankIndex)
  43.       if bankIndex ~= #turbineBank then
  44.         bankIndex = bankIndex - 1
  45.       end
  46.       return powerNeeded
  47.     end
  48.     turbineSpeed = turbine.getRotorSpeed()
  49.     if turbineSpeed < 1800 then
  50.         turbine.setActive(true)
  51.   powerNeeded = true   
  52.  else
  53.         turbine.setActive(false)
  54.     end
  55.     if engPct < 15 then
  56.         turbine.setInductorEngaged(true)
  57.         powerNeeded = true
  58.     elseif engPct > 98 then
  59.         turbine.setInductorEngaged(false)
  60.  end
  61.     if turbine.getActive() == true then
  62.         state = "Online"
  63.     else
  64.         state = "Offline"
  65.     end
  66.     if turbine.getInductorEngaged() == true then
  67.         inductor = "Generating"
  68.     else
  69.         inductor = "Not Generating"
  70.     end
  71.     print("Turbine "..bankIndex.." is "..state.." and "..inductor..".")
  72.   end
  73.   return powerNeeded
  74. end
  75. function reactor(powerNeeded)
  76.   reactorBank, reactorNames = getDevices("BigReactors-Reactor")
  77.   for bankIndex = 1, #reactorBank do
  78.  
  79.    reactor = reactorBank[bankIndex]
  80.    if not reactor then
  81.      table.remove(reactorBank, bankIndex)
  82.      if bankIndex ~= #reactorBank then
  83.        bankIndex = bankIndex - 1
  84.      end
  85.      return
  86.    end
  87.       if powerNeeded == true then
  88.            reactor.setActive(true)
  89.            print("Reactor Online")
  90.       else
  91.            reactor.setActive(false)
  92.         print("Reactor Offline")
  93.     end
  94.  end
  95.  return
  96. end
  97.  
  98. while true do
  99. bankIndex = 1
  100. term.clear()
  101. numCapacitors = 3 --enter the number of capacitors in your storage ba
  102. engPct = nil
  103. powerNeeded = false
  104. engPct = energyStorage(numCapacitors)
  105. powerNeeded = turbines(engPct)
  106. holder = reactor(powerNeeded)
  107. sleep(2)
  108. end
Advertisement
Add Comment
Please, Sign In to add comment