Exemplo n.º 1
0
        //this will search for an AA target that is immediately in front of the AI during an extend when it would otherwise be helpless
        public static TargetInfo GetAirToAirTargetAbortExtend(MissileFire mf, float maxDistance, float cosAngleCheck)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;
            TargetInfo finalTarget         = null;

            float finalTargetSuitability = 0;        //this will determine how suitable the target is, based on where it is located relative to the targeting vessel and how far it is

            foreach (var target in TargetDatabase[team])
            {
                if (target && target.Vessel && !target.isLanded && !target.isMissile)
                {
                    Vector3 targetRelPos = target.Vessel.vesselTransform.position - mf.vessel.vesselTransform.position;

                    float distance, dot;
                    distance = targetRelPos.magnitude;
                    dot      = Vector3.Dot(targetRelPos.normalized, mf.vessel.ReferenceTransform.up);

                    if (distance > maxDistance || cosAngleCheck > dot)
                    {
                        continue;
                    }

                    float targetSuitability = dot;                                         //prefer targets ahead to those behind
                    targetSuitability += 500 / (distance + 100);                           //same suitability check as above

                    if (finalTarget == null || targetSuitability > finalTargetSuitability) //just pick the most suitable one
                    {
                        finalTarget            = target;
                        finalTargetSuitability = targetSuitability;
                    }
                }
            }

            return(finalTarget);
        }
Exemplo n.º 2
0
        public static TargetInfo GetClosestMissileTarget(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = BoolToTeam(mf.team);
            TargetInfo finalTarget         = null;

            List <TargetInfo> .Enumerator target = TargetDatabase[team].GetEnumerator();
            while (target.MoveNext())
            {
                if (target.Current == null)
                {
                    continue;
                }
                if (target.Current && target.Current.Vessel && mf.CanSeeTarget(target.Current) && target.Current.isMissile)
                {
                    bool isHostile = false;
                    if (target.Current.isThreat)
                    {
                        isHostile = true;
                    }

                    if (isHostile && (finalTarget == null || target.Current.IsCloser(finalTarget, mf)))
                    {
                        finalTarget = target.Current;
                    }
                }
            }
            target.Dispose();
            return(finalTarget);
        }
Exemplo n.º 3
0
        void FlyCircular(FlightCtrlState s)
        {
            debugString += "\nFlying circular";

            if (vessel.srfSpeed < minSpeed)
            {
                RegainEnergy(s);
            }

            bool enemiesNearby = false;

            if (weaponManager)
            {
                BDArmorySettings.BDATeams team = weaponManager.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;
                if (BDATargetManager.TargetDatabase[team].Count > 0)
                {
                    threatLevel   = 1;
                    enemiesNearby = true;
                }
            }

            if (!enemiesNearby)
            {
                threatLevel = Mathf.MoveTowards(threatLevel, 0.5f, 0.05f * Time.deltaTime);
            }
            Vector3 axis      = Vector3.Project(-vesselTransform.right, upDirection).normalized;
            Vector3 target    = DefaultAltPosition() + Quaternion.AngleAxis(15, axis) * Vector3.ProjectOnPlane(vesselTransform.up * 1000, upDirection);
            Vector3 dirToAxis = target - vesselTransform.position;

            dirToAxis = Vector3.RotateTowards(Vector3.ProjectOnPlane(dirToAxis, upDirection), dirToAxis, 15 * Mathf.Deg2Rad, 0).normalized;
            target    = vesselTransform.position + (dirToAxis * 1000);
            FlyToPosition(s, target);
        }
