< Summary

Class:RotaryWingThreat
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Threats/RotaryWingThreat.cs
Covered lines:17
Uncovered lines:26
Coverable lines:43
Total lines:74
Line coverage:39.5% (17 of 43)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:8
Method coverage:25% (2 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%110100%
FixedUpdate()0%2100%
UpdateReady(...)0%2100%
UpdateBoost(...)0%2100%
UpdateMidCourse(...)0%12300%
UpdateWaypointAndPower()0%2100%
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
 78  protected override void Start() {
 79    base.Start();
 710  }
 11
 012  protected override void FixedUpdate() {
 013    base.FixedUpdate();
 014  }
 15
 016  protected override void UpdateReady(double deltaTime) {}
 17
 018  protected override void UpdateBoost(double deltaTime) {}
 19
 020  protected override void UpdateMidCourse(double deltaTime) {
 021    Vector3 accelerationInput = Vector3.zero;
 22
 023    if (ShouldEvade()) {
 024      accelerationInput = EvadeInterceptor(GetClosestInterceptor());
 025    } else if (HasAssignedTarget()) {
 26      // Update waypoint and power setting.
 027      UpdateWaypointAndPower();
 28
 29      // Calculate and apply acceleration.
 030      accelerationInput = CalculateAccelerationToWaypoint();
 031    }
 32
 33    // For rotary wing threats, we don't need to compensate for gravity or consider drag.
 034    GetComponent<Rigidbody>().AddForce(accelerationInput, ForceMode.Acceleration);
 035  }
 36
 037  private void UpdateWaypointAndPower() {
 038    (_currentWaypoint, _currentPower) =
 39        _attackBehavior.GetNextWaypoint(transform.position, _target.transform.position);
 040  }
 41
 342  private Vector3 CalculateAccelerationToWaypoint() {
 343    float desiredSpeed = LookupPowerTable(_currentPower);
 44
 345    IController controller = new WaypointController(this, desiredSpeed);
 346    Vector3 accelerationInput = controller.PlanToWaypoint(_currentWaypoint);
 47
 348    Vector3 forwardAccelerationInput = Vector3.Project(accelerationInput, transform.forward);
 349    Vector3 normalAccelerationInput = accelerationInput - forwardAccelerationInput;
 50
 51    // Limit the acceleration magnitude.
 352    float maxForwardAcceleration = CalculateMaxForwardAcceleration();
 353    forwardAccelerationInput =
 54        Vector3.ClampMagnitude(forwardAccelerationInput, maxForwardAcceleration);
 355    float maxNormalAcceleration = CalculateMaxNormalAcceleration();
 356    normalAccelerationInput =
 57        Vector3.ClampMagnitude(normalAccelerationInput, maxNormalAcceleration);
 358    accelerationInput = forwardAccelerationInput + normalAccelerationInput;
 59
 360    _accelerationInput = accelerationInput;
 361    return accelerationInput;
 362  }
 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}