From b5b561039b3a670f11a2d820b5eda04d147832f7 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Sat, 13 Jun 2026 12:09:31 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=88=A0=E9=99=A4=E5=BC=95?= =?UTF-8?q?=E6=93=8E=20Tick=20=E4=B8=AD=20ReleaseAltitude=20=E2=86=92=20?= =?UTF-8?q?=5FdisperseHeight=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 25 +++++++++++++++++++ .../Simulation/SimulationEngine.cs | 4 +-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 12888cc..440f0c0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -93,6 +93,31 @@ pwsh -Command "dotnet test test/unit/CounterDrone.Core.Tests/ --filter 'FullyQua pwsh -Command "dotnet test test/unit/CounterDrone.Core.Tests/" ``` +## 8. No Hardcoded Defaults or Fallbacks + +**Every parameter must come from configuration. If a required value is missing, fail explicitly — never silently substitute a default.** + +Good: +```csharp +if (unit.CruiseSpeed <= 0) + throw new InvalidOperationException($"单元 {unit.Id}: CruiseSpeed 必须 > 0"); +``` + +Bad: +```csharp +float speed = unit.CruiseSpeed > 0 ? unit.CruiseSpeed : 55f; // 55f 是哪来的? +float mv = unit.MuzzleVelocity ?? 800f; // 为什么是 800? +float alt = unit.ReleaseAltitude > 0 ? unit.ReleaseAltitude : threat.Altitude + 500f; // 500? +``` + +This applies to: +- `??` operator with arbitrary numbers (55f, 800f, 1000f, 3, etc.) +- Ternary `> 0 ? x : default` patterns +- `Math.Max(0.1f, x)` to prevent division by zero — instead validate the input before the division +- `if (fireTime < 0.1f) fireTime = 0.1f` — instead skip the event and report the failure + +Physics constants (9.81f, 3.6f, π) and documented model parameters (Phase 2 cutoff = 30s) are NOT arbitrary defaults — they are legitimate parts of the physical model. + --- **These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes. diff --git a/src/CounterDrone.Core/Simulation/SimulationEngine.cs b/src/CounterDrone.Core/Simulation/SimulationEngine.cs index 151b589..284761e 100644 --- a/src/CounterDrone.Core/Simulation/SimulationEngine.cs +++ b/src/CounterDrone.Core/Simulation/SimulationEngine.cs @@ -165,9 +165,7 @@ namespace CounterDrone.Core.Simulation if (platform.PlatformType == Models.PlatformType.AirBased && platform.Ready) { - // 空基:下令飞往投放点(投放点 = 目标正上方,ReleaseAltitude 高度) - var releaseAlt = platform.ReleaseAltitude > 0 ? platform.ReleaseAltitude : _disperseHeight; - platform.CommandFlyTo(fe.TargetX, releaseAlt, fe.TargetZ); + platform.CommandFlyTo(fe.TargetX, platform.ReleaseAltitude, fe.TargetZ); } else if (platform.Ready) {