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) {