diff --git a/Models/MissileBase.cs b/Models/MissileBase.cs index 6eceee6..3ec1080 100644 --- a/Models/MissileBase.cs +++ b/Models/MissileBase.cs @@ -322,7 +322,7 @@ namespace ActiveProtect.Models $" 距离目标: {missileRunningState.DistanceToTarget:F2}\n" + $" 发动机工作时间: {missileRunningState.EngineBurnTime:F2}/{MaxEngineBurnTime:F2}\n" + $" 有引导: {(missileRunningState.HasGuidance ? "是" : "否")}\n" + - $" 失去引导时间: {missileRunningState.LostGuidanceTime:F2}"; + $" 失去引导时间: {missileRunningState.LostGuidanceTime:F2}\n"; } /// diff --git a/Models/Sensors.cs b/Models/Sensors.cs index 3d5c50d..82354ee 100644 --- a/Models/Sensors.cs +++ b/Models/Sensors.cs @@ -152,14 +152,14 @@ namespace ActiveProtect.Models public class MillimeterWaveRadiometer : Sensor { /// - /// 工作频率 + /// 工作频率(3mm 或 8mm) /// public double Frequency { get; set; } /// - /// 灵敏度 + /// 辐射温度差检测阈值,辐射计高温物体与低温物体的检测温差,单位K,默认 50K /// - public double Sensitivity { get; set; } + public double DetectionTemperatureDifferenceThreshold { get; set; } = 50; /// /// 构造函数 @@ -167,12 +167,12 @@ namespace ActiveProtect.Models /// 辐射计的位置 /// 辐射计的朝向 /// 工作频率 - /// 灵敏度 - public MillimeterWaveRadiometer(Vector3D position, Orientation orientation, double frequency, double sensitivity) + /// 辐射检测阈值 + public MillimeterWaveRadiometer(Vector3D position, Orientation orientation, double frequency, double detectionTemperatureDifferenceThreshold) : base(position, orientation) { Frequency = frequency; - Sensitivity = sensitivity; + DetectionTemperatureDifferenceThreshold = detectionTemperatureDifferenceThreshold; } /// diff --git a/Models/TerminalSensitiveSubmunition.cs b/Models/TerminalSensitiveSubmunition.cs index dda2cd5..e2f6e80 100644 --- a/Models/TerminalSensitiveSubmunition.cs +++ b/Models/TerminalSensitiveSubmunition.cs @@ -39,8 +39,8 @@ namespace ActiveProtect.Models // 攻击速度 500 m/s private const double AttackSpeed = 500; - // 是否检测到目标 - private bool targetDetected; + // 检测到目标的时间 + private double? lastDetectionTime = null; /// /// 螺旋角度 @@ -66,7 +66,6 @@ namespace ActiveProtect.Models { currentStage = SubmunitionStage.Separation; spiralAngle = 0; - targetDetected = false; detectionAngle = 0; // 初始化传感器 @@ -164,11 +163,9 @@ namespace ActiveProtect.Models private void UpdateSpiralScanStage(double deltaTime) { GuidanceAcceleration = Vector3D.Zero; - Velocity = new Vector3D(0, -VerticalDescentSpeed, 0); - // 螺旋扫描 - spiralAngle %= (2 * Math.PI); - spiralAngle += SpiralRotationSpeed * deltaTime; + // 更新螺旋角度 + spiralAngle = (spiralAngle + SpiralRotationSpeed * deltaTime) % (2 * Math.PI); // 计算水平速度分量 double horizontalSpeed = VerticalDescentSpeed * Math.Tan(ScanAngle); @@ -179,7 +176,7 @@ namespace ActiveProtect.Models ); // 更新速度 - Velocity = new Vector3D(horizontalVelocity.X, -VerticalDescentSpeed, horizontalVelocity.Z); + Velocity = new(horizontalVelocity.X, -VerticalDescentSpeed, horizontalVelocity.Z); // 计算扫描方向 Vector3D scanDirection = new( @@ -191,18 +188,27 @@ namespace ActiveProtect.Models if (DetectTarget(scanDirection)) { Console.WriteLine("检测到目标"); - if (!targetDetected) + double currentTime = SimulationManager.CurrentTime; + if (lastDetectionTime == null) { - targetDetected = true; - detectionAngle = spiralAngle; + lastDetectionTime = currentTime; } - else if (Math.Abs(spiralAngle - detectionAngle) < 0.1) // 允许一定的误差 + else { - currentStage = SubmunitionStage.Attack; + double timeSinceLastDetection = currentTime - lastDetectionTime.Value; + // 重新检测到目标的时间大于等于螺旋周期的90%,则二次确认目标 + if (timeSinceLastDetection >= 0.9 * 2 * Math.PI / SpiralRotationSpeed) + { + Console.WriteLine($"目标确认,进入攻击阶段。距离上次检测时间:{timeSinceLastDetection:F2}秒"); + currentStage = SubmunitionStage.Attack; + return; + } } } - if (((AltimeterSensorData)altimeter.GetSensorData()).Altitude <= SelfDestructHeight) + // 使用模式匹配简化类型转换 + if (altimeter.GetSensorData() is AltimeterSensorData altimeterData && + altimeterData.Altitude <= SelfDestructHeight) { currentStage = SubmunitionStage.SelfDestruct; } @@ -273,7 +279,7 @@ namespace ActiveProtect.Models /// 子弹状态 public override string GetStatus() { - return $"{base.GetStatus()}\nSubmunition Stage: {currentStage}\nDetection Angle: {detectionAngle * 180 / Math.PI:F2}°\nSpiral Angle: {spiralAngle * 180 / Math.PI:F2}°\nTarget Detected: {targetDetected}"; + return $"{base.GetStatus()}\nSubmunition Stage: {currentStage}\nDetection Angle: {detectionAngle * 180 / Math.PI:F2}°\nSpiral Angle: {spiralAngle * 180 / Math.PI:F2}°\nTarget Detected: {lastDetectionTime != null}"; } } }