< Summary

Class:CarrierInterceptor
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Interceptors/CarrierInterceptor.cs
Covered lines:29
Uncovered lines:22
Coverable lines:51
Total lines:80
Line coverage:56.8% (29 of 51)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:7
Method coverage:71.4% (5 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CarrierInterceptor()0%110100%
SetDynamicAgentConfig(...)0%220100%
IsAssignable()0%110100%
FixedUpdate()0%6.25063.64%
UpdateMidCourse(...)0%2100%
DrawDebugVectors()0%220100%
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 {
 28  private bool _submunitionsLaunched = false;
 9
 110  public override void SetDynamicAgentConfig(DynamicAgentConfig config) {
 111    base.SetDynamicAgentConfig(config);
 212    if (!HasAssignedTarget()) {
 13      // Create a DummyTarget that is projected 100km out from the initialRotation
 114      Vector3 initialPosition = config.initial_state.position;
 115      Quaternion initialRotation = Quaternion.Euler(config.initial_state.rotation);
 116      Vector3 forwardDirection = initialRotation * Vector3.forward;
 117      Vector3 dummyTargetPosition =
 18          initialPosition + forwardDirection * 100000f;  // 100km in meters
 19
 20      // Calculate a reasonable velocity for the dummy target
 121      Vector3 dummyTargetVelocity = Vector3.zero;  // Assuming 1000 m/s speed
 22
 23      // Create the dummy agent using SimManager
 124      Agent dummyAgent =
 25          SimManager.Instance.CreateDummyAgent(dummyTargetPosition, dummyTargetVelocity);
 26
 27      // Assign the dummy agent as the target
 128      AssignTarget(dummyAgent);
 129    }
 130  }
 31
 132  public override bool IsAssignable() {
 133    return false;
 134  }
 35
 5136  protected override void FixedUpdate() {
 5137    base.FixedUpdate();
 5038    float launchTimeVariance = 0.5f;
 5039    float launchTimeNoise = Random.Range(-launchTimeVariance, launchTimeVariance);
 5040    double launchTimeWithNoise =
 41        dynamicAgentConfig.submunitions_config.dispense_time + launchTimeNoise;
 42    // Check if it's time to launch submunitions
 5043    if (!_submunitionsLaunched &&
 44        (GetFlightPhase() == FlightPhase.MIDCOURSE || GetFlightPhase() == FlightPhase.BOOST) &&
 045        SimManager.Instance.GetElapsedSimulationTime() >= launchTimeWithNoise) {
 046      SpawnSubmunitions();
 047      _submunitionsLaunched = true;
 048    }
 5049  }
 50
 051  protected override void UpdateMidCourse(double deltaTime) {
 052    base.UpdateMidCourse(deltaTime);
 053  }
 54
 5055  protected override void DrawDebugVectors() {
 5056    base.DrawDebugVectors();
 10057    if (_acceleration != null) {
 5058      Debug.DrawRay(transform.position, _acceleration * 1f, Color.green);
 5059    }
 5060  }
 61
 062  public void SpawnSubmunitions() {
 063    List<Interceptor> submunitions = new List<Interceptor>();
 064    for (int i = 0; i < dynamicAgentConfig.submunitions_config.num_submunitions; i++) {
 065      DynamicAgentConfig convertedConfig = DynamicAgentConfig.FromSubmunitionDynamicAgentConfig(
 66          dynamicAgentConfig.submunitions_config.dynamic_agent_config);
 067      convertedConfig.initial_state.position = transform.position;
 068      convertedConfig.initial_state.velocity = GetComponent<Rigidbody>().linearVelocity;
 069      Interceptor submunition = SimManager.Instance.CreateInterceptor(convertedConfig);
 070      submunition.SetFlightPhase(FlightPhase.READY);
 71      // Force the submunition to be launched with the same velocity as the carrier
 072      submunition.SetVelocity(GetComponent<Rigidbody>().linearVelocity);
 073      submunitions.Add(submunition);
 074    }
 075    IADS.Instance.RequestThreatAssignment(submunitions);
 76
 077    SimManager.Instance.AddSubmunitionsSwarm(
 078        submunitions.ConvertAll(submunition => submunition as Agent));
 079  }
 80}