using System; using System.Collections.Generic; using UnityEngine; // The assignment class is an interface for assigning a target to each missile. public abstract class Assignment { // Assignment item type. // The first element corresponds to the missile index, and the second element // corresponds to the target index. public struct AssignmentItem { public int MissileIndex; public int TargetIndex; public AssignmentItem(int missileIndex, int targetIndex) { MissileIndex = missileIndex; TargetIndex = targetIndex; } } // A list containing the missile-target assignments. protected LinkedList missileToTargetAssignments = new LinkedList(); // Return the missile-target assignments. public IEnumerable Assignments => missileToTargetAssignments; // Assign a target to each missile that has not been assigned a target yet. public abstract void Assign(List missiles, List targets); // Get the list of assignable missile indices. protected static List GetAssignableMissileIndices(List missiles) { List assignableMissileIndices = new List(); for (int missileIndex = 0; missileIndex < missiles.Count; missileIndex++) { if (missiles[missileIndex].IsAssignable()) { assignableMissileIndices.Add(missileIndex); } } return assignableMissileIndices; } // Get the list of active target indices. protected static List GetActiveTargetIndices(List targets) { List activeTargetIndices = new List(); for (int targetIndex = 0; targetIndex < targets.Count; targetIndex++) { if (!targets[targetIndex].IsHit()) { activeTargetIndices.Add(targetIndex); } } return activeTargetIndices; } }