public static TargetInfo GetLeastEngagedTarget(MissileFire mf) { TargetInfo finalTarget = null; List <TargetInfo> .Enumerator target = TargetList(mf.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 (finalTarget == null || target.Current.NumFriendliesEngaging(mf.Team) < finalTarget.NumFriendliesEngaging(mf.Team)) { finalTarget = target.Current; } } } target.Dispose(); return(finalTarget); }
public static TargetInfo GetMissileTarget(MissileFire mf, bool targetingMeOnly = false) { TargetInfo finalTarget = null; List <TargetInfo> .Enumerator target = TargetList(mf.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 { if (BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.LogWarning("checking target missile - doesn't have missile module"); } } if (((finalTarget == null && target.Current.NumFriendliesEngaging(mf.Team) < 2) || (finalTarget != null && target.Current.NumFriendliesEngaging(mf.Team) < finalTarget.NumFriendliesEngaging(mf.Team)))) { finalTarget = target.Current; } } } target.Dispose(); return(finalTarget); }
public static TargetInfo GetAirToAirTarget(MissileFire mf) { 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 = TargetList(mf.Team).GetEnumerator(); while (target.MoveNext()) { if (target.Current == null) { continue; } if (target.Current.NumFriendliesEngaging(mf.Team) >= 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(mf.Team) < finalTarget.NumFriendliesEngaging(mf.Team)) || targetSuitability > finalTargetSuitability + finalTarget.NumFriendliesEngaging(mf.Team)) { finalTarget = target.Current; finalTargetSuitability = targetSuitability; } } } return(finalTarget); }