Beispiel #1
0
        void ReceiveLaunchWarning(Vector3 source, Vector3 direction)
        {
            if (referenceTransform == null)
            {
                return;
            }
            if (part == null || !part.isActiveAndEnabled)
            {
                return;
            }
            if (weaponManager == null)
            {
                return;
            }

            float sqrDist = (part.transform.position - source).sqrMagnitude;

            if (sqrDist < Mathf.Pow(BDArmorySettings.MAX_ENGAGEMENT_RANGE, 2) && sqrDist > Mathf.Pow(100, 2) &&
                Vector3.Angle(direction, part.transform.position - source) < 15)
            {
                StartCoroutine(
                    LaunchWarningRoutine(new TargetSignatureData(Vector3.zero,
                                                                 RadarUtils.WorldToRadar(source, referenceTransform, RwrDisplayRect, rwrDisplayRange), Vector3.zero,
                                                                 true, (float)RWRThreatTypes.MissileLaunch)));
                PlayWarningSound(RWRThreatTypes.MissileLaunch);

                if (weaponManager && weaponManager.guardMode)
                {
                    weaponManager.FireAllCountermeasures(Random.Range(1, 2)); // Was 2-4, but we don't want to take too long doing this initial dump before other routines kick in
                    weaponManager.incomingThreatPosition = source;
                }
            }
        }
Beispiel #2
0
        void ReceiveLaunchWarning(Vector3 source, Vector3 direction)
        {
            if (referenceTransform == null)
            {
                return;
            }
            if (part == null)
            {
                return;
            }
            if (weaponManager == null)
            {
                return;
            }

            float sqrDist = (part.transform.position - source).sqrMagnitude;

            if (sqrDist < Mathf.Pow(BDArmorySettings.MAX_ENGAGEMENT_RANGE, 2) && sqrDist > Mathf.Pow(100, 2) &&
                Vector3.Angle(direction, part.transform.position - source) < 15)
            {
                StartCoroutine(
                    LaunchWarningRoutine(new TargetSignatureData(Vector3.zero,
                                                                 RadarUtils.WorldToRadar(source, referenceTransform, displayRect, rwrDisplayRange), Vector3.zero,
                                                                 true, (float)RWRThreatTypes.MissileLaunch)));
                PlayWarningSound(RWRThreatTypes.MissileLaunch);

                if (weaponManager && weaponManager.guardMode)
                {
                    weaponManager.FireAllCountermeasures(Random.Range(2, 4));
                    weaponManager.incomingThreatPosition = source;
                }
            }
        }
Beispiel #3
0
        void ReceivePing(Vessel v, Vector3 source, RWRThreatTypes type, float persistTime)
        {
            if (v == null)
            {
                return;
            }
            if (referenceTransform == null)
            {
                return;
            }
            if (weaponManager == null)
            {
                return;
            }

            if (rwrEnabled && vessel && v == vessel)
            {
                //if we are airborne or on land, no Sonar or SLW type weapons on the RWR!
                if ((type == RWRThreatTypes.Torpedo || type == RWRThreatTypes.TorpedoLock || type == RWRThreatTypes.Sonar) && (vessel.situation != Vessel.Situations.SPLASHED))
                {
                    // rwr stays silent...
                    return;
                }

                if (type == RWRThreatTypes.MissileLaunch || type == RWRThreatTypes.Torpedo)
                {
                    StartCoroutine(
                        LaunchWarningRoutine(new TargetSignatureData(Vector3.zero,
                                                                     RadarUtils.WorldToRadar(source, referenceTransform, RwrDisplayRect, rwrDisplayRange),
                                                                     Vector3.zero, true, (float)type)));
                    PlayWarningSound(type, (source - vessel.transform.position).sqrMagnitude);
                    return;
                }
                else if (type == RWRThreatTypes.MissileLock)
                {
                    if (weaponManager && weaponManager.guardMode)
                    {
                        weaponManager.FireChaff();
                        // TODO: if torpedo inbound, also fire accoustic decoys (not yet implemented...)
                    }
                }

                int openIndex = -1;
                for (int i = 0; i < dataCount; i++)
                {
                    if (pingsData[i].exists &&
                        ((Vector2)pingsData[i].position -
                         RadarUtils.WorldToRadar(source, referenceTransform, RwrDisplayRect, rwrDisplayRange)).sqrMagnitude < 900f)    //prevent ping spam
                    {
                        break;
                    }

                    if (!pingsData[i].exists && openIndex == -1)
                    {
                        openIndex = i;
                    }
                }

                if (openIndex >= 0)
                {
                    referenceTransform.rotation = Quaternion.LookRotation(vessel.ReferenceTransform.up,
                                                                          VectorUtils.GetUpDirection(transform.position));

                    pingsData[openIndex] = new TargetSignatureData(Vector3.zero,
                                                                   RadarUtils.WorldToRadar(source, referenceTransform, RwrDisplayRect, rwrDisplayRange), Vector3.zero,
                                                                   true, (float)type); // HACK! Evil misuse of signalstrength for the threat type!
                    pingWorldPositions[openIndex] = source;
                    StartCoroutine(PingLifeRoutine(openIndex, persistTime));

                    PlayWarningSound(type, (source - vessel.transform.position).sqrMagnitude);
                }
            }
        }