Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions Assets/Scripts/Interceptors/CarrierBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,29 @@ private IEnumerator ReleaseManager(float period) {
// Determine whether to release the sub-interceptors.
if (ReleaseStrategy != null) {
List<IAgent> releasedAgents = ReleaseStrategy.Release();
NumSubInterceptorsRemaining -= releasedAgents.Count;
List<IAgent> unexpectedAgents =
releasedAgents.Where(agent => agent is not InterceptorBase).ToList();
List<InterceptorBase> releasedInterceptors =
releasedAgents.OfType<InterceptorBase>().Distinct().ToList();
if (unexpectedAgents.Count > 0) {
string unexpectedTypes =
string.Join(", ", unexpectedAgents.Select(agent => agent?.GetType().Name ?? "null"));
Debug.LogError($"Carrier release expected only {nameof(InterceptorBase)} entries but " +
$"received {unexpectedAgents.Count} unexpected " +
$"agent(s) [{unexpectedTypes}] out of {releasedAgents.Count} released " +
$"agent(s).");
}
NumSubInterceptorsRemaining =
Mathf.Max(0, NumSubInterceptorsRemaining - releasedInterceptors.Count);

foreach (var agent in releasedAgents) {
if (agent is IInterceptor subInterceptor) {
subInterceptor.OnAssignSubInterceptor += AssignSubInterceptor;
subInterceptor.OnReassignTarget += ReassignTarget;
if (subInterceptor is InterceptorBase interceptorBase) {
interceptorBase.CommsParent = this;
}
if (subInterceptor.Movement is MissileMovement movement) {
movement.FlightPhase = Simulation.FlightPhase.Boost;
}
foreach (InterceptorBase subInterceptor in releasedInterceptors) {
// Register parent (carrier) that releases interceptor to interceptor.
subInterceptor.CommsParent = this;
if (subInterceptor.Movement is MissileMovement movement) {
movement.FlightPhase = Simulation.FlightPhase.Boost;
}
}
}

yield return new WaitForSeconds(period);
}
_releaseCoroutine = null;
Expand Down
Loading
Loading