| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Linq; |
| | | 3 | | using UnityEngine; |
| | | 4 | | |
| | | 5 | | [System.Serializable] |
| | | 6 | | public enum ThreatClusterStatus { UNASSIGNED, ASSIGNED, DELEGATED } |
| | | 7 | | |
| | | 8 | | [System.Serializable] |
| | | 9 | | public class ThreatClusterData { |
| | | 10 | | private Cluster _cluster; |
| | | 11 | | |
| | | 12 | | // The agent tracks the centroid of the cluster. |
| | | 13 | | private Agent _agent; |
| | | 14 | | |
| | | 15 | | [SerializeField] |
| | 177 | 16 | | private ThreatClusterStatus _status = ThreatClusterStatus.UNASSIGNED; |
| | | 17 | | |
| | | 18 | | [SerializeField] |
| | 177 | 19 | | private List<Interceptor> _assignedInterceptors = new List<Interceptor>(); |
| | | 20 | | |
| | 354 | 21 | | public ThreatClusterData(Cluster cluster) { |
| | 177 | 22 | | _cluster = cluster; |
| | 177 | 23 | | _agent = SimManager.Instance.CreateDummyAgent(cluster.Centroid(), cluster.Velocity()); |
| | 177 | 24 | | } |
| | | 25 | | |
| | | 26 | | public Cluster Cluster { |
| | 0 | 27 | | get { return _cluster; } |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | public Agent Centroid { |
| | 0 | 31 | | get { return _agent; } |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | public ThreatClusterStatus Status { |
| | 0 | 35 | | get { return _status; } |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | public int AssignedInterceptorCount { |
| | 0 | 39 | | get { return _assignedInterceptors.Count; } |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | // Read-only view of interceptors currently assigned to this cluster. |
| | | 43 | | public IReadOnlyList<Interceptor> AssignedInterceptors { |
| | 0 | 44 | | get { return _assignedInterceptors; } |
| | | 45 | | } |
| | | 46 | | |
| | 474 | 47 | | public void UpdateCentroid() { |
| | 474 | 48 | | _agent.SetPosition(_cluster.Centroid()); |
| | 474 | 49 | | _agent.SetVelocity(_cluster.Velocity()); |
| | 474 | 50 | | } |
| | | 51 | | |
| | 0 | 52 | | public void AssignInterceptor(Interceptor interceptor) { |
| | 0 | 53 | | _status = ThreatClusterStatus.ASSIGNED; |
| | 0 | 54 | | _assignedInterceptors.Add(interceptor); |
| | | 55 | | |
| | | 56 | | // Assign the interceptor to all threats within the cluster. |
| | 0 | 57 | | foreach (var threat in _cluster.Threats.ToList()) { |
| | 0 | 58 | | threat.AddInterceptor(interceptor); |
| | 0 | 59 | | } |
| | 0 | 60 | | } |
| | | 61 | | |
| | 0 | 62 | | public void RemoveInterceptor(Interceptor interceptor, bool delegated = false) { |
| | 0 | 63 | | _assignedInterceptors.Remove(interceptor); |
| | 0 | 64 | | if (AssignedInterceptorCount == 0) { |
| | 0 | 65 | | _status = delegated ? ThreatClusterStatus.DELEGATED : ThreatClusterStatus.UNASSIGNED; |
| | 0 | 66 | | } |
| | | 67 | | |
| | | 68 | | // Remove the interceptor from all threats within the cluster. |
| | 0 | 69 | | foreach (var threat in _cluster.Threats.ToList()) { |
| | 0 | 70 | | threat.RemoveInterceptor(interceptor); |
| | 0 | 71 | | } |
| | 0 | 72 | | } |
| | | 73 | | } |