< Summary

Class:ProximityReleaseStrategy
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Release/ProximityReleaseStrategy.cs
Covered lines:0
Uncovered lines:17
Coverable lines:17
Total lines:43
Line coverage:0% (0 of 17)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:2
Method coverage:0% (0 of 2)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ProximityReleaseStrategy(...)0%2100%
PlanRelease(...)0%42600%

File(s)

/github/workspace/Assets/Scripts/Release/ProximityReleaseStrategy.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4// The proximity release strategy decides to launch an interceptor against an incoming target
 5// depending on the distance and bearing to the target.
 6public class ProximityReleaseStrategy : MassReleaseStrategyBase {
 7  // Geometric parameters for determining when to launch.
 8  // The carrier interceptor will spawn submunitions when any target is greater than 30 degrees away
 9  // from the carrier interceptor's current velocity or when any threat is within 1000 meters of the
 10  // interceptor.
 11  private const float _maxBearingDegrees = 30f;
 12  private const float _minDistanceToThreat = 1000f;
 13  private const float _maxDistanceToThreat = 2500f;
 14  // TODO(titan): The prediction time should be a function of the sub-interceptor characteristic,
 15  // such as the boost time.
 16  private const float _predictionTime = 0.6f;
 17
 018  public ProximityReleaseStrategy(IAgent agent, IAssignment assignment) : base(agent, assignment) {}
 19
 020  protected override LaunchPlan PlanRelease(IEnumerable<IHierarchical> targets) {
 021    foreach (var target in targets) {
 022      var predictor = new LinearExtrapolator(target);
 023      PredictorState predictedState = predictor.Predict(_predictionTime);
 024      Vector3 positionToPredictedTarget = predictedState.Position - Agent.Position;
 025      float predictedDistanceToTarget = positionToPredictedTarget.magnitude;
 26
 27      // Check whether the distance to the target is less than the minimum distance.
 028      if (predictedDistanceToTarget < _minDistanceToThreat) {
 029        return new LaunchPlan { ShouldLaunch = true };
 30      }
 31
 32      // Check whether the bearing exceeds the maximum bearing.
 033      float lateralDistance =
 34          (Vector3.ProjectOnPlane(positionToPredictedTarget, Agent.Velocity)).magnitude;
 035      float sinBearing = Mathf.Clamp01(lateralDistance / predictedDistanceToTarget);
 036      float bearing = Mathf.Asin(sinBearing) * Mathf.Rad2Deg;
 037      if (bearing > _maxBearingDegrees && predictedDistanceToTarget < _maxDistanceToThreat) {
 038        return new LaunchPlan { ShouldLaunch = true };
 39      }
 040    }
 041    return LaunchPlan.NoLaunch();
 042  }
 43}