Advertisement
Zgragselus

Space Engineers: Airlock Open

Sep 26th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. public Program()
  2. {
  3. // The constructor, called only once every session and
  4. // always before any other method is called. Use it to
  5. // initialize your script.
  6. //
  7. // The constructor is optional and can be removed if not
  8. // needed.
  9. //
  10. // It's recommended to set RuntimeInfo.UpdateFrequency
  11. // here, which will allow your script to run itself without a
  12. // timer block.
  13. }
  14.  
  15. public void Save()
  16. {
  17. // Called when the program needs to save its state. Use
  18. // this method to save your state to the Storage field
  19. // or some other means.
  20. //
  21. // This method is optional and can be removed if not
  22. // needed.
  23. }
  24.  
  25. // Method for finding blocks by names
  26. List<IMyTerminalBlock> SearchBlocksByName(string blockName) {
  27. var blocks = new List<IMyTerminalBlock>();
  28. GridTerminalSystem.SearchBlocksOfName(blockName, blocks);
  29. return blocks;
  30. }
  31.  
  32. public void DebugLog(IMyTextPanel console, string text)
  33. {
  34. if (console != null)
  35. {
  36. console.WriteText(text);
  37. }
  38. }
  39.  
  40. public void Main(string argument, UpdateType updateSource)
  41. {
  42. string debug = "";
  43.  
  44. IMyTextPanel console = GridTerminalSystem.GetBlockWithName("Text panel") as IMyTextPanel;
  45.  
  46. var tanks = SearchBlocksByName("Oxygen Tank");
  47. float oxygenLevel = 1.0f;
  48. for (int i = 0; i < tanks.Count; i++)
  49. {
  50. IMyGasTank tank = (IMyGasTank)tanks[i];
  51. oxygenLevel = (oxygenLevel > (float)tank.FilledRatio ? (float)tank.FilledRatio : oxygenLevel);
  52. }
  53.  
  54. var vents = SearchBlocksByName("AirHangar");
  55. List<IMyAirVent> airVents = new List<IMyAirVent>();
  56. bool pressurized = true;
  57. for (int i = 0; i < vents.Count; i++)
  58. {
  59. airVents.Add(vents[i] as IMyAirVent);
  60. }
  61.  
  62. float level = 0.0f;
  63. for (int i = 0; i < airVents.Count(); i++)
  64. {
  65. level = (airVents[i].GetOxygenLevel() > level ? airVents[i].GetOxygenLevel() : level);
  66. if (airVents[i].GetOxygenLevel() > 0.05f)
  67. {
  68. airVents[i].ApplyAction("Depressurize_On");
  69. }
  70. }
  71. debug += level + "\n";
  72.  
  73. if (level < 0.01f)
  74. {
  75. pressurized = false;
  76. }
  77.  
  78. if (pressurized == false || oxygenLevel > 0.99f)
  79. {
  80. List<IMyTerminalBlock> doors = new List<IMyTerminalBlock>();
  81. GridTerminalSystem.GetBlocksOfType<IMyDoor>(doors);
  82. List<IMyDoor> hangarDoors = new List<IMyDoor>();
  83.  
  84. for (int i = 0; i < doors.Count; i++)
  85. {
  86. if (doors[i].CustomName.Contains("Airtight"))
  87. {
  88. hangarDoors.Add(doors[i] as IMyDoor);
  89. }
  90. }
  91.  
  92. for (int i = 0; i < hangarDoors.Count; i++)
  93. {
  94. hangarDoors[i].ApplyAction("Open_On");
  95. }
  96.  
  97. for (int i = 0; i < airVents.Count(); i++)
  98. {
  99. airVents[i].ApplyAction("Depressurize_Off");
  100. }
  101.  
  102. IMyTimerBlock time = GridTerminalSystem.GetBlockWithName("Timer Block") as IMyTimerBlock;
  103. time.ApplyAction("OnOff_Off");
  104. }
  105.  
  106. if (console != null)
  107. console.WriteText(debug);
  108. }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement