Morphik08

Space Engineers Airlock Test 1

May 7th, 2015
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 KB | None | 0 0
  1. void Main()  
  2. {  
  3. // Name a LCD or Text Panel to "Vent Output: ..." Where ... is the name of the vent that  
  4. // de-pressurizes your airlock. Keep in mind the space after : is needed!
  5.  
  6. // Name your Interior and Exterior Door.
  7. string intDoor = "Airlock Interior";
  8. string extDoor = "Airlock Exterior";
  9.  
  10. List<IMyTerminalBlock> screens = new List<IMyTerminalBlock>();  
  11. List<IMyTerminalBlock> doors = new List<IMyTerminalBlock>();  
  12.  
  13. GridTerminalSystem.GetBlocksOfType<IMyDoor>(doors);  
  14. GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(screens);  
  15.  
  16.     for (int i = 0; i < screens.Count; i++)  
  17.     {  
  18.     IMyTextPanel screen = (IMyTextPanel)screens[i];  
  19.     var door1 = GridTerminalSystem.GetBlockWithName(intDoor) as IMyDoor;
  20.     var door2 =  GridTerminalSystem.GetBlockWithName (extDoor) as IMyDoor;
  21.         if (screen.CustomName.IndexOf("Vent Output: ") == 0)  
  22.         {  
  23.         IMyAirVent vent = (IMyAirVent)GridTerminalSystem.GetBlockWithName(screen.CustomName.Substring(13));  
  24.  
  25.         float airLevel;                      
  26.         airLevel = vent.GetOxygenLevel();  
  27.  
  28.         StringBuilder depressurize = new StringBuilder();    
  29.         vent.GetActionWithName("Depressurize").WriteValue(vent, depressurize);  
  30.  
  31.         StringBuilder seal = new StringBuilder();    
  32.         door2.GetActionWithName("Open").WriteValue(door2, seal);
  33.  
  34.         screen.SetValue("FontSize", 3f);  
  35.         screen.ShowTextureOnScreen();  
  36.         screen.WritePublicText("\r\n  Oxygen:\r\n  "  
  37.             + String.Format("{0:P2}", airLevel)  
  38.             + "\r\n  Depres: " + depressurize
  39.             + "\r\n  Seal: " + seal);  
  40.         screen.ShowPublicTextOnScreen();
  41.  
  42.         // Close Interior and Turn On Exterior
  43.         if (depressurize.ToString() == "On" && airLevel > 0 && vent.IsPressurized() == true)    
  44.         {    
  45.             door1.GetActionWithName("Open_Off").Apply(door1);  
  46.             door2.GetActionWithName("OnOff_On").Apply(door2);    
  47.         }
  48.  
  49.         // Open Exterior and Turn Off Interior
  50.         if (depressurize.ToString() == "On" && airLevel == 0 && vent.IsPressurized() == true)    
  51.         {    
  52.             door2.GetActionWithName("Open_On").Apply(door2);  
  53.             door1.GetActionWithName("OnOff_Off").Apply(door1);  
  54.         }  
  55.  
  56.         // Close Exterior and Turn On Interior
  57.         if (depressurize.ToString() == "Off" && airLevel == 0 && vent.IsPressurized() == false)  
  58.         {    
  59.             door2.GetActionWithName("Open_Off").Apply(door2);  
  60.             door1.GetActionWithName("OnOff_On").Apply(door1);    
  61.         }  
  62.  
  63.         // Open Interior and Turn Off Exterior
  64.         if (depressurize.ToString() == "Off" && airLevel > 0 && vent.IsPressurized() == true)  
  65.         {  
  66.         door1.GetActionWithName("Open_On").Apply(door1);  
  67.         door2.GetActionWithName("OnOff_Off").Apply(door2);  
  68.         }  
  69.         }  
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment