Check if missiles doors are open before launching missiles

This commit is contained in:
Greg Burri 2025-08-23 21:44:45 +02:00
parent 7656b66348
commit 5dc10e361b

View file

@ -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<Launcher> launchers = new List<Launcher>();
readonly IEnumerable<IMyDoor> 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<IMyDoor>(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();