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(5000, 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(UnityEngine.Random.Range(2, 4)); weaponManager.incomingThreatPosition = source; } } }
void ReceivePing(Vessel v, Vector3 source, RWRThreatTypes type, float persistTime) { if (rwrEnabled && vessel && v == vessel) { if (type == RWRThreatTypes.MissileLaunch) { StartCoroutine(LaunchWarningRoutine(new TargetSignatureData(Vector3.zero, RadarUtils.WorldToRadar(source, referenceTransform, displayRect, rwrDisplayRange), Vector3.zero, true, (float)type))); PlayWarningSound(type); return; } else if (type == RWRThreatTypes.MissileLock) { if (!BDArmorySettings.ALLOW_LEGACY_TARGETING && weaponManager && weaponManager.guardMode) { weaponManager.FireChaff(); } } int openIndex = -1; for (int i = 0; i < dataCount; i++) { if (pingsData[i].exists && ((Vector2)pingsData[i].position - RadarUtils.WorldToRadar(source, referenceTransform, displayRect, rwrDisplayRange)).sqrMagnitude < Mathf.Pow(20, 2)) { 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, displayRect, rwrDisplayRange), Vector3.zero, true, (float)type); pingWorldPositions[openIndex] = source; StartCoroutine(PingLifeRoutine(openIndex, persistTime)); PlayWarningSound(type); } } }