< Summary

Class:CarrierBase
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Interceptors/CarrierBase.cs
Covered lines:0
Uncovered lines:35
Coverable lines:35
Total lines:62
Line coverage:0% (0 of 35)
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
Awake()0%2100%
Start()0%2100%
OnDestroy()0%6200%
ReleaseManager()0%72800%

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.
 017  public IReleaseStrategy ReleaseStrategy { get; set; }
 18
 019  protected override void Awake() {
 020    base.Awake();
 21
 022    EscapeDetector = new GeometricEscapeDetector(this);
 023  }
 24
 025  protected override void Start() {
 026    base.Start();
 27
 028    _releaseCoroutine = StartCoroutine(ReleaseManager(_releasePeriod));
 029  }
 30
 031  protected override void OnDestroy() {
 032    base.OnDestroy();
 33
 034    if (_releaseCoroutine != null) {
 035      StopCoroutine(_releaseCoroutine);
 036      _releaseCoroutine = null;
 037    }
 038  }
 39
 040  private IEnumerator ReleaseManager(float period) {
 041    while (NumSubInterceptorsRemaining > 0) {
 42      // Determine whether to release the sub-interceptors.
 043      if (ReleaseStrategy != null) {
 044        List<IAgent> releasedAgents = ReleaseStrategy.Release();
 045        NumSubInterceptorsRemaining -= releasedAgents.Count;
 46
 047        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        }
 056      }
 57
 058      yield return new WaitForSeconds(period);
 059    }
 060    _releaseCoroutine = null;
 061  }
 62}