diff --git a/MissileLauncher/Program.cs b/MissileLauncher/Program.cs index 0bcea26..1116d01 100644 --- a/MissileLauncher/Program.cs +++ b/MissileLauncher/Program.cs @@ -185,12 +185,14 @@ namespace IngameScript public const double HYDRO_TANK_FILLED_PERCENT = 20; const string LAUNCHER_SMALL_CONNECTOR_NAME = "Connector Launcher"; // Following by a number: "01", "02", etc. + const string DOORS_MISSILES_GROUP = "Doors Missiles"; const float EPSILON = 0.05f; readonly Output output; readonly List launchers = new List(); + readonly IEnumerable missilesDoors; int nbLaunched = 0; int nextToLaunch = 0; @@ -203,6 +205,13 @@ namespace IngameScript this.output = new Output(output); this.output.Print("Missile launcher system starting..."); + this.missilesDoors = Utils.GetBlocksFromGroup(this.GridTerminalSystem, String.Format("{0} {1}", GRID_PREFIX, DOORS_MISSILES_GROUP)); + if (missilesDoors.Count() == 0) + { + this.output.Print("No missile doors found: Aborted"); + return; + } + var connectorNamePrefix = String.Format("{0} {1} ", GRID_PREFIX, LAUNCHER_SMALL_CONNECTOR_NAME); // Find all launcher sub-grid and create the associated launcher. @@ -225,6 +234,16 @@ namespace IngameScript void LaunchNext() { + // Check if the hangar door is open. + foreach (var missileDoor in this.missilesDoors) + { + if (missileDoor.Status != DoorStatus.Open) + { + this.output.Print("Can't launch when missile doors are closed: Aborted"); + return; + } + } + if (this.launchers.Count > 0) { this.launchers[this.nextToLaunch].Launch();