< Summary

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

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)
 28658      : 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)
 699513      GetNextWaypoint(in Vector3 targetPosition) {
 699514    if (FlightPlan.Waypoints.Count == 0) {
 15      // If no waypoints are defined, directly target the target position.
 016      return (targetPosition, Configs.Power.Max);
 17    }
 18
 699519    Vector3 directionToTarget = targetPosition - Agent.Position;
 699520    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.
 699524    int waypointIndex = 0;
 2300125    for (waypointIndex = 0; waypointIndex < FlightPlan.Waypoints.Count; ++waypointIndex) {
 1466226      if (distanceToTarget > FlightPlan.Waypoints[waypointIndex].Distance) {
 699527        break;
 28      }
 67229    }
 30
 699531    Vector3 waypointPosition = targetPosition;
 699532    Configs.Power power = Configs.Power.Idle;
 699533    if (waypointIndex == FlightPlan.Waypoints.Count) {
 34      // This is the last waypoint, so target the final position with the last waypoint's power
 35      // setting.
 036      power = FlightPlan.Waypoints[FlightPlan.Waypoints.Count - 1].Power;
 037      return (waypointPosition, power);
 38    }
 39    // There is a next waypoint.
 699540    Configs.FlightPlanWaypoint waypoint = FlightPlan.Waypoints[waypointIndex];
 699541    waypointPosition = targetPosition - directionToTarget.normalized * waypoint.Distance;
 699542    waypointPosition.y = waypoint.Altitude;
 699543    power = waypoint.Power;
 699544    return (waypointPosition, power);
 699545  }
 46}