< 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:76
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
 8  // Start is called before the first frame update.
 569  protected override void Start() {
 5610    base.Start();
 5611  }
 12
 13  // Update is called once per frame.
 91714  protected override void FixedUpdate() {
 91715    base.FixedUpdate();
 91716  }
 17
 018  protected override void UpdateReady(double deltaTime) {}
 19
 11220  protected override void UpdateBoost(double deltaTime) {}
 21
 86122  protected override void UpdateMidCourse(double deltaTime) {
 86123    Vector3 accelerationInput = Vector3.zero;
 24
 86125    if (ShouldEvade()) {
 026      accelerationInput = EvadeInterceptor(GetClosestInterceptor());
 172227    } else if (HasAssignedTarget()) {
 28      // Update waypoint and power setting.
 86129      UpdateWaypointAndPower();
 30
 31      // Calculate and apply acceleration.
 86132      accelerationInput = CalculateAccelerationToWaypoint();
 86133    }
 34
 35    // For rotary wing threats, we don't need to compensate for gravity or consider drag.
 86136    GetComponent<Rigidbody>().AddForce(accelerationInput, ForceMode.Acceleration);
 86137  }
 38
 86139  private void UpdateWaypointAndPower() {
 86140    (_currentWaypoint, _currentPowerSetting) =
 41        _attackBehavior.GetNextWaypoint(transform.position, _target.transform.position);
 86142  }
 43
 86144  private Vector3 CalculateAccelerationToWaypoint() {
 86145    float desiredSpeed = PowerTableLookup(_currentPowerSetting);
 46
 86147    IController controller = new WaypointController(this, desiredSpeed);
 86148    Vector3 accelerationInput = controller.PlanToWaypoint(_currentWaypoint);
 49
 86150    Vector3 forwardAccelerationInput = Vector3.Project(accelerationInput, transform.forward);
 86151    Vector3 normalAccelerationInput = accelerationInput - forwardAccelerationInput;
 52
 53    // Limit the acceleration magnitude.
 86154    float maxForwardAcceleration = CalculateMaxForwardAcceleration();
 86155    forwardAccelerationInput =
 56        Vector3.ClampMagnitude(forwardAccelerationInput, maxForwardAcceleration);
 86157    float maxNormalAcceleration = CalculateMaxNormalAcceleration();
 86158    normalAccelerationInput =
 59        Vector3.ClampMagnitude(normalAccelerationInput, maxNormalAcceleration);
 86160    accelerationInput = forwardAccelerationInput + normalAccelerationInput;
 61
 86162    _accelerationInput = accelerationInput;
 86163    return accelerationInput;
 86164  }
 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}