< Summary

Class:SingleReleaseStrategyBase
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Release/SingleReleaseStrategyBase.cs
Covered lines:0
Uncovered lines:31
Coverable lines:31
Total lines:62
Line coverage:0% (0 of 31)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:3
Method coverage:0% (0 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SingleReleaseStrategyBase(...)0%2100%
Release(...)0%30500%
ReleaseSingle(...)0%30500%

File(s)

/github/workspace/Assets/Scripts/Release/SingleReleaseStrategyBase.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4// Base implementation of a single release strategy.
 5//
 6// The single release strategy checks whether a sub-interceptor should be released for every
 7// sub-hierarchical object of the target hierarchical object. No assignment is performed as a result
 8// of the per-target check.
 9public abstract class SingleReleaseStrategyBase : ReleaseStrategyBase {
 10  // The sub-interceptors are launched with a nonzero speed for their rotation to be set correctly.
 11  private const float _initialSpeed = 1e-3f;
 12
 013  public SingleReleaseStrategyBase(IAgent agent) : base(agent) {}
 14
 015  protected override List<IAgent> Release(IEnumerable<IHierarchical> hierarchicals) {
 016    var carrier = Agent as CarrierBase;
 017    var releasedAgents = new List<IAgent>();
 018    foreach (var hierarchical in hierarchicals) {
 019      if (carrier.NumSubInterceptorsRemaining - releasedAgents.Count <= 0) {
 020        break;
 21      }
 022      IAgent releasedAgent = ReleaseSingle(hierarchical);
 023      if (releasedAgent != null) {
 024        releasedAgents.Add(releasedAgent);
 025      }
 026    }
 027    return releasedAgents;
 028  }
 29
 30  // Plan the release for the given target.
 31  protected abstract LaunchPlan PlanRelease(IHierarchical target);
 32
 033  private IAgent ReleaseSingle(IHierarchical hierarchical) {
 034    IHierarchical target = hierarchical.Target;
 035    if (target == null || hierarchical.LaunchedHierarchicals.Count != 0) {
 036      return null;
 37    }
 038    LaunchPlan launchPlan = PlanRelease(target);
 039    if (!launchPlan.ShouldLaunch) {
 040      return null;
 41    }
 42
 043    Simulation.State initialState = new Simulation.State() {
 44      Position = Coordinates3.ToProto(Agent.Position),
 45      Velocity =
 46          Coordinates3.ToProto(launchPlan.NormalizedLaunchVector(Agent.Position) * _initialSpeed),
 47    };
 048    IAgent subInterceptor = SimManager.Instance.CreateInterceptor(
 49        Agent.AgentConfig.SubAgentConfig.AgentConfig, initialState);
 050    if (subInterceptor is not IInterceptor subInterceptorInterceptor) {
 051      return null;
 52    }
 053    subInterceptor.HierarchicalAgent.Target = target;
 054    hierarchical.AddLaunchedHierarchical(subInterceptor.HierarchicalAgent);
 55
 056    Debug.Log(
 57        $"Launching a {subInterceptor.StaticConfig.AgentType} from {Agent} at an elevation of {launchPlan.LaunchAngle} d
 058    UIManager.Instance.LogActionMessage(
 59        $"[IADS] Launching a {subInterceptor.StaticConfig.AgentType} from {Agent} at an elevation of {launchPlan.LaunchA
 060    return subInterceptor;
 061  }
 62}