< Summary

Class:DirectAttackBehavior
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Behavior/DirectAttackBehavior.cs
Covered lines:19
Uncovered lines:4
Coverable lines:23
Total lines:43
Line coverage:82.6% (19 of 23)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:2
Method coverage:100% (2 of 2)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DirectAttackBehavior(...)0%110100%
GetNextWaypoint(...)0%5.255078.57%

File(s)

/github/workspace/Assets/Scripts/Behavior/DirectAttackBehavior.cs

#LineLine coverage
 1using UnityEngine;
 2
 3public class DirectAttackBehavior : AttackBehavior {
 22654  public DirectAttackBehavior(in Configs.AttackBehaviorConfig config) : base(config) {}
 5
 6  // Return the next waypoint for the threat to navigate to and the power setting to use towards the
 7  // waypoint.
 8  public override (Vector3 waypointPosition, Configs.Power power)
 52199      GetNextWaypoint(Vector3 currentPosition, Vector3 targetPosition) {
 521910    if (FlightPlan.Waypoints.Count == 0) {
 11      // If no waypoints are defined, directly target the target position.
 012      return (targetPosition, Configs.Power.Max);
 13    }
 14
 521915    Vector3 directionToTarget = targetPosition - currentPosition;
 521916    float distanceToTarget = directionToTarget.magnitude;
 17
 18    // Find the index of the first waypoint whose position is closer to the target than the current
 19    // position.
 521920    int waypointIndex = 0;
 1771221    for (waypointIndex = 0; waypointIndex < FlightPlan.Waypoints.Count; ++waypointIndex) {
 1112322      if (distanceToTarget > FlightPlan.Waypoints[waypointIndex].Distance) {
 521923        break;
 24      }
 68525    }
 26
 521927    Vector3 waypointPosition = targetPosition;
 521928    Configs.Power power = Configs.Power.Idle;
 521929    if (waypointIndex == FlightPlan.Waypoints.Count) {
 30      // This is the last waypoint, so target the final position with the last waypoint's power
 31      // setting.
 032      waypointPosition = targetPosition;
 033      power = FlightPlan.Waypoints[FlightPlan.Waypoints.Count - 1].Power;
 034      return (waypointPosition, power);
 35    }
 36    // There is a next waypoint.
 521937    var waypoint = FlightPlan.Waypoints[waypointIndex];
 521938    waypointPosition = targetPosition - directionToTarget.normalized * waypoint.Distance;
 521939    waypointPosition.y = waypoint.Altitude;
 521940    power = waypoint.Power;
 521941    return (waypointPosition, power);
 521942  }
 43}