Esempio n. 1
0
        public Program()
        {
            try
            {
                UpdateSettings();
                ResetDisplay();

                this.remote = GridTerminalSystem.GetBlockOfType <IMyRemoteControl>(rm => rm.CubeGrid == Me.CubeGrid && MyIni.HasSection(rm.CustomData, REFERENCE_RM));

                if (remote == null)
                {
                    throw new InvalidOperationException("Missile MUST have a remote. (That is forward facing)");
                }
                LogLine($"Found remote {remote.CustomName}");

                this.separator = GridTerminalSystem.GetBlockOfType <IMyShipMergeBlock>(mb => mb.CubeGrid == Me.CubeGrid && MyIni.HasSection(mb.CustomData, SEPARATOR_MARKER));
                if (this.separator != null)
                {
                    LogLine($"Found separator merge-block {separator.CustomName}");
                }
                else
                {
                    LogLine($"Warning: No separator block found. Missile can launch without one, but if you do have a separator, add a [{SEPARATOR_MARKER}] line to its custom data.");
                }

                this.statusLogger = new Logger(this, STATUS_DISPLAY_SECTION, true);

                GridTerminalSystem.GetBlocksOfType(allThrusters, th => th.CubeGrid == Me.CubeGrid);

                foreach (var thruster in allThrusters)
                {
                    if (thruster.WorldMatrix.Forward == remote.WorldMatrix.Backward)
                    {
                        fwdThrusters.Add(thruster);
                        LogLine($"Found forward thruster {thruster.CustomName}");
                    }
                    if (thruster.WorldMatrix.Forward == remote.WorldMatrix.Up)
                    {
                        downThrusters.Add(thruster);
                        LogLine($"Found down thruster {thruster.CustomName}");
                    }
                    thruster.Enabled = false;
                    thruster.ThrustOverridePercentage = 0;
                }

                GridTerminalSystem.GetBlocksOfType(warheads, b => b.CubeGrid == Me.CubeGrid);
                LogLine($"Found {warheads.Count} warheads.");

                foreach (var warhead in warheads)
                {
                    warhead.IsArmed = false;
                }

                GridTerminalSystem.GetBlocksOfType(gyros, b => b.CubeGrid == Me.CubeGrid);
                foreach (var gyro in gyros)
                {
                    gyro.Enabled = false;
                }

                GridTerminalSystem.GetBlocksOfType(antennas, b => b.CubeGrid == Me.CubeGrid && MyIni.HasSection(b.CustomData, MISSILE_ANTENNA));
                foreach (var ant in antennas)
                {
                    ant.Enabled    = false;
                    ant.Radius     = 50000f;
                    ant.CustomName = $"{uuid} Antenna";
                }

                LogLine("Missile is ready to launch");
                LogStatus("Missile: Pre-flight");
                this.msgHandler = CreateMessageHandler();
                IGC.SendBroadcast(new RegisterMissileCommand()
                {
                    UUID = uuid
                });
            }
            catch (Exception ex)
            {
                LogLine($"[{uuid}] Program() expection: {ex}\nStacktrace: \n{ex.StackTrace}");
            }
        }