< Summary

Class:DirectAttackBehavior
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Behavior/DirectAttackBehavior.cs
Covered lines:22
Uncovered lines:1
Coverable lines:23
Total lines:43
Line coverage:95.6% (22 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.015092.86%

File(s)

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

#LineLine coverage
 1using UnityEngine;
 2
 3public class DirectAttackBehavior : AttackBehavior {
 514  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)
 79      GetNextWaypoint(Vector3 currentPosition, Vector3 targetPosition) {
 710    if (FlightPlan.Waypoints.Count == 0) {
 11      // If no waypoints are defined, directly target the target position.
 012      return (targetPosition, Configs.Power.Max);
 13    }
 14
 715    Vector3 directionToTarget = targetPosition - currentPosition;
 716    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.
 720    int waypointIndex = 0;
 4921    for (waypointIndex = 0; waypointIndex < FlightPlan.Waypoints.Count; ++waypointIndex) {
 2022      if (distanceToTarget > FlightPlan.Waypoints[waypointIndex].Distance) {
 523        break;
 24      }
 1025    }
 26
 727    Vector3 waypointPosition = targetPosition;
 728    Configs.Power power = Configs.Power.Idle;
 929    if (waypointIndex == FlightPlan.Waypoints.Count) {
 30      // This is the last waypoint, so target the final position with the last waypoint's power
 31      // setting.
 232      waypointPosition = targetPosition;
 233      power = FlightPlan.Waypoints[FlightPlan.Waypoints.Count - 1].Power;
 234      return (waypointPosition, power);
 35    }
 36    // There is a next waypoint.
 537    var waypoint = FlightPlan.Waypoints[waypointIndex];
 538    waypointPosition = targetPosition - directionToTarget.normalized * waypoint.Distance;
 539    waypointPosition.y = waypoint.Altitude;
 540    power = waypoint.Power;
 541    return (waypointPosition, power);
 742  }
 43}