188 lines
6.1 KiB
C#
188 lines
6.1 KiB
C#
using ActiveProtect.Simulation;
|
|
using ActiveProtect.Utility;
|
|
namespace ActiveProtect.Models
|
|
{
|
|
public class LaserBeamRiderMissile : MissileBase
|
|
{
|
|
/// <summary>
|
|
/// 激光驾束制导导弹阶段
|
|
/// </summary>
|
|
private enum LBRM_Stage
|
|
{
|
|
Launch, // 发射阶段
|
|
Cruise, // 巡航阶段
|
|
Explode, // 爆炸阶段
|
|
SelfDestruct // 自毁阶段
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前阶段
|
|
/// </summary>
|
|
private LBRM_Stage currentStage;
|
|
|
|
/// <summary>
|
|
/// 激光驾束制导系统
|
|
/// </summary>
|
|
private readonly LaserBeamRiderGuidanceSystem LaserBeamRiderGuidanceSystem;
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
/// <param name="config">导弹配置</param>
|
|
/// <param name="manager">模拟管理器</param>
|
|
public LaserBeamRiderMissile(MissileConfig config, ISimulationManager manager)
|
|
: base(config, manager)
|
|
{
|
|
LaserBeamRiderGuidanceSystem = new LaserBeamRiderGuidanceSystem(config.MaxAcceleration, config.ProportionalNavigationCoefficient);
|
|
currentStage = LBRM_Stage.Launch;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 激光束开启事件
|
|
/// </summary>
|
|
/// <param name="evt">激光束开启事件</param>
|
|
private void OnLaserBeamStart(LaserBeamStartEvent evt)
|
|
{
|
|
if (evt?.LaserBeamRider != null)
|
|
{
|
|
LaserBeamRiderGuidanceSystem?.UpdateLaserBeamRider(evt.LaserBeamRider.Position, evt.LaserBeamRider.LaserDirection, evt.LaserBeamRider.LaserPower);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 激光束更新事件
|
|
/// </summary>
|
|
/// <param name="evt">激光束更新事件</param>
|
|
private void OnLaserBeamUpdate(LaserBeamUpdateEvent evt)
|
|
{
|
|
if (evt?.LaserBeamRider != null)
|
|
{
|
|
LaserBeamRiderGuidanceSystem?.UpdateLaserBeamRider(evt.LaserBeamRider.Position, evt.LaserBeamRider.LaserDirection, evt.LaserBeamRider.LaserPower);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 激光束停止事件
|
|
/// </summary>
|
|
/// <param name="evt">激光束停止事件</param>
|
|
private void OnLaserBeamStop(LaserBeamStopEvent evt)
|
|
{
|
|
if (evt?.LaserBeamRider != null)
|
|
{
|
|
LaserBeamRiderGuidanceSystem?.DeactivateLaserBeam();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新导弹
|
|
/// </summary>
|
|
/// <param name="deltaTime">时间步长</param>
|
|
public override void Update(double deltaTime)
|
|
{
|
|
switch (currentStage)
|
|
{
|
|
case LBRM_Stage.Launch:
|
|
UpdateLaunchStage(deltaTime);
|
|
break;
|
|
case LBRM_Stage.Cruise:
|
|
UpdateCruiseStage(deltaTime);
|
|
break;
|
|
case LBRM_Stage.Explode:
|
|
UpdateExplodeStage(deltaTime);
|
|
break;
|
|
case LBRM_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.01)
|
|
{
|
|
currentStage = LBRM_Stage.Cruise;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新巡航阶段
|
|
/// </summary>
|
|
/// <param name="deltaTime">时间步长</param>
|
|
private void UpdateCruiseStage(double deltaTime)
|
|
{
|
|
// 巡航阶段
|
|
LaserBeamRiderGuidanceSystem.Update(deltaTime, Position, Velocity);
|
|
GuidanceAcceleration = LaserBeamRiderGuidanceSystem.GetGuidanceAcceleration();
|
|
if (DistanceToTarget <= ExplosionRadius)
|
|
{
|
|
currentStage = LBRM_Stage.Explode;
|
|
}
|
|
if(ShouldSelfDestruct())
|
|
{
|
|
currentStage = LBRM_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>
|
|
/// <returns>导弹状态</returns>
|
|
public override string GetStatus()
|
|
{
|
|
string baseStatus = base.GetStatus().Replace("导弹", "激光驾束制导导弹");
|
|
string additionalStatus = LaserBeamRiderGuidanceSystem.HasGuidance ? LaserBeamRiderGuidanceSystem.GetStatus() : "";
|
|
return baseStatus + additionalStatus;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 激活导弹
|
|
/// </summary>
|
|
public override void Activate()
|
|
{
|
|
base.Activate();
|
|
SimulationManager.SubscribeToEvent<LaserBeamStartEvent>(OnLaserBeamStart);
|
|
SimulationManager.SubscribeToEvent<LaserBeamStopEvent>(OnLaserBeamStop);
|
|
SimulationManager.SubscribeToEvent<LaserBeamUpdateEvent>(OnLaserBeamUpdate);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭导弹
|
|
/// </summary>
|
|
public override void Deactivate()
|
|
{
|
|
base.Deactivate();
|
|
SimulationManager.UnsubscribeFromEvent<LaserBeamStartEvent>(OnLaserBeamStart);
|
|
SimulationManager.UnsubscribeFromEvent<LaserBeamStopEvent>(OnLaserBeamStop);
|
|
SimulationManager.UnsubscribeFromEvent<LaserBeamUpdateEvent>(OnLaserBeamUpdate);
|
|
}
|
|
}
|
|
}
|