Guest User

battest

a guest
Sep 29th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.41 KB | None | 0 0
  1. local ReactorCount = 0
  2. local Reactor = {}
  3. local TurbineCount = 0
  4. local Turbine = {}
  5. local Capacitor = {}
  6. local CapConnections = 0
  7. local Computers = {}
  8. local CompCount = 0
  9. local Started = false
  10. local Status = "normal"
  11. local on = on
  12.  
  13. --Debug--
  14. Debug = true
  15.  
  16.  
  17. --Enderio Capacitor Bank Calculations--
  18. CapCount = 1154
  19. CapBasic = 1000000
  20. CapStandard = 5000000
  21. CapVibrant = 25000000
  22. CapType = (CapBasic)
  23. TotalCapacity = (CapCount) * (CapType)
  24.  
  25. --Enderio Capacitor Bank Fill Levels--
  26. EmptyLevel = (TotalCapacity * 0.01)
  27. LowLevel = (TotalCapacity * 0.15)
  28. MedLevel = (TotalCapacity * 0.35)
  29. HighLevel = (TotalCapacity * 0.65)
  30. FullLevel = (TotalCapacity * 0.95)
  31.  
  32. --Program Functions--
  33.  
  34. --Debug--
  35. function debugPeripherals()
  36.  
  37.   shell.run("clear")
  38.   print("Debug On")
  39.   print("----------")
  40.   print(" ")
  41.   print("Reactors Connected:   ", ReactorCount)
  42.   print("Reactor Connected:    ", Reactor[1].getConnected())
  43.   print("Turbines Connected:   ", TurbineCount)
  44.   print("Turbine 1 Connected:  ", Turbine[1].getConnected())
  45.   print("Turbine 2 Connected:  ", Turbine[2].getConnected())
  46.   print("Cap. Banks Connected: ", CapConnections)
  47.   print("Capacitor Count:    ", CapCount)
  48.   print("Capacitor Type:     ", CapType)
  49.   print("Total Capacity:  ", TotalCapacity)
  50.   print("Computers Connected:   ", CompCount)
  51.   print(" ")
  52.   print("Press any key to Continue.")
  53.   wait = read()
  54.  
  55.   shell.run("clear")
  56.   print("Debug On")
  57.   print("----------")
  58.   print()
  59.   print("Empty Level:  ", EmptyLevel)
  60.   print("Low Level:    ", LowLevel)
  61.   print("Medium Level: ", MedLevel)
  62.   print("High Level:   ", HighLevel)
  63.   print("Full Level:   ", FullLevel)
  64.   print()
  65.   print("Press any key to Continue")
  66.   wait = read()
  67.   end
  68.  
  69.  
  70. --Peripheral Search--
  71. function peripheralSearch()
  72.  
  73.   print("Initializing Connections...")
  74.   sleep(.2)
  75.    
  76.   for a,b in pairs(peripheral.getNames()) do
  77.  
  78.     if peripheral.getType(b) == "BigReactors-Turbine" then
  79.       print("Turbine Synced.")
  80.       Turbine[#Turbine+1] = peripheral.wrap(b)
  81.       TurbineCount = TurbineCount + 1
  82.       sleep(.15)
  83.      
  84.     elseif peripheral.getType(b) == "tile_blockcapacitorbank_name" then
  85.       print("Capacitor Bank Synced.")
  86.       Capacitor[#Capacitor+1] = peripheral.wrap(b)
  87.       CapConnections = CapConnections + 1
  88.       sleep(.15)
  89.      
  90.     elseif peripheral.getType(b) == "BigReactors-Reactor" then
  91.       print("Reactor Synced.")
  92.       Reactor[#Reactor+1] = peripheral.wrap(b)
  93.       ReactorCount = ReactorCount + 1
  94.       sleep(.15)
  95.            
  96.     elseif peripheral.getType(b) == "computer" then
  97.       print("Computer Synced.")
  98.       Computers[#Computers+1] = peripheral.wrap(b)
  99.       CompCount = CompCount + 1
  100.       sleep(.15)
  101.      
  102.     elseif peripheral.getType(b) == "drive" then
  103.      TestDrive = peripheral.wrap(b)
  104.      for k,v in pairs(rs.getSides()) do
  105.        
  106.        if peripheral.getType(v) =='drive' then
  107.          LocalDrive = peripheral.wrap(v)      
  108.        end
  109.      end
  110.          
  111.      if TestDrive == LocalDrive then
  112.        print("Command Drive Initialized")
  113.        sleep(.15)
  114.        
  115.      else
  116.        print("Incompatible Drive.")
  117.        wait = read()
  118.        
  119.      end  
  120.  
  121.     else    
  122.       print("Incompatible Device.")
  123.       sleep(.15)
  124.     end
  125.   end  
  126.  
  127.  
  128. sleep(5)
  129. print()
  130. print()
  131. print()
  132. end
  133.  
  134. --System Start--
  135. function systemStart(Boot)
  136.  
  137.   if Boot == false then
  138.  
  139.     print("Starting Computers.")
  140.     sleep(.15)
  141.     print("Please Wait..")
  142.    
  143.     for a,b in pairs(Computers) do
  144.       b.turnOn()
  145.       sleep(.25)
  146.     end
  147.     Started = true
  148.     print("All Computers Started")
  149.     sleep(.2)
  150.  
  151.   else
  152.  
  153.     for a,b in pairs(Computers) do
  154.         if b.isOn() == false then
  155.           b.turnOn()
  156.           if Debug == true then
  157.            print("Connection Reestablished")
  158.           end
  159.         end
  160.     end
  161.   end
  162. end  
  163.  
  164. --System ShutDown--
  165. --Yellow Alert--
  166. --Red Alert--
  167. --Defense Systems--
  168. --Offensive Systems--
  169. --WarpCore Operations--
  170. --Stargate Command--
  171. --Self Destruct Sequence--
  172. --Full Power Operation--
  173. --Overdrive Operation--
  174.  
  175. --Economy Operation--
  176. function economy()
  177.  
  178.   CapEnergyStored = Capacitor[1].getEnergyStored()
  179.   EnergyStored = (CapEnergyStored) * (CapCount)
  180.  
  181.   if Debug == true then
  182.     print(EnergyStored)
  183.   end
  184.    
  185.   if EnergyStored <= EmptyLevel or EnergyStored == 0 then
  186.     Reactor[1].setAllControlRodLevels(11)
  187.     Turbine[1].setFluidFlowRateMax(1270)
  188.     Turbine[2].setFluidFlowRateMax(1270)
  189.  
  190.   elseif EnergyStored >= EmptyLevel and EnergyStored <= LowLevel then
  191.     Reactor[1].setAllControlRodLevels(11)
  192.     Turbine[1].setFluidFlowRateMax(1260)
  193.     Turbine[2].setFluidFlowRateMax(1260)
  194.  
  195.   elseif EnergyStored >= LowLevel and EnergyStored <= MedLevel then
  196.     Reactor[1].setAllControlRodLevels(37)
  197.     Turbine[1].setFluidFlowRateMax(1260)
  198.     Turbine[2].setFluidFlowRateMax(550)
  199.  
  200.   elseif EnergyStored >= MedLevel and EnergyStored < HighLevel then
  201.     Reactor[1].setAllControlRodLevels(61)
  202.     Turbine[1].setFluidFlowRateMax(1260)
  203.     Turbine[2].setFluidFlowRateMax(0)
  204.  
  205.   elseif EnergyStored >= HighLevel and EnergyStored <= FullLevel then
  206.     Reactor[1].setAllControlRodLevels(82)
  207.     Turbine[1].setFluidFlowRateMax(550)
  208.     Turbine[2].setFluidFlowRateMax(0)
  209.  
  210.   elseif EnergyStored >= FullLevel then
  211.     Reactor[1].setAllControlRodLevels(100)
  212.   end
  213.   print("Running Economy Operation")    
  214. end
  215.  
  216.  
  217. --Normal Running Operations--
  218. function normalOperation()
  219.  
  220.   CapEnergyStored = Capacitor[1].getEnergyStored()
  221.   EnergyStored = (CapEnergyStored) * (CapCount)
  222.  
  223.   if Debug == true then
  224.     print(EnergyStored)
  225.   end
  226.    
  227.   if EnergyStored <= EmptyLevel or EnergyStored == 0 then
  228.     Reactor[1].setAllControlRodLevels(11)
  229.     Turbine[1].setFluidFlowRateMax(1270)
  230.     Turbine[2].setFluidFlowRateMax(1270)
  231.  
  232.   elseif EnergyStored >= EmptyLevel and EnergyStored <= LowLevel then
  233.     Reactor[1].setAllControlRodLevels(11)
  234.     Turbine[1].setFluidFlowRateMax(1260)
  235.     Turbine[2].setFluidFlowRateMax(1260)
  236.  
  237.   elseif EnergyStored >= LowLevel and EnergyStored <= MedLevel then
  238.     Reactor[1].setAllControlRodLevels(37)
  239.     Turbine[1].setFluidFlowRateMax(1260)
  240.     Turbine[2].setFluidFlowRateMax(550)
  241.  
  242.   elseif EnergyStored >= MedLevel and EnergyStored < HighLevel then
  243.     Reactor[1].setAllControlRodLevels(61)
  244.     Turbine[1].setFluidFlowRateMax(1260)
  245.     Turbine[2].setFluidFlowRateMax(0)
  246.  
  247.   elseif EnergyStored >= HighLevel and EnergyStored <= FullLevel then
  248.     Reactor[1].setAllControlRodLevels(82)
  249.     Turbine[1].setFluidFlowRateMax(550)
  250.     Turbine[2].setFluidFlowRateMax(0)
  251.  
  252.   elseif EnergyStored >= FullLevel then
  253.     Reactor[1].setAllControlRodLevels(100)
  254.   end
  255.   print("Running Normal Operation")    
  256. end
  257.  
  258. --Run Routine--
  259.  
  260. peripheralSearch()
  261.  
  262. if Debug == true then
  263.   debugPeripherals()
  264. end
  265.  
  266. systemStart(Started)
  267.  
  268. while true do
  269.   local myTimer = os.startTimer(5)
  270.   local evt = {os.pullEvent()}
  271.   if evt[1] == "timer" and evt[2] == myTimer and on then
  272.  
  273.     if Status == "normal" then
  274.       normalOperation()
  275.       systemStart(Started)
  276.    
  277.     elseif Status == "economy" then
  278.       economy()
  279.       systemStart(Started)
  280.      
  281.     end
  282.      
  283.   elseif evt[1] == "disk" then
  284.     for a,b in pairs(Computers) do
  285.       b.turnOn()
  286.     end
  287.     on = true
  288.  
  289.   elseif evt[1] == "disk_eject" then
  290.      
  291.     for a,b in pairs(Computers) do
  292.       b.shutdown()
  293.     end
  294.     on = false
  295.   end
  296.   os.cancelTimer(myTimer)
  297. end
Advertisement
Add Comment
Please, Sign In to add comment