Guest User

battest

a guest
Sep 28th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.24 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 = economy
  11. local on = on
  12. --Debug--
  13. Debug = true
  14.  
  15.  
  16. --Enderio Capacitor Bank Calculations--
  17. CapCount = 1154
  18. CapBasic = 1000000
  19. CapStandard = 5000000
  20. CapVibrant = 25000000
  21. CapType = (CapBasic)
  22. TotalCapacity = (CapCount) * (CapType)
  23.  
  24. --Enderio Capacitor Bank Fill Levels--
  25. EmptyLevel = (TotalCapacity * 0.01)
  26. LowLevel = (TotalCapacity * 0.15)
  27. MedLevel = (TotalCapacity * 0.35)
  28. HighLevel = (TotalCapacity * 0.65)
  29. FullLevel = (TotalCapacity * 0.95)
  30.  
  31. --Program Functions--
  32.  
  33. --Debug--
  34. function debugPeripherals()
  35.  
  36.   shell.run("clear")
  37.   print("Debug On")
  38.   print("----------")
  39.   print(" ")
  40.   print("Reactors Connected:   ", ReactorCount)
  41.   print("Reactor Connected:    ", Reactor[1].getConnected())
  42.   print("Turbines Connected:   ", TurbineCount)
  43.   print("Turbine 1 Connected:  ", Turbine[1].getConnected())
  44.   print("Turbine 2 Connected:  ", Turbine[2].getConnected())
  45.   print("Cap. Banks Connected: ", CapConnections)
  46.   print("Capacitor Count:    ", CapCount)
  47.   print("Capacitor Type:     ", CapType)
  48.   print("Total Capacity:  ", TotalCapacity)
  49.   print("Computers Connected:   ", CompCount)
  50.   print(" ")
  51.   print("Press any key to Continue.")
  52.   wait = read()
  53.  
  54.   shell.run("clear")
  55.   print("Debug On")
  56.   print("----------")
  57.   print()
  58.   print("Empty Level:  ", EmptyLevel)
  59.   print("Low Level:    ", LowLevel)
  60.   print("Medium Level: ", MedLevel)
  61.   print("High Level:   ", HighLevel)
  62.   print("Full Level:   ", FullLevel)
  63.   print()
  64.   print("Press any key to Continue")
  65.   wait = read()
  66.   end
  67.  
  68.  
  69. --Peripheral Search--
  70. function peripheralSearch()
  71.  
  72.   print("Initializing Connections...")
  73.   sleep(.2)
  74.    
  75.   for a,b in pairs(peripheral.getNames()) do
  76.  
  77.     if peripheral.getType(b) == "BigReactors-Turbine" then
  78.       print("Turbine Synced.")
  79.       Turbine[#Turbine+1] = peripheral.wrap(b)
  80.       TurbineCount = TurbineCount + 1
  81.       sleep(.15)
  82.      
  83.     elseif peripheral.getType(b) == "tile_blockcapacitorbank_name" then
  84.       print("Capacitor Bank Synced")
  85.       Capacitor[#Capacitor+1] = peripheral.wrap(b)
  86.       CapConnections = CapConnections + 1
  87.       sleep(.15)
  88.      
  89.     elseif peripheral.getType(b) == "BigReactors-Reactor" then
  90.       print("Reactor Synced.")
  91.       Reactor[#Reactor+1] = peripheral.wrap(b)
  92.       ReactorCount = ReactorCount + 1
  93.       sleep(.15)
  94.            
  95.     elseif peripheral.getType(b) == "computer" then
  96.       print("Computer Synced")
  97.       Computers[#Computers+1] = peripheral.wrap(b)
  98.       CompCount = CompCount + 1
  99.       sleep(.15)
  100.      
  101.     else    
  102.       print("Incompatible Device.")
  103.       sleep(.15)
  104.     end
  105.    end  
  106. sleep(.5)
  107. print()
  108. print()
  109. print()
  110. end
  111.  
  112. --System Start--
  113. function systemStart(Boot)
  114.  
  115.   if Boot == false then
  116.  
  117.     print("Starting Computers.")
  118.     sleep(.15)
  119.     print("Please Wait..")
  120.    
  121.     for a,b in pairs(Computers) do
  122.       b.turnOn()
  123.       sleep(.25)
  124.     end
  125.     Started = true
  126.     print("All Computers Started")
  127.     sleep(.2)
  128.  
  129.   else
  130.  
  131.     for a,b in pairs(Computers) do
  132.         if b.getActive == false then
  133.           b.turnOn()
  134.           if Debug == true then
  135.             print("Computer Check Complete")
  136.           end
  137.         end
  138.     end
  139.   end
  140. end  
  141.  
  142. --System ShutDown--
  143. --Yellow Alert--
  144. --Red Alert--
  145. --Defense Systems--
  146. --Offensive Systems--
  147. --WarpCore Operations--
  148. --Stargate Command--
  149. --Self Destruct Sequence--
  150. --Full Power Operation--
  151. --Overdrive Operation--
  152. --Economy Operation--
  153.  
  154. --Normal Running Operations--
  155. function normalOperation()
  156.  
  157.   CapEnergyStored = Capacitor[1].getEnergyStored()
  158.   EnergyStored = (CapEnergyStored) * (CapCount)
  159.  
  160.   if Debug == true then
  161.     print(EnergyStored)
  162.   end
  163.    
  164.   if EnergyStored <= EmptyLevel or EnergyStored == 0 then
  165.     Reactor[1].setAllControlRodLevels(11)
  166.     Turbine[1].setFluidFlowRateMax(1270)
  167.     Turbine[2].setFluidFlowRateMax(1270)
  168.  
  169.   elseif EnergyStored >= EmptyLevel and EnergyStored <= LowLevel then
  170.     Reactor[1].setAllControlRodLevels(11)
  171.     Turbine[1].setFluidFlowRateMax(1260)
  172.     Turbine[2].setFluidFlowRateMax(1260)
  173.  
  174.   elseif EnergyStored >= LowLevel and EnergyStored <= MedLevel then
  175.     Reactor[1].setAllControlRodLevels(37)
  176.     Turbine[1].setFluidFlowRateMax(1260)
  177.     Turbine[2].setFluidFlowRateMax(550)
  178.  
  179.   elseif EnergyStored >= MedLevel and EnergyStored < HighLevel then
  180.     Reactor[1].setAllControlRodLevels(61)
  181.     Turbine[1].setFluidFlowRateMax(1260)
  182.     Turbine[2].setFluidFlowRateMax(0)
  183.  
  184.   elseif EnergyStored >= HighLevel and EnergyStored <= FullLevel then
  185.     Reactor[1].setAllControlRodLevels(82)
  186.     Turbine[1].setFluidFlowRateMax(550)
  187.     Turbine[2].setFluidFlowRateMax(0)
  188.  
  189.   elseif EnergyStored >= FullLevel then
  190.     Reactor[1].setAllControlRodLevels(100)
  191.   end
  192.   print("Running Normal Operation")    
  193. end
  194.  
  195. --Run Routine--
  196.  
  197. peripheralSearch()
  198.  
  199. if Debug == true then
  200.   debugPeripherals()
  201. end
  202.  
  203. systemStart(Started)
  204.  
  205. while true do
  206.   local myTimer = os.startTimer(5) --# starting a timer to fire after 5 seconds
  207.   local evt = {os.pullEvent()} --# catching the events and all the parameters in a table
  208.   if evt[1] == "timer" and evt[2] == myTimer and on then --# checking to see if the event is a "timer" event, and checking if the timer event is one we are looking for, I will explain "on" below
  209.     --# this is essentially replacing the sleep that you had at the end of your original code
  210.     normalOperation()
  211.    
  212.   elseif evt[1] == "disk" then
  213.     --# a disk was just added to the system
  214.     local computers = peripheral.find("computer")
  215.     for k,v in pairs(computers) do --# begin looping through and turning on all computers
  216.       v.turnOn()
  217.     end
  218.     on = true --# i will explain the importance of this below
  219.   elseif evt[1] == "disk_eject" then
  220.     --# a disk was just removed from the system
  221.     local computers = peripheral.find("computer")
  222.     for k,v in pairs("computer") do --# begin looping through and turning off all computers
  223.       v.shutdown()
  224.     end
  225.     on = false --# I will explain the importance of this below
  226.   end
  227.   os.stopTimer(myTimer) --# I will further explain this below
  228. end
Advertisement
Add Comment
Please, Sign In to add comment