Advertisement
Guest User

command

a guest
Nov 2nd, 2015
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.63 KB | None | 0 0
  1. local Stargate
  2. local ReactorCount = 0
  3. local ReactorPassiveCount = 0
  4. local ReactorActiveCount = 0
  5. local ReactorPassive = {}
  6. local ReactorActive = {}
  7. local TurbineCount = 0
  8. local Turbine = {}
  9. local Capacitor = {}
  10. local CapConnections = 0
  11. local Computers = {}
  12. local CompCount = 0
  13. local Started = false
  14. local Status = "normal"
  15. local on = false
  16. local hasRun = false
  17. local CommandLabel = "FaradayMk1"
  18. local CommandDrive
  19.  
  20. --Debug--
  21. Debug = true
  22.  
  23.  
  24. --Enderio Capacitor Bank Calculations--
  25. CapCount = 3269
  26. CapBasic = 1000000
  27. CapStandard = 5000000
  28. CapVibrant = 25000000
  29. CapType = (CapBasic)
  30. TotalCapacity = (CapCount) * (CapType)
  31.  
  32. --Enderio Capacitor Bank Fill Levels--
  33. EmptyLevel = (TotalCapacity * 0.01)
  34. LowLevel = (TotalCapacity * 0.15)
  35. MedLevel = (TotalCapacity * 0.35)
  36. HighLevel = (TotalCapacity * 0.65)
  37. FullLevel = (TotalCapacity * 0.95)
  38.  
  39. --Program Functions--
  40.  
  41. --Debug--
  42. function debugPeripherals()
  43.  
  44.   shell.run("clear")
  45.   print("Debug On")
  46.   print("----------")
  47.   print(" ")
  48.   print("Reactors Connected:   ", ReactorCount)
  49.   if ReactorCount ~= 0 then
  50.     i = 1
  51.       while i <= ReactorCount do
  52.         x = 1
  53.         while x <= ReactorActiveCount do
  54.           print("Actively Cooled Reactor "..x.." Connected: ", ReactorActive[x].getConnected())
  55.           x = x + 1
  56.           i = i + 1
  57.         end
  58.        
  59.         y = 1
  60.         while y <= ReactorPassiveCount do
  61.           print("Passively Cooled Reactor "..y.." Connected: ", ReactorPassive[y].getConnected())
  62.           y = y +1          
  63.           i = i + 1
  64.         end
  65.       end
  66.   end
  67.   sleep(3)
  68.   shell.run("clear")
  69.   print("Debug On")
  70.   print("----------")
  71.   print(" ")
  72.   print("Turbines Connected:   ", TurbineCount)
  73.   if TurbineCount ~= 0 then
  74.     i = 1
  75.     while i <= TurbineCount do
  76.       print("Turbine "..i.." Connected:  ", Turbine[i].getConnected())
  77.       i = i + 1
  78.     end
  79.   end
  80.   sleep(3)
  81.   shell.run("clear")
  82.   print("Debug On")
  83.   print("----------")
  84.   print(" ")
  85.   print("Cap. Banks Connected: ", CapConnections)
  86.   print("Capacitor Count:    ", CapCount)
  87.   print("Capacitor Type:     ", CapType)
  88.   print("Total Capacity:  ", TotalCapacity)
  89.   print("Computers Connected:   ", CompCount)
  90.   print("Stargate Connected: ")
  91.   sleep(3)
  92.  
  93.   shell.run("clear")
  94.   print("Debug On")
  95.   print("----------")
  96.   print()
  97.   print("Empty Level:  ", EmptyLevel)
  98.   print("Low Level:    ", LowLevel)
  99.   print("Medium Level: ", MedLevel)
  100.   print("High Level:   ", HighLevel)
  101.   print("Full Level:   ", FullLevel)
  102.   sleep(3)
  103.   end
  104.  
  105.  
  106. --Peripheral Search--
  107. function peripheralSearch()
  108.  
  109.   print("Initializing Connections...")
  110.   sleep(.2)
  111.    
  112.   for a,b in pairs(peripheral.getNames()) do
  113.  
  114.     if peripheral.getType(b) == "BigReactors-Turbine" then
  115.       print("Big Reactors Turbine Synced.")
  116.       Turbine[#Turbine+1] = peripheral.wrap(b)
  117.       TurbineCount = TurbineCount + 1
  118.       sleep(.15)
  119.      
  120.     elseif peripheral.getType(b) == "tile_blockcapacitorbank_name" then
  121.       print("Enderio Capacitor Bank Synced.")
  122.       Capacitor[#Capacitor+1] = peripheral.wrap(b)
  123.       CapConnections = CapConnections + 1
  124.       sleep(.15)
  125.      
  126.     elseif peripheral.getType(b) == "BigReactors-Reactor" then
  127.       print("Big Reactors Reactor Synced.")
  128.       i = peripheral.wrap(b)
  129.       if i.isActivelyCooled() == true then
  130.         print("Reactor is Actively Cooled.")
  131.         ReactorActive[#ReactorActive+1] = peripheral.wrap(b)
  132.         ReactorCount = ReactorCount + 1
  133.         ReactorActiveCount = ReactorActiveCount + 1
  134.         sleep(.15)
  135.       else
  136.         print("Reactor is Passively Cooled.")
  137.         ReactorPassive[#ReactorPassive + 1] = peripheral.wrap(b)
  138.         ReactorCount = ReactorCount + 1
  139.         ReactorPassiveCount = ReactorPassiveCount + 1
  140.         sleep(.15)
  141.       end  
  142.            
  143.     elseif peripheral.getType(b) == "stargate" then
  144.       print("Stargate Controller Synced.")
  145.       Stargate = peripheral.wrap(b)
  146.       sleep(.15)
  147.      
  148.     elseif peripheral.getType(b) == "computer" then
  149.       print("Computer Terminal Synced.")
  150.       Computers[#Computers+1] = peripheral.wrap(b)
  151.       CompCount = CompCount + 1
  152.       sleep(.15)
  153.      
  154.     elseif peripheral.getType(b) == "drive" then
  155.       if disk.isPresent(b) == true then
  156.         DiskLabel = disk.getLabel(b)
  157.         if DiskLabel == CommandLabel then
  158.           print("Command Program Identified.")
  159.           CommandDrive = peripheral.wrap(b)      
  160.         else
  161.           print("Unconnected Drive")
  162.         end
  163.       else
  164.         print("Empty Drive.")    
  165.       end
  166.                              
  167.     else    
  168.       print("Incompatible Device.")
  169.       sleep(.15)
  170.     end  
  171.   end
  172.  
  173. sleep(5)
  174. print()
  175. print()
  176. print()
  177. end
  178.  
  179. --System Start--
  180. function systemStart(Boot)
  181.  
  182.   if Boot == false then
  183.  
  184.     shell.run("clear")
  185.     print("Starting Computers.")
  186.     sleep(.15)
  187.     print("Please Wait..")
  188.    
  189.     for a,b in pairs(Computers) do
  190.       b.turnOn()
  191.       sleep(.15)
  192.     end
  193.    
  194.     Started = true
  195.     print("All Computers Started")
  196.     sleep(.2)
  197.  
  198.   else
  199.  
  200.     for k,v in pairs(Computers) do
  201.         if v.isOn() == false then
  202.           v.turnOn()
  203.           if Debug == true then
  204.             print("Connection Reestablished")
  205.           end
  206.         end
  207.     end
  208.   end
  209. end  
  210.  
  211. -- Big Reactors Turbine Spinup--
  212. function turbineSpinup()
  213.   i = 1
  214.   while i <= TurbineCount do
  215.     Flow= Turbine[i].getFluidFlowRateMax()
  216.       if Flow >= 1001 then
  217.         Speed = "High"
  218.       else
  219.         Speed = "Low"
  220.       end
  221.     if Speed == "High" and Turbine[i].getRotorSpeed() < 1750 then
  222.       Turbine[i].setInductorEngaged(false)
  223.      
  224.     elseif Speed == "Low" and Turbine[i].getRotorSpeed() < 750 then
  225.       Turbine[i].setInductorEngaged(false)
  226.    
  227.     elseif Speed == "High" and Turbine[i].getRotorSpeed() >= 1750 then
  228.       if Turbine[i].getInductorEngaged() == false then
  229.         Turbine[i].setInductorEngaged(true)
  230.       end
  231.      
  232.     elseif Speed == "Low" and Turbine[i].getRotorSpeed() >= 750 then
  233.       if Turbine[i].getInductorEngaged() == false then
  234.         Turbine[i].setInductorEngaged(true)
  235.       end
  236.     elseif Turbine[i].getRotorSpeed() == 0 then
  237.       if Turbine[i].getInductorEngaged() == true then
  238.         Turbine[i].setInductorEngaged(false)
  239.       end  
  240.     end
  241.   i =i +1
  242.   end  
  243. end
  244.  
  245.                              
  246. --System ShutDown--
  247. --Yellow Alert--
  248. --Red Alert--
  249. --Defense Systems--
  250. --Offensive Systems--
  251. --WarpCore Operations--
  252. --Stargate Command--
  253. --Self Destruct Sequence--
  254. --Full Power Operation--
  255. --Overdrive Operation--
  256.  
  257. --Economy Operation--
  258. function economy()
  259.  
  260.   CapEnergyStored = Capacitor[1].getEnergyStored()
  261.   EnergyStored = (CapEnergyStored) * (CapCount)
  262.  
  263.   if Debug == true then
  264.     print(EnergyStored)
  265.   end
  266.    
  267.   if EnergyStored <= EmptyLevel or EnergyStored == 0 then
  268.     ReactorActive[1].setAllControlRodLevels(27)
  269.     Turbine[1].setFluidFlowRateMax(1270)
  270.     Turbine[2].setFluidFlowRateMax(1270)
  271.     turbineSpinup()  
  272.          
  273.   elseif EnergyStored >= EmptyLevel and EnergyStored <= LowLevel then
  274.     ReactorActive[1].setAllControlRodLevels(28)
  275.     Turbine[1].setFluidFlowRateMax(1270)
  276.     Turbine[2].setFluidFlowRateMax(1270)
  277.     turbineSpinup()
  278.        
  279.   elseif EnergyStored >= LowLevel and EnergyStored <= MedLevel then
  280.     ReactorActive[1].setAllControlRodLevels(49)
  281.     Turbine[1].setFluidFlowRateMax(1270)
  282.     Turbine[2].setFluidFlowRateMax(550)
  283.     turbineSpinup()
  284.  
  285.   elseif EnergyStored >= MedLevel and EnergyStored < HighLevel then
  286.     ReactorActive[1].setAllControlRodLevels(65)
  287.     Turbine[1].setFluidFlowRateMax(1270)
  288.     Turbine[2].setFluidFlowRateMax(0)
  289.     turbineSpinup()
  290.    
  291.    elseif EnergyStored >= HighLevel and EnergyStored <= FullLevel then
  292.     ReactorActive[1].setAllControlRodLevels(85)
  293.     Turbine[1].setFluidFlowRateMax(550)
  294.     Turbine[2].setFluidFlowRateMax(0)
  295.     turbineSpinup()  
  296.  
  297.   elseif EnergyStored >= FullLevel then
  298.     ReactorActive[1].setAllControlRodLevels(100)
  299.     Turbine[1].setFluidFlowRateMax(0)
  300.     if Turbine[2].getFluidFlowRateMax() == 0 then
  301.       Turbine[2].setFluidFlowRateMax(0)
  302.     end  
  303.     turbineSpinup()
  304.   end
  305.   print("Running Economy Operation")    
  306. end
  307.  
  308.  
  309. --Normal Running Operations--
  310. function normalOperation()
  311.  
  312.   CapEnergyStored = Capacitor[1].getEnergyStored()
  313.   EnergyStored = (CapEnergyStored) * (CapCount)
  314.  
  315.   if Debug == true then
  316.     print(EnergyStored)
  317.   end
  318.    
  319. if EnergyStored >= 0 and EnergyStored <= MedLevel then
  320.     i = 1
  321.     while i <= ReactorActiveCount do
  322.       if ReactorActive[i].getActive() == false then
  323.         ReactorActive[i].setActive(true)
  324.         i = i + 1
  325.       else
  326.         i = i + 1  
  327.       end  
  328.     end  
  329.      
  330.     ReactorActive[1].setAllControlRodLevels(55)
  331.     i = 1
  332.     while i <= TurbineCount do
  333.       if Turbine[i].getInductorEngaged() == false then
  334.         Turbine[i].setInductorEngaged(true)
  335.       end
  336.        
  337.       Turbine[i].setFluidFlowRateMax(2000)
  338.       i = i + 1
  339.     end
  340.     turbineSpinup()
  341.  
  342.   elseif EnergyStored >= MedLevel and EnergyStored <= FullLevel then
  343.     ReactorActive[1].setAllControlRodLevels(69)
  344.     i = 1
  345.     while i <= TurbineCount do
  346.       if Turbine[i].getInductorEngaged() == false then
  347.         Turbine[i].setInductorEngaged(true)
  348.       end
  349.        
  350.       Turbine[i].setFluidFlowRateMax(1000)
  351.       i = i + 1
  352.     end
  353.     turbineSpinup()
  354.  
  355.   else
  356.     ReactorActive[1].setAllControlRodLevels(100)
  357.     i = 1
  358.     while i <= TurbineCount do
  359.       if Turbine[i].getInductorEngaged() == true then
  360.         Turbine[i].setInductorEngaged(false)
  361.       end
  362.       i = i + 1
  363.     end
  364.   end
  365.   print("Running Normal Operation")    
  366. end
  367.  
  368. --Run Routine--
  369.  
  370. peripheralSearch()
  371.  
  372. if Debug == true then
  373.   debugPeripherals()
  374. end
  375.  
  376. systemStart(Started)
  377.  
  378. while true do
  379.    local myTimer = os.startTimer(5)
  380.   local evt = {os.pullEvent()}
  381.   if evt[1] == "timer" and evt[2] == myTimer and on == false  then
  382.  
  383.     if not hasRun and disk.getLabel("CommandDrive")== CommandLabel then
  384.       hasRun = not hasRun
  385.       for k,v in pairs({peripheral.find("computer")}) do
  386.         v.reboot() --# I think this is function name
  387.       end
  388.     end
  389.  
  390.     if Status == "normal" then
  391.       normalOperation()
  392.       systemStart(Started)
  393.  
  394.     elseif Status == "economy" then
  395.       economy()
  396.       systemStart(Started)
  397.  
  398.     end
  399.  
  400.   elseif evt[1] == "disk" then
  401.     hasRun = false --# Changing hasRun back to false for the new disk
  402.     for a,b in pairs(Computers) do
  403.       b.turnOn()
  404.     end
  405.     on = true
  406.  
  407.   elseif evt[1] == "disk_eject" then
  408.  
  409.     for a,b in pairs(Computers) do
  410.       b.shutdown()
  411.     end
  412.     on = false
  413.   end
  414.   os.cancelTimer(myTimer)
  415. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement