From a29efbb4caa5d6d5a0216b91b1a69875244c4c57 Mon Sep 17 00:00:00 2001 From: Daniel Lovell Date: Tue, 24 Sep 2024 19:59:25 -0700 Subject: [PATCH] Refactor "Missile" -> "Interceptor" --- .../{DroneTarget.prefab => Drone.prefab} | 2 +- ...neTarget.prefab.meta => Drone.prefab.meta} | 0 Assets/Scripts/Assignment/Assignment.cs | 22 ++--- .../Assignment/RoundRobinAssignment.cs | 8 +- Assets/Scripts/Assignment/ThreatAssignment.cs | 10 +- Assets/Scripts/Config/ConfigLoader.cs | 14 +-- Assets/Scripts/Config/SimulationConfig.cs | 16 +-- Assets/Scripts/IADS/IADS.cs | 10 +- Assets/Scripts/IADS/Vessel.cs | 18 ++-- Assets/Scripts/{Missile.cs => Interceptor.cs} | 10 +- .../{Missile.cs.meta => Interceptor.cs.meta} | 0 Assets/Scripts/Interceptors/Hydra70.cs | 12 +-- Assets/Scripts/Interceptors/Micromissile.cs | 4 +- Assets/Scripts/Monitor.cs | 2 +- Assets/Scripts/SimManager.cs | 98 +++++++++---------- .../{MissileTarget.cs => AntishipMissile.cs} | 2 +- ...Target.cs.meta => AntishipMissile.cs.meta} | 0 .../Scripts/UI/Dialogs/AgentStatusDialog.cs | 2 +- Assets/Scripts/UI/UIElementMouseCapturer.cs | 3 - .../Configs/1_salvo_1_hydra_7_drones.json | 12 +-- .../Configs/3_salvo_10_hydra_200_drones.json | 20 ++-- Telemetry/visualize_telemetry.py | 2 +- docs/Simulation_Config_Guide.md | 46 ++++----- 23 files changed, 155 insertions(+), 158 deletions(-) rename Assets/Resources/Prefabs/{DroneTarget.prefab => Drone.prefab} (99%) rename Assets/Resources/Prefabs/{DroneTarget.prefab.meta => Drone.prefab.meta} (100%) rename Assets/Scripts/{Missile.cs => Interceptor.cs} (95%) rename Assets/Scripts/{Missile.cs.meta => Interceptor.cs.meta} (100%) rename Assets/Scripts/Threats/{MissileTarget.cs => AntishipMissile.cs} (81%) rename Assets/Scripts/Threats/{MissileTarget.cs.meta => AntishipMissile.cs.meta} (100%) diff --git a/Assets/Resources/Prefabs/DroneTarget.prefab b/Assets/Resources/Prefabs/Drone.prefab similarity index 99% rename from Assets/Resources/Prefabs/DroneTarget.prefab rename to Assets/Resources/Prefabs/Drone.prefab index 01bca3f..86ec4ce 100644 --- a/Assets/Resources/Prefabs/DroneTarget.prefab +++ b/Assets/Resources/Prefabs/Drone.prefab @@ -284,7 +284,7 @@ GameObject: - component: {fileID: 4571646124809534626} - component: {fileID: 4451965530778273955} m_Layer: 0 - m_Name: DroneTarget + m_Name: Drone m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/Assets/Resources/Prefabs/DroneTarget.prefab.meta b/Assets/Resources/Prefabs/Drone.prefab.meta similarity index 100% rename from Assets/Resources/Prefabs/DroneTarget.prefab.meta rename to Assets/Resources/Prefabs/Drone.prefab.meta diff --git a/Assets/Scripts/Assignment/Assignment.cs b/Assets/Scripts/Assignment/Assignment.cs index 42c5382..427c356 100644 --- a/Assets/Scripts/Assignment/Assignment.cs +++ b/Assets/Scripts/Assignment/Assignment.cs @@ -2,35 +2,35 @@ using System; using System.Collections.Generic; using UnityEngine; -// The assignment class is an interface for assigning a threat to each missile. +// The assignment class is an interface for assigning a threat to each interceptor. public interface IAssignment { // Assignment item type. - // The first element corresponds to the missile index, and the second element + // The first element corresponds to the interceptor index, and the second element // corresponds to the threat index. public struct AssignmentItem { - public int MissileIndex; + public int InterceptorIndex; public int ThreatIndex; public AssignmentItem(int missileIndex, int threatIndex) { - MissileIndex = missileIndex; + InterceptorIndex = missileIndex; ThreatIndex = threatIndex; } } - // A list containing the missile-target assignments. + // A list containing the interceptor-target assignments. - // Assign a target to each missile that has not been assigned a target yet. + // Assign a target to each interceptor that has not been assigned a target yet. public abstract IEnumerable Assign(List missiles, List targets); - // Get the list of assignable missile indices. - protected static List GetAssignableMissileIndices(List missiles) { - List assignableMissileIndices = new List(); + // Get the list of assignable interceptor indices. + protected static List GetAssignableInterceptorIndices(List missiles) { + List assignableInterceptorIndices = new List(); for (int missileIndex = 0; missileIndex < missiles.Count; missileIndex++) { if (missiles[missileIndex].IsAssignable()) { - assignableMissileIndices.Add(missileIndex); + assignableInterceptorIndices.Add(missileIndex); } } - return assignableMissileIndices; + return assignableInterceptorIndices; } // Get the list of active target indices. diff --git a/Assets/Scripts/Assignment/RoundRobinAssignment.cs b/Assets/Scripts/Assignment/RoundRobinAssignment.cs index e6d3e29..f046772 100644 --- a/Assets/Scripts/Assignment/RoundRobinAssignment.cs +++ b/Assets/Scripts/Assignment/RoundRobinAssignment.cs @@ -9,11 +9,11 @@ public class RoundRobinAssignment : IAssignment { // Previous target index that was assigned. private int prevTargetIndex = -1; - // Assign a target to each missile that has not been assigned a target yet. + // Assign a target to each interceptor that has not been assigned a target yet. public IEnumerable Assign(List missiles, List targets) { List assignments = new List(); - List assignableMissileIndices = IAssignment.GetAssignableMissileIndices(missiles); - if (assignableMissileIndices.Count == 0) { + List assignableInterceptorIndices = IAssignment.GetAssignableInterceptorIndices(missiles); + if (assignableInterceptorIndices.Count == 0) { return assignments; } @@ -22,7 +22,7 @@ public class RoundRobinAssignment : IAssignment { return assignments; } - foreach (int missileIndex in assignableMissileIndices) { + foreach (int missileIndex in assignableInterceptorIndices) { int nextActiveTargetIndex = activeThreatIndices.FindIndex(index => index > prevTargetIndex); if (nextActiveTargetIndex == -1) { diff --git a/Assets/Scripts/Assignment/ThreatAssignment.cs b/Assets/Scripts/Assignment/ThreatAssignment.cs index 33eaf45..9b710ff 100644 --- a/Assets/Scripts/Assignment/ThreatAssignment.cs +++ b/Assets/Scripts/Assignment/ThreatAssignment.cs @@ -7,12 +7,12 @@ using UnityEngine; // The threat assignment class assigns missiles to the targets based // on the threat level of the targets. public class ThreatAssignment : IAssignment { - // Assign a target to each missile that has not been assigned a target yet. + // Assign a target to each interceptor that has not been assigned a target yet. public IEnumerable Assign(List missiles, List targets) { List assignments = new List(); - List assignableMissileIndices = IAssignment.GetAssignableMissileIndices(missiles); - if (assignableMissileIndices.Count == 0) { + List assignableInterceptorIndices = IAssignment.GetAssignableInterceptorIndices(missiles); + if (assignableInterceptorIndices.Count == 0) { return assignments; } @@ -25,13 +25,13 @@ public class ThreatAssignment : IAssignment { List threatInfos = CalculateThreatLevels(targets, activeThreatIndices, positionToDefend); - foreach (int missileIndex in assignableMissileIndices) { + foreach (int missileIndex in assignableInterceptorIndices) { if (missiles[missileIndex].HasAssignedTarget()) continue; if (threatInfos.Count == 0) break; - // Find the optimal target for this missile based on distance and threat + // Find the optimal target for this interceptor based on distance and threat ThreatInfo optimalTarget = null; float optimalScore = float.MinValue; diff --git a/Assets/Scripts/Config/ConfigLoader.cs b/Assets/Scripts/Config/ConfigLoader.cs index 945f040..71576b1 100644 --- a/Assets/Scripts/Config/ConfigLoader.cs +++ b/Assets/Scripts/Config/ConfigLoader.cs @@ -42,16 +42,16 @@ public static class ConfigLoader { Debug.Log("SimulationConfig:"); Debug.Log($"Time Scale: {config.timeScale}"); - Debug.Log("Missile Swarm Configurations:"); - for (int i = 0; i < config.missile_swarm_configs.Count; i++) + Debug.Log("Interceptor Swarm Configurations:"); + for (int i = 0; i < config.interceptor_swarm_configs.Count; i++) { - PrintSwarmConfig(config.missile_swarm_configs[i], $"Missile Swarm {i + 1}"); + PrintSwarmConfig(config.interceptor_swarm_configs[i], $"Interceptor Swarm {i + 1}"); } Debug.Log("Threat Swarm Configurations:"); - for (int i = 0; i < config.target_swarm_configs.Count; i++) + for (int i = 0; i < config.threat_swarm_configs.Count; i++) { - PrintSwarmConfig(config.target_swarm_configs[i], $"Threat Swarm {i + 1}"); + PrintSwarmConfig(config.threat_swarm_configs[i], $"Threat Swarm {i + 1}"); } } @@ -65,7 +65,7 @@ public static class ConfigLoader { private static void PrintAgentConfig(AgentConfig agentConfig) { Debug.Log(" Agent Configuration:"); - Debug.Log($" Missile Type: {agentConfig.missile_type}"); + Debug.Log($" Interceptor Type: {agentConfig.interceptor_type}"); Debug.Log($" Threat Type: {agentConfig.target_type}"); PrintInitialState(agentConfig.initial_state); PrintStandardDeviation(agentConfig.standard_deviation); @@ -122,7 +122,7 @@ public static class ConfigLoader { private static void PrintSubmunitionAgentConfig(SubmunitionAgentConfig agentConfig) { Debug.Log(" Submunition Agent Configuration:"); - Debug.Log($" Missile Type: {agentConfig.missile_type}"); + Debug.Log($" Interceptor Type: {agentConfig.interceptor_type}"); PrintInitialState(agentConfig.initial_state); PrintStandardDeviation(agentConfig.standard_deviation); PrintDynamicConfig(agentConfig.dynamic_config); diff --git a/Assets/Scripts/Config/SimulationConfig.cs b/Assets/Scripts/Config/SimulationConfig.cs index 8ffa841..d51b499 100644 --- a/Assets/Scripts/Config/SimulationConfig.cs +++ b/Assets/Scripts/Config/SimulationConfig.cs @@ -10,11 +10,11 @@ public class SimulationConfig { [Header("Simulation Settings")] public float timeScale = 0.05f; - [Header("Missile Swarm Configurations")] - public List missile_swarm_configs = new List(); + [Header("Interceptor Swarm Configurations")] + public List interceptor_swarm_configs = new List(); [Header("Threat Swarm Configurations")] - public List target_swarm_configs = new List(); + public List threat_swarm_configs = new List(); } [Serializable] @@ -31,7 +31,7 @@ public class SwarmConfig { [Serializable] public class AgentConfig { - public MissileType missile_type; + public InterceptorType interceptor_type; public ThreatType target_type; public InitialState initial_state; public StandardDeviation standard_deviation; @@ -41,7 +41,7 @@ public class AgentConfig { public static AgentConfig FromSubmunitionAgentConfig(SubmunitionAgentConfig submunitionConfig) { return new AgentConfig { - missile_type = submunitionConfig.missile_type, + interceptor_type = submunitionConfig.interceptor_type, initial_state = submunitionConfig.initial_state, standard_deviation = submunitionConfig.standard_deviation, dynamic_config = submunitionConfig.dynamic_config, @@ -87,7 +87,7 @@ public class SubmunitionsConfig { [Serializable] public class SubmunitionAgentConfig { - public MissileType missile_type; + public InterceptorType interceptor_type; public InitialState initial_state; public StandardDeviation standard_deviation; public DynamicConfig dynamic_config; @@ -110,9 +110,9 @@ public class TargetConfig { // Enums [JsonConverter(typeof(StringEnumConverter))] -public enum MissileType { HYDRA_70, MICROMISSILE } +public enum InterceptorType { HYDRA_70, MICROMISSILE } [JsonConverter(typeof(StringEnumConverter))] -public enum ThreatType { DRONE, MISSILE } +public enum ThreatType { DRONE, ANTISHIP_MISSILE } [JsonConverter(typeof(StringEnumConverter))] public enum ConfigColor { BLUE, GREEN, RED } [JsonConverter(typeof(StringEnumConverter))] diff --git a/Assets/Scripts/IADS/IADS.cs b/Assets/Scripts/IADS/IADS.cs index 07e2dd0..27da001 100644 --- a/Assets/Scripts/IADS/IADS.cs +++ b/Assets/Scripts/IADS/IADS.cs @@ -12,19 +12,19 @@ public class IADS : MonoBehaviour { private List _threats; - private List _missiles; + private List _interceptors; private List _vessels; - public delegate void RegisterNewTargetDelegate(Threat threat); - public event RegisterNewTargetDelegate OnRegisterNewTarget; + public delegate void RegisterNewThreatDelegate(Threat threat); + public event RegisterNewThreatDelegate OnRegisterNewThreat; void Start() { _threats = new List(); } - public void RegisterNewTarget(Threat threat) { + public void RegisterNewThreat(Threat threat) { _threats.Add(threat); - OnRegisterNewTarget?.Invoke(threat); + OnRegisterNewThreat?.Invoke(threat); } } \ No newline at end of file diff --git a/Assets/Scripts/IADS/Vessel.cs b/Assets/Scripts/IADS/Vessel.cs index 84afd78..170f0b3 100644 --- a/Assets/Scripts/IADS/Vessel.cs +++ b/Assets/Scripts/IADS/Vessel.cs @@ -3,23 +3,23 @@ using System.Collections.Generic; public class Vessel : MonoBehaviour { [SerializeField] - private List missileInventory = new List(); + private List missileInventory = new List(); - public void AddMissile(Missile missile) { - if (missile != null) { - missileInventory.Add(missile); + public void AddInterceptor(Interceptor interceptor) { + if (interceptor != null) { + missileInventory.Add(interceptor); } } - public void RemoveMissile(Missile missile) { - missileInventory.Remove(missile); + public void RemoveInterceptor(Interceptor interceptor) { + missileInventory.Remove(interceptor); } - public List GetMissileInventory() { - return new List(missileInventory); + public List GetInterceptorInventory() { + return new List(missileInventory); } - public int GetMissileCount() { + public int GetInterceptorCount() { return missileInventory.Count; } diff --git a/Assets/Scripts/Missile.cs b/Assets/Scripts/Interceptor.cs similarity index 95% rename from Assets/Scripts/Missile.cs rename to Assets/Scripts/Interceptor.cs index 7d469fc..fecc394 100644 --- a/Assets/Scripts/Missile.cs +++ b/Assets/Scripts/Interceptor.cs @@ -2,22 +2,22 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class Missile : Agent { +public class Interceptor : Agent { [SerializeField] protected bool _showDebugVectors = true; - // Return whether a target can be assigned to the missile. + // Return whether a target can be assigned to the interceptor. public override bool IsAssignable() { bool assignable = !HasLaunched() && !HasAssignedTarget(); return assignable; } - // Assign the given target to the missile. + // Assign the given target to the interceptor. public override void AssignTarget(Agent target) { base.AssignTarget(target); } - // Unassign the target from the missile. + // Unassign the target from the interceptor. public override void UnassignTarget() { base.UnassignTarget(); } @@ -36,7 +36,7 @@ public class Missile : Agent { } protected override void UpdateBoost(double deltaTime) { - // The missile only accelerates along its roll axis (forward in Unity) + // The interceptor only accelerates along its roll axis (forward in Unity) Vector3 rollAxis = transform.forward; // Calculate boost acceleration diff --git a/Assets/Scripts/Missile.cs.meta b/Assets/Scripts/Interceptor.cs.meta similarity index 100% rename from Assets/Scripts/Missile.cs.meta rename to Assets/Scripts/Interceptor.cs.meta diff --git a/Assets/Scripts/Interceptors/Hydra70.cs b/Assets/Scripts/Interceptors/Hydra70.cs index 1d3e0b3..66e0c00 100644 --- a/Assets/Scripts/Interceptors/Hydra70.cs +++ b/Assets/Scripts/Interceptors/Hydra70.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using JetBrains.Annotations; using UnityEngine; -public class Hydra70 : Missile { +public class Hydra70 : Interceptor { private bool _submunitionsLaunched = false; protected override void FixedUpdate() { @@ -34,20 +34,20 @@ public class Hydra70 : Missile { } public void SpawnSubmunitions() { - List submunitions = new List(); - switch (_agentConfig.submunitions_config.agent_config.missile_type) { - case MissileType.MICROMISSILE: + List submunitions = new List(); + switch (_agentConfig.submunitions_config.agent_config.interceptor_type) { + case InterceptorType.MICROMISSILE: for (int i = 0; i < _agentConfig.submunitions_config.num_submunitions; i++) { AgentConfig convertedConfig = AgentConfig.FromSubmunitionAgentConfig(_agentConfig.submunitions_config.agent_config); convertedConfig.initial_state.position = transform.position; convertedConfig.initial_state.velocity = GetComponent().velocity; - Missile submunition = SimManager.Instance.CreateMissile(convertedConfig); + Interceptor submunition = SimManager.Instance.CreateInterceptor(convertedConfig); submunitions.Add(submunition); } break; } - SimManager.Instance.AssignMissilesToThreats(submunitions); + SimManager.Instance.AssignInterceptorsToThreats(submunitions); } } diff --git a/Assets/Scripts/Interceptors/Micromissile.cs b/Assets/Scripts/Interceptors/Micromissile.cs index d094cbc..ad9244b 100644 --- a/Assets/Scripts/Interceptors/Micromissile.cs +++ b/Assets/Scripts/Interceptors/Micromissile.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class Micromissile : Missile { +public class Micromissile : Interceptor { [SerializeField] private float _navigationGain = 3f; // Typically 3-5 @@ -57,7 +57,7 @@ public class Micromissile : Missile { float acc_az = N * closing_velocity * los_rate_az; float acc_el = N * closing_velocity * los_rate_el; - // Convert acceleration commands to missile body frame + // Convert acceleration commands to craft body frame accelerationCommand = transform.right * acc_az + transform.up * acc_el; // Clamp the acceleration command to the maximum acceleration diff --git a/Assets/Scripts/Monitor.cs b/Assets/Scripts/Monitor.cs index 4500103..ef7f38a 100644 --- a/Assets/Scripts/Monitor.cs +++ b/Assets/Scripts/Monitor.cs @@ -41,7 +41,7 @@ public class SimMonitor : MonoBehaviour private void ExportTelemetry() { float time = (float)SimManager.Instance.GetElapsedSimulationTime(); - foreach (var agent in SimManager.Instance.GetActiveThreats().Cast().Concat(SimManager.Instance.GetActiveMissiles().Cast())) + foreach (var agent in SimManager.Instance.GetActiveThreats().Cast().Concat(SimManager.Instance.GetActiveInterceptors().Cast())) { Vector3 pos = agent.transform.position; if(pos == Vector3.zero) { diff --git a/Assets/Scripts/SimManager.cs b/Assets/Scripts/SimManager.cs index 633b1eb..dbe7ff0 100644 --- a/Assets/Scripts/SimManager.cs +++ b/Assets/Scripts/SimManager.cs @@ -19,8 +19,8 @@ public class SimManager : MonoBehaviour { [SerializeField] public SimulationConfig simulationConfig; - private List _missiles = new List(); - private List _activeMissiles = new List(); + private List _interceptors = new List(); + private List _activeInterceptors = new List(); private List _unassignedThreats = new List(); private List _threats = new List(); private List _activeThreats = new List(); @@ -42,8 +42,8 @@ public class SimManager : MonoBehaviour { return _elapsedSimulationTime; } - public List GetActiveMissiles() { - return _activeMissiles; + public List GetActiveInterceptors() { + return _activeInterceptors; } public List GetActiveThreats() { @@ -51,7 +51,7 @@ public class SimManager : MonoBehaviour { } public List GetActiveAgents() { - return _activeMissiles.ConvertAll(missile => missile as Agent) + return _activeInterceptors.ConvertAll(interceptor => interceptor as Agent) .Concat(_activeThreats.ConvertAll(threat => threat as Agent)) .ToList(); } @@ -102,19 +102,19 @@ public class SimManager : MonoBehaviour { } private void InitializeSimulation() { - List missiles = new List(); + List missiles = new List(); // Create missiles based on config - foreach (var swarmConfig in simulationConfig.missile_swarm_configs) { + foreach (var swarmConfig in simulationConfig.interceptor_swarm_configs) { for (int i = 0; i < swarmConfig.num_agents; i++) { - var missile = CreateMissile(swarmConfig.agent_config); - missile.OnAgentHit += RegisterMissileHit; - missile.OnAgentMiss += RegisterMissileMiss; + var interceptor = CreateInterceptor(swarmConfig.agent_config); + interceptor.OnAgentHit += RegisterInterceptorHit; + interceptor.OnAgentMiss += RegisterInterceptorMiss; } } List targets = new List(); // Create targets based on config - foreach (var swarmConfig in simulationConfig.target_swarm_configs) { + foreach (var swarmConfig in simulationConfig.threat_swarm_configs) { for (int i = 0; i < swarmConfig.num_agents; i++) { var threat = CreateThreat(swarmConfig.agent_config); threat.OnAgentHit += RegisterThreatHit; @@ -129,19 +129,19 @@ public class SimManager : MonoBehaviour { OnSimulationStarted?.Invoke(); } - public void AssignMissilesToThreats() { - AssignMissilesToThreats(_missiles); + public void AssignInterceptorsToThreats() { + AssignInterceptorsToThreats(_interceptors); } - public void RegisterMissileHit(Agent missile) { - if (missile is Missile missileComponent) { - _activeMissiles.Remove(missileComponent); + public void RegisterInterceptorHit(Agent interceptor) { + if (interceptor is Interceptor missileComponent) { + _activeInterceptors.Remove(missileComponent); } } - public void RegisterMissileMiss(Agent missile) { - if (missile is Missile missileComponent) { - _activeMissiles.Remove(missileComponent); + public void RegisterInterceptorMiss(Agent interceptor) { + if (interceptor is Interceptor missileComponent) { + _activeInterceptors.Remove(missileComponent); } } @@ -161,8 +161,8 @@ public class SimManager : MonoBehaviour { /// Assigns the specified list of missiles to available targets based on the assignment scheme. /// /// The list of missiles to assign. - public void AssignMissilesToThreats(List missilesToAssign) { - // Convert Missile and Threat lists to Agent lists + public void AssignInterceptorsToThreats(List missilesToAssign) { + // Convert Interceptor and Threat lists to Agent lists List missileAgents = new List(missilesToAssign.ConvertAll(m => m as Agent)); // Convert Threat list to Agent list, excluding already assigned targets List targetAgents = _unassignedThreats.ToList(); @@ -173,33 +173,33 @@ public class SimManager : MonoBehaviour { // Apply the assignments to the missiles foreach (var assignment in assignments) { - if (assignment.MissileIndex < missilesToAssign.Count) { - Missile missile = missilesToAssign[assignment.MissileIndex]; + if (assignment.InterceptorIndex < missilesToAssign.Count) { + Interceptor interceptor = missilesToAssign[assignment.InterceptorIndex]; Threat threat = _unassignedThreats[assignment.ThreatIndex]; - missile.AssignTarget(threat); - Debug.Log($"Missile {missile.name} assigned to threat {threat.name}"); + interceptor.AssignTarget(threat); + Debug.Log($"Interceptor {interceptor.name} assigned to threat {threat.name}"); } } // TODO this whole function should be optimized _unassignedThreats.RemoveAll( - threat => missilesToAssign.Any(missile => missile.GetAssignedTarget() == threat)); + threat => missilesToAssign.Any(interceptor => interceptor.GetAssignedTarget() == threat)); } /// - /// Creates a missile based on the provided configuration. + /// Creates a interceptor based on the provided configuration. /// - /// Configuration settings for the missile. - /// The created Missile instance, or null if creation failed. - public Missile CreateMissile(AgentConfig config) { - string prefabName = config.missile_type switch { MissileType.HYDRA_70 => "Hydra70", - MissileType.MICROMISSILE => "Micromissile", + /// Configuration settings for the interceptor. + /// The created Interceptor instance, or null if creation failed. + public Interceptor CreateInterceptor(AgentConfig config) { + string prefabName = config.interceptor_type switch { InterceptorType.HYDRA_70 => "Hydra70", + InterceptorType.MICROMISSILE => "Micromissile", _ => "Hydra70" }; GameObject missileObject = CreateAgent(config, prefabName); if (missileObject == null) return null; - // Missile-specific logic + // Interceptor-specific logic switch (config.dynamic_config.sensor_config.type) { case SensorType.IDEAL: missileObject.AddComponent(); @@ -209,13 +209,13 @@ public class SimManager : MonoBehaviour { break; } - _missiles.Add(missileObject.GetComponent()); - _activeMissiles.Add(missileObject.GetComponent()); + _interceptors.Add(missileObject.GetComponent()); + _activeInterceptors.Add(missileObject.GetComponent()); // Assign a unique and simple ID - int missileId = _missiles.Count; - missileObject.name = $"{config.missile_type}_Missile_{missileId}"; - return missileObject.GetComponent(); + int missileId = _interceptors.Count; + missileObject.name = $"{config.interceptor_type}_Interceptor_{missileId}"; + return missileObject.GetComponent(); } /// @@ -225,7 +225,7 @@ public class SimManager : MonoBehaviour { /// The created Threat instance, or null if creation failed. private Threat CreateThreat(AgentConfig config) { string prefabName = config.target_type switch { - ThreatType.DRONE => "DroneTarget", ThreatType.MISSILE => "MissileTarget", + ThreatType.DRONE => "Drone", ThreatType.ANTISHIP_MISSILE => "AntishipMissile", _ => throw new System.ArgumentException($"Unsupported threat type: {config.target_type}") }; GameObject threatObject = CreateAgent(config, prefabName); @@ -243,7 +243,7 @@ public class SimManager : MonoBehaviour { } /// - /// Creates an agent (missile or threat) based on the provided configuration and prefab name. + /// Creates an agent (interceptor or threat) based on the provided configuration and prefab name. /// /// Configuration settings for the agent. /// Name of the prefab to instantiate. @@ -289,9 +289,9 @@ public class SimManager : MonoBehaviour { simulationRunning = true; // Clear existing missiles and targets - foreach (var missile in _missiles) { - if (missile != null) { - Destroy(missile.gameObject); + foreach (var interceptor in _interceptors) { + if (interceptor != null) { + Destroy(interceptor.gameObject); } } @@ -301,7 +301,7 @@ public class SimManager : MonoBehaviour { } } - _missiles.Clear(); + _interceptors.Clear(); _threats.Clear(); _unassignedThreats.Clear(); @@ -310,15 +310,15 @@ public class SimManager : MonoBehaviour { void Update() { // Check if all missiles have terminated - bool allMissilesTerminated = true; - foreach (var missile in _missiles) { - if (missile != null && !missile.IsHit() && !missile.IsMiss()) { - allMissilesTerminated = false; + bool allInterceptorsTerminated = true; + foreach (var interceptor in _interceptors) { + if (interceptor != null && !interceptor.IsHit() && !interceptor.IsMiss()) { + allInterceptorsTerminated = false; break; } } // If all missiles have terminated, restart the simulation - if (allMissilesTerminated) { + if (allInterceptorsTerminated) { RestartSimulation(); } diff --git a/Assets/Scripts/Threats/MissileTarget.cs b/Assets/Scripts/Threats/AntishipMissile.cs similarity index 81% rename from Assets/Scripts/Threats/MissileTarget.cs rename to Assets/Scripts/Threats/AntishipMissile.cs index a756c31..e5cecf7 100644 --- a/Assets/Scripts/Threats/MissileTarget.cs +++ b/Assets/Scripts/Threats/AntishipMissile.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class MissileTarget : MonoBehaviour { +public class AntishipMissile : MonoBehaviour { // Start is called before the first frame update void Start() {} diff --git a/Assets/Scripts/Threats/MissileTarget.cs.meta b/Assets/Scripts/Threats/AntishipMissile.cs.meta similarity index 100% rename from Assets/Scripts/Threats/MissileTarget.cs.meta rename to Assets/Scripts/Threats/AntishipMissile.cs.meta diff --git a/Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs b/Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs index e011dad..6f75d26 100644 --- a/Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs +++ b/Assets/Scripts/UI/Dialogs/AgentStatusDialog.cs @@ -11,7 +11,7 @@ public class BotStatusDialog : UIDialog UISelectableEntry missiles = CreateSelectableEntry(); - missiles.SetTextContent(new List(new string[] { "Missiles" })); + missiles.SetTextContent(new List(new string[] { "Interceptors" })); missiles.SetIsSelectable(false); UISelectableEntry submunitions = CreateSelectableEntry(); diff --git a/Assets/Scripts/UI/UIElementMouseCapturer.cs b/Assets/Scripts/UI/UIElementMouseCapturer.cs index 986ae5a..28092b4 100644 --- a/Assets/Scripts/UI/UIElementMouseCapturer.cs +++ b/Assets/Scripts/UI/UIElementMouseCapturer.cs @@ -5,18 +5,15 @@ using UnityEngine.EventSystems; public class UIElementMouseCapturer : EventTrigger { - private bool _hasPointerEntered = false; public override void OnPointerEnter(PointerEventData eventData) { InputManager.Instance.mouseActive = false; - _hasPointerEntered = true; base.OnPointerEnter(eventData); } public override void OnPointerExit(PointerEventData eventData) { InputManager.Instance.mouseActive = true; - _hasPointerEntered = false; base.OnPointerExit(eventData); } diff --git a/Assets/StreamingAssets/Configs/1_salvo_1_hydra_7_drones.json b/Assets/StreamingAssets/Configs/1_salvo_1_hydra_7_drones.json index 1a8a1c9..5d116d6 100644 --- a/Assets/StreamingAssets/Configs/1_salvo_1_hydra_7_drones.json +++ b/Assets/StreamingAssets/Configs/1_salvo_1_hydra_7_drones.json @@ -1,10 +1,10 @@ { "timeScale": 1, - "missile_swarm_configs": [ + "interceptor_swarm_configs": [ { "num_agents": 1, "agent_config": { - "missile_type": "HYDRA_70", + "interceptor_type": "HYDRA_70", "target_type": "DRONE", "initial_state": { "position": { "x": 0, "y": 20, "z": 0 }, @@ -26,7 +26,7 @@ "num_submunitions": 7, "launch_config": { "launch_time": 4 }, "agent_config": { - "missile_type": "MICROMISSILE", + "interceptor_type": "MICROMISSILE", "initial_state": { "position": { "x": 0, "y": 0, "z": 0 }, "rotation": { "x": 0, "y": 0, "z": 0 }, @@ -48,11 +48,11 @@ } } ], - "target_swarm_configs": [ + "threat_swarm_configs": [ { "num_agents": 7, "agent_config": { - "missile_type": "HYDRA_70", + "interceptor_type": "HYDRA_70", "target_type": "DRONE", "initial_state": { "position": { "x": 0, "y": 600, "z": 6000 }, @@ -74,7 +74,7 @@ "num_submunitions": 0, "launch_config": { "launch_time": 0 }, "agent_config": { - "missile_type": "HYDRA_70", + "interceptor_type": "HYDRA_70", "initial_state": { "position": { "x": 0, "y": 0, "z": 0 }, "rotation": { "x": 0, "y": 0, "z": 0 }, diff --git a/Assets/StreamingAssets/Configs/3_salvo_10_hydra_200_drones.json b/Assets/StreamingAssets/Configs/3_salvo_10_hydra_200_drones.json index 8f1da62..5999f4e 100644 --- a/Assets/StreamingAssets/Configs/3_salvo_10_hydra_200_drones.json +++ b/Assets/StreamingAssets/Configs/3_salvo_10_hydra_200_drones.json @@ -1,10 +1,10 @@ { "timeScale": 1, - "missile_swarm_configs": [ + "interceptor_swarm_configs": [ { "num_agents": 10, "agent_config": { - "missile_type": "HYDRA_70", + "interceptor_type": "HYDRA_70", "target_type": "DRONE", "initial_state": { "position": { "x": 0, "y": 20, "z": 0 }, @@ -26,7 +26,7 @@ "num_submunitions": 7, "launch_config": { "launch_time": 4 }, "agent_config": { - "missile_type": "MICROMISSILE", + "interceptor_type": "MICROMISSILE", "initial_state": { "position": { "x": -171.3253, "y": 683.85236, "z": 846.74677 }, "rotation": { "x": 0, "y": 0, "z": 0 }, @@ -50,7 +50,7 @@ { "num_agents": 10, "agent_config": { - "missile_type": "HYDRA_70", + "interceptor_type": "HYDRA_70", "target_type": "DRONE", "initial_state": { "position": { "x": 200, "y": 20, "z": 0 }, @@ -72,7 +72,7 @@ "num_submunitions": 7, "launch_config": { "launch_time": 12 }, "agent_config": { - "missile_type": "MICROMISSILE", + "interceptor_type": "MICROMISSILE", "initial_state": { "position": { "x": -3.2042065, "y": 781.2401, "z": 1043.2384 }, "rotation": { "x": 0, "y": 0, "z": 0 }, @@ -96,7 +96,7 @@ { "num_agents": 10, "agent_config": { - "missile_type": "HYDRA_70", + "interceptor_type": "HYDRA_70", "target_type": "DRONE", "initial_state": { "position": { "x": -100, "y": 20, "z": 0 }, @@ -118,7 +118,7 @@ "num_submunitions": 7, "launch_config": { "launch_time": 23 }, "agent_config": { - "missile_type": "MICROMISSILE", + "interceptor_type": "MICROMISSILE", "initial_state": { "position": { "x": -246.4463, "y": 976.02924, "z": 1081.1262 }, "rotation": { "x": 0, "y": 0, "z": 0 }, @@ -140,11 +140,11 @@ } } ], - "target_swarm_configs": [ + "threat_swarm_configs": [ { "num_agents": 200, "agent_config": { - "missile_type": "HYDRA_70", + "interceptor_type": "HYDRA_70", "target_type": "DRONE", "initial_state": { "position": { "x": 0, "y": 600, "z": 6000 }, @@ -166,7 +166,7 @@ "num_submunitions": 0, "launch_config": { "launch_time": 0 }, "agent_config": { - "missile_type": "HYDRA_70", + "interceptor_type": "HYDRA_70", "initial_state": { "position": { "x": 0, "y": 0, "z": 0 }, "rotation": { "x": 0, "y": 0, "z": 0 }, diff --git a/Telemetry/visualize_telemetry.py b/Telemetry/visualize_telemetry.py index 6788cae..2aec6db 100644 --- a/Telemetry/visualize_telemetry.py +++ b/Telemetry/visualize_telemetry.py @@ -61,7 +61,7 @@ def plot_telemetry(file_path): plt.title('Agents Trajectories (X: Right, Z: Forward, Y: Up)') legend = [ plt.Line2D([0], [0], color='red', lw=2, label='Threat'), - plt.Line2D([0], [0], color='blue', lw=2, label='Missile') + plt.Line2D([0], [0], color='blue', lw=2, label='Interceptor') ] plt.legend(handles=legend) plt.tight_layout() diff --git a/docs/Simulation_Config_Guide.md b/docs/Simulation_Config_Guide.md index bd1448c..5675b5d 100644 --- a/docs/Simulation_Config_Guide.md +++ b/docs/Simulation_Config_Guide.md @@ -1,6 +1,6 @@ # Simulation Configuration Guide -This guide provides instructions on how to configure the simulation by editing the configuration files. You can customize missile and threat behaviors, simulation parameters, and more to suit your needs. +This guide provides instructions on how to configure the simulation by editing the configuration files. You can customize interceptor and threat behaviors, simulation parameters, and more to suit your needs. ## Configuration Files @@ -35,16 +35,16 @@ The simulation configurations are defined in JSON files that specify the initial #### `1_salvo_1_hydra_7_drones.json` -This is a basic configuration featuring a single salvo with one missile type (`HYDRA_70`) and seven threat drones. +This is a basic configuration featuring a single salvo with one interceptor type (`HYDRA_70`) and seven threat drones. ```json:Assets/StreamingAssets/Configs/1_salvo_1_hydra_7_drones.json { "timeScale": 1, - "missile_swarm_configs": [ + "interceptor_swarm_configs": [ { "num_agents": 1, "agent_config": { - "missile_type": "HYDRA_70", + "interceptor_type": "HYDRA_70", "initial_state": { "position": { "x": 0, "y": 20, "z": 0 }, "rotation": { "x": -45, "y": 0, "z": 0 }, @@ -61,14 +61,14 @@ This is a basic configuration featuring a single salvo with one missile type (`H "num_submunitions": 7, "launch_config": { "launch_time": 4 }, "agent_config": { - "missile_type": "MICROMISSILE", + "interceptor_type": "MICROMISSILE", // Submunition configuration... } } } } ], - "target_swarm_configs": [ + "threat_swarm_configs": [ { "num_agents": 7, "agent_config": { @@ -92,11 +92,11 @@ This configuration demonstrates a more complex scenario with three salvos, each ```json:Assets/StreamingAssets/Configs/3_salvo_10_hydra_200_drones.json { "timeScale": 1, - "missile_swarm_configs": [ + "interceptor_swarm_configs": [ { "num_agents": 10, "agent_config": { - "missile_type": "HYDRA_70", + "interceptor_type": "HYDRA_70", "initial_state": { "position": { "x": 0, "y": 20, "z": 0 }, "rotation": { "x": -45, "y": 0, "z": 0 }, @@ -113,15 +113,15 @@ This configuration demonstrates a more complex scenario with three salvos, each "num_submunitions": 7, "launch_config": { "launch_time": 4 }, "agent_config": { - "missile_type": "MICROMISSILE", + "interceptor_type": "MICROMISSILE", // Submunition configuration... } } } }, - // Two more similar missile_swarm_configs with different launch times... + // Two more similar interceptor_swarm_configs with different launch times... ], - "target_swarm_configs": [ + "threat_swarm_configs": [ { "num_agents": 200, "agent_config": { @@ -140,43 +140,43 @@ This configuration demonstrates a more complex scenario with three salvos, each **Key Differences Between the Examples**: -The key difference between the examples is that the **Number of Salvos** in `3_salvo_10_hydra_200_drones.json` file includes multiple salvos by adding multiple entries in the `missile_swarm_configs` array, each with its own `launch_time`. +The key difference between the examples is that the **Number of Salvos** in `3_salvo_10_hydra_200_drones.json` file includes multiple salvos by adding multiple entries in the `interceptor_swarm_configs` array, each with its own `launch_time`. **Achieving Multiple Salvos**: Multiple salvos are achieved by: -- Adding multiple configurations in the `missile_swarm_configs` array. +- Adding multiple configurations in the `interceptor_swarm_configs` array. - Specifying different `launch_time` values in the `dynamic_config` for each salvo to control when they launch. ### Key Configuration Parameters - **`timeScale`**: Adjusts the speed of the simulation. -- **`missile_swarm_configs`**: Contains settings for missile swarms. Each entry represents a salvo. -- **`target_swarm_configs`**: Contains settings for threat swarms. +- **`interceptor_swarm_configs`**: Contains settings for interceptor swarms. Each entry represents a salvo. +- **`threat_swarm_configs`**: Contains settings for threat swarms. #### Within Each Swarm Configuration - **`num_agents`**: Number of agents (missiles or targets) in the swarm. - **`agent_config`**: Settings for each agent, including: - - **`missile_type`** / **`target_type`**: Defines the type of missile or threat. + - **`interceptor_type`** / **`target_type`**: Defines the type of interceptor or threat. - **`initial_state`**: Sets the starting position, rotation, and velocity. - **`standard_deviation`**: Adds random noise to initial states for variability. - **`dynamic_config`**: Time-dependent settings like `launch_time` and sensor configurations. - - **`submunitions_config`**: Details for any submunitions (e.g., micromissiles deployed by a larger missile). + - **`submunitions_config`**: Details for any submunitions (e.g., micromissiles deployed by a larger interceptor). ### Adding or Modifying Agents 1. **Add a New Swarm Configuration**: - To introduce a new missile or threat swarm (or an additional salvo), create a new entry in `missile_swarm_configs` or `target_swarm_configs`. + To introduce a new interceptor or threat swarm (or an additional salvo), create a new entry in `interceptor_swarm_configs` or `threat_swarm_configs`. ```json { "num_agents": 5, "agent_config": { - "missile_type": "MICROMISSILE", + "interceptor_type": "MICROMISSILE", // Additional configurations... "dynamic_config": { "launch_config": { "launch_time": 15 }, @@ -194,7 +194,7 @@ Multiple salvos are achieved by: ## Model Configurations -The model configurations define the physical and performance characteristics of missile and threat models. The default models provided can be customized to suit your research needs. +The model configurations define the physical and performance characteristics of interceptor and threat models. The default models provided can be customized to suit your research needs. ### Available Models @@ -234,7 +234,7 @@ This file defines parameters for the micromissile model. **Configurable Parameters**: - **`accelerationConfig`**: Controls acceleration characteristics. -- **`boostConfig`**: Settings for the boost phase of the missile. +- **`boostConfig`**: Settings for the boost phase of the craft. - **`liftDragConfig`**: Aerodynamic properties. - **`bodyConfig`**: Physical attributes like mass and area. - **`hitConfig`**: Collision detection and damage properties. @@ -249,7 +249,7 @@ You can tweak the parameters in these model files to adjust performance. For exa ### Adding New Models -To define a new missile or threat model: +To define a new inte or threat model: 1. **Create a New JSON File** in `Assets/StreamingAssets/Configs/Models/`. @@ -275,7 +275,7 @@ This script defines the data structures used to interpret the JSON simulation co **Enums**: -- `MissileType`, `ThreatType`, and `SensorType` define available types. +- `InterceptorType`, `ThreatType`, and `SensorType` define available types. ### `StaticConfig.cs`