예제 #1
0
        private void UpdateSettings()
        {
            var parser = new MyIni();

            if (!parser.TryParse(Me.CustomData))
            {
                throw new InvalidOperationException("Couldn't parse CustomData as INI!");
            }
            this.tag       = parser.Get(SETTINGS_SECTION, "tag").ToString(MissileCommons.DEFAULT_TAG);
            this.statusTag = parser.Get(SETTINGS_SECTION, "statusTag").ToString(MissileCommons.STATUS_TAG);
            this.directing = parser.Get(SETTINGS_SECTION, "directing").ToBoolean(true);
            if (this.directing)
            {
                this.directorTurret = GridTerminalSystem.GetBlockOfType <IMyLargeTurretBase>(t => MyIni.HasSection(t.CustomData, DIRECTOR_TURRET_SECTION));
                if (this.directorTurret != null)
                {
                    LogLine($"Director mode on, found director turret {directorTurret.CustomName}");
                }
                else
                {
                    LogLine($"No director turret was found. If you have one, add the [{DIRECTOR_TURRET_SECTION}] line to its Custom Data. Disabling director mode.");
                    this.directing = false;
                }
            }
            if (missileMsgListener != null)
            {
                missileMsgListener.DisableMessageCallback();
            }
            missileMsgListener = IGC.RegisterBroadcastListener(this.tag);
            missileMsgListener.SetMessageCallback();

            if (missileStatusListener != null)
            {
                missileStatusListener.DisableMessageCallback();
            }
            missileStatusListener = IGC.RegisterBroadcastListener(MissileCommons.STATUS_TAG);
            missileStatusListener.SetMessageCallback();
        }
예제 #2
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}");
            }
        }