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