< Summary

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

File(s)

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

#LineLine coverage
 1using UnityEngine;
 2
 3// Direct attack behavior.
 4//
 5// The agent will navigate directly to each waypoint on the way to the final target.
 6public class DirectAttackBehavior : AttackBehaviorBase {
 7  public DirectAttackBehavior(IAgent agent, Configs.AttackBehaviorConfig config)
 188      : base(agent, config) {}
 9
 10  // Return the next waypoint for the agent to navigate to and the power setting to use towards the
 11  // waypoint.
 12  public override (Vector3 waypointPosition, Configs.Power power)
 613      GetNextWaypoint(in Vector3 targetPosition) {
 614    if (FlightPlan.Waypoints.Count == 0) {
 15      // If no waypoints are defined, directly target the target position.
 016      return (targetPosition, Configs.Power.Max);
 17    }
 18
 619    Vector3 directionToTarget = targetPosition - Agent.Position;
 620    float distanceToTarget = directionToTarget.magnitude;
 21
 22    // Find the index of the first waypoint whose position is closer to the target than the current
 23    // position.
 624    int waypointIndex = 0;
 4425    for (waypointIndex = 0; waypointIndex < FlightPlan.Waypoints.Count; ++waypointIndex) {
 1926      if (distanceToTarget > FlightPlan.Waypoints[waypointIndex].Distance) {
 527        break;
 28      }
 929    }
 30
 631    Vector3 waypointPosition = targetPosition;
 632    Configs.Power power = Configs.Power.Idle;
 733    if (waypointIndex == FlightPlan.Waypoints.Count) {
 34      // This is the last waypoint, so target the final position with the last waypoint's power
 35      // setting.
 136      power = FlightPlan.Waypoints[FlightPlan.Waypoints.Count - 1].Power;
 137      return (waypointPosition, power);
 38    }
 39    // There is a next waypoint.
 540    Configs.FlightPlanWaypoint waypoint = FlightPlan.Waypoints[waypointIndex];
 541    waypointPosition = targetPosition - directionToTarget.normalized * waypoint.Distance;
 542    waypointPosition.y = waypoint.Altitude;
 543    power = waypoint.Power;
 544    return (waypointPosition, power);
 645  }
 46}