Guest User

command

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