< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CarrierInterceptor()0%2100%
SetDynamicAgentConfig(...)0%6200%
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 void SetDynamicAgentConfig(DynamicAgentConfig config) {
 011    base.SetDynamicAgentConfig(config);
 012    if (!HasAssignedTarget()) {
 13      // Create a DummyTarget that is projected 100km out from the initialRotation
 014      Vector3 initialPosition = config.initial_state.position;
 015      Quaternion initialRotation = Quaternion.Euler(config.initial_state.rotation);
 016      Vector3 forwardDirection = initialRotation * Vector3.forward;
 017      Vector3 dummyTargetPosition =
 18          initialPosition + forwardDirection * 100000f;  // 100km in meters
 19
 20      // Calculate a reasonable velocity for the dummy target
 021      Vector3 dummyTargetVelocity = Vector3.zero;  // Assuming 1000 m/s speed
 22
 23      // Create the dummy agent using SimManager
 024      Agent dummyAgent =
 25          SimManager.Instance.CreateDummyAgent(dummyTargetPosition, dummyTargetVelocity);
 26
 27      // Assign the dummy agent as the target
 028      AssignTarget(dummyAgent);
 029    }
 030  }
 31
 032  public override bool IsAssignable() {
 033    return false;
 034  }
 35
 036  protected override void FixedUpdate() {
 037    base.FixedUpdate();
 038    float launchTimeVariance = 0.5f;
 039    float launchTimeNoise = Random.Range(-launchTimeVariance, launchTimeVariance);
 040    double launchTimeWithNoise =
 41        dynamicAgentConfig.submunitions_config.dispense_time + launchTimeNoise;
 42    // Check if it's time to launch submunitions
 043    if (!_submunitionsLaunched &&
 44        (GetFlightPhase() == FlightPhase.MIDCOURSE || GetFlightPhase() == FlightPhase.BOOST) &&
 045        SimManager.Instance.GetElapsedSimulationTime() >= launchTimeWithNoise) {
 046      SpawnSubmunitions();
 047      _submunitionsLaunched = true;
 048    }
 049  }
 50
 051  protected override void UpdateMidCourse(double deltaTime) {
 052    base.UpdateMidCourse(deltaTime);
 053  }
 54
 055  protected override void DrawDebugVectors() {
 056    base.DrawDebugVectors();
 057    if (_acceleration != null) {
 058      Debug.DrawRay(transform.position, _acceleration * 1f, Color.green);
 059    }
 060  }
 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}