Exemplo n.º 4
0
        //checks to see if a friendly is too close to the gun trajectory to fire them
        public static bool CheckSafeToFireGuns(MissileFire weaponManager, Vector3 aimDirection, float safeDistance, float cosUnsafeAngle)
        {
            BDArmorySettings.BDATeams     team           = weaponManager.team ? BDArmorySettings.BDATeams.A : BDArmorySettings.BDATeams.B;
            List <TargetInfo> .Enumerator friendlyTarget = TargetDatabase[team].GetEnumerator();
            while (friendlyTarget.MoveNext())
            {
                if (friendlyTarget.Current == null || !friendlyTarget.Current.Vessel)
                {
                    continue;
                }
                float friendlyPosDot = Vector3.Dot(friendlyTarget.Current.position - weaponManager.vessel.vesselTransform.position, aimDirection);
                if (!(friendlyPosDot > 0))
                {
                    continue;
                }
                float friendlyDistance   = (friendlyTarget.Current.position - weaponManager.vessel.vesselTransform.position).magnitude;
                float friendlyPosDotNorm = friendlyPosDot / friendlyDistance;               //scale down the dot to be a 0-1 so we can check it againts cosUnsafeAngle

                if (friendlyDistance < safeDistance && cosUnsafeAngle < friendlyPosDotNorm) //if it's too close and it's within the Unsafe Angle, don't fire
                {
                    return(false);
                }
            }
            friendlyTarget.Dispose();
            return(true);
        }
Exemplo n.º 5
0
        public static TargetInfo GetAirToAirTarget(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;
            TargetInfo finalTarget         = null;

            float finalTargetSuitability = 0;        //this will determine how suitable the target is, based on where it is located relative to the targeting vessel and how far it is

            List <TargetInfo> .Enumerator target = TargetDatabase[team].GetEnumerator();
            while (target.MoveNext())
            {
                if (target.Current == null)
                {
                    continue;
                }
                if (target.Current.numFriendliesEngaging >= 2)
                {
                    continue;
                }
                if (target.Current && target.Current.Vessel && target.Current.isFlying && !target.Current.isMissile && target.Current.isThreat)
                {
                    Vector3 targetRelPos      = target.Current.Vessel.vesselTransform.position - mf.vessel.vesselTransform.position;
                    float   targetSuitability = Vector3.Dot(targetRelPos.normalized, mf.vessel.ReferenceTransform.up);     //prefer targets ahead to those behind
                    targetSuitability += 500 / (targetRelPos.magnitude + 100);

                    if (finalTarget == null || (target.Current.numFriendliesEngaging < finalTarget.numFriendliesEngaging) || targetSuitability > finalTargetSuitability + finalTarget.numFriendliesEngaging)
                    {
                        finalTarget            = target.Current;
                        finalTargetSuitability = targetSuitability;
                    }
                }
            }

            return(finalTarget);
        }
Exemplo n.º 6
0
 private void MissileFireOnToggleTeam(MissileFire wm, BDArmorySettings.BDATeams team)
 {
     if (_showGui)
     {
         UpdateList();
     }
 }
Exemplo n.º 7
0
        public TargetSignatureData(Vessel v, float _signalStrength)
        {
            velocity       = v.srf_velocity;
            geoPos         = VectorUtils.WorldPositionToGeoCoords(v.CoM, v.mainBody);
            acceleration   = v.acceleration;
            exists         = true;
            timeAcquired   = Time.time;
            signalStrength = _signalStrength;

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

            team = BDArmorySettings.BDATeams.None;
            if (targetInfo)
            {
                team = targetInfo.team;
            }
            else
            {
                foreach (var mf in v.FindPartModulesImplementing <MissileFire>())
                {
                    team = BDATargetManager.BoolToTeam(mf.team);
                    break;
                }
            }

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

            pingPosition = Vector2.zero;
        }
Exemplo n.º 8
0
        public static TargetInfo GetMissileTarget(MissileFire mf, bool targetingMeOnly = false)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;
            TargetInfo finalTarget         = null;

            foreach (var target in TargetDatabase[team])
            {
                if (target && target.Vessel && target.isMissile && target.isThreat && mf.CanSeeTarget(target.Vessel))
                {
                    if (target.missileModule)
                    {
                        if (targetingMeOnly)
                        {
                            if (Vector3.SqrMagnitude(target.missileModule.targetPosition - mf.vessel.CoM) > 60 * 60)
                            {
                                continue;
                            }
                        }
                    }
                    else
                    {
                        Debug.LogWarning("checking target missile -  doesn't have missile module");
                    }


                    if (((finalTarget == null && target.numFriendliesEngaging < 2) || target.numFriendliesEngaging < finalTarget.numFriendliesEngaging))
                    {
                        finalTarget = target;
                    }
                }
            }

            return(finalTarget);
        }
