< Summary

Class:CarrierBase
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Interceptors/CarrierBase.cs
Covered lines:24
Uncovered lines:11
Coverable lines:35
Total lines:62
Line coverage:68.5% (24 of 35)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:6
Method coverage:100% (6 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
Start()0%110100%
OnDestroy()0%220100%
ReleaseManager()0%18.988044.44%

File(s)

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

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using System.Linq;
 4using UnityEngine;
 5
 6// Base implementation of a carrier.
 7//
 8// A carrier carries other interceptors, such as a launcher or a carrier interceptor.
 9public abstract class CarrierBase : InterceptorBase {
 10  // Time between checking whether to release sub-interceptors.
 11  private const float _releasePeriod = 0.2f;
 12
 13  // Coroutine for releasing sub-interceptors.
 14  private Coroutine _releaseCoroutine;
 15
 16  // Release strategy for sub-interceptors.
 4217  public IReleaseStrategy ReleaseStrategy { get; set; }
 18
 1419  protected override void Awake() {
 1420    base.Awake();
 21
 1422    EscapeDetector = new GeometricEscapeDetector(this);
 1423  }
 24
 1425  protected override void Start() {
 1426    base.Start();
 27
 1428    _releaseCoroutine = StartCoroutine(ReleaseManager(_releasePeriod));
 1429  }
 30
 1331  protected override void OnDestroy() {
 1332    base.OnDestroy();
 33
 2634    if (_releaseCoroutine != null) {
 1335      StopCoroutine(_releaseCoroutine);
 1336      _releaseCoroutine = null;
 1337    }
 1338  }
 39
 1440  private IEnumerator ReleaseManager(float period) {
 2841    while (NumSubInterceptorsRemaining > 0) {
 42      // Determine whether to release the sub-interceptors.
 2843      if (ReleaseStrategy != null) {
 1444        List<IAgent> releasedAgents = ReleaseStrategy.Release();
 1445        NumSubInterceptorsRemaining -= releasedAgents.Count;
 46
 4247        foreach (var agent in releasedAgents) {
 048          if (agent is IInterceptor subInterceptor) {
 049            subInterceptor.OnAssignSubInterceptor += AssignSubInterceptor;
 050            subInterceptor.OnReassignTarget += ReassignTarget;
 051            if (subInterceptor.Movement is MissileMovement movement) {
 052              movement.FlightPhase = Simulation.FlightPhase.Boost;
 053            }
 054          }
 055        }
 1456      }
 57
 1458      yield return new WaitForSeconds(period);
 059    }
 060    _releaseCoroutine = null;
 061  }
 62}