1374 lines
55 KiB
C#
1374 lines
55 KiB
C#
using ThreatSource.Missile;
|
||
using ThreatSource.Simulation;
|
||
using ThreatSource.Utils;
|
||
using ThreatSource.Jammable;
|
||
using ThreatSource.Jammer;
|
||
using ThreatSource.Sensor;
|
||
using ThreatSource.Equipment;
|
||
using ThreatSource.Guidance;
|
||
using ThreatSource.Indicator;
|
||
using ThreatSource.Data;
|
||
using AirTransmission;
|
||
using System.Diagnostics;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace ThreatSource.Tools.MissileSimulation
|
||
{
|
||
/// <summary>
|
||
/// 综合导弹模拟器 - 支持6种不同类型的导弹模拟
|
||
/// </summary>
|
||
public class ComprehensiveMissileSimulator
|
||
{
|
||
// 定义仿真结束事件
|
||
public event EventHandler? SimulationEnded;
|
||
|
||
private ConsoleTraceListener consoleListener;
|
||
private EventTypeFilter logLevelFilter;
|
||
|
||
private readonly SimulationManager simulationManager;
|
||
private readonly ThreatSourceFactory _threatSourceFactory;
|
||
private readonly ThreatSourceDataManager _dataManager;
|
||
private readonly Dictionary<string, BaseMissile> missiles;
|
||
private readonly Dictionary<string, SimulationElement> targets;
|
||
private readonly Dictionary<string, SimulationElement> indicators;
|
||
private readonly Dictionary<string, BaseJammer> jammers;
|
||
private readonly Dictionary<string, bool> missileActiveStatus;
|
||
private readonly double timeStep = 0.005; // 时间步长,单位:秒
|
||
|
||
// 导弹-干扰映射表
|
||
private Dictionary<string, List<(JammingType Type, string DisplayName, string JammerId, string Mode, string Target)>> missileJammingMap;
|
||
|
||
// 当前选中的导弹ID
|
||
public string SelectedMissileId { get; private set; }
|
||
|
||
private List<(JammingType Type, string DisplayName, string JammerId, string Mode, string Target)> activeJammings;
|
||
|
||
/// <summary>
|
||
/// 获取当前选中导弹的显示名称
|
||
/// </summary>
|
||
public string SelectedMissileDisplayName
|
||
{
|
||
get
|
||
{
|
||
switch (SelectedMissileId)
|
||
{
|
||
case "LSGM_1": return "激光半主动制导导弹";
|
||
case "LBRM_1": return "激光驾束制导导弹";
|
||
case "TSM_1": return "末敏子弹药";
|
||
case "ICGM_1": return "红外指令制导导弹";
|
||
case "ITGM_1": return "红外成像末制导导弹";
|
||
case "MMWG_1": return "毫米波末制导导弹";
|
||
default: return "未知导弹";
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化综合导弹模拟器
|
||
/// </summary>
|
||
public ComprehensiveMissileSimulator()
|
||
{
|
||
// Initialize filter and listener first
|
||
this.logLevelFilter = new EventTypeFilter(SourceLevels.Verbose); // Default to Verbose
|
||
this.consoleListener = new ConsoleTraceListener();
|
||
this.consoleListener.Filter = this.logLevelFilter;
|
||
|
||
// Clear any existing ConsoleTraceListeners and add our controlled instance
|
||
for (int i = Trace.Listeners.Count - 1; i >= 0; i--)
|
||
{
|
||
if (Trace.Listeners[i] is ConsoleTraceListener)
|
||
{
|
||
Trace.Listeners.RemoveAt(i);
|
||
}
|
||
}
|
||
Trace.Listeners.Add(this.consoleListener);
|
||
|
||
simulationManager = new SimulationManager();
|
||
_dataManager = new ThreatSourceDataManager("../ThreatSource/data");
|
||
_threatSourceFactory = new ThreatSourceFactory(_dataManager, simulationManager);
|
||
missiles = [];
|
||
targets = [];
|
||
indicators = [];
|
||
jammers = [];
|
||
missileActiveStatus = [];
|
||
missileJammingMap = [];
|
||
SelectedMissileId = "";
|
||
|
||
this.activeJammings = new List<(JammingType Type, string DisplayName, string JammerId, string Mode, string Target)>();
|
||
|
||
// 初始化导弹-干扰映射
|
||
InitializeMissileJammingMap();
|
||
|
||
InitializeSimulation();
|
||
}
|
||
|
||
public SourceLevels CurrentLogLevel => logLevelFilter?.EventType ?? SourceLevels.Off;
|
||
|
||
public void SetLogLevel(SourceLevels level)
|
||
{
|
||
if (logLevelFilter != null)
|
||
{
|
||
logLevelFilter.EventType = level;
|
||
Console.WriteLine($"[Simulator] 日志输出级别已设置为: {level}");
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("[Simulator] Error: Log level filter not initialized.");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化导弹-干扰映射关系
|
||
/// </summary>
|
||
private void InitializeMissileJammingMap()
|
||
{
|
||
missileJammingMap = new Dictionary<string, List<(JammingType, string, string, string, string)>>();
|
||
|
||
// 激光驾束导弹
|
||
missileJammingMap["LBRM_1"] =
|
||
[
|
||
(JammingType.Laser, "激光干扰", "LaserJammer_Designator", "阻塞", "驾束仪"),
|
||
(JammingType.SmokeGrenade, "烟幕弹", "SG_1", "遮蔽", "驾束仪")
|
||
];
|
||
|
||
// 激光半主动制导导弹
|
||
missileJammingMap["LSGM_1"] =
|
||
[
|
||
(JammingType.Laser, "激光干扰(指示器)", "LaserJammer_Designator", "阻塞", "指示器"),
|
||
(JammingType.Laser, "激光干扰(导弹)", "LaserJammer_Missile", "阻塞", "导弹"),
|
||
(JammingType.LaserDecoy, "激光诱偏目标", "LDY_1", "欺骗", "导弹"),
|
||
(JammingType.SmokeGrenade, "烟幕弹", "SG_1", "遮蔽", "两者")
|
||
];
|
||
|
||
// 红外指令制导导弹
|
||
missileJammingMap["ICGM_1"] =
|
||
[
|
||
(JammingType.Infrared, "红外干扰", "InfraredJammer_Designator", "阻塞", "指示器"),
|
||
(JammingType.SmokeGrenade, "烟幕弹", "SG_2", "遮蔽", "指示器")
|
||
];
|
||
|
||
// 红外成像末制导导弹
|
||
missileJammingMap["ITGM_1"] =
|
||
[
|
||
(JammingType.Infrared, "红外干扰", "InfraredJammer_Missile", "阻塞", "导弹"),
|
||
(JammingType.SmokeGrenade, "红外烟幕弹", "SG_2", "遮蔽", "导弹")
|
||
];
|
||
|
||
// 毫米波末制导导弹
|
||
missileJammingMap["MMWG_1"] =
|
||
[
|
||
(JammingType.MillimeterWave, "毫米波干扰", "MillimeterWaveJammer_Missile", "阻塞", "导弹"),
|
||
(JammingType.SmokeGrenade, "烟幕弹", "SG_3", "遮蔽", "导弹")
|
||
];
|
||
|
||
// 末敏子弹药
|
||
missileJammingMap["TSM_1"] =
|
||
[
|
||
(JammingType.Laser, "激光干扰", "LaserJammer_Submunition", "阻塞", "子弹药"),
|
||
(JammingType.Infrared, "红外干扰", "InfraredJammer_Submunition", "阻塞", "子弹药"),
|
||
(JammingType.MillimeterWave, "毫米波干扰", "MillimeterWaveJammer_Submunition", "阻塞", "子弹药"),
|
||
(JammingType.MillimeterWave, "毫米波假信号", "MillimeterWaveCompensationJammer_Submunition", "欺骗", "子弹药"),
|
||
(JammingType.SmokeGrenade, "烟幕弹", "SG_4", "遮蔽", "子弹药")
|
||
];
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化仿真环境
|
||
/// </summary>
|
||
private void InitializeSimulation()
|
||
{
|
||
// 添加天气
|
||
AddWeathers();
|
||
|
||
// 添加目标(坦克)
|
||
AddTankTarget();
|
||
|
||
// 添加各种类型的导弹
|
||
AddLaserSemiActiveMissile();
|
||
AddLaserBeamRiderMissile();
|
||
AddTerminalSensitiveMissile();
|
||
AddInfraredCommandMissile();
|
||
AddInfraredImagingMissile();
|
||
AddMillimeterWaveMissile();
|
||
|
||
// 添加各种传感器和指示器
|
||
AddIndicators();
|
||
|
||
// 添加烟幕弹
|
||
AddSmokeGrenade();
|
||
|
||
// 添加激光诱偏目标
|
||
AddLaserDecoy();
|
||
|
||
// 添加各类型干扰器
|
||
AddJammers();
|
||
|
||
// 打印所有注册的干扰器
|
||
PrintAllJammers();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加天气
|
||
/// </summary>
|
||
private void AddWeathers()
|
||
{
|
||
// 创建雨天天气并设置为当前天气
|
||
var rainWeather = _threatSourceFactory.CreateWeather("sunny");
|
||
simulationManager.SetWeather(rainWeather);
|
||
Console.WriteLine("已添加并设置晴天天气环境");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加目标
|
||
/// </summary>
|
||
private void AddTankTarget()
|
||
{
|
||
var motionParameters = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 1.2, 0),
|
||
Orientation = new Orientation(0.0, 0.0, 0.0),
|
||
Speed = 1.0
|
||
};
|
||
string targetId = "Tank_1";
|
||
var target = _threatSourceFactory.CreateTarget(targetId, "mbt_001", motionParameters);
|
||
targets[targetId] = target;
|
||
simulationManager.RegisterEntity(targetId, target);
|
||
Console.WriteLine($"添加目标 {targetId},位置:{motionParameters.Position}");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加激光诱偏目标
|
||
/// </summary>
|
||
private void AddLaserDecoy()
|
||
{
|
||
var motionParameters = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 0, 50),
|
||
Orientation = new Orientation(Math.PI/2, 0.0, 0.0),
|
||
Speed = 0.0
|
||
};
|
||
string laserDecoyId = "LDY_1";
|
||
if (_threatSourceFactory.CreateJammer(laserDecoyId, "laser_decoy", motionParameters, "Tank_1") is LaserDecoy laserDecoy)
|
||
{
|
||
simulationManager.RegisterEntity(laserDecoyId, laserDecoy);
|
||
jammers[laserDecoyId] = laserDecoy as BaseJammer;
|
||
Console.WriteLine($"注册激光诱偏目标 {laserDecoyId}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加烟幕弹
|
||
/// </summary>
|
||
private void AddSmokeGrenade()
|
||
{
|
||
var motionParameters = new KinematicState
|
||
{
|
||
Position = new Vector3D(50, 5, 0),
|
||
Orientation = new Orientation(Math.PI/2, 0.0, 0.0),
|
||
Speed = 0.0
|
||
};
|
||
string smokeGrenadeId = "SG_1";
|
||
var smokeGrenade = _threatSourceFactory.CreateJammer(smokeGrenadeId, "surround", motionParameters, "Tank_1");
|
||
if (smokeGrenade is BaseJammer jammer1)
|
||
{
|
||
simulationManager.RegisterEntity(smokeGrenadeId, jammer1);
|
||
jammers[smokeGrenadeId] = jammer1;
|
||
Console.WriteLine($"注册烟幕弹 {smokeGrenadeId}");
|
||
}
|
||
|
||
smokeGrenadeId = "SG_2";
|
||
smokeGrenade = _threatSourceFactory.CreateJammer(smokeGrenadeId, "infrared", motionParameters, "Tank_1");
|
||
if (smokeGrenade is BaseJammer jammer2)
|
||
{
|
||
simulationManager.RegisterEntity(smokeGrenadeId, jammer2);
|
||
jammers[smokeGrenadeId] = jammer2;
|
||
Console.WriteLine($"注册烟幕弹 {smokeGrenadeId}");
|
||
}
|
||
|
||
smokeGrenadeId = "SG_3";
|
||
smokeGrenade = _threatSourceFactory.CreateJammer(smokeGrenadeId, "mmw", motionParameters, "Tank_1");
|
||
if (smokeGrenade is BaseJammer jammer3)
|
||
{
|
||
simulationManager.RegisterEntity(smokeGrenadeId, jammer3);
|
||
jammers[smokeGrenadeId] = jammer3;
|
||
Console.WriteLine($"注册烟幕弹 {smokeGrenadeId}");
|
||
}
|
||
|
||
var motionParametersTop = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 10, 0),
|
||
Orientation = new Orientation(0, Math.PI/2, 0.0),
|
||
Speed = 0.0
|
||
};
|
||
smokeGrenadeId = "SG_4";
|
||
smokeGrenade = _threatSourceFactory.CreateJammer(smokeGrenadeId, "top", motionParametersTop, "Tank_1");
|
||
if (smokeGrenade is BaseJammer jammer4)
|
||
{
|
||
simulationManager.RegisterEntity(smokeGrenadeId, jammer4);
|
||
jammers[smokeGrenadeId] = jammer4;
|
||
Console.WriteLine($"注册烟幕弹 {smokeGrenadeId}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加激光半主动制导导弹
|
||
/// </summary>
|
||
private void AddLaserSemiActiveMissile()
|
||
{
|
||
var motionParameters = new KinematicState
|
||
{
|
||
Position = new Vector3D(2000, 10, 10),
|
||
Orientation = new Orientation(Math.PI/2, -0.01, 0),
|
||
Speed = 700
|
||
};
|
||
string missileId = "LSGM_1";
|
||
var missile = _threatSourceFactory.CreateMissile(missileId, "lsgm_001", "Tank_1", motionParameters);
|
||
missiles[missileId] = missile;
|
||
simulationManager.RegisterEntity(missileId, missile);
|
||
Console.WriteLine($"注册激光半主动制导导弹 {missileId}");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加激光驾束制导导弹
|
||
/// </summary>
|
||
private void AddLaserBeamRiderMissile()
|
||
{
|
||
var motionParameters = new KinematicState
|
||
{
|
||
Position = new Vector3D(2000, 10, 10),
|
||
Orientation = new Orientation(Math.PI/2, -0.01, 0.0),
|
||
Speed = 300
|
||
};
|
||
string missileId = "LBRM_1";
|
||
var missile = _threatSourceFactory.CreateMissile(missileId, "hj10", "Tank_1", motionParameters);
|
||
missiles[missileId] = missile;
|
||
simulationManager.RegisterEntity(missileId, missile);
|
||
Console.WriteLine($"注册激光驾束制导导弹 {missileId}");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加末敏弹
|
||
/// </summary>
|
||
private void AddTerminalSensitiveMissile()
|
||
{
|
||
var motionParameters = new KinematicState
|
||
{
|
||
Position = new Vector3D(3000, 0, 20),
|
||
Orientation = new Orientation(Math.PI/2, 0.0, 0.0),
|
||
Speed = 800
|
||
};
|
||
|
||
string missileId = "TSM_1";
|
||
var missile = _threatSourceFactory.CreateMissile(missileId, "tsm_001", "Tank_1", motionParameters);
|
||
|
||
missiles[missileId] = missile;
|
||
simulationManager.RegisterEntity(missileId, missile);
|
||
Console.WriteLine($"注册末敏弹 {missileId}");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加红外指令制导导弹
|
||
/// </summary>
|
||
private void AddInfraredCommandMissile()
|
||
{
|
||
var motionParameters = new KinematicState
|
||
{
|
||
Position = new Vector3D(2000, 1, 20),
|
||
Orientation = new Orientation(Math.PI/2, 0.01, 0),
|
||
Speed = 300
|
||
};
|
||
|
||
string missileId = "ICGM_1";
|
||
var missile = _threatSourceFactory.CreateMissile(missileId, "irc_001", "Tank_1", motionParameters);
|
||
missiles[missileId] = missile;
|
||
simulationManager.RegisterEntity(missileId, missile);
|
||
Console.WriteLine($"注册红外指令制导导弹 {missileId}");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加红外成像末制导导弹
|
||
/// </summary>
|
||
private void AddInfraredImagingMissile()
|
||
{
|
||
var motionParameters = new KinematicState
|
||
{
|
||
Position = new Vector3D(2000, 10, 0),
|
||
Orientation = new Orientation(Math.PI/2, -0.001, 0),
|
||
Speed = 300
|
||
};
|
||
string missileId = "ITGM_1";
|
||
var missile = _threatSourceFactory.CreateMissile(missileId, "itg_001", "Tank_1", motionParameters);
|
||
missiles[missileId] = missile;
|
||
simulationManager.RegisterEntity(missileId, missile);
|
||
Console.WriteLine($"注册红外成像末制导导弹 {missileId}");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加毫米波末制导导弹
|
||
/// </summary>
|
||
private void AddMillimeterWaveMissile()
|
||
{
|
||
var motionParameters = new KinematicState
|
||
{
|
||
Position = new Vector3D(2000, 1, 20),
|
||
Orientation = new Orientation(Math.PI/2, 0.01, 0),
|
||
Speed = 300
|
||
};
|
||
string missileId = "MMWG_1";
|
||
var missile = _threatSourceFactory.CreateMissile(missileId, "mmw_001", "Tank_1", motionParameters);
|
||
missiles[missileId] = missile;
|
||
simulationManager.RegisterEntity(missileId, missile);
|
||
Console.WriteLine($"注册毫米波末制导导弹 {missileId}");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加传感器和指示器
|
||
/// </summary>
|
||
private void AddIndicators()
|
||
{
|
||
// 添加激光目标指示器
|
||
string laserDesignatorId = "LD_1";
|
||
var laserDesignatorLaunchParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(2100, 1, 100),
|
||
Orientation = new Orientation(Math.PI/2, 0.01, 0),
|
||
Speed = 0
|
||
};
|
||
var laserDesignator = _threatSourceFactory.CreateIndicator(laserDesignatorId, "ld_001", "Tank_1", "LSGM_1", laserDesignatorLaunchParams);
|
||
indicators[laserDesignatorId] = (SimulationElement)laserDesignator;
|
||
simulationManager.RegisterEntity(laserDesignatorId, laserDesignator);
|
||
Console.WriteLine($"注册激光目标指示器 {laserDesignatorId}");
|
||
|
||
// 添加激光驾束仪
|
||
string laserBeamRiderId = "LBR_1";
|
||
var laserBeamRiderLaunchParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(2100, 1, 10),
|
||
Orientation = new Orientation(Math.PI/2, 0, 0),
|
||
Speed = 0
|
||
};
|
||
var laserBeamRider = _threatSourceFactory.CreateIndicator(laserBeamRiderId, "br_001", "Tank_1", "LBRM_1", laserBeamRiderLaunchParams);
|
||
indicators[laserBeamRiderId] = (SimulationElement)laserBeamRider;
|
||
simulationManager.RegisterEntity(laserBeamRiderId, laserBeamRider);
|
||
Console.WriteLine($"注册激光驾束仪 {laserBeamRiderId}");
|
||
|
||
// 添加红外测角仪
|
||
string infraredTrackerId = "IT_1";
|
||
var infraredTrackerLaunchParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(2100, 1, 0),
|
||
Orientation = new Orientation(Math.PI/2, 0, 0),
|
||
Speed = 0
|
||
};
|
||
var infraredTracker = _threatSourceFactory.CreateIndicator(infraredTrackerId, "ir_001", "Tank_1", "ITGM_1", infraredTrackerLaunchParams);
|
||
indicators[infraredTrackerId] = (SimulationElement)infraredTracker;
|
||
simulationManager.RegisterEntity(infraredTrackerId, infraredTracker);
|
||
Console.WriteLine($"注册红外测角仪 {infraredTrackerId}");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加各类型干扰器
|
||
/// </summary>
|
||
private void AddJammers()
|
||
{
|
||
// 添加激光干扰器 - 指向指示器
|
||
var laserJammerParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 0, 0),
|
||
Orientation = CalculateOrientationToEntity(indicators["LD_1"]), // 朝向激光指示器
|
||
Speed = 0.0
|
||
};
|
||
string laserJammerId = "LaserJammer_Designator";
|
||
var laserJammer = _threatSourceFactory.CreateJammer(laserJammerId, "laser_blocking", laserJammerParams, "Tank_1");
|
||
if (laserJammer is BaseJammer jammer4)
|
||
{
|
||
simulationManager.RegisterEntity(laserJammerId, laserJammer);
|
||
jammers[laserJammerId] = jammer4;
|
||
Console.WriteLine($"注册激光干扰器(指向指示器) {laserJammerId}");
|
||
}
|
||
|
||
// 添加激光干扰器 - 指向导弹
|
||
laserJammerParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 0, 0),
|
||
Orientation = CalculateOrientationToEntity(missiles["LSGM_1"]), // 朝向激光半主动导弹
|
||
Speed = 0.0
|
||
};
|
||
laserJammerId = "LaserJammer_Missile";
|
||
laserJammer = _threatSourceFactory.CreateJammer(laserJammerId, "laser_blocking", laserJammerParams, "Tank_1");
|
||
if (laserJammer is BaseJammer jammer5)
|
||
{
|
||
simulationManager.RegisterEntity(laserJammerId, laserJammer);
|
||
jammers[laserJammerId] = jammer5;
|
||
Console.WriteLine($"注册激光干扰器(指向导弹) {laserJammerId}");
|
||
}
|
||
|
||
// 添加红外干扰器 - 指向指示器
|
||
var irJammerParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 0, 0),
|
||
Orientation = CalculateOrientationToEntity(indicators["IT_1"]), // 朝向红外指示器
|
||
Speed = 0.0
|
||
};
|
||
string irJammerId = "InfraredJammer_Designator";
|
||
var irJammer = _threatSourceFactory.CreateJammer(irJammerId, "infrared_blocking", irJammerParams, "Tank_1");
|
||
if (irJammer is BaseJammer jammer6)
|
||
{
|
||
simulationManager.RegisterEntity(irJammerId, irJammer);
|
||
jammers[irJammerId] = jammer6;
|
||
Console.WriteLine($"注册红外干扰器(指向指示器) {irJammerId}");
|
||
}
|
||
|
||
// 添加红外干扰器 - 指向导弹
|
||
irJammerParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 0, 0),
|
||
Orientation = CalculateOrientationToEntity(missiles["ITGM_1"]), // 朝向红外成像导弹
|
||
Speed = 0.0
|
||
};
|
||
irJammerId = "InfraredJammer_Missile";
|
||
irJammer = _threatSourceFactory.CreateJammer(irJammerId, "infrared_blocking", irJammerParams, "Tank_1");
|
||
if (irJammer is BaseJammer jammer7)
|
||
{
|
||
simulationManager.RegisterEntity(irJammerId, irJammer);
|
||
jammers[irJammerId] = jammer7;
|
||
Console.WriteLine($"注册红外干扰器(指向导弹) {irJammerId}");
|
||
}
|
||
|
||
// 添加毫米波干扰器 - 指向导弹
|
||
var mmwJammerParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 0, 0),
|
||
Orientation = CalculateOrientationToEntity(missiles["MMWG_1"]), // 朝向毫米波导弹
|
||
Speed = 0.0
|
||
};
|
||
string mmwJammerId = "MillimeterWaveJammer_Missile";
|
||
var mmwJammer = _threatSourceFactory.CreateJammer(mmwJammerId, "mmw_blocking", mmwJammerParams, "Tank_1");
|
||
if (mmwJammer is BaseJammer jammer8)
|
||
{
|
||
simulationManager.RegisterEntity(mmwJammerId, mmwJammer);
|
||
jammers[mmwJammerId] = jammer8;
|
||
Console.WriteLine($"注册毫米波干扰器(指向导弹) {mmwJammerId}");
|
||
}
|
||
|
||
// 添加激光干扰器 - 指向子弹药
|
||
laserJammerParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 0, 0),
|
||
Orientation = new Orientation(0, Math.PI/2, 0), // 朝向垂直向上
|
||
Speed = 0.0
|
||
};
|
||
laserJammerId = "LaserJammer_Submunition";
|
||
laserJammer = _threatSourceFactory.CreateJammer(laserJammerId, "laser_top_blocking", laserJammerParams, "Tank_1");
|
||
if (laserJammer is BaseJammer jammer9)
|
||
{
|
||
simulationManager.RegisterEntity(laserJammerId, laserJammer);
|
||
jammers[laserJammerId] = jammer9;
|
||
Console.WriteLine($"注册激光干扰器(垂直向上) {laserJammerId}");
|
||
}
|
||
|
||
// 添加红外干扰器 - 指向子弹药
|
||
irJammerParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 0, 0),
|
||
Orientation = new Orientation(0, Math.PI/2, 0), // 朝向垂直向上
|
||
Speed = 0.0
|
||
};
|
||
irJammerId = "InfraredJammer_Submunition";
|
||
irJammer = _threatSourceFactory.CreateJammer(irJammerId, "infrared_top_blocking", irJammerParams, "Tank_1");
|
||
if (irJammer is BaseJammer jammer10)
|
||
{
|
||
simulationManager.RegisterEntity(irJammerId, irJammer);
|
||
jammers[irJammerId] = jammer10;
|
||
Console.WriteLine($"注册红外干扰器(垂直向上) {irJammerId}");
|
||
}
|
||
|
||
// 添加毫米波干扰器 - 指向子弹药
|
||
mmwJammerParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 0, 0),
|
||
Orientation = new Orientation(0, Math.PI/2, 0), // 朝向垂直向上
|
||
Speed = 0.0
|
||
};
|
||
mmwJammerId = "MillimeterWaveJammer_Submunition";
|
||
mmwJammer = _threatSourceFactory.CreateJammer(mmwJammerId, "mmw_top_blocking", mmwJammerParams, "Tank_1");
|
||
if (mmwJammer is BaseJammer jammer11)
|
||
{
|
||
simulationManager.RegisterEntity(mmwJammerId, mmwJammer);
|
||
jammers[mmwJammerId] = jammer11;
|
||
Console.WriteLine($"注册毫米波干扰器(垂直向上) {mmwJammerId}");
|
||
}
|
||
|
||
// 添加毫米波补偿干扰器 - 指向导弹
|
||
mmwJammerParams = new KinematicState
|
||
{
|
||
Position = new Vector3D(0, 0, 0),
|
||
Orientation = new Orientation(0, Math.PI/2, 0), // 朝向垂直向上
|
||
Speed = 0.0
|
||
};
|
||
string mmwCompensationJammerId = "MillimeterWaveCompensationJammer_Submunition";
|
||
var mmwCompensationJammer = _threatSourceFactory.CreateJammer(mmwCompensationJammerId, "mmw_compensation", mmwJammerParams, "Tank_1");
|
||
if (mmwCompensationJammer is BaseJammer jammer12)
|
||
{
|
||
simulationManager.RegisterEntity(mmwCompensationJammerId, mmwCompensationJammer);
|
||
jammers[mmwCompensationJammerId] = jammer12;
|
||
Console.WriteLine($"注册毫米波补偿干扰器(垂直向上) {mmwCompensationJammerId}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计算朝向实体的方向
|
||
/// </summary>
|
||
private Orientation CalculateOrientationToEntity(SimulationElement target)
|
||
{
|
||
// 使用CalculateDirectionToTarget获取归一化方向向量
|
||
Vector3D direction = CalculateDirectionToTarget(new Vector3D(0, 0, 0), target.KState.Position);
|
||
|
||
// 创建朝向目标的方向
|
||
return Orientation.FromVector(direction);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选择要激活的导弹
|
||
/// </summary>
|
||
public void SelectMissile(string missileId)
|
||
{
|
||
if (!missiles.ContainsKey(missileId))
|
||
{
|
||
Console.WriteLine($"错误:找不到导弹 {missileId}");
|
||
return;
|
||
}
|
||
|
||
// 先停用所有导弹、传感器、干扰器
|
||
foreach (var id in missiles.Keys)
|
||
{
|
||
missileActiveStatus[id] = false;
|
||
missiles[id].Deactivate();
|
||
}
|
||
foreach (var indicator in indicators.Values)
|
||
{
|
||
indicator.Deactivate();
|
||
}
|
||
foreach (var jammer in jammers.Values)
|
||
{
|
||
jammer.Deactivate();
|
||
}
|
||
|
||
// 激活选中的导弹
|
||
missileActiveStatus[missileId] = true;
|
||
missiles[missileId].Activate();
|
||
SelectedMissileId = missileId;
|
||
Console.WriteLine($"已选择导弹:{missileId} ({SelectedMissileDisplayName})");
|
||
|
||
// 确保所有目标都处于激活状态
|
||
foreach (var target in targets.Values)
|
||
{
|
||
target.Activate();
|
||
Console.WriteLine($"确保目标 {target.Id} 处于激活状态");
|
||
}
|
||
|
||
// 激活相关的传感器和指示器
|
||
ActivateRelatedIndicators(missileId);
|
||
|
||
// 打印所有注册的组件
|
||
PrintSimulationRegisteredComponents();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 激活与导弹相关的传感器、指示器、干扰器
|
||
/// </summary>
|
||
private void ActivateRelatedIndicators(string missileId)
|
||
{
|
||
// 根据导弹类型激活相应的传感器
|
||
switch (missileId)
|
||
{
|
||
case "LSGM_1": // 激光半主动制导导弹
|
||
if (indicators.ContainsKey("LD_1"))
|
||
{
|
||
indicators["LD_1"].Activate();
|
||
}
|
||
Console.WriteLine($"干扰器数量 {jammers.Count}");
|
||
break;
|
||
case "LBRM_1": // 激光驾束制导导弹
|
||
if (indicators.ContainsKey("LBR_1"))
|
||
{
|
||
indicators["LBR_1"].Activate();
|
||
}
|
||
break;
|
||
case "ICGM_1": // 红外指令制导导弹
|
||
if (indicators.ContainsKey("IT_1"))
|
||
{
|
||
indicators["IT_1"].Activate();
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取当前选中导弹可用的干扰选项
|
||
/// </summary>
|
||
public (JammingType Type, string DisplayName, string JammerId, string Mode, string Target)[] GetAvailableJammingOptions()
|
||
{
|
||
if (string.IsNullOrEmpty(SelectedMissileId) || !missileJammingMap.ContainsKey(SelectedMissileId))
|
||
{
|
||
return Array.Empty<(JammingType, string, string, string, string)>();
|
||
}
|
||
|
||
return missileJammingMap[SelectedMissileId].ToArray();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 应用干扰
|
||
/// </summary>
|
||
public void ApplyJamming(JammingType type, string displayName, string jammerId, string mode, string target)
|
||
{
|
||
// 检查并激活干扰器
|
||
if (jammers.ContainsKey(jammerId))
|
||
{
|
||
var jammerToActivate = jammers[jammerId];
|
||
jammerToActivate.Activate();
|
||
Console.WriteLine($"激活干扰器并开始干扰: {jammerId}: {displayName} (模式: {mode}, 作用: {target})");
|
||
|
||
// Add to activeJammings list if not already present
|
||
var jammingTuple = (Type: type, DisplayName: displayName, JammerId: jammerId, Mode: mode, Target: target);
|
||
if (!this.activeJammings.Any(j => j.JammerId == jammerId && j.Type == type)) // Simple check to avoid duplicates
|
||
{
|
||
this.activeJammings.Add(jammingTuple);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine($"警告:找不到干扰器 {jammerId}...");
|
||
PrintAllJammers();
|
||
}
|
||
|
||
// 根据干扰目标对象应用干扰
|
||
ApplyJammingToTargets(type, displayName, mode, target);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打印所有注册的干扰器信息
|
||
/// </summary>
|
||
private void PrintAllJammers()
|
||
{
|
||
Console.WriteLine("\n所有注册的干扰器:");
|
||
if (jammers.Count == 0)
|
||
{
|
||
Console.WriteLine("没有任何干扰器被注册!");
|
||
return;
|
||
}
|
||
|
||
foreach (var jammer in jammers)
|
||
{
|
||
Console.WriteLine($"- {jammer.Key}: 类型={jammer.Value.GetType().Name}, 激活状态={jammer.Value.IsActive}");
|
||
if (jammer.Value.IsActive)
|
||
{
|
||
Console.WriteLine($" 状态: {jammer.Value.GetStatus()}");
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据目标类型应用干扰
|
||
/// </summary>
|
||
private void ApplyJammingToTargets(JammingType type, string displayName, string mode, string target)
|
||
{
|
||
// 根据target决定干扰作用对象
|
||
switch (target.ToLower())
|
||
{
|
||
case "指示器":
|
||
ApplyJammingToIndicators(type, mode);
|
||
break;
|
||
|
||
case "导弹":
|
||
ApplyJammingToMissiles(type, mode);
|
||
break;
|
||
|
||
case "两者":
|
||
ApplyJammingToIndicators(type, mode);
|
||
ApplyJammingToMissiles(type, mode);
|
||
break;
|
||
|
||
case "子弹药":
|
||
ApplyJammingToMissiles(type, mode);
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 应用干扰到指示器
|
||
/// </summary>
|
||
private void ApplyJammingToIndicators(JammingType type, string mode)
|
||
{
|
||
foreach (var indicator in indicators.Values.Where(i => i.IsActive))
|
||
{
|
||
Console.WriteLine($"应用{mode}干扰到指示器 {indicator.Id}");
|
||
try
|
||
{
|
||
// 根据干扰类型选择合适的干扰器ID
|
||
string jammerId = string.Empty;
|
||
switch (type)
|
||
{
|
||
case JammingType.Laser:
|
||
jammerId = "LaserJammer_Designator";
|
||
break;
|
||
case JammingType.Infrared:
|
||
jammerId = "InfraredJammer_Designator";
|
||
break;
|
||
case JammingType.MillimeterWave:
|
||
jammerId = "MillimeterWaveJammer_Missile"; // 假设这个也可以用于指示器
|
||
break;
|
||
case JammingType.SmokeGrenade:
|
||
if (indicator.Id.Contains("LD"))
|
||
jammerId = "SG_1"; // 激光烟幕
|
||
else if (indicator.Id.Contains("IR"))
|
||
jammerId = "SG_2"; // 红外烟幕
|
||
else
|
||
jammerId = "SG_3"; // 默认烟幕
|
||
break;
|
||
case JammingType.LaserDecoy:
|
||
jammerId = "LDY_1";
|
||
break;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(jammerId) && jammers.ContainsKey(jammerId))
|
||
{
|
||
var jammer = jammers[jammerId];
|
||
|
||
// 创建干扰参数
|
||
JammingParameters jammingParams = new JammingParameters
|
||
{
|
||
Type = type,
|
||
Mode = mode.Equals("阻塞") ? JammingMode.Blocking :
|
||
mode.Equals("欺骗") ? JammingMode.Deception :
|
||
mode.Equals("噪声") ? JammingMode.Noise : JammingMode.Blocking,
|
||
JammerId = jammerId,
|
||
SourceId = jammer.Id,
|
||
Power = 800, // 设置合适功率
|
||
Direction = CalculateDirectionToTarget(jammer.KState.Position, indicator.KState.Position),
|
||
SourcePosition = jammer.KState.Position,
|
||
StartTime = DateTime.UtcNow,
|
||
Duration = 600 // 10分钟
|
||
};
|
||
|
||
// 找到指示器的实际实现类
|
||
if (indicator is IJammable jammableIndicator)
|
||
{
|
||
// 调用IJammable接口的ApplyJamming方法
|
||
jammableIndicator.ApplyJamming(jammingParams);
|
||
Console.WriteLine($"成功应用干扰到指示器 {indicator.Id},干扰源: {jammerId}");
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine($"警告: 指示器 {indicator.Id} 不支持IJammable接口");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine($"警告: 找不到合适的干扰器ID: {jammerId}");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine($"对指示器 {indicator.Id} 应用干扰时出错: {ex.Message}");
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 应用干扰到导弹
|
||
/// </summary>
|
||
private void ApplyJammingToMissiles(JammingType type, string mode)
|
||
{
|
||
foreach (var missile in missiles.Values.Where(m => m.IsActive))
|
||
{
|
||
Console.WriteLine($"应用{mode}干扰到导弹 {missile.Id}");
|
||
try
|
||
{
|
||
// 根据干扰类型和导弹类型选择合适的干扰器ID
|
||
string jammerId = string.Empty;
|
||
switch (type)
|
||
{
|
||
case JammingType.Laser:
|
||
jammerId = "LaserJammer_Missile";
|
||
break;
|
||
case JammingType.Infrared:
|
||
jammerId = "InfraredJammer_Missile";
|
||
break;
|
||
case JammingType.MillimeterWave:
|
||
if (missile.Id.Contains("TSM"))
|
||
jammerId = "MillimeterWaveJammer_Submunition"; // 针对子弹药
|
||
else
|
||
jammerId = "MillimeterWaveJammer_Missile";
|
||
break;
|
||
case JammingType.SmokeGrenade:
|
||
if (missile.Id.Contains("ITGM") || missile.Id.Contains("ICGM"))
|
||
jammerId = "SG_2"; // 红外烟幕用于红外导弹
|
||
else if (missile.Id.Contains("TSM"))
|
||
jammerId = "SG_3"; // 顶部烟幕用于子弹药
|
||
else
|
||
jammerId = "SG_1"; // 默认烟幕
|
||
break;
|
||
case JammingType.LaserDecoy:
|
||
jammerId = "LDY_1";
|
||
break;
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(jammerId) && jammers.ContainsKey(jammerId))
|
||
{
|
||
var jammer = jammers[jammerId];
|
||
|
||
// 创建干扰参数
|
||
JammingParameters jammingParams = new JammingParameters
|
||
{
|
||
Type = type,
|
||
Mode = mode.Equals("阻塞") ? JammingMode.Blocking :
|
||
mode.Equals("欺骗") ? JammingMode.Deception :
|
||
mode.Equals("噪声") ? JammingMode.Noise : JammingMode.Blocking,
|
||
JammerId = jammerId,
|
||
SourceId = jammer.Id,
|
||
Power = 1000, // 设置高功率
|
||
Direction = CalculateDirectionToTarget(jammer.KState.Position, missile.KState.Position),
|
||
SourcePosition = jammer.KState.Position,
|
||
StartTime = DateTime.UtcNow,
|
||
Duration = 600 // 10分钟
|
||
};
|
||
|
||
// 判断导弹是否实现了IJammable接口
|
||
if (missile is IJammable jammableMissile)
|
||
{
|
||
// 调用IJammable接口的ApplyJamming方法
|
||
jammableMissile.ApplyJamming(jammingParams);
|
||
Console.WriteLine($"成功应用干扰到导弹 {missile.Id},干扰源: {jammerId}");
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine($"警告: 导弹 {missile.Id} 不支持IJammable接口");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine($"警告: 找不到合适的干扰器ID: {jammerId}");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine($"对导弹 {missile.Id} 应用干扰时出错: {ex.Message}");
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计算从源位置到目标位置的方向向量
|
||
/// </summary>
|
||
private Vector3D CalculateDirectionToTarget(Vector3D sourcePosition, Vector3D targetPosition)
|
||
{
|
||
Vector3D direction = targetPosition - sourcePosition;
|
||
return direction.Normalize();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清除干扰
|
||
/// </summary>
|
||
public void ClearJamming(JammingType type, string displayName, string jammerId)
|
||
{
|
||
if (jammers.ContainsKey(jammerId))
|
||
{
|
||
jammers[jammerId].Deactivate();
|
||
Console.WriteLine($"关闭干扰器 {jammerId}: {displayName}");
|
||
|
||
// Remove from activeJammings list
|
||
this.activeJammings.RemoveAll(j => j.JammerId == jammerId && j.Type == type);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 应用干扰 (原有方法,保留向后兼容)
|
||
/// </summary>
|
||
public void ApplyJamming(JammingType type, string category)
|
||
{
|
||
switch (type)
|
||
{
|
||
case JammingType.SmokeGrenade:
|
||
if (category == "水平烟幕弹")
|
||
{
|
||
jammers["SG_1"].Activate();
|
||
}
|
||
else if (category == "红外烟幕弹")
|
||
{
|
||
jammers["SG_2"].Activate();
|
||
}
|
||
else if (category == "顶部烟幕弹")
|
||
{
|
||
jammers["SG_3"].Activate();
|
||
}
|
||
break;
|
||
case JammingType.LaserDecoy:
|
||
jammers["LDY_1"].Activate();
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清除干扰 (原有方法,保留向后兼容)
|
||
/// </summary>
|
||
public void ClearJamming(JammingType type, string category)
|
||
{
|
||
var jammingParams = new JammingParameters
|
||
{
|
||
Type = type,
|
||
Power = 0,
|
||
Duration = 0,
|
||
Direction = new Vector3D(1, 0, 0),
|
||
SourcePosition = new Vector3D(0, 0, 0)
|
||
};
|
||
|
||
// 保留原有实现...
|
||
}
|
||
|
||
/// <summary>
|
||
/// 开始模拟
|
||
/// </summary>
|
||
public void Start()
|
||
{
|
||
Console.WriteLine("开始综合导弹模拟...");
|
||
|
||
// 确保所有激活的导弹和传感器都处于正确状态
|
||
foreach (var missile in missiles.Values)
|
||
{
|
||
if (missileActiveStatus[missile.Id])
|
||
{
|
||
missile.Fire();
|
||
}
|
||
}
|
||
|
||
// 打印仿真开始前的组件状态
|
||
PrintSimulationRegisteredComponents();
|
||
|
||
// 启动仿真系统
|
||
simulationManager.StartSimulation(timeStep);
|
||
|
||
while (simulationManager.State == SimulationState.Running)
|
||
{
|
||
// 让仿真管理器统一处理所有实体的更新
|
||
simulationManager.Update(timeStep);
|
||
|
||
// 检查是否还有活跃的导弹
|
||
var activeMissiles = simulationManager.GetEntitiesByType<BaseMissile>()
|
||
.Where(m => m.IsActive);
|
||
|
||
if (!activeMissiles.Any())
|
||
{
|
||
simulationManager.StopSimulation();
|
||
SimulationEnded?.Invoke(this, EventArgs.Empty);
|
||
ResetSimulation();
|
||
break;
|
||
}
|
||
|
||
// 打印状态
|
||
PrintSimulationStatus();
|
||
|
||
Thread.Sleep((int)(timeStep * 1000));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打印当前模拟状态
|
||
/// </summary>
|
||
private void PrintSimulationStatus()
|
||
{
|
||
// 获取当前仿真时间
|
||
double simulationTime = simulationManager.CurrentTime;
|
||
var weather = simulationManager.CurrentWeather;
|
||
|
||
Console.WriteLine($"\n========== 模拟状态 (时间: {simulationTime:F1}s)==========");
|
||
|
||
// 天气状态
|
||
Console.WriteLine("\n--- 天气状态 ---");
|
||
if (weather != null)
|
||
{
|
||
Console.WriteLine($"天气类型: {weather.Type}");
|
||
Console.WriteLine($"温度: {weather.Temperature:F1}°C, 湿度: {weather.RelativeHumidity:F1}%");
|
||
Console.WriteLine($"风速: {weather.WindSpeed:F1} m/s, 方向: ({weather.WindDirection:F1}°)");
|
||
Console.WriteLine($"雨量: {weather.Precipitation:F1} mm");
|
||
Console.WriteLine($"能见度: {weather.Visibility:F1} m");
|
||
}
|
||
|
||
// 导弹状态
|
||
Console.WriteLine("\n--- 导弹状态 ---");
|
||
var activeMissiles = simulationManager.GetEntitiesByType<BaseMissile>()
|
||
.Where(m => m.IsActive)
|
||
.ToList();
|
||
if (activeMissiles.Any())
|
||
{
|
||
foreach (var missile in activeMissiles)
|
||
{
|
||
// 直接调用导弹的GetStatus方法
|
||
Console.WriteLine(missile.GetStatus());
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("没有激活的导弹");
|
||
}
|
||
|
||
// 目标状态
|
||
Console.WriteLine("\n--- 目标状态 ---");
|
||
var activeTargets = targets.Values.Where(t => t.IsActive).ToList();
|
||
if (activeTargets.Any())
|
||
{
|
||
foreach (var target in activeTargets)
|
||
{
|
||
// 调用目标的GetStatus方法
|
||
Console.WriteLine(target.GetStatus());
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("没有激活的目标");
|
||
}
|
||
|
||
// 传感器状态
|
||
Console.WriteLine("\n--- 指示器状态 ---");
|
||
var activeIndicators = indicators.Values.Where(i => i.IsActive).ToList();
|
||
if (activeIndicators.Any())
|
||
{
|
||
foreach (var indicator in activeIndicators)
|
||
{
|
||
// 调用指示器的GetStatus方法
|
||
Console.WriteLine(indicator.GetStatus());
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("没有激活的指示器");
|
||
}
|
||
|
||
// 干扰器状态
|
||
Console.WriteLine("\n--- 干扰器状态 ---");
|
||
var activeJammers = jammers.Values.Where(j => j.IsActive).ToList();
|
||
if (activeJammers.Any())
|
||
{
|
||
foreach (var jammer in activeJammers)
|
||
{
|
||
// 调用干扰器的GetStatus方法
|
||
Console.WriteLine(jammer.GetStatus());
|
||
|
||
// 如果正在干扰,显示更多详细信息
|
||
if (jammer.IsJamming)
|
||
{
|
||
try
|
||
{
|
||
var runningState = jammer.GetRunningState();
|
||
if (runningState.CurrentParameters != null)
|
||
{
|
||
var jammingParams = runningState.CurrentParameters;
|
||
|
||
// 计算已干扰时间和剩余时间
|
||
var jammingTimeSeconds = (DateTime.UtcNow.Ticks - jammingParams.StartTime.Ticks) / TimeSpan.TicksPerSecond;
|
||
Console.WriteLine($"- 已干扰时间: {jammingTimeSeconds:F1} 秒");
|
||
|
||
if (jammingParams.Duration.HasValue)
|
||
{
|
||
var remainingTime = jammingParams.Duration.Value - jammingTimeSeconds;
|
||
if (remainingTime > 0)
|
||
Console.WriteLine($"- 剩余时间: {remainingTime:F1} 秒");
|
||
else
|
||
Console.WriteLine("- 干扰即将结束");
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine($" 获取干扰器详细状态出错: {ex.Message}");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("没有激活的干扰器");
|
||
}
|
||
|
||
Console.WriteLine("\n========================================");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 停止模拟
|
||
/// </summary>
|
||
public void Stop()
|
||
{
|
||
simulationManager.StopSimulation();
|
||
Console.WriteLine("模拟结束");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 暂停模拟
|
||
/// </summary>
|
||
public void Pause()
|
||
{
|
||
simulationManager.PauseSimulation();
|
||
Console.WriteLine("模拟暂停");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 恢复模拟
|
||
/// </summary>
|
||
public void Resume()
|
||
{
|
||
simulationManager.ResumeSimulation();
|
||
Console.WriteLine("模拟恢复");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 重置仿真状态
|
||
/// </summary>
|
||
public void ResetSimulation()
|
||
{
|
||
// 获取所有活跃的导弹
|
||
var activeMissiles = simulationManager.GetEntitiesByType<BaseMissile>();
|
||
foreach (var missile in activeMissiles)
|
||
{
|
||
// 获取导弹的初始属性
|
||
var motionParameters = missile.GetType().GetField("motionParameters",
|
||
System.Reflection.BindingFlags.NonPublic |
|
||
System.Reflection.BindingFlags.Instance)?.GetValue(missile) as KinematicState;
|
||
|
||
if (motionParameters != null)
|
||
{
|
||
// 重置导弹位置和状态
|
||
missile.KState.Position = motionParameters.Position;
|
||
missile.KState.Velocity = Vector3D.Zero;
|
||
}
|
||
missile.Deactivate();
|
||
}
|
||
|
||
// 重置所有传感器状态
|
||
var activeIndicators = simulationManager.GetEntitiesByType<SimulationElement>()
|
||
.Where(e => indicators.ContainsValue(e));
|
||
foreach (var indicator in activeIndicators)
|
||
{
|
||
indicator.Deactivate();
|
||
}
|
||
|
||
// 重置所有目标状态
|
||
var activeTargets = simulationManager.GetEntitiesByType<Tank>();
|
||
foreach (var target in activeTargets)
|
||
{
|
||
var initialPosition = target.KState.Position;
|
||
target.Deactivate();
|
||
target.KState.Position = initialPosition;
|
||
target.Activate();
|
||
}
|
||
|
||
// 重置导弹激活状态
|
||
missileActiveStatus.Clear();
|
||
foreach (var missile in missiles.Values)
|
||
{
|
||
missileActiveStatus[missile.Id] = false;
|
||
}
|
||
|
||
Console.WriteLine("仿真状态已重置");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打印所有注册到仿真管理器中的组件
|
||
/// </summary>
|
||
public void PrintSimulationRegisteredComponents()
|
||
{
|
||
Console.WriteLine("\n========== 仿真管理器中的注册组件 ==========");
|
||
var allEntities = simulationManager.GetAllEntities();
|
||
foreach (var entity in allEntities)
|
||
{
|
||
if (entity is SimulationElement simElement)
|
||
{
|
||
Console.WriteLine($"{simElement.Id} ({entity.GetType().Name})");
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine($"未知组件 ({entity.GetType().Name})");
|
||
}
|
||
}
|
||
Console.WriteLine($"总计: {allEntities.Count()} 个组件");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取当前活动的传感器列表
|
||
/// </summary>
|
||
public (string Id, string Name, bool IsActive)[] GetActiveIndicators()
|
||
{
|
||
return indicators.Select(s => (
|
||
s.Value.Id,
|
||
GetIndicatorDisplayName(s.Value),
|
||
s.Value.IsActive
|
||
)).ToArray();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取传感器的显示名称
|
||
/// </summary>
|
||
private string GetIndicatorDisplayName(SimulationElement indicator)
|
||
{
|
||
return indicator switch
|
||
{
|
||
LaserDesignator _ => "激光目标指示器",
|
||
LaserBeamRider _ => "激光驾束仪",
|
||
InfraredTracker _ => "红外测角仪",
|
||
_ => indicator.Id
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// 切换传感器的激活状态
|
||
/// </summary>
|
||
public void ToggleIndicator(string indicatorId)
|
||
{
|
||
if (indicators.TryGetValue(indicatorId, out var indicator))
|
||
{
|
||
if (indicator.IsActive)
|
||
indicator.Deactivate();
|
||
else
|
||
indicator.Activate();
|
||
|
||
Console.WriteLine($"指示器 {GetIndicatorDisplayName(indicator)} 已{(indicator.IsActive ? "激活" : "停用")}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 切换天气
|
||
/// </summary>
|
||
/// <param name="weatherType">天气类型</param>
|
||
public void SwitchWeather(string weatherType)
|
||
{
|
||
// 创建新的天气实例
|
||
var newWeather = _threatSourceFactory.CreateWeather(weatherType);
|
||
|
||
// 设置为当前天气
|
||
simulationManager.SetWeather(newWeather);
|
||
|
||
// 打印天气详情
|
||
Console.WriteLine($"已切换到 {weatherType} 天气环境");
|
||
Console.WriteLine($"温度: {newWeather.Temperature}°C");
|
||
Console.WriteLine($"湿度: {newWeather.RelativeHumidity}%");
|
||
Console.WriteLine($"能见度: {newWeather.Visibility}公里");
|
||
Console.WriteLine($"风速: {newWeather.WindSpeed}米/秒");
|
||
Console.WriteLine($"风向: {newWeather.WindDirection}°");
|
||
}
|
||
|
||
public string GetActiveJammingDescription()
|
||
{
|
||
if (this.activeJammings == null || !this.activeJammings.Any())
|
||
{
|
||
return "(无干扰)";
|
||
}
|
||
return $"(已激活: {this.activeJammings.First().DisplayName})";
|
||
}
|
||
|
||
public List<(JammingType Type, string DisplayName, string JammerId, string Mode, string Target)> GetCurrentlyActiveJammings()
|
||
{
|
||
// Return a new list to prevent external modification of the internal list
|
||
return new List<(JammingType Type, string DisplayName, string JammerId, string Mode, string Target)>(this.activeJammings);
|
||
}
|
||
}
|
||
} |