Exemplo n.º 9
0
 public TargetSignatureData(CMFlare flare, float _signalStrength)
 {
     velocity       = flare.velocity;
     geoPos         = VectorUtils.WorldPositionToGeoCoords(flare.transform.position, FlightGlobals.currentMainBody);
     exists         = true;
     acceleration   = Vector3.zero;
     timeAcquired   = Time.time;
     signalStrength = _signalStrength;
     targetInfo     = null;
     vesselJammer   = null;
     team           = BDArmorySettings.BDATeams.None;
     pingPosition   = Vector2.zero;
 }
Exemplo n.º 10
0
 public TargetSignatureData(Vector3 _velocity, Vector3 _position, Vector3 _acceleration, bool _exists, float _signalStrength)
 {
     velocity       = _velocity;
     geoPos         = VectorUtils.WorldPositionToGeoCoords(_position, FlightGlobals.currentMainBody);
     acceleration   = _acceleration;
     exists         = _exists;
     timeAcquired   = Time.time;
     signalStrength = _signalStrength;
     targetInfo     = null;
     vesselJammer   = null;
     team           = BDArmorySettings.BDATeams.None;
     pingPosition   = Vector2.zero;
 }
Exemplo n.º 11
0
        //returns the target that owns this weapon manager
        public static TargetInfo GetTargetFromWeaponManager(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.A : BDArmorySettings.BDATeams.B;

            foreach (var target in TargetDatabase[team])
            {
                if (target && target.Vessel && target.weaponManager == mf)
                {
                    return(target);
                }
            }

            return(null);
        }
Exemplo n.º 12
0
 void Update()
 {
     if (!vessel)
     {
         AboutToBeDestroyed();
     }
     else
     {
         if (vessel.vesselType == VesselType.Debris)
         {
             RemoveFromDatabases();
             team = BDArmorySettings.BDATeams.None;
         }
     }
 }
Exemplo n.º 13
0
        public static List <TargetInfo> GetAllTargetsExcluding(List <TargetInfo> excluding, MissileFire mf)
        {
            List <TargetInfo> finalTargets = new List <TargetInfo>();

            BDArmorySettings.BDATeams team = BoolToTeam(mf.team);

            foreach (var target in TargetDatabase[team])
            {
                if (target && target.Vessel && mf.CanSeeTarget(target.Vessel) && !excluding.Contains(target))
                {
                    finalTargets.Add(target);
                }
            }

            return(finalTargets);
        }
Exemplo n.º 14
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;
        }
