2024-09-12 00:17:21 -07:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2024-09-29 23:45:59 -07:00
|
|
|
using System.Collections;
|
2024-09-12 00:17:21 -07:00
|
|
|
using UnityEngine;
|
2024-09-29 23:18:40 -07:00
|
|
|
using System.Linq;
|
|
|
|
using System.Diagnostics.Contracts;
|
2024-09-12 00:17:21 -07:00
|
|
|
|
2024-09-24 19:59:25 -07:00
|
|
|
// The assignment class is an interface for assigning a threat to each interceptor.
|
2024-09-13 22:45:25 -07:00
|
|
|
public interface IAssignment {
|
|
|
|
// Assignment item type.
|
2024-09-24 19:59:25 -07:00
|
|
|
// The first element corresponds to the interceptor index, and the second element
|
2024-09-24 19:24:50 -07:00
|
|
|
// corresponds to the threat index.
|
2024-09-13 22:45:25 -07:00
|
|
|
public struct AssignmentItem {
|
2024-09-29 23:18:40 -07:00
|
|
|
public Interceptor Interceptor;
|
|
|
|
public Threat Threat;
|
2024-09-12 00:17:21 -07:00
|
|
|
|
2024-09-29 23:18:40 -07:00
|
|
|
public AssignmentItem(Interceptor interceptor, Threat threat) {
|
|
|
|
Interceptor = interceptor;
|
|
|
|
Threat = threat;
|
2024-09-12 00:17:21 -07:00
|
|
|
}
|
2024-09-13 22:45:25 -07:00
|
|
|
}
|
2024-09-12 00:17:21 -07:00
|
|
|
|
2024-09-24 19:59:25 -07:00
|
|
|
// A list containing the interceptor-target assignments.
|
2024-09-12 00:17:21 -07:00
|
|
|
|
2024-09-24 19:59:25 -07:00
|
|
|
// Assign a target to each interceptor that has not been assigned a target yet.
|
2024-09-29 23:18:40 -07:00
|
|
|
[Pure]
|
|
|
|
public abstract IEnumerable<AssignmentItem> Assign(in IReadOnlyList<Interceptor> interceptors, in IReadOnlyList<ThreatData> threatTable);
|
2024-09-12 00:17:21 -07:00
|
|
|
|
2024-09-24 19:59:25 -07:00
|
|
|
// Get the list of assignable interceptor indices.
|
2024-09-29 23:18:40 -07:00
|
|
|
[Pure]
|
|
|
|
protected static List<Interceptor> GetAssignableInterceptors(in IReadOnlyList<Interceptor> interceptors) {
|
|
|
|
return interceptors.Where(interceptor => interceptor.IsAssignable()).ToList();
|
2024-09-13 22:45:25 -07:00
|
|
|
}
|
2024-09-12 00:17:21 -07:00
|
|
|
|
2024-09-29 23:18:40 -07:00
|
|
|
// Get the list of active threats.
|
|
|
|
[Pure]
|
|
|
|
protected static List<ThreatData> GetActiveThreats(in IReadOnlyList<ThreatData> threats) {
|
|
|
|
return threats.Where(t => t.Status != ThreatStatus.DESTROYED).ToList();
|
2024-09-13 22:45:25 -07:00
|
|
|
}
|
2024-09-12 00:17:21 -07:00
|
|
|
}
|