Пример #1
0
        public static void ScanInDirection(MissileFire myWpnManager, float directionAngle, Transform referenceTransform, float fov, Vector3 position, float minSignature, ref TargetSignatureData[] dataArray, float dataPersistTime, bool pingRWR, RadarWarningReceiver.RWRThreatTypes rwrType, bool radarSnapshot)
        {
            Vector3d geoPos        = VectorUtils.WorldPositionToGeoCoords(position, FlightGlobals.currentMainBody);
            Vector3  forwardVector = referenceTransform.forward;
            Vector3  upVector      = referenceTransform.up;      //VectorUtils.GetUpDirection(position);
            Vector3  lookDirection = Quaternion.AngleAxis(directionAngle, upVector) * forwardVector;

            int dataIndex = 0;

            foreach (var vessel in BDATargetManager.LoadedVessels)
            {
                if (vessel == null)
                {
                    continue;
                }
                if (!vessel.loaded)
                {
                    continue;
                }

                if (myWpnManager)
                {
                    if (vessel == myWpnManager.vessel)
                    {
                        continue;                                                   //ignore self
                    }
                }
                else if ((vessel.transform.position - position).sqrMagnitude < 3600)
                {
                    continue;
                }

                Vector3 vesselDirection = Vector3.ProjectOnPlane(vessel.CoM - position, upVector);

                if (Vector3.Angle(vesselDirection, lookDirection) < fov / 2)
                {
                    if (TerrainCheck(referenceTransform.position, vessel.transform.position))
                    {
                        continue;                                                                                          //blocked by terrain
                    }
                    float sig = float.MaxValue;
                    if (radarSnapshot && minSignature > 0)
                    {
                        sig = GetModifiedSignature(vessel, position);
                    }

                    RadarWarningReceiver.PingRWR(vessel, position, rwrType, dataPersistTime);

                    float detectSig = sig;

                    VesselECMJInfo vesselJammer = vessel.GetComponent <VesselECMJInfo>();
                    if (vesselJammer)
                    {
                        sig       *= vesselJammer.rcsReductionFactor;
                        detectSig += vesselJammer.jammerStrength;
                    }

                    if (detectSig > minSignature)
                    {
                        if (vessel.vesselType == VesselType.Debris)
                        {
                            vessel.gameObject.AddComponent <TargetInfo>();
                        }
                        else if (myWpnManager != null)
                        {
                            BDATargetManager.ReportVessel(vessel, myWpnManager);
                        }

                        while (dataIndex < dataArray.Length - 1)
                        {
                            if ((dataArray[dataIndex].exists && Time.time - dataArray[dataIndex].timeAcquired > dataPersistTime) || !dataArray[dataIndex].exists)
                            {
                                break;
                            }
                            dataIndex++;
                        }
                        if (dataIndex >= dataArray.Length)
                        {
                            break;
                        }
                        dataArray[dataIndex] = new TargetSignatureData(vessel, sig);
                        dataIndex++;
                        if (dataIndex >= dataArray.Length)
                        {
                            break;
                        }
                    }
                }
            }
        }
Пример #2
0
        public static void ScanInDirection(Ray ray, float fov, float minSignature, ref TargetSignatureData[] dataArray, float dataPersistTime, bool pingRWR, RadarWarningReceiver.RWRThreatTypes rwrType, bool radarSnapshot)
        {
            int dataIndex = 0;

            foreach (var vessel in BDATargetManager.LoadedVessels)
            {
                if (vessel == null)
                {
                    continue;
                }
                if (!vessel.loaded)
                {
                    continue;
                }
                if (vessel.Landed)
                {
                    continue;
                }

                Vector3 vectorToTarget = vessel.transform.position - ray.origin;
                if ((vectorToTarget).sqrMagnitude < 10)
                {
                    continue;                                                    //ignore self
                }
                if (Vector3.Dot(vectorToTarget, ray.direction) < 0)
                {
                    continue;                                                                //ignore behind ray
                }
                if (Vector3.Angle(vessel.CoM - ray.origin, ray.direction) < fov / 2)
                {
                    if (TerrainCheck(ray.origin, vessel.transform.position))
                    {
                        continue;                                                                         //blocked by terrain
                    }
                    float sig = float.MaxValue;
                    if (radarSnapshot)
                    {
                        sig = GetModifiedSignature(vessel, ray.origin);
                    }

                    if (pingRWR && sig > minSignature * 0.66f)
                    {
                        RadarWarningReceiver.PingRWR(vessel, ray.origin, rwrType, dataPersistTime);
                    }

                    if (sig > minSignature)
                    {
                        while (dataIndex < dataArray.Length - 1)
                        {
                            if ((dataArray[dataIndex].exists && Time.time - dataArray[dataIndex].timeAcquired > dataPersistTime) || !dataArray[dataIndex].exists)
                            {
                                break;
                            }
                            dataIndex++;
                        }
                        if (dataIndex >= dataArray.Length)
                        {
                            break;
                        }
                        dataArray[dataIndex] = new TargetSignatureData(vessel, sig);
                        dataIndex++;
                        if (dataIndex >= dataArray.Length)
                        {
                            break;
                        }
                    }
                }
            }
        }
