修改了Jammer 的工厂方法和烟幕弹的生成
This commit is contained in:
parent
cadad7bdf5
commit
b10d6901ed
@ -3,6 +3,7 @@
|
||||
"zh": "周边烟幕弹",
|
||||
"en": "Surround Smoke Grenade"
|
||||
},
|
||||
"type": "SmokeGrenade",
|
||||
"smokeType": "Wall",
|
||||
"concentration": 0.2,
|
||||
"duration": 60.0,
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
"zh": "顶部烟幕弹",
|
||||
"en": "Top Smoke Grenade"
|
||||
},
|
||||
"type": "SmokeGrenade",
|
||||
"smokeType": "Cloud",
|
||||
"concentration": 0.2,
|
||||
"duration": 60.0,
|
||||
|
||||
@ -461,22 +461,34 @@ namespace ThreatSource.Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 烟幕弹数据模型
|
||||
/// 干扰机数据模型
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 包含烟幕弹的基本信息和参数
|
||||
/// 用于创建和初始化烟幕弹实例
|
||||
/// 包含干扰机的基本信息和参数
|
||||
/// 用于创建和初始化干扰机实例
|
||||
/// </remarks>
|
||||
public class SmokeGrenadeData
|
||||
public class JammerData
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置烟幕弹的多语言名称
|
||||
/// 获取或设置干扰机的多语言名称
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 包含中英文名称
|
||||
/// 用于显示和文档
|
||||
/// </remarks>
|
||||
public LocalizedName Name { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置干扰机的类型
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 可选值:
|
||||
/// - LaserJammer:激光干扰机
|
||||
/// - IRJammer:红外干扰机
|
||||
/// - MMWJammer:毫米波干扰机
|
||||
/// - SmokeGrenade:烟幕弹
|
||||
/// </remarks>
|
||||
public string Type { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置烟幕弹的配置
|
||||
|
||||
@ -37,7 +37,7 @@ namespace ThreatSource.Data
|
||||
private readonly Dictionary<string, SensorData> _sensors = new();
|
||||
private readonly Dictionary<string, TargetData> _targets = new();
|
||||
private readonly Dictionary<string, WeatherData> _weathers = new();
|
||||
private readonly Dictionary<string, SmokeGrenadeData> _smokeGrenades = new();
|
||||
private readonly Dictionary<string, JammerData> _jammers = new();
|
||||
/// <summary>
|
||||
/// 初始化威胁源数据管理器
|
||||
/// </summary>
|
||||
@ -61,6 +61,7 @@ namespace ThreatSource.Data
|
||||
LoadSensors(Path.Combine(path, "sensors"));
|
||||
LoadTargets(Path.Combine(path, "targets"));
|
||||
LoadWeathers(Path.Combine(path, "weathers"));
|
||||
LoadJammers(Path.Combine(path, "jammers"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -250,13 +251,13 @@ namespace ThreatSource.Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载烟幕弹数据
|
||||
/// 加载干扰机数据
|
||||
/// </summary>
|
||||
private void LoadSmokeGrenades(string path)
|
||||
private void LoadJammers(string path)
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Console.WriteLine($"烟幕弹数据目录不存在:{path}");
|
||||
Console.WriteLine($"干扰机数据目录不存在:{path}");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -265,17 +266,17 @@ namespace ThreatSource.Data
|
||||
try
|
||||
{
|
||||
var jsonContent = File.ReadAllText(file);
|
||||
var data = JsonSerializer.Deserialize<SmokeGrenadeData>(jsonContent, _jsonOptions);
|
||||
var data = JsonSerializer.Deserialize<JammerData>(jsonContent, _jsonOptions);
|
||||
if (data != null)
|
||||
{
|
||||
string model = Path.GetFileNameWithoutExtension(file);
|
||||
_smokeGrenades[model] = data;
|
||||
Console.WriteLine($"已加载烟幕弹数据:{model}");
|
||||
_jammers[model] = data;
|
||||
Console.WriteLine($"已加载干扰机数据:{model}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"加载烟幕弹数据文件失败:{file},错误:{ex.Message}");
|
||||
Console.WriteLine($"加载干扰机数据文件失败:{file},错误:{ex.Message}");
|
||||
Console.WriteLine($"异常堆栈:{ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
@ -342,15 +343,15 @@ namespace ThreatSource.Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取烟幕弹配置数据
|
||||
/// 获取干扰机配置数据
|
||||
/// </summary>
|
||||
/// <param name="model">烟幕弹型号</param>
|
||||
/// <returns>烟幕弹配置数据</returns>
|
||||
public SmokeGrenadeData GetSmokeGrenade(string model)
|
||||
/// <param name="model">干扰机型号</param>
|
||||
/// <returns>干扰机配置数据</returns>
|
||||
public JammerData GetJammer(string model)
|
||||
{
|
||||
if (_smokeGrenades.TryGetValue(model, out var data))
|
||||
if (_jammers.TryGetValue(model, out var data))
|
||||
return data;
|
||||
throw new KeyNotFoundException($"SmokeGrenade {model} not found");
|
||||
throw new KeyNotFoundException($"Jammer {model} not found");
|
||||
}
|
||||
|
||||
|
||||
@ -380,8 +381,8 @@ namespace ThreatSource.Data
|
||||
public IEnumerable<string> GetAvailableWeathers() => _weathers.Keys;
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有可用的烟幕弹ID列表
|
||||
/// 获取所有可用的干扰机ID列表
|
||||
/// </summary>
|
||||
public IEnumerable<string> GetAvailableSmokeGrenades() => _smokeGrenades.Keys;
|
||||
public IEnumerable<string> GetAvailableJammers() => _jammers.Keys;
|
||||
}
|
||||
}
|
||||
@ -266,18 +266,24 @@ namespace ThreatSource.Data
|
||||
/// <summary>
|
||||
/// 创建烟幕弹实例
|
||||
/// </summary>
|
||||
/// <param name="smokeGrenadeModel">烟幕弹型号</param>
|
||||
/// <param name="jammerModel">干扰机型号</param>
|
||||
/// <param name="motionParameters">初始运动参数</param>
|
||||
/// <returns>烟幕弹实例</returns>
|
||||
public SmokeGrenade CreateSmokeGrenade(string smokeGrenadeModel, MotionParameters motionParameters)
|
||||
/// <returns>干扰机实例</returns>
|
||||
public IJammer CreateJammer(string jammerModel, MotionParameters motionParameters)
|
||||
{
|
||||
var data = _dataManager.GetSmokeGrenade(smokeGrenadeModel);
|
||||
return new SmokeGrenade(
|
||||
smokeGrenadeModel,
|
||||
data.SmokeGrenadeConfig,
|
||||
motionParameters,
|
||||
_simulationManager
|
||||
);
|
||||
var data = _dataManager.GetJammer(jammerModel);
|
||||
switch (data.Type)
|
||||
{
|
||||
case "SmokeGrenade":
|
||||
return new SmokeGrenade(
|
||||
jammerModel,
|
||||
data.SmokeGrenadeConfig,
|
||||
motionParameters,
|
||||
_simulationManager
|
||||
);
|
||||
default:
|
||||
throw new ArgumentException($"不支持的干扰机类型: {data.Type}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@ using ThreatSource.Utils;
|
||||
using ThreatSource.Simulation;
|
||||
using ThreatSource.Sensor;
|
||||
using ThreatSource.Indicator;
|
||||
using ThreatSource.Jammer;
|
||||
using System.Diagnostics;
|
||||
using ThreatSource.Jamming;
|
||||
using AirTransmission;
|
||||
@ -315,29 +316,37 @@ namespace ThreatSource.Guidance
|
||||
/// <param name="evt">烟幕事件</param>
|
||||
private void OnSmokeScreen(SmokeScreenEvent evt)
|
||||
{
|
||||
if (evt == null) return;
|
||||
|
||||
// 创建干扰参数
|
||||
var parameters = new JammingParameters
|
||||
if (evt != null && evt.SmokeGrenadeId != null)
|
||||
{
|
||||
Type = JammingType.SmokeScreen,
|
||||
SourcePosition = evt.Position,
|
||||
Direction = evt.Orientation,
|
||||
AngleRange = evt.SmokeType == SmokeScreenType.Wall ? Math.PI : Math.PI * 2, // 墙状烟幕为半球形覆盖,云状为全方位
|
||||
SmokeConcentration = evt.Concentration,
|
||||
SmokeType = evt.SmokeType,
|
||||
SmokeThickness = evt.SmokeType == SmokeScreenType.Wall ? evt.Width : evt.Width * 2, // 墙状使用宽度,云状使用直径
|
||||
Duration = evt.RemainingTime,
|
||||
Mode = JammingMode.Obscuration
|
||||
};
|
||||
// 获取烟幕弹的配置
|
||||
var smokeGrenade = SimulationManager.GetEntityById(evt.SmokeGrenadeId) as SmokeGrenade;
|
||||
if (smokeGrenade != null)
|
||||
{
|
||||
var config = smokeGrenade.config;
|
||||
|
||||
// 使用JammableComponent进行干扰判断
|
||||
ApplyJamming(parameters);
|
||||
|
||||
// 如果被干扰,记录信息
|
||||
if (IsJammed)
|
||||
{
|
||||
Debug.WriteLine($"激光半主动制导系统被烟幕干扰 - 浓度: {evt.Concentration}g/m³, 位置: {evt.Position}, 类型: {evt.SmokeType}");
|
||||
// 创建干扰参数
|
||||
var parameters = new JammingParameters
|
||||
{
|
||||
Type = JammingType.SmokeScreen,
|
||||
SourcePosition = smokeGrenade.Position,
|
||||
Direction = smokeGrenade.Orientation.ToVector(),
|
||||
AngleRange = config.SmokeType == SmokeScreenType.Wall ? Math.PI : Math.PI * 2, // 墙状烟幕为半球形覆盖,云状为全方位
|
||||
SmokeConcentration = config.Concentration,
|
||||
SmokeType = config.SmokeType,
|
||||
SmokeThickness = config.Thickness,
|
||||
Duration = config.Duration,
|
||||
Mode = JammingMode.Obscuration
|
||||
};
|
||||
|
||||
// 使用JammableComponent进行干扰判断
|
||||
ApplyJamming(parameters);
|
||||
|
||||
// 如果被干扰,记录信息
|
||||
if (IsJammed)
|
||||
{
|
||||
Debug.WriteLine($"激光半主动制导系统被烟幕干扰 - 浓度: {config.Concentration}g/m³, 位置: {smokeGrenade.Position}, 类型: {config.SmokeType}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ namespace ThreatSource.Jammer
|
||||
/// <summary>
|
||||
/// 烟幕配置
|
||||
/// </summary>
|
||||
private readonly SmokeGrenadeConfig config;
|
||||
public readonly SmokeGrenadeConfig config;
|
||||
|
||||
/// <summary>
|
||||
/// 获取干扰器类型
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
- 事件描述
|
||||
- 分析处理
|
||||
|
||||
## 2005-04-10 增加了 Jammer 架构,实现了烟幕弹逻辑
|
||||
|
||||
## 2025-04-09 改进各导弹导弹制导系统的大气透过率计算
|
||||
|
||||
- 使用AtmosphereDllWrapper封装的计算函数,实现了激光在大气中传输的透过率精确计算
|
||||
|
||||
@ -70,6 +70,8 @@ namespace ThreatSource.Tools.MissileSimulation
|
||||
// 添加各种传感器和指示器
|
||||
AddSensorsAndDesignators();
|
||||
|
||||
// 添加烟幕弹
|
||||
AddSmokeGrenade();
|
||||
|
||||
}
|
||||
|
||||
@ -106,6 +108,23 @@ namespace ThreatSource.Tools.MissileSimulation
|
||||
tank.LaunchLaserDecoy(new Vector3D(0, 0, 1), 50, 25, 20);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加烟幕弹
|
||||
/// </summary>
|
||||
private void AddSmokeGrenade()
|
||||
{
|
||||
var motionParameters = new MotionParameters
|
||||
{
|
||||
Position = new Vector3D(100, 0, 0),
|
||||
Orientation = new Orientation(Math.PI, 0, 0),
|
||||
InitialSpeed = 0.0
|
||||
};
|
||||
string smokeGrenadeId = "SG_1";
|
||||
var smokeGrenade = _threatSourceFactory.CreateJammer("surround", motionParameters);
|
||||
simulationManager.RegisterEntity(smokeGrenadeId, smokeGrenade);
|
||||
Console.WriteLine($"注册烟幕弹 {smokeGrenadeId}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加激光半主动制导导弹
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user