< Summary

Class:RotaryWingThreat
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Threats/RotaryWingThreat.cs
Covered lines:33
Uncovered lines:10
Coverable lines:43
Total lines:74
Line coverage:76.7% (33 of 43)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:8
Method coverage:75% (6 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%110100%
FixedUpdate()0%110100%
UpdateReady(...)0%2100%
UpdateBoost(...)0%110100%
UpdateMidCourse(...)0%3.113076.92%
UpdateWaypointAndPower()0%110100%
CalculateAccelerationToWaypoint()0%110100%
OnDrawGizmos()0%6200%

File(s)

/github/workspace/Assets/Scripts/Threats/RotaryWingThreat.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5public class RotaryWingThreat : Threat {
 6  private Vector3 _accelerationInput;
 7
 568  protected override void Start() {
 569    base.Start();
 5610  }
 11
 42712  protected override void FixedUpdate() {
 42713    base.FixedUpdate();
 42714  }
 15
 016  protected override void UpdateReady(double deltaTime) {}
 17
 11218  protected override void UpdateBoost(double deltaTime) {}
 19
 37120  protected override void UpdateMidCourse(double deltaTime) {
 37121    Vector3 accelerationInput = Vector3.zero;
 22
 37123    if (ShouldEvade()) {
 024      accelerationInput = EvadeInterceptor(GetClosestInterceptor());
 74225    } else if (HasAssignedTarget()) {
 26      // Update waypoint and power setting.
 37127      UpdateWaypointAndPower();
 28
 29      // Calculate and apply acceleration.
 37130      accelerationInput = CalculateAccelerationToWaypoint();
 37131    }
 32
 33    // For rotary wing threats, we don't need to compensate for gravity or consider drag.
 37134    GetComponent<Rigidbody>().AddForce(accelerationInput, ForceMode.Acceleration);
 37135  }
 36
 37137  private void UpdateWaypointAndPower() {
 37138    (_currentWaypoint, _currentPower) =
 39        _attackBehavior.GetNextWaypoint(transform.position, _target.transform.position);
 37140  }
 41
 37142  private Vector3 CalculateAccelerationToWaypoint() {
 37143    float desiredSpeed = LookupPowerTable(_currentPower);
 44
 37145    IController controller = new WaypointController(this, desiredSpeed);
 37146    Vector3 accelerationInput = controller.PlanToWaypoint(_currentWaypoint);
 47
 37148    Vector3 forwardAccelerationInput = Vector3.Project(accelerationInput, transform.forward);
 37149    Vector3 normalAccelerationInput = accelerationInput - forwardAccelerationInput;
 50
 51    // Limit the acceleration magnitude.
 37152    float maxForwardAcceleration = CalculateMaxForwardAcceleration();
 37153    forwardAccelerationInput =
 54        Vector3.ClampMagnitude(forwardAccelerationInput, maxForwardAcceleration);
 37155    float maxNormalAcceleration = CalculateMaxNormalAcceleration();
 37156    normalAccelerationInput =
 57        Vector3.ClampMagnitude(normalAccelerationInput, maxNormalAcceleration);
 37158    accelerationInput = forwardAccelerationInput + normalAccelerationInput;
 59
 37160    _accelerationInput = accelerationInput;
 37161    return accelerationInput;
 37162  }
 63
 64  // Optional: Add this method to visualize debug information
 065  protected virtual void OnDrawGizmos() {
 066    if (Application.isPlaying) {
 067      Gizmos.color = Color.yellow;
 068      Gizmos.DrawLine(transform.position, _currentWaypoint);
 69
 070      Gizmos.color = Color.green;
 071      Gizmos.DrawRay(transform.position, _accelerationInput);
 072    }
 073  }
 74}