using ActiveProtect.SimulationEnvironment;
using System;
namespace ActiveProtect.Models
{
///
/// 表示仿真中的坦克
///
public class Tank : SimulationElement
{
///
/// 当前速度(米/秒)
///
public double Speed { get; set; }
///
/// 最大速度(米/秒)
///
public double MaxSpeed { get; private set; }
///
/// 最大装甲值
///
public double MaxArmor { get; private set; }
///
/// 当前装甲值
///
public double CurrentArmor { get; private set; }
///
/// 红外辐射强度 (W/sr)
///
public double InfraredRadiationIntensity { get; set; }
///
/// 雷达截面积 (m^2)
///
public double RadarCrossSection { get; set; }
///
/// 构造函数
///
/// 坦克配置
/// 仿真管理器
public Tank(TankConfig tankConfig, ISimulationManager simulationManager)
: base(tankConfig.Id, tankConfig.InitialPosition, tankConfig.InitialOrientation, tankConfig.InitialSpeed, simulationManager)
{
Speed = tankConfig.InitialSpeed;
MaxSpeed = tankConfig.MaxSpeed;
MaxArmor = tankConfig.MaxArmor;
CurrentArmor = tankConfig.MaxArmor;
InfraredRadiationIntensity = tankConfig.InfraredRadiationIntensity;
RadarCrossSection = tankConfig.RadarCrossSection;
IsActive = false;
}
///
/// 更新坦克状态
///
/// 时间步长(秒)
public override void Update(double deltaTime)
{
if (!IsActive) return;
UpdatePosition(deltaTime);
}
///
/// 更新坦克位置
///
/// 时间步长(秒)
private void UpdatePosition(double deltaTime)
{
Vector3D direction = Orientation.ToVector();
Vector3D movement = direction * Speed * deltaTime;
Position += movement;
}
///
/// 坦克受到伤害
///
/// 伤害值
/// 是否为导弹造成的伤害
public void TakeDamage(double damage, bool isMissileDamage = false)
{
if (isMissileDamage)
{
damage = CurrentArmor * 0.5;
}
CurrentArmor = Math.Max(0, CurrentArmor - damage);
if (CurrentArmor <= 0)
{
Deactivate();
}
}
///
/// 获取坦克状态信息
///
/// 坦克状态字符串
public override string GetStatus()
{
return $"坦克 {Id}:\n" +
$" 位置: {Position}\n" +
$" 速度: {Speed:F2}/{MaxSpeed:F2}\n" +
$" 装甲: {CurrentArmor:F2}/{MaxArmor:F2}\n" +
$" 状态: {(IsActive ? "活动" : "已销毁")}\n";
}
}
}