Exemplo n.º 15
0
        public static TargetInfo GetUnengagedMissileTarget(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;

            foreach (var target in TargetDatabase[team])
            {
                if (target && target.Vessel && mf.CanSeeTarget(target.Vessel) && target.isMissile && target.isThreat)
                {
                    if (target.numFriendliesEngaging == 0)
                    {
                        return(target);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 16
0
        public TargetSignatureData(Vessel v, float _signalStrength)
        {
            /*
             * if(v.situation == Vessel.Situations.SUB_ORBITAL || v.situation == Vessel.Situations.ESCAPING || v.situation == Vessel.Situations.SUB_ORBITAL)
             * {
             *      velocity = v.obt_velocity;
             *      orbit = v.orbit;
             *      orbital = true;
             * }
             * else
             * {
             */
            orbital  = false;
            orbit    = null;
            velocity = v.srf_velocity;
            //}
            vessel         = v;
            geoPos         = VectorUtils.WorldPositionToGeoCoords(v.CoM, v.mainBody);
            acceleration   = v.acceleration;
            exists         = true;
            timeAcquired   = Time.time;
            signalStrength = _signalStrength;

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

            team = BDArmorySettings.BDATeams.None;
            if (targetInfo)
            {
                team = targetInfo.team;
            }
            else
            {
                foreach (var mf in v.FindPartModulesImplementing <MissileFire>())
                {
                    team = BDATargetManager.BoolToTeam(mf.team);
                    break;
                }
            }

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

            pingPosition = Vector2.zero;

            lockedByRadar = null;
        }
Exemplo n.º 17
0
        public static TargetInfo GetClosestTarget(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;
            TargetInfo finalTarget         = null;

            foreach (var target in TargetDatabase[team])
            {
                if (target && target.Vessel && mf.CanSeeTarget(target.Vessel) && !target.isMissile)
                {
                    if (finalTarget == null || (target.IsCloser(finalTarget, mf)))
                    {
                        finalTarget = target;
                    }
                }
            }

            return(finalTarget);
        }
Exemplo n.º 18
0
        //returns the nearest friendly target
        public static TargetInfo GetClosestFriendly(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.A : BDArmorySettings.BDATeams.B;
            TargetInfo finalTarget         = null;

            foreach (var target in TargetDatabase[team])
            {
                if (target && target.Vessel && target.weaponManager != mf)
                {
                    if (finalTarget == null || (target.IsCloser(finalTarget, mf)))
                    {
                        finalTarget = target;
                    }
                }
            }

            return(finalTarget);
        }
Exemplo n.º 19
0
        public static TargetInfo GetLeastEngagedTarget(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;
            TargetInfo finalTarget         = null;

            foreach (var target in TargetDatabase[team])
            {
                if (target && target.Vessel && mf.CanSeeTarget(target.Vessel) && !target.isMissile)
                {
                    if (finalTarget == null || target.numFriendliesEngaging < finalTarget.numFriendliesEngaging)
                    {
                        finalTarget = target;
                    }
                }
            }

            return(finalTarget);
        }
Exemplo n.º 20
0
        //returns the target that owns this weapon manager
        public static TargetInfo GetTargetFromWeaponManager(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.A : BDArmorySettings.BDATeams.B;

            List <TargetInfo> .Enumerator target = TargetDatabase[team].GetEnumerator();
            while (target.MoveNext())
            {
                if (target.Current == null)
                {
                    continue;
                }
                if (target.Current.Vessel && target.Current.weaponManager == mf)
                {
                    return(target.Current);
                }
            }
            target.Dispose();
            return(null);
        }
Exemplo n.º 21
0
        //returns the nearest friendly target
        public static TargetInfo GetClosestFriendly(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.A : BDArmorySettings.BDATeams.B;
            TargetInfo finalTarget         = null;

            List <TargetInfo> .Enumerator target = TargetDatabase[team].GetEnumerator();
            while (target.MoveNext())
            {
                if (target.Current == null || !target.Current.Vessel || target.Current.weaponManager == mf)
                {
                    continue;
                }
                if (finalTarget == null || (target.Current.IsCloser(finalTarget, mf)))
                {
                    finalTarget = target.Current;
                }
            }
            target.Dispose();
            return(finalTarget);
        }
Exemplo n.º 22
0
        public static List <TargetInfo> GetAllTargetsExcluding(List <TargetInfo> excluding, MissileFire mf)
        {
            List <TargetInfo> finalTargets = new List <TargetInfo>();

            BDArmorySettings.BDATeams team = BoolToTeam(mf.team);

            List <TargetInfo> .Enumerator target = TargetDatabase[team].GetEnumerator();
            while (target.MoveNext())
            {
                if (target.Current == null)
                {
                    continue;
                }
                if (target.Current && target.Current.Vessel && mf.CanSeeTarget(target.Current) && !excluding.Contains(target.Current))
                {
                    finalTargets.Add(target.Current);
                }
            }
            target.Dispose();
            return(finalTargets);
        }
Exemplo n.º 23
0
        public static TargetInfo GetUnengagedMissileTarget(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;

            List <TargetInfo> .Enumerator target = TargetDatabase[team].GetEnumerator();
            while (target.MoveNext())
            {
                if (target.Current == null)
                {
                    continue;
                }
                if (target.Current && target.Current.Vessel && mf.CanSeeTarget(target.Current) && target.Current.isMissile && target.Current.isThreat)
                {
                    if (target.Current.numFriendliesEngaging == 0)
                    {
                        return(target.Current);
                    }
                }
            }
            target.Dispose();
            return(null);
        }
Exemplo n.º 24
0
        public static TargetInfo GetMissileTarget(MissileFire mf, bool targetingMeOnly = false)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;
            TargetInfo finalTarget         = null;

            List <TargetInfo> .Enumerator target = TargetDatabase[team].GetEnumerator();
            while (target.MoveNext())
            {
                if (target.Current == null)
                {
                    continue;
                }
                if (target.Current && target.Current.Vessel && target.Current.isMissile && target.Current.isThreat && mf.CanSeeTarget(target.Current))
                {
                    if (target.Current.MissileBaseModule)
                    {
                        if (targetingMeOnly)
                        {
                            if (Vector3.SqrMagnitude(target.Current.MissileBaseModule.TargetPosition - mf.vessel.CoM) > 60 * 60)
                            {
                                continue;
                            }
                        }
                    }
                    else
                    {
                        Debug.LogWarning("checking target missile -  doesn't have missile module");
                    }


                    if (((finalTarget == null && target.Current.numFriendliesEngaging < 2) || (finalTarget != null && target.Current.numFriendliesEngaging < finalTarget.numFriendliesEngaging)))
                    {
                        finalTarget = target.Current;
                    }
                }
            }
            target.Dispose();
            return(finalTarget);
        }
Exemplo n.º 25
0
        public static TargetInfo GetClosestTarget(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;
            TargetInfo finalTarget         = null;

            List <TargetInfo> .Enumerator target = TargetDatabase[team].GetEnumerator();
            while (target.MoveNext())
            {
                if (target.Current == null)
                {
                    continue;
                }
                if (target.Current && target.Current.Vessel && mf.CanSeeTarget(target.Current) && !target.Current.isMissile)
                {
                    if (finalTarget == null || (target.Current.IsCloser(finalTarget, mf)))
                    {
                        finalTarget = target.Current;
                    }
                }
            }
            target.Dispose();
            return(finalTarget);
        }
Exemplo n.º 26
0
        //checks to see if a friendly is too close to the gun trajectory to fire them
        public static bool CheckSafeToFireGuns(MissileFire weaponManager, Vector3 aimDirection, float safeDistance, float cosUnsafeAngle)
        {
            BDArmorySettings.BDATeams team = weaponManager.team ? BDArmorySettings.BDATeams.A : BDArmorySettings.BDATeams.B;
            foreach (var friendlyTarget in TargetDatabase[team])
            {
                if (friendlyTarget && friendlyTarget.Vessel)
                {
                    float friendlyPosDot = Vector3.Dot(friendlyTarget.position - weaponManager.vessel.vesselTransform.position, aimDirection);
                    if (friendlyPosDot > 0)  //only bother if the friendly is actually in front of us
                    {
                        float friendlyDistance   = (friendlyTarget.position - weaponManager.vessel.vesselTransform.position).magnitude;
                        float friendlyPosDotNorm = friendlyPosDot / friendlyDistance;               //scale down the dot to be a 0-1 so we can check it againts cosUnsafeAngle

                        if (friendlyDistance < safeDistance && cosUnsafeAngle < friendlyPosDotNorm) //if it's too close and it's within the Unsafe Angle, don't fire
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 27
0
        public static TargetInfo GetClosestMissileTarget(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = BoolToTeam(mf.team);
            TargetInfo finalTarget         = null;

            foreach (var target in TargetDatabase[team])
            {
                if (target && target.Vessel && mf.CanSeeTarget(target.Vessel) && target.isMissile)
                {
                    bool isHostile = false;
                    if (target.isThreat)
                    {
                        isHostile = true;
                    }

                    if (isHostile && (finalTarget == null || target.IsCloser(finalTarget, mf)))
                    {
                        finalTarget = target;
                    }
                }
            }

            return(finalTarget);
        }
Exemplo n.º 28
0
        public static TargetInfo GetMissileTarget(MissileFire mf)
        {
            BDArmorySettings.BDATeams team = mf.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;
            TargetInfo finalTarget         = null;

            foreach (var target in TargetDatabase[team])
            {
                if (target && target.Vessel && mf.CanSeeTarget(target.Vessel) && target.isMissile)
                {
                    bool isHostile = false;
                    if (target.missileModule && target.missileModule.targetMf && target.missileModule.targetMf.team == mf.team)
                    {
                        isHostile = true;
                    }

                    if (isHostile && ((finalTarget == null && target.numFriendliesEngaging < 2) || target.numFriendliesEngaging < finalTarget.numFriendliesEngaging))
                    {
                        finalTarget = target;
                    }
                }
            }

            return(finalTarget);
        }
Exemplo n.º 29
0
 void RemoveTarget(TargetInfo target, BDArmorySettings.BDATeams team)
 {
     TargetDatabase[team].Remove(target);
 }
Exemplo n.º 30
0
		void Update()
		{
			if(!vessel)
			{
				AboutToBeDestroyed();
			}
			else
			{
				if(vessel.vesselType == VesselType.Debris)
				{
					RemoveFromDatabases();
					team = BDArmorySettings.BDATeams.None;
				}
			}
		}
Exemplo n.º 31
0
		void Awake()
		{
			if(!vessel)
			{
				vessel = GetComponent<Vessel>();
			}
			if(!vessel)
			{
				Debug.Log ("TargetInfo was added to a non-vessel");
				Destroy (this);
				return;
			}

			//destroy this if a target info is already attached to the vessel
			foreach(var otherInfo in vessel.gameObject.GetComponents<TargetInfo>())
			{
				if(otherInfo != this)
				{
					Destroy(this);
					return;
				}
			}

			team = BDArmorySettings.BDATeams.None;

			bool foundMf = false;
			foreach(var mf in vessel.FindPartModulesImplementing<MissileFire>())
			{
				foundMf = true;
				team = BDATargetManager.BoolToTeam(mf.team);
				weaponManager = mf;
				break;
			}
			if(!foundMf)
			{
				foreach(var ml in vessel.FindPartModulesImplementing<MissileLauncher>())
				{
					isMissile = true;
					missileModule = ml;
					team = BDATargetManager.BoolToTeam(ml.team);
					break;
				}
			}
				
			if(team != BDArmorySettings.BDATeams.None)
			{
				if(!BDATargetManager.TargetDatabase[BDATargetManager.OtherTeam(team)].Contains(this))
				{
					BDATargetManager.TargetDatabase[BDATargetManager.OtherTeam(team)].Add(this);
				}
			}

			friendliesEngaging = new List<MissileFire>();

			vessel.OnJustAboutToBeDestroyed += AboutToBeDestroyed;
			lifeRoutine = StartCoroutine(LifetimeRoutine());
			//add delegate to peace enable event
			BDArmorySettings.OnPeaceEnabled += OnPeaceEnabled;

			if(!isMissile && team != BDArmorySettings.BDATeams.None)
			{
				massRoutine = StartCoroutine(MassRoutine());
			}
		}
Exemplo n.º 32
0
 void OnToggleTeam(MissileFire mf, BDArmorySettings.BDATeams team)
 {
     RefreshFriendlies();
     RefreshWingmen();
 }
Exemplo n.º 33
0
        void Awake()
        {
            if(!vessel)
            {
                vessel = GetComponent<Vessel>();
            }
            if(!vessel)
            {
                Debug.Log ("TargetInfo was added to a non-vessel");
                Destroy (this);
            }

            bool foundMf = false;
            foreach(var mf in vessel.FindPartModulesImplementing<MissileFire>())
            {
                foundMf = true;
                team = mf.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;
                break;
            }
            bool foundMl = false;
            if(!foundMf)
            {
                foreach(var ml in vessel.FindPartModulesImplementing<MissileLauncher>())
                {
                    foundMl = true;
                    isMissile = true;
                    team = ml.team ? BDArmorySettings.BDATeams.B : BDArmorySettings.BDATeams.A;
                    break;
                }

                if(!foundMl)
                {
                    //Debug.Log("TargetInfo was added to vessel with mo WpnMgr or MissileLauncher");
                    team = BDArmorySettings.BDATeams.None;
                    Destroy(this);
                }
            }

            if(!BDATargetManager.TargetDatabase[BDATargetManager.OtherTeam(team)].Contains(this))
            {
                BDATargetManager.TargetDatabase[BDATargetManager.OtherTeam(team)].Add(this);
            }

            friendliesEngaging = new List<MissileFire>();
            if(!hasStarted)
            {
                vessel.OnJustAboutToBeDestroyed += AboutToBeDestroyed;
            }
            hasStarted = true;
        }