< 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:76
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
 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
 014  protected override void FixedUpdate() {
 015    base.FixedUpdate();
 016  }
 17
 018  protected override void UpdateReady(double deltaTime) {}
 19
 020  protected override void UpdateBoost(double deltaTime) {}
 21
 022  protected override void UpdateMidCourse(double deltaTime) {
 023    Vector3 accelerationInput = Vector3.zero;
 24
 025    if (ShouldEvade()) {
 026      accelerationInput = EvadeInterceptor(GetClosestInterceptor());
 027    } else if (HasAssignedTarget()) {
 28      // Update waypoint and power setting
 029      UpdateWaypointAndPower();
 30
 31      // Calculate and apply acceleration
 032      accelerationInput = CalculateAccelerationToWaypoint();
 033    }
 34
 35    // For RotaryWingThreat, we don't need to compensate for gravity or consider drag
 036    GetComponent<Rigidbody>().AddForce(accelerationInput, ForceMode.Acceleration);
 037  }
 38
 039  private void UpdateWaypointAndPower() {
 040    (_currentWaypoint, _currentPowerSetting) =
 41        _attackBehavior.GetNextWaypoint(transform.position, _target.transform.position);
 042  }
 43
 344  private Vector3 CalculateAccelerationToWaypoint() {
 345    float desiredSpeed = PowerTableLookup(_currentPowerSetting);
 46
 347    IController controller = new WaypointController(this, desiredSpeed);
 348    Vector3 accelerationInput = controller.PlanToWaypoint(_currentWaypoint);
 49
 350    Vector3 forwardAccelerationInput = Vector3.Project(accelerationInput, transform.forward);
 351    Vector3 normalAccelerationInput = accelerationInput - forwardAccelerationInput;
 52
 53    // Limit the acceleration magnitude.
 354    float maxForwardAcceleration = CalculateMaxForwardAcceleration();
 355    forwardAccelerationInput =
 56        Vector3.ClampMagnitude(forwardAccelerationInput, maxForwardAcceleration);
 357    float maxNormalAcceleration = CalculateMaxNormalAcceleration();
 358    normalAccelerationInput =
 59        Vector3.ClampMagnitude(normalAccelerationInput, maxNormalAcceleration);
 360    accelerationInput = forwardAccelerationInput + normalAccelerationInput;
 61
 362    _accelerationInput = accelerationInput;
 363    return accelerationInput;
 364  }
 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}