Пример #3
0
        public static void UpdateRadarLock(MissileFire myWpnManager, float directionAngle, Transform referenceTransform, float fov, Vector3 position, float minSignature, ModuleRadar radar, bool pingRWR, RadarWarningReceiver.RWRThreatTypes rwrType, bool radarSnapshot)
        {
            Vector3d geoPos        = VectorUtils.WorldPositionToGeoCoords(position, FlightGlobals.currentMainBody);
            Vector3  forwardVector = referenceTransform.forward;
            Vector3  upVector      = referenceTransform.up;      //VectorUtils.GetUpDirection(position);
            Vector3  lookDirection = Quaternion.AngleAxis(directionAngle, upVector) * forwardVector;

            foreach (var vessel in BDATargetManager.LoadedVessels)
            {
                if (vessel == null)
                {
                    continue;
                }
                if (!vessel.loaded)
                {
                    continue;
                }

                if (myWpnManager)
                {
                    if (vessel == myWpnManager.vessel)
                    {
                        continue;                                                   //ignore self
                    }
                }
                else if ((vessel.transform.position - position).sqrMagnitude < 3600)
                {
                    continue;
                }

                Vector3 vesselDirection = Vector3.ProjectOnPlane(vessel.CoM - position, upVector);

                if (Vector3.Angle(vesselDirection, lookDirection) < fov / 2)
                {
                    if (TerrainCheck(referenceTransform.position, vessel.transform.position))
                    {
                        continue;                                                                                          //blocked by terrain
                    }
                    float sig = float.MaxValue;
                    if (radarSnapshot && minSignature > 0)
                    {
                        sig = GetModifiedSignature(vessel, position);
                    }

                    RadarWarningReceiver.PingRWR(vessel, position, rwrType, radar.signalPersistTime);

                    float detectSig = sig;

                    VesselECMJInfo vesselJammer = vessel.GetComponent <VesselECMJInfo>();
                    if (vesselJammer)
                    {
                        sig       *= vesselJammer.rcsReductionFactor;
                        detectSig += vesselJammer.jammerStrength;
                    }

                    if (detectSig > minSignature)
                    {
                        if (vessel.vesselType == VesselType.Debris)
                        {
                            vessel.gameObject.AddComponent <TargetInfo>();
                        }
                        else if (myWpnManager != null)
                        {
                            BDATargetManager.ReportVessel(vessel, myWpnManager);
                        }

                        //radar.vesselRadarData.AddRadarContact(radar, new TargetSignatureData(vessel, detectSig), false);
                        radar.ReceiveContactData(new TargetSignatureData(vessel, detectSig), false);
                    }
                }
            }
        }
Пример #4
0
        public static void UpdateRadarLock(Ray ray, Vector3 predictedPos, float fov, float minSignature, ModuleRadar radar, bool pingRWR, bool radarSnapshot, float dataPersistTime, bool locked, int lockIndex, Vessel lockedVessel)
        {
            RadarWarningReceiver.RWRThreatTypes rwrType = radar.rwrType;
            //Vessel lockedVessel = null;
            float closestSqrDist = 100;

            if (lockedVessel == null)
            {
                foreach (var vessel in BDATargetManager.LoadedVessels)
                {
                    if (vessel == null)
                    {
                        continue;
                    }
                    if (!vessel.loaded)
                    {
                        continue;
                    }
                    //if(vessel.Landed) continue;

                    Vector3 vectorToTarget = vessel.transform.position - ray.origin;
                    if ((vectorToTarget).sqrMagnitude < 10)
                    {
                        continue;                                                        //ignore self
                    }
                    if (Vector3.Dot(vectorToTarget, ray.direction) < 0)
                    {
                        continue;                                                                    //ignore behind ray
                    }
                    if (Vector3.Angle(vessel.CoM - ray.origin, ray.direction) < fov / 2)
                    {
                        float sqrDist = Vector3.SqrMagnitude(vessel.CoM - predictedPos);
                        if (sqrDist < closestSqrDist)
                        {
                            closestSqrDist = sqrDist;
                            lockedVessel   = vessel;
                        }
                    }
                }
            }

            if (lockedVessel != null)
            {
                if (TerrainCheck(ray.origin, lockedVessel.transform.position))
                {
                    radar.UnlockTargetAt(lockIndex, true);                     //blocked by terrain
                    return;
                }

                float sig = float.MaxValue;
                if (radarSnapshot)
                {
                    sig = GetModifiedSignature(lockedVessel, ray.origin);
                }

                if (pingRWR && sig > minSignature * 0.66f)
                {
                    RadarWarningReceiver.PingRWR(lockedVessel, ray.origin, rwrType, dataPersistTime);
                }

                if (sig > minSignature)
                {
                    //radar.vesselRadarData.AddRadarContact(radar, new TargetSignatureData(lockedVessel, sig), locked);
                    radar.ReceiveContactData(new TargetSignatureData(lockedVessel, sig), locked);
                }
                else
                {
                    radar.UnlockTargetAt(lockIndex, true);
                    return;
                }
            }
            else
            {
                radar.UnlockTargetAt(lockIndex, true);
            }
        }
