< 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.
 81214  protected override void FixedUpdate() {
 81215    base.FixedUpdate();
 81216  }
 17
 018  protected override void UpdateReady(double deltaTime) {}
 19
 11220  protected override void UpdateBoost(double deltaTime) {}
 21
 75622  protected override void UpdateMidCourse(double deltaTime) {
 75623    Vector3 accelerationInput = Vector3.zero;
 24
 75625    if (ShouldEvade()) {
 026      accelerationInput = EvadeInterceptor(GetClosestInterceptor());
 151227    } else if (HasAssignedTarget()) {
 28      // Update waypoint and power setting.
 75629      UpdateWaypointAndPower();
 30
 31      // Calculate and apply acceleration.
 75632      accelerationInput = CalculateAccelerationToWaypoint();
 75633    }
 34
 35    // For rotary wing threats, we don't need to compensate for gravity or consider drag.
 75636    GetComponent<Rigidbody>().AddForce(accelerationInput, ForceMode.Acceleration);
 75637  }
 38
 75639  private void UpdateWaypointAndPower() {
 75640    (_currentWaypoint, _currentPowerSetting) =
 41        _attackBehavior.GetNextWaypoint(transform.position, _target.transform.position);
 75642  }
 43
 75644  private Vector3 CalculateAccelerationToWaypoint() {
 75645    float desiredSpeed = PowerTableLookup(_currentPowerSetting);
 46
 75647    IController controller = new WaypointController(this, desiredSpeed);
 75648    Vector3 accelerationInput = controller.PlanToWaypoint(_currentWaypoint);
 49
 75650    Vector3 forwardAccelerationInput = Vector3.Project(accelerationInput, transform.forward);
 75651    Vector3 normalAccelerationInput = accelerationInput - forwardAccelerationInput;
 52
 53    // Limit the acceleration magnitude.
 75654    float maxForwardAcceleration = CalculateMaxForwardAcceleration();
 75655    forwardAccelerationInput =
 56        Vector3.ClampMagnitude(forwardAccelerationInput, maxForwardAcceleration);
 75657    float maxNormalAcceleration = CalculateMaxNormalAcceleration();
 75658    normalAccelerationInput =
 59        Vector3.ClampMagnitude(normalAccelerationInput, maxNormalAcceleration);
 75660    accelerationInput = forwardAccelerationInput + normalAccelerationInput;
 61
 75662    _accelerationInput = accelerationInput;
 75663    return accelerationInput;
 75664  }
 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}