158 lines
4.7 KiB
C#
158 lines
4.7 KiB
C#
using ActiveProtect.SimulationEnvironment;
|
|
using System;
|
|
|
|
namespace ActiveProtect.Models
|
|
{
|
|
public class LaserBeamRider : SimulationElement
|
|
{
|
|
// 激光功率(瓦特)
|
|
public double LaserPower { get; private set; }
|
|
|
|
// 激光发散角(毫弧度)
|
|
public double BeamDivergence { get; private set; } = 0.0;
|
|
|
|
// 控制场直径(米)
|
|
public double ControlFieldDiameter { get; private set; }
|
|
|
|
// 激光方向
|
|
public Vector3D LaserDirection { get; private set; }
|
|
|
|
// 最大导引距离(米)
|
|
public double MaxGuidanceDistance { get; private set; }
|
|
|
|
// 激光束是否开启
|
|
public bool IsBeamOn { get; private set; }
|
|
|
|
// 导弹
|
|
public string MissileId { get; private set; }
|
|
|
|
// 目标
|
|
public string TargetId { get; private set; }
|
|
|
|
public LaserBeamRider(string id, string missileId, string targetId, LaserBeamRiderConfig config, ISimulationManager simulationManager)
|
|
: base(id, config.InitialPosition, new Orientation(0, 0, 0), simulationManager)
|
|
{
|
|
LaserPower = config.LaserPower;
|
|
ControlFieldDiameter = config.ControlFieldDiameter;
|
|
LaserDirection = Vector3D.Zero;
|
|
MaxGuidanceDistance = config.MaxGuidanceDistance;
|
|
IsActive = false; // 初始状态为非激活
|
|
IsBeamOn = false;
|
|
MissileId = missileId;
|
|
TargetId = targetId;
|
|
SimulationManager = simulationManager;
|
|
}
|
|
|
|
public override void Update(double deltaTime)
|
|
{
|
|
if (IsActive && IsBeamOn)
|
|
{
|
|
// 更新驾束仪的激光指向
|
|
Vector3D targetPosition = SimulationManager.GetEntityById(TargetId).Position;
|
|
LaserDirection = (targetPosition - Position).Normalize();
|
|
|
|
Console.WriteLine($"激光驾束仪 {Id} 更新激光指向: {LaserDirection}");
|
|
|
|
PublishLaserBeamUpdateEvent();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 激活激光驾束仪
|
|
/// </summary>
|
|
public override void Activate()
|
|
{
|
|
if (!IsActive)
|
|
{
|
|
IsActive = true;
|
|
Console.WriteLine($"激光驾束仪 {Id} 已激活");
|
|
}
|
|
base.Activate();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 停用激光驾束仪
|
|
/// </summary>
|
|
public override void Deactivate()
|
|
{
|
|
if (IsActive)
|
|
{
|
|
IsActive = false;
|
|
if (IsBeamOn)
|
|
{
|
|
StopBeamIllumination();
|
|
}
|
|
Console.WriteLine($"激光驾束仪 {Id} 已停用");
|
|
}
|
|
base.Deactivate();
|
|
}
|
|
|
|
public void StartBeamIllumination()
|
|
{
|
|
if (!IsBeamOn)
|
|
{
|
|
LaserDirection = (SimulationManager.GetEntityById(TargetId).Position - Position).Normalize();
|
|
IsBeamOn = true;
|
|
PublishLaserBeamStartEvent();
|
|
}
|
|
}
|
|
|
|
public void StopBeamIllumination()
|
|
{
|
|
if (IsBeamOn)
|
|
{
|
|
IsBeamOn = false;
|
|
LaserDirection = Vector3D.Zero;
|
|
PublishLaserBeamStopEvent();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发布激光束开始事件
|
|
/// </summary>
|
|
private void PublishLaserBeamStartEvent()
|
|
{
|
|
PublishEvent(new LaserBeamStartEvent
|
|
{
|
|
LaserBeamRider = this
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发布激光束更新事件
|
|
/// </summary>
|
|
private void PublishLaserBeamUpdateEvent()
|
|
{
|
|
PublishEvent(new LaserBeamUpdateEvent
|
|
{
|
|
LaserBeamRider = this
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发布激光束停止事件
|
|
/// </summary>
|
|
private void PublishLaserBeamStopEvent()
|
|
{
|
|
PublishEvent(new LaserBeamStopEvent
|
|
{
|
|
LaserBeamRider = this
|
|
});
|
|
}
|
|
|
|
public override string GetStatus()
|
|
{
|
|
return $"激光驾束仪 {Id}:\n" +
|
|
$" 位置: {Position}\n" +
|
|
$" 方向: {LaserDirection}\n" +
|
|
$" 激活状态: {(IsActive ? "激活" : "未激活")}\n" +
|
|
$" 激光功率: {LaserPower} W\n" +
|
|
$" 发散角: {BeamDivergence} rad\n" +
|
|
$" 控制场直径: {ControlFieldDiameter} m\n" +
|
|
$" 最大导引距离: {MaxGuidanceDistance} m\n" +
|
|
$" 激光束状态: {(IsBeamOn ? "开启" : "关闭")}";
|
|
}
|
|
}
|
|
}
|