Пример #5
0
        protected void UpdateRadarTarget()
        {
            TargetAcquired = false;

            float angleToTarget = Vector3.Angle(radarTarget.predictedPosition - transform.position, GetForwardTransform());

            if (radarTarget.exists)
            {
                if (!ActiveRadar && ((radarTarget.predictedPosition - transform.position).sqrMagnitude > Mathf.Pow(activeRadarRange, 2) || angleToTarget > maxOffBoresight * 0.75f))
                {
                    if (vrd)
                    {
                        TargetSignatureData        t = TargetSignatureData.noTarget;
                        List <TargetSignatureData> possibleTargets = vrd.GetLockedTargets();
                        for (int i = 0; i < possibleTargets.Count; i++)
                        {
                            if (possibleTargets[i].vessel == radarTarget.vessel)
                            {
                                t = possibleTargets[i];
                            }
                        }


                        if (t.exists)
                        {
                            TargetAcquired     = true;
                            radarTarget        = t;
                            TargetPosition     = radarTarget.predictedPosition;
                            TargetVelocity     = radarTarget.velocity;
                            TargetAcceleration = radarTarget.acceleration;
                            _radarFailTimer    = 0;
                            return;
                        }
                        else
                        {
                            if (_radarFailTimer > maxRadarFailTime)
                            {
                                Debug.Log("[BDArmory]: Semi-Active Radar guidance failed. Parent radar lost target.");
                                radarTarget        = TargetSignatureData.noTarget;
                                legacyTargetVessel = null;
                                return;
                            }
                            else
                            {
                                if (_radarFailTimer == 0)
                                {
                                    Debug.Log("[BDArmory]: Semi-Active Radar guidance failed - waiting for data");
                                }
                                _radarFailTimer         += Time.fixedDeltaTime;
                                radarTarget.timeAcquired = Time.time;
                                radarTarget.position     = radarTarget.predictedPosition;
                                TargetPosition           = radarTarget.predictedPosition;
                                TargetVelocity           = radarTarget.velocity;
                                TargetAcceleration       = Vector3.zero;
                                TargetAcquired           = true;
                            }
                        }
                    }
                    else
                    {
                        Debug.Log("[BDArmory]: Semi-Active Radar guidance failed. Out of range and no data feed.");
                        radarTarget        = TargetSignatureData.noTarget;
                        legacyTargetVessel = null;
                        return;
                    }
                }
                else
                {
                    vrd = null;

                    if (angleToTarget > maxOffBoresight)
                    {
                        Debug.Log("[BDArmory]: Radar guidance failed.  Target is out of active seeker gimbal limits.");
                        radarTarget        = TargetSignatureData.noTarget;
                        legacyTargetVessel = null;
                        return;
                    }
                    else
                    {
                        if (scannedTargets == null)
                        {
                            scannedTargets = new TargetSignatureData[5];
                        }
                        TargetSignatureData.ResetTSDArray(ref scannedTargets);
                        Ray  ray     = new Ray(transform.position, radarTarget.predictedPosition - transform.position);
                        bool pingRWR = Time.time - lastRWRPing > 0.4f;
                        if (pingRWR)
                        {
                            lastRWRPing = Time.time;
                        }
                        bool radarSnapshot = (snapshotTicker > 20);
                        if (radarSnapshot)
                        {
                            snapshotTicker = 0;
                        }
                        else
                        {
                            snapshotTicker++;
                        }
                        RadarUtils.UpdateRadarLock(ray, lockedSensorFOV, activeRadarMinThresh, ref scannedTargets, 0.4f, pingRWR, RadarWarningReceiver.RWRThreatTypes.MissileLock, radarSnapshot);
                        float sqrThresh = radarLOALSearching ? Mathf.Pow(500, 2) : Mathf.Pow(40, 2);

                        if (radarLOAL && radarLOALSearching && !radarSnapshot)
                        {
                            //only scan on snapshot interval
                        }
                        else
                        {
                            for (int i = 0; i < scannedTargets.Length; i++)
                            {
                                if (scannedTargets[i].exists && (scannedTargets[i].predictedPosition - radarTarget.predictedPosition).sqrMagnitude < sqrThresh)
                                {
                                    radarTarget        = scannedTargets[i];
                                    TargetAcquired     = true;
                                    radarLOALSearching = false;
                                    TargetPosition     = radarTarget.predictedPosition + (radarTarget.velocity * Time.fixedDeltaTime);
                                    TargetVelocity     = radarTarget.velocity;
                                    TargetAcceleration = radarTarget.acceleration;
                                    _radarFailTimer    = 0;
                                    if (!ActiveRadar && Time.time - TimeFired > 1)
                                    {
                                        if (locksCount == 0)
                                        {
                                            RadarWarningReceiver.PingRWR(ray, lockedSensorFOV, RadarWarningReceiver.RWRThreatTypes.MissileLaunch, 2f);
                                            Debug.Log("[BDArmory]: Pitbull! Radar missileBase has gone active.  Radar sig strength: " + radarTarget.signalStrength.ToString("0.0"));
                                        }
                                        else if (locksCount > 2)
                                        {
                                            guidanceActive = false;
                                            checkMiss      = true;
                                            if (BDArmorySettings.DRAW_DEBUG_LABELS)
                                            {
                                                Debug.Log("[BDArmory]: Radar missileBase reached max re-lock attempts.");
                                            }
                                        }
                                        locksCount++;
                                    }
                                    ActiveRadar = true;
                                    return;
                                }
                            }
                        }

                        if (radarLOAL)
                        {
                            radarLOALSearching = true;
                            TargetAcquired     = true;
                            TargetPosition     = radarTarget.predictedPosition + (radarTarget.velocity * Time.fixedDeltaTime);
                            TargetVelocity     = radarTarget.velocity;
                            TargetAcceleration = Vector3.zero;
                            ActiveRadar        = false;
                        }
                        else
                        {
                            radarTarget = TargetSignatureData.noTarget;
                        }
                    }
                }
            }
            else if (radarLOAL && radarLOALSearching)
            {
                if (scannedTargets == null)
                {
                    scannedTargets = new TargetSignatureData[5];
                }
                TargetSignatureData.ResetTSDArray(ref scannedTargets);
                Ray  ray     = new Ray(transform.position, GetForwardTransform());
                bool pingRWR = Time.time - lastRWRPing > 0.4f;
                if (pingRWR)
                {
                    lastRWRPing = Time.time;
                }
                bool radarSnapshot = (snapshotTicker > 6);
                if (radarSnapshot)
                {
                    snapshotTicker = 0;
                }
                else
                {
                    snapshotTicker++;
                }
                RadarUtils.UpdateRadarLock(ray, lockedSensorFOV * 3, activeRadarMinThresh * 2, ref scannedTargets, 0.4f, pingRWR, RadarWarningReceiver.RWRThreatTypes.MissileLock, radarSnapshot);
                float sqrThresh = Mathf.Pow(300, 2);

                float smallestAngle = 360;
                TargetSignatureData lockedTarget = TargetSignatureData.noTarget;

                for (int i = 0; i < scannedTargets.Length; i++)
                {
                    if (scannedTargets[i].exists && (scannedTargets[i].predictedPosition - radarTarget.predictedPosition).sqrMagnitude < sqrThresh)
                    {
                        float angle = Vector3.Angle(scannedTargets[i].predictedPosition - transform.position, GetForwardTransform());
                        if (angle < smallestAngle)
                        {
                            lockedTarget  = scannedTargets[i];
                            smallestAngle = angle;
                        }


                        ActiveRadar = true;
                        return;
                    }
                }

                if (lockedTarget.exists)
                {
                    radarTarget        = lockedTarget;
                    TargetAcquired     = true;
                    radarLOALSearching = false;
                    TargetPosition     = radarTarget.predictedPosition + (radarTarget.velocity * Time.fixedDeltaTime);
                    TargetVelocity     = radarTarget.velocity;
                    TargetAcceleration = radarTarget.acceleration;

                    if (!ActiveRadar && Time.time - TimeFired > 1)
                    {
                        RadarWarningReceiver.PingRWR(new Ray(transform.position, radarTarget.predictedPosition - transform.position), lockedSensorFOV, RadarWarningReceiver.RWRThreatTypes.MissileLaunch, 2f);
                        Debug.Log("[BDArmory]: Pitbull! Radar missileBase has gone active.  Radar sig strength: " + radarTarget.signalStrength.ToString("0.0"));
                    }
                    return;
                }
                else
                {
                    TargetAcquired     = true;
                    TargetPosition     = transform.position + (startDirection * 500);
                    TargetVelocity     = Vector3.zero;
                    TargetAcceleration = Vector3.zero;
                    radarLOALSearching = true;
                    return;
                }
            }

            if (!radarTarget.exists)
            {
                legacyTargetVessel = null;
            }
        }