示例#1
0
        protected void  AddTargetInfoToVessel()
        {
            TargetInfo info = vessel.gameObject.AddComponent <TargetInfo>();

            info.team              = BDATargetManager.BoolToTeam(Team);
            info.isMissile         = true;
            info.MissileBaseModule = this;
        }
        IEnumerator GPSRoutine()
        {
            GetSatInfo();
            scanning    = true;
            targetCount = 0;

            ScreenMsg("Initializing Scan ......");
            yield return(new WaitForSeconds(1.5f));

            ScreenMsg("Initializing Scan ......");
            yield return(new WaitForSeconds(1.5f));

            ScreenMsg("Scanning in Progress ......");
            yield return(new WaitForSeconds(1.5f));

            ScreenMsg("Scanning in Progress ......");
            yield return(new WaitForSeconds(1.5f));

            ScreenMsg("Scanning in Progress ......");
            yield return(new WaitForSeconds(1.5f));

            foreach (Vessel v in FlightGlobals.Vessels)
            {
                if (v.LandedOrSplashed && !v.HoldPhysics)
                {
                    List <MissileFire> targets = new List <MissileFire>(200);
                    foreach (Part t in v.Parts)
                    {
                        targets.AddRange(t.FindModulesImplementing <MissileFire>());
                    }
                    foreach (MissileFire target in targets)
                    {
                        if (myTeam != target.team)
                        {
                            _altitude  = v.altitude;
                            _latitude  = v.latitude;
                            _longitude = v.longitude;

                            targetCount += 1;
                            ScreenMsg2("Retrieving GPS Coords for " + v.vesselName);
                            yield return(new WaitForSeconds(1.5f));

                            BDATargetManager.GPSTargets[BDATargetManager.BoolToTeam(myTeam)].Add(new GPSTargetInfo(getTargetCoords, v.vesselName));
                            ScreenMsg2(v.vesselName + " added to GPS Database");
                            yield return(new WaitForSeconds(1.5f));
                        }
                    }
                }
            }
            yield return(new WaitForSeconds(1.5f));

            ScreenMsg2("Scan Complete ... " + targetCount + " Targets added to GPS Database");
            scan     = false;
            scanning = false;
        }
示例#3
0
        public TargetSignatureData(Vessel v, float _signalStrength)
        {
            orbital = false;
            orbit   = null;

            timeAcquired = Time.time;
            vessel       = v;
            velocity     = v.Velocity();

            geoPos       = VectorUtils.WorldPositionToGeoCoords(v.CoM, v.mainBody);
            acceleration = v.acceleration;
            exists       = true;

            signalStrength = _signalStrength;

            targetInfo = v.gameObject.GetComponent <TargetInfo> ();

            // vessel never been picked up on radar before: create new targetinfo record
            if (targetInfo == null)
            {
                targetInfo = v.gameObject.AddComponent <TargetInfo>();
            }

            team = BDArmorySettings.BDATeams.None;

            if (targetInfo)
            {
                team = targetInfo.team;
                targetInfo.detectedTime = Time.time;
            }
            else
            {
                List <MissileFire> .Enumerator mf = v.FindPartModulesImplementing <MissileFire>().GetEnumerator();
                while (mf.MoveNext())
                {
                    team = BDATargetManager.BoolToTeam(mf.Current.team);
                    break;
                }
                mf.Dispose();
            }

            vesselJammer = v.gameObject.GetComponent <VesselECMJInfo>();

            pingPosition  = Vector2.zero;
            lockedByRadar = null;
        }
示例#4
0
        /// <summary>
        /// GPS
        /// </summary>
        ///
        private void SaveGPS()
        {
            List <MissileFire> wmParts = new List <MissileFire>(200);

            foreach (Part p in FlightGlobals.ActiveVessel.Parts)
            {
                wmParts.AddRange(p.FindModulesImplementing <MissileFire>());
            }
            foreach (MissileFire wmPart in wmParts)
            {
                var _latitude_  = double.Parse(_guiX);
                var _longitude_ = double.Parse(_guiY);
                var _altitude_  = double.Parse(_guiZ);
                _latitude  = _latitude_;
                _longitude = _longitude_;
                _altitude  = _altitude_;
                BDATargetManager.GPSTargets[BDATargetManager.BoolToTeam(wmPart.team)].Add(new GPSTargetInfo(getTargetCoords, "Saved GPS"));
                ScreenMsg("GPS Target Saved");
            }
        }
