< Summary

Class:CarrierInterceptor
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Interceptors/CarrierInterceptor.cs
Covered lines:0
Uncovered lines:41
Coverable lines:41
Total lines:69
Line coverage:0% (0 of 41)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:6
Method coverage:0% (0 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CarrierInterceptor()0%2100%
IsAssignable()0%2100%
FixedUpdate()0%30500%
UpdateMidCourse(...)0%2100%
DrawDebugVectors()0%6200%
SpawnSubmunitions()0%12300%

File(s)

/github/workspace/Assets/Scripts/Interceptors/CarrierInterceptor.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using JetBrains.Annotations;
 4using UnityEngine;
 5using System.Linq;
 6
 7public class CarrierInterceptor : Interceptor {
 08  private bool _submunitionsLaunched = false;
 9
 010  public override bool IsAssignable() {
 011    return false;
 012  }
 13
 014  protected override void FixedUpdate() {
 015    base.FixedUpdate();
 16    // Check whether to launch submunitions.
 017    if ((GetFlightPhase() == FlightPhase.MIDCOURSE || GetFlightPhase() == FlightPhase.BOOST) &&
 018        !_submunitionsLaunched && IADS.Instance.ShouldLaunchSubmunitions(this)) {
 019      SpawnSubmunitions();
 020      _submunitionsLaunched = true;
 021    }
 022  }
 23
 024  protected override void UpdateMidCourse(double deltaTime) {
 025    base.UpdateMidCourse(deltaTime);
 026  }
 27
 028  protected override void DrawDebugVectors() {
 029    base.DrawDebugVectors();
 030    if (_acceleration != null) {
 031      Debug.DrawRay(transform.position, _acceleration * 1f, Color.green);
 032    }
 033  }
 34
 035  private void SpawnSubmunitions() {
 036    List<Interceptor> submunitions = new List<Interceptor>();
 037    for (int i = 0; i < dynamicAgentConfig.submunitions_config.num_submunitions; ++i) {
 038      DynamicAgentConfig convertedConfig = DynamicAgentConfig.FromSubmunitionDynamicAgentConfig(
 39          dynamicAgentConfig.submunitions_config.dynamic_agent_config);
 040      InitialState initialState = new InitialState();
 041      initialState.position = transform.position;
 42
 43      // Fan the submunitions radially outwards by 60 degrees from the carrier interceptor's
 44      // velocity vector.
 45      const float SubmunitionsAngularDeviation = 60.0f * Mathf.Deg2Rad;
 046      Vector3 velocity = GetComponent<Rigidbody>().linearVelocity;
 047      Vector3 perpendicularDirection = Vector3.Cross(velocity, Vector3.up);
 048      Vector3 lateralDirection =
 49          Quaternion.AngleAxis(i * 360 / dynamicAgentConfig.submunitions_config.num_submunitions,
 50                               velocity) *
 51          perpendicularDirection;
 052      initialState.velocity = Vector3.RotateTowards(
 53          velocity, lateralDirection, maxRadiansDelta: SubmunitionsAngularDeviation,
 54          maxMagnitudeDelta: Mathf.Cos(SubmunitionsAngularDeviation));
 55
 056      Interceptor submunition =
 57          SimManager.Instance.CreateInterceptor(convertedConfig, initialState);
 058      submunition.SetFlightPhase(FlightPhase.READY);
 59      // Launch the submunitions with the same velocity as the carrier interceptor's.
 060      submunition.SetVelocity(GetComponent<Rigidbody>().linearVelocity);
 061      submunitions.Add(submunition);
 062    }
 063    UnassignTarget();
 064    IADS.Instance.AssignSubmunitionsToThreats(this, submunitions);
 65
 066    SimManager.Instance.AddSubmunitionsSwarm(
 067        submunitions.ConvertAll(submunition => submunition as Agent));
 068  }
 69}