184 lines
6.4 KiB
C#
184 lines
6.4 KiB
C#
using ActiveProtect.SimulationEnvironment;
|
|
using System;
|
|
|
|
namespace ActiveProtect.Models
|
|
{
|
|
/// <summary>
|
|
/// 激光半主动制导导弹类,继承自基础导弹类
|
|
/// </summary>
|
|
public class LaserSemiActiveGuidedMissile : MissileBase
|
|
{
|
|
/// <summary>
|
|
/// 激光半主动制导导弹阶段
|
|
/// </summary>
|
|
private enum LSAGM_Stage
|
|
{
|
|
Launch, // 发射阶段
|
|
Cruise, // 巡航阶段
|
|
Explode, // 爆炸阶段
|
|
SelfDestruct // 自毁阶段
|
|
}
|
|
private LSAGM_Stage currentStage;
|
|
private LaserSemiActiveGuidanceSystem LaserGuidanceSystem;
|
|
public string LaserDesignatorId { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
/// <param name="id">导弹ID</param>
|
|
/// <param name="laserDesignatorId">激光指示器ID</param>
|
|
/// <param name="config">导弹配置</param>
|
|
/// <param name="simulationManager">仿真管理器</param>
|
|
public LaserSemiActiveGuidedMissile(MissileConfig config, ISimulationManager manager)
|
|
: base(config, manager)
|
|
{
|
|
LaserGuidanceSystem = new LaserSemiActiveGuidanceSystem(config.MaxAcceleration, config.ProportionalNavigationCoefficient);
|
|
currentStage = LSAGM_Stage.Launch;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理激光照射事件
|
|
/// </summary>
|
|
/// <param name="evt">激光照射事件</param>
|
|
private void OnLaserIlluminationStart(LaserIlluminationStartEvent evt)
|
|
{
|
|
if (evt?.LaserDesignator != null && evt?.Target != null)
|
|
{
|
|
LaserGuidanceSystem.UpdateLaserDesignator(evt.LaserDesignator.Position, evt.Target.Position, evt.Target.Velocity,
|
|
evt.LaserDesignator.LaserPower, evt.LaserDesignator.LaserDivergenceAngle);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理激光照射更新事件
|
|
/// </summary>
|
|
/// <param name="evt">激光照射更新事件</param>
|
|
private void OnLaserIlluminationUpdate(LaserIlluminationUpdateEvent evt)
|
|
{
|
|
if (evt?.LaserDesignator != null && evt?.Target != null)
|
|
{
|
|
LaserGuidanceSystem.UpdateLaserDesignator(evt.LaserDesignator.Position, evt.Target.Position, evt.Target.Velocity,
|
|
evt.LaserDesignator.LaserPower, evt.LaserDesignator.LaserDivergenceAngle);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理激光照射停止事件
|
|
/// </summary>
|
|
/// <param name="evt">激光照射停止事件</param>
|
|
private void OnLaserIlluminationStop(LaserIlluminationStopEvent evt)
|
|
{
|
|
LaserGuidanceSystem.DeactivateLaserDesignator();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 激活导弹
|
|
/// </summary>
|
|
public override void Activate()
|
|
{
|
|
base.Activate();
|
|
SimulationManager.SubscribeToEvent<LaserIlluminationStartEvent>(OnLaserIlluminationStart);
|
|
SimulationManager.SubscribeToEvent<LaserIlluminationUpdateEvent>(OnLaserIlluminationUpdate);
|
|
SimulationManager.SubscribeToEvent<LaserIlluminationStopEvent>(OnLaserIlluminationStop);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 停用导弹
|
|
/// </summary>
|
|
public override void Deactivate()
|
|
{
|
|
base.Deactivate();
|
|
SimulationManager.UnsubscribeFromEvent<LaserIlluminationStartEvent>(OnLaserIlluminationStart);
|
|
SimulationManager.UnsubscribeFromEvent<LaserIlluminationUpdateEvent>(OnLaserIlluminationUpdate);
|
|
SimulationManager.UnsubscribeFromEvent<LaserIlluminationStopEvent>(OnLaserIlluminationStop);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新导弹状态
|
|
/// </summary>
|
|
/// <param name="deltaTime">时间步长</param>
|
|
public override void Update(double deltaTime)
|
|
{
|
|
switch (currentStage)
|
|
{
|
|
case LSAGM_Stage.Launch:
|
|
UpdateLaunchStage(deltaTime);
|
|
break;
|
|
case LSAGM_Stage.Cruise:
|
|
UpdateCruiseStage(deltaTime);
|
|
break;
|
|
case LSAGM_Stage.Explode:
|
|
UpdateExplodeStage(deltaTime);
|
|
break;
|
|
case LSAGM_Stage.SelfDestruct:
|
|
UpdateSelfDestructStage(deltaTime);
|
|
break;
|
|
}
|
|
base.Update(deltaTime);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新发射阶段
|
|
/// </summary>
|
|
/// <param name="deltaTime">时间步长</param>
|
|
private void UpdateLaunchStage(double deltaTime)
|
|
{
|
|
// 发射阶段
|
|
GuidanceAcceleration = Vector3D.Zero;
|
|
if (FlightTime >= 0.1)
|
|
{
|
|
currentStage = LSAGM_Stage.Cruise;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新巡航阶段
|
|
/// </summary>
|
|
/// <param name="deltaTime">时间步长</param>
|
|
private void UpdateCruiseStage(double deltaTime)
|
|
{
|
|
LaserGuidanceSystem.Update(deltaTime, Position, Velocity);
|
|
GuidanceAcceleration = LaserGuidanceSystem.GetGuidanceAcceleration();
|
|
if (DistanceToTarget <= ExplosionRadius)
|
|
{
|
|
currentStage = LSAGM_Stage.Explode;
|
|
}
|
|
if(ShouldSelfDestruct())
|
|
{
|
|
currentStage = LSAGM_Stage.SelfDestruct;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新爆炸阶段
|
|
/// </summary>
|
|
/// <param name="deltaTime">时间步长</param>
|
|
private void UpdateExplodeStage(double deltaTime)
|
|
{
|
|
base.Explode();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新自毁阶段
|
|
/// </summary>
|
|
/// <param name="deltaTime">时间步长</param>
|
|
private void UpdateSelfDestructStage(double deltaTime)
|
|
{
|
|
SelfDestruct();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取导弹状态信息
|
|
/// </summary>
|
|
/// <returns>状态信息字符串</returns>
|
|
public override string GetStatus()
|
|
{
|
|
string baseStatus = base.GetStatus().Replace("导弹", "激光半主动制导导弹");
|
|
string additionalStatus = LaserGuidanceSystem.HasGuidance ? LaserGuidanceSystem.GetStatus() : "";
|
|
return baseStatus + additionalStatus;
|
|
}
|
|
|
|
}
|
|
}
|