< Summary

Class:RotaryWingThreat
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Threats/RotaryWingThreat.cs
Covered lines:32
Uncovered lines:11
Coverable lines:43
Total lines:76
Line coverage:74.4% (32 of 43)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:8
Method coverage:62.5% (5 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%110100%
FixedUpdate()0%110100%
UpdateReady(...)0%2100%
UpdateBoost(...)0%2100%
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
 8  // Start is called before the first frame update
 79  protected override void Start() {
 710    base.Start();
 711  }
 12
 13  // Update is called once per frame
 35714  protected override void FixedUpdate() {
 35715    base.FixedUpdate();
 35716  }
 17
 018  protected override void UpdateReady(double deltaTime) {}
 19
 020  protected override void UpdateBoost(double deltaTime) {}
 21
 35722  protected override void UpdateMidCourse(double deltaTime) {
 35723    Vector3 accelerationInput = Vector3.zero;
 24
 35725    if (ShouldEvade()) {
 026      accelerationInput = EvadeInterceptor(GetClosestInterceptor());
 71427    } else if (HasAssignedTarget()) {
 28      // Update waypoint and power setting
 35729      UpdateWaypointAndPower();
 30
 31      // Calculate and apply acceleration
 35732      accelerationInput = CalculateAccelerationToWaypoint();
 35733    }
 34
 35    // For RotaryWingThreat, we don't need to compensate for gravity or consider drag
 35736    GetComponent<Rigidbody>().AddForce(accelerationInput, ForceMode.Acceleration);
 35737  }
 38
 35739  private void UpdateWaypointAndPower() {
 35740    (_currentWaypoint, _currentPowerSetting) =
 41        _attackBehavior.GetNextWaypoint(transform.position, _target.transform.position);
 35742  }
 43
 35744  private Vector3 CalculateAccelerationToWaypoint() {
 35745    float desiredSpeed = PowerTableLookup(_currentPowerSetting);
 46
 35747    IController controller = new WaypointController(this, desiredSpeed);
 35748    Vector3 accelerationInput = controller.PlanToWaypoint(_currentWaypoint);
 49
 35750    Vector3 forwardAccelerationInput = Vector3.Project(accelerationInput, transform.forward);
 35751    Vector3 normalAccelerationInput = accelerationInput - forwardAccelerationInput;
 52
 53    // Limit the acceleration magnitude.
 35754    float maxForwardAcceleration = CalculateMaxForwardAcceleration();
 35755    forwardAccelerationInput =
 56        Vector3.ClampMagnitude(forwardAccelerationInput, maxForwardAcceleration);
 35757    float maxNormalAcceleration = CalculateMaxNormalAcceleration();
 35758    normalAccelerationInput =
 59        Vector3.ClampMagnitude(normalAccelerationInput, maxNormalAcceleration);
 35760    accelerationInput = forwardAccelerationInput + normalAccelerationInput;
 61
 35762    _accelerationInput = accelerationInput;
 35763    return accelerationInput;
 35764  }
 65
 66  // Optional: Add this method to visualize debug information
 067  protected virtual void OnDrawGizmos() {
 068    if (Application.isPlaying) {
 069      Gizmos.color = Color.yellow;
 070      Gizmos.DrawLine(transform.position, _currentWaypoint);
 71
 072      Gizmos.color = Color.green;
 073      Gizmos.DrawRay(transform.position, _accelerationInput);
 074    }
 075  }
 76}