190 lines
5.6 KiB
C#
190 lines
5.6 KiB
C#
using System;
|
|
using ActiveProtect.SimulationEnvironment;
|
|
|
|
namespace ActiveProtect.Models
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
/// 红外指令制导导弹类
|
|
/// </summary>
|
|
public class InfraredCommandGuidedMissile : MissileBase
|
|
{
|
|
/// <summary>
|
|
/// 红外指令制导导弹阶段
|
|
/// </summary>
|
|
private enum ICGM_Stage
|
|
{
|
|
Launch, // 发射阶段
|
|
Cruise, // 巡航阶段
|
|
Explode, // 爆炸阶段
|
|
SelfDestruct // 自毁阶段
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前阶段
|
|
/// </summary>
|
|
private ICGM_Stage currentStage;
|
|
|
|
/// <summary>
|
|
/// 红外热源辐射功率(瓦特)
|
|
/// </summary>
|
|
public double RadiationPower { get; set; }
|
|
|
|
/// <summary>
|
|
/// 红外指令导引系统
|
|
/// </summary>
|
|
private readonly InfraredCommandGuidanceSystem guidanceSystem;
|
|
|
|
/// <summary>
|
|
/// 红外测角仪
|
|
/// </summary>
|
|
private InfraredTracker infraredTracker;
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
public InfraredCommandGuidedMissile(MissileConfig config, ISimulationManager manager) : base(config, manager)
|
|
{
|
|
infraredTracker = null!;
|
|
RadiationPower = 1000;
|
|
|
|
// 初始化红外指令导引系统,包括自适应 PID 参数
|
|
guidanceSystem = new InfraredCommandGuidanceSystem(
|
|
maxAcceleration: config.MaxAcceleration,
|
|
guidanceCoefficient: config.ProportionalNavigationCoefficient
|
|
);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新导弹状态
|
|
/// </summary>
|
|
protected override void UpdateMotionState(double deltaTime)
|
|
{
|
|
// 点亮红外热源
|
|
LightInfraredSource();
|
|
|
|
switch (currentStage)
|
|
{
|
|
case ICGM_Stage.Launch:
|
|
UpdateLaunchStage(deltaTime);
|
|
break;
|
|
case ICGM_Stage.Cruise:
|
|
UpdateCruiseStage(deltaTime);
|
|
break;
|
|
case ICGM_Stage.Explode:
|
|
UpdateExplodeStage(deltaTime);
|
|
break;
|
|
case ICGM_Stage.SelfDestruct:
|
|
UpdateSelfDestructStage(deltaTime);
|
|
break;
|
|
}
|
|
|
|
base.UpdateMotionState(deltaTime);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新发射阶段
|
|
/// </summary>
|
|
/// <param name="deltaTime">时间步长</param>
|
|
private void UpdateLaunchStage(double deltaTime)
|
|
{
|
|
// 发射阶段
|
|
GuidanceAcceleration = Vector3D.Zero;
|
|
if (FlightTime >= 0.1)
|
|
{
|
|
currentStage = ICGM_Stage.Cruise;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 更新巡航阶段
|
|
/// </summary>
|
|
/// <param name="deltaTime">时间步长</param>
|
|
private void UpdateCruiseStage(double deltaTime)
|
|
{
|
|
guidanceSystem.Update(deltaTime, Position, Velocity);
|
|
GuidanceAcceleration = guidanceSystem.GetGuidanceAcceleration();
|
|
if (DistanceToTarget <= ExplosionRadius)
|
|
{
|
|
currentStage = ICGM_Stage.Explode;
|
|
}
|
|
if(ShouldSelfDestruct())
|
|
{
|
|
currentStage = ICGM_Stage.SelfDestruct;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新爆炸阶段
|
|
/// </summary>
|
|
/// <param name="deltaTime">时间步长</param>
|
|
private void UpdateExplodeStage(double deltaTime)
|
|
{
|
|
// 爆炸阶段
|
|
Explode();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新自毁阶段
|
|
/// </summary>
|
|
/// <param name="deltaTime">时间步长</param>
|
|
private void UpdateSelfDestructStage(double deltaTime)
|
|
{
|
|
// 自毁阶段
|
|
SelfDestruct();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 处理制导指令事件
|
|
/// </summary>
|
|
private void HandleGuidanceCommand(InfraredGuidanceCommandEvent evt)
|
|
{
|
|
if (evt.TargetMissileId == Id)
|
|
{
|
|
if (infraredTracker == null && evt.SenderId != null)
|
|
{
|
|
if (SimulationManager.GetEntityById(evt.SenderId) is InfraredTracker tracker)
|
|
{
|
|
infraredTracker = tracker;
|
|
}
|
|
}
|
|
|
|
guidanceSystem.ReceiveGuidanceCommand(evt.TrackerToMissileVector, evt.TrackerToTargetVector);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 点亮红外热源
|
|
/// </summary>
|
|
public void LightInfraredSource()
|
|
{
|
|
SimulationManager.PublishEvent(new InfraredGuidanceMissileLightEvent { RadiationPower = this.RadiationPower, SenderId = this.Id });
|
|
}
|
|
|
|
public override void Activate()
|
|
{
|
|
base.Activate();
|
|
// 订阅红外指令制导事件
|
|
SimulationManager.SubscribeToEvent<InfraredGuidanceCommandEvent>(HandleGuidanceCommand);
|
|
}
|
|
|
|
public override void Deactivate()
|
|
{
|
|
base.Deactivate();
|
|
// 取消订阅红外指令制导事件
|
|
SimulationManager.UnsubscribeFromEvent<InfraredGuidanceCommandEvent>(HandleGuidanceCommand);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取导弹状态
|
|
/// </summary>
|
|
public override string GetStatus()
|
|
{
|
|
return base.GetStatus() + $"\n 当前阶段:{currentStage}\n 导引系统状态: {guidanceSystem.GetStatus()}";
|
|
}
|
|
}
|
|
}
|