示例#5
0
        IEnumerator DogfightCompetitionModeRoutine(float distance)
        {
            competitionStarting = true;
            competitionStatus   = "Competition: Pilots are taking off.";
            Dictionary <BDArmorySetup.BDATeams, List <IBDAIControl> > pilots =
                new Dictionary <BDArmorySetup.BDATeams, List <IBDAIControl> >();

            pilots.Add(BDArmorySetup.BDATeams.A, new List <IBDAIControl>());
            pilots.Add(BDArmorySetup.BDATeams.B, new List <IBDAIControl>());
            List <Vessel> .Enumerator loadedVessels = BDATargetManager.LoadedVessels.GetEnumerator();
            while (loadedVessels.MoveNext())
            {
                if (loadedVessels.Current == null)
                {
                    continue;
                }
                if (!loadedVessels.Current.loaded)
                {
                    continue;
                }
                IBDAIControl pilot = null;
                IEnumerator <IBDAIControl> ePilots = loadedVessels.Current.FindPartModulesImplementing <IBDAIControl>().AsEnumerable().GetEnumerator();
                while (ePilots.MoveNext())
                {
                    pilot = ePilots.Current;
                    break;
                }
                ePilots.Dispose();
                if (pilot == null || !pilot.weaponManager)
                {
                    continue;
                }

                pilots[BDATargetManager.BoolToTeam(pilot.weaponManager.team)].Add(pilot);
                pilot.CommandTakeOff();
                if (pilot.weaponManager.guardMode)
                {
                    pilot.weaponManager.ToggleGuardMode();
                }
            }
            loadedVessels.Dispose();

            //clear target database so pilots don't attack yet
            BDATargetManager.ClearDatabase();

            if (pilots[BDArmorySetup.BDATeams.A].Count == 0 || pilots[BDArmorySetup.BDATeams.B].Count == 0)
            {
                Debug.Log("[BDArmory]: Unable to start competition mode - one or more teams is empty");
                competitionStatus = "Competition: Failed!  One or more teams is empty.";
                yield return(new WaitForSeconds(2));

                competitionStarting = false;
                yield break;
            }

            IBDAIControl aLeader = pilots[BDArmorySetup.BDATeams.A][0];
            IBDAIControl bLeader = pilots[BDArmorySetup.BDATeams.B][0];

            aLeader.weaponManager.wingCommander.CommandAllFollow();
            bLeader.weaponManager.wingCommander.CommandAllFollow();


            //wait till the leaders are ready to engage (airborne for PilotAI)
            while (aLeader != null && bLeader != null && (!aLeader.CanEngage() || !bLeader.CanEngage()))
            {
                yield return(null);
            }

            if (aLeader == null || bLeader == null)
            {
                StopCompetition();
            }

            competitionStatus = "Competition: Sending pilots to start position.";
            Vector3 aDirection =
                Vector3.ProjectOnPlane(aLeader.vessel.CoM - bLeader.vessel.CoM, aLeader.vessel.upAxis).normalized;
            Vector3 bDirection =
                Vector3.ProjectOnPlane(bLeader.vessel.CoM - aLeader.vessel.CoM, bLeader.vessel.upAxis).normalized;

            Vector3 center       = (aLeader.vessel.CoM + bLeader.vessel.CoM) / 2f;
            Vector3 aDestination = center + (aDirection * (distance + 1250f));
            Vector3 bDestination = center + (bDirection * (distance + 1250f));

            aDestination = VectorUtils.WorldPositionToGeoCoords(aDestination, FlightGlobals.currentMainBody);
            bDestination = VectorUtils.WorldPositionToGeoCoords(bDestination, FlightGlobals.currentMainBody);

            aLeader.CommandFlyTo(aDestination);
            bLeader.CommandFlyTo(bDestination);

            Vector3 centerGPS = VectorUtils.WorldPositionToGeoCoords(center, FlightGlobals.currentMainBody);

            //wait till everyone is in position
            bool waiting = true;

            while (waiting)
            {
                waiting = false;

                if (aLeader == null || bLeader == null)
                {
                    StopCompetition();
                }

                if (Vector3.Distance(aLeader.transform.position, bLeader.transform.position) < distance * 1.95f)
                {
                    waiting = true;
                }
                else
                {
                    Dictionary <BDArmorySetup.BDATeams, List <IBDAIControl> > .KeyCollection.Enumerator keys = pilots.Keys.GetEnumerator();
                    while (keys.MoveNext())
                    {
                        List <IBDAIControl> .Enumerator ePilots = pilots[keys.Current].GetEnumerator();
                        while (ePilots.MoveNext())
                        {
                            if (ePilots.Current == null)
                            {
                                continue;
                            }
                            if (ePilots.Current.currentCommand != PilotCommands.Follow ||
                                !(Vector3.ProjectOnPlane(
                                      ePilots.Current.vessel.CoM - ePilots.Current.commandLeader.vessel.CoM,
                                      VectorUtils.GetUpDirection(ePilots.Current.commandLeader.vessel.transform.position)
                                      ).sqrMagnitude > 1000f * 1000f))
                            {
                                continue;
                            }
                            competitionStatus = "Competition: Waiting for teams to get in position.";
                            waiting           = true;
                        }
                        ePilots.Dispose();
                    }
                    keys.Dispose();
                }

                yield return(null);
            }

            //start the match
            Dictionary <BDArmorySetup.BDATeams, List <IBDAIControl> > .KeyCollection.Enumerator pKeys = pilots.Keys.GetEnumerator();
            while (pKeys.MoveNext())
            {
                List <IBDAIControl> .Enumerator pPilots = pilots[pKeys.Current].GetEnumerator();
                while (pPilots.MoveNext())
                {
                    if (pPilots.Current == null)
                    {
                        continue;
                    }

                    //enable guard mode
                    if (!pPilots.Current.weaponManager.guardMode)
                    {
                        pPilots.Current.weaponManager.ToggleGuardMode();
                    }

                    //report all vessels
                    if (BDATargetManager.BoolToTeam(pPilots.Current.weaponManager.team) == BDArmorySetup.BDATeams.B)
                    {
                        BDATargetManager.ReportVessel(pPilots.Current.vessel, aLeader.weaponManager);
                    }
                    else
                    {
                        BDATargetManager.ReportVessel(pPilots.Current.vessel, bLeader.weaponManager);
                    }

                    //release command
                    pPilots.Current.ReleaseCommand();
                    pPilots.Current.CommandAttack(centerGPS);
                }
            }
            pKeys.Dispose();
            competitionStatus = "Competition starting!  Good luck!";
            yield return(new WaitForSeconds(2));

            competitionStarting = false;
        }
示例#6
0
        void Awake()
        {
            if (!vessel)
            {
                vessel = GetComponent <Vessel>();
            }

            if (!vessel)
            {
                //Debug.Log ("[BDArmory]: TargetInfo was added to a non-vessel");
                Destroy(this);
                return;
            }

            //destroy this if a target info is already attached to the vessel
            IEnumerator otherInfo = vessel.gameObject.GetComponents <TargetInfo>().GetEnumerator();

            while (otherInfo.MoveNext())
            {
                if ((object)otherInfo.Current != this)
                {
                    Destroy(this);
                    return;
                }
            }

            team = BDArmorySetup.BDATeams.None;
            bool foundMf = false;

            List <MissileFire> .Enumerator mf = vessel.FindPartModulesImplementing <MissileFire>().GetEnumerator();
            while (mf.MoveNext())
            {
                foundMf       = true;
                team          = BDATargetManager.BoolToTeam(mf.Current.team);
                weaponManager = mf.Current;
                break;
            }
            mf.Dispose();

            if (!foundMf)
            {
                List <MissileBase> .Enumerator ml = vessel.FindPartModulesImplementing <MissileBase>().GetEnumerator();
                while (ml.MoveNext())
                {
                    isMissile         = true;
                    MissileBaseModule = ml.Current;
                    team = BDATargetManager.BoolToTeam(ml.Current.Team);
                    break;
                }
                ml.Dispose();
            }

            if (team != BDArmorySetup.BDATeams.None)
            {
                BDATargetManager.AddTarget(this);
            }

            friendliesEngaging = new List <MissileFire>();

            vessel.OnJustAboutToBeDestroyed += AboutToBeDestroyed;

            //add delegate to peace enable event
            BDArmorySetup.OnPeaceEnabled += OnPeaceEnabled;

            //lifeRoutine = StartCoroutine(LifetimeRoutine());              // TODO: CHECK BEHAVIOUR AND SIDE EFFECTS!

            if (!isMissile && team != BDArmorySetup.BDATeams.None)
            {
                GameEvents.onVesselPartCountChanged.Add(VesselModified);
                //massRoutine = StartCoroutine(MassRoutine());              // TODO: CHECK BEHAVIOUR AND SIDE EFFECTS!
            }
        }