添加 .editorconfig + dotnet format 格式化全部代码

This commit is contained in:
tian 2026-06-11 16:48:22 +08:00
parent cde7702b12
commit 2697225aff
19 changed files with 255 additions and 63 deletions

19
.editorconfig Normal file
View File

@ -0,0 +1,19 @@
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.cs]
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true

View File

@ -9,8 +9,8 @@ namespace CounterDrone.Core.Algorithms
private static readonly Dictionary<Type, Func<object>> _registry = new()
{
[typeof(ICloudDispersionModel)] = () => new GaussianPuffDispersion(),
[typeof(IDamageModel)] = () => new DamageModelRouter(),
[typeof(IDefenseAdvisor)] = () => new DefaultDefenseAdvisor(null),
[typeof(IDamageModel)] = () => new DamageModelRouter(),
[typeof(IDefenseAdvisor)] = () => new DefaultDefenseAdvisor(null),
};
public static void Register<TInterface>(Func<object> factory)

View File

@ -167,7 +167,8 @@ namespace CounterDrone.Core.Algorithms
{
AerosolType = (int)aerosolType,
PositionX = start.X + (end.X - start.X) * 0.25f,
PositionY = start.Y, PositionZ = start.Z,
PositionY = start.Y,
PositionZ = start.Z,
DisperseHeight = (float)target.TypicalAltitude,
Duration = (int)maxDur,
Source = "Algorithm",

View File

@ -3,7 +3,7 @@ using CounterDrone.Core.Models;
namespace CounterDrone.Core.Algorithms
{
/// <summary>云团扩散模型接口</summary>
public interface ICloudDispersionModel
public interface ICloudDispersionModel
{
void Initialize(AmmunitionSpec ammo, CombatScene env, Vector3 releasePos, float releaseTime);
void Tick(float deltaTime, float windSpeed, WindDirection windDir);

View File

@ -3,7 +3,7 @@ using CounterDrone.Core.Models;
namespace CounterDrone.Core.Algorithms
{
/// <summary>毁伤模型接口</summary>
public interface IDamageModel
public interface IDamageModel
{
float CalculateDamage(TargetType droneType, PowerType powerType,
AerosolType aerosolType, float cloudDensity, float exposureTime, float deltaTime);

View File

@ -3,7 +3,7 @@ using CounterDrone.Core.Models;
namespace CounterDrone.Core.Algorithms
{
/// <summary>防御推荐接口 — 威胁驱动</summary>
public interface IDefenseAdvisor
public interface IDefenseAdvisor
{
DefenseRecommendation Recommend(ThreatProfile threat);
}

View File

@ -4,7 +4,7 @@ using CounterDrone.Core.Models;
namespace CounterDrone.Core.Services
{
/// <summary>模型管理服务 — 3D 模型的导入、删除、查询</summary>
public interface IModelService
public interface IModelService
{
ModelInfo ImportModel(string filePath, string name);
void DeleteModel(string id);

View File

@ -5,7 +5,7 @@ using SimEvent = CounterDrone.Core.Simulation.SimEvent;
namespace CounterDrone.Core.Services
{
/// <summary>报告服务</summary>
public interface IReportService
public interface IReportService
{
SimulationReport Generate(string taskId, TaskFullConfig config,
List<SimEvent> events, string finalDroneStatus, float duration);

View File

@ -4,7 +4,7 @@ using CounterDrone.Core.Models;
namespace CounterDrone.Core.Services
{
/// <summary>想定管理服务</summary>
public interface IScenarioService
public interface IScenarioService
{
SimTask CreateTask(string name, string taskNumber);
void DeleteTask(string id);

View File

@ -74,7 +74,10 @@ namespace CounterDrone.Core.Services
return new PagedResult<SimulationReport>
{
Items = items, TotalCount = total, Page = page, PageSize = pageSize,
Items = items,
TotalCount = total,
Page = page,
PageSize = pageSize,
};
}

View File

@ -20,7 +20,7 @@ namespace CounterDrone.Core.Simulation
/// <summary>仿真引擎 — 纯执行器,不包含任何决策逻辑</summary>
/// <summary>仿真引擎 — 纯执行器,接收发射计划按时间表执行</summary>
public class SimulationEngine
public class SimulationEngine
{
private readonly IScenarioService _scenarioService;
private readonly FrameDataStore _frameStore;
@ -162,8 +162,10 @@ public class SimulationEngine
_munitions.Add(m);
frameEvents.Add(new SimEvent
{
Type = SimEventType.MunitionLaunched, OccurredAt = SimulationTime,
SourceId = platform.Id, Description = $"计划发射 {m.Id}",
Type = SimEventType.MunitionLaunched,
OccurredAt = SimulationTime,
SourceId = platform.Id,
Description = $"计划发射 {m.Id}",
});
}
}
@ -181,7 +183,8 @@ public class SimulationEngine
_munitions.Remove(m);
frameEvents.Add(new SimEvent
{
Type = SimEventType.CloudGenerated, OccurredAt = SimulationTime,
Type = SimEventType.CloudGenerated,
OccurredAt = SimulationTime,
Description = $"云团生成",
});
}
@ -209,8 +212,10 @@ public class SimulationEngine
if (drone.Status == DroneStatus.Destroyed)
frameEvents.Add(new SimEvent
{
Type = SimEventType.DroneDestroyed, OccurredAt = SimulationTime,
TargetId = drone.Id, Description = $"无人机 {drone.Id} 被摧毁",
Type = SimEventType.DroneDestroyed,
OccurredAt = SimulationTime,
TargetId = drone.Id,
Description = $"无人机 {drone.Id} 被摧毁",
});
}
}
@ -223,8 +228,10 @@ public class SimulationEngine
if (drone.Status == DroneStatus.ReachedTarget)
frameEvents.Add(new SimEvent
{
Type = SimEventType.DroneReachedTarget, OccurredAt = SimulationTime,
SourceId = drone.Id, Description = "到达攻击目标",
Type = SimEventType.DroneReachedTarget,
OccurredAt = SimulationTime,
SourceId = drone.Id,
Description = "到达攻击目标",
});
}
@ -241,8 +248,11 @@ public class SimulationEngine
drone.MarkZoneIntruded();
frameEvents.Add(new SimEvent
{
Type = SimEventType.ZoneIntruded, OccurredAt = SimulationTime,
SourceId = drone.Id, TargetId = zone.Id, Description = $"侵入 {zone.Name}",
Type = SimEventType.ZoneIntruded,
OccurredAt = SimulationTime,
SourceId = drone.Id,
TargetId = zone.Id,
Description = $"侵入 {zone.Name}",
});
}
}
@ -264,8 +274,11 @@ public class SimulationEngine
return new SimulationFrameResult
{
EntitySnapshots = snapshots, NewEvents = frameEvents,
State = State, FrameIndex = FrameIndex, SimulationTime = SimulationTime,
EntitySnapshots = snapshots,
NewEvents = frameEvents,
State = State,
FrameIndex = FrameIndex,
SimulationTime = SimulationTime,
};
}
@ -281,16 +294,22 @@ public class SimulationEngine
var stage = _damageModel.GetDamageStage(1 - d.Hp);
list.Add(new EntitySnapshot
{
EntityId = d.Id, EntityType = Models.EntityType.Drone,
PosX = d.PosX, PosY = d.PosY, PosZ = d.PosZ,
EntityId = d.Id,
EntityType = Models.EntityType.Drone,
PosX = d.PosX,
PosY = d.PosY,
PosZ = d.PosZ,
StateData = JsonSerializer.Serialize(new { damageStage = (int)stage, hp = d.Hp }),
});
}
foreach (var c in _clouds)
list.Add(new EntitySnapshot
{
EntityId = c.Id, EntityType = Models.EntityType.Cloud,
PosX = c.Dispersion.Center.X, PosY = c.Dispersion.Center.Y, PosZ = c.Dispersion.Center.Z,
EntityId = c.Id,
EntityType = Models.EntityType.Cloud,
PosX = c.Dispersion.Center.X,
PosY = c.Dispersion.Center.Y,
PosZ = c.Dispersion.Center.Z,
StateData = JsonSerializer.Serialize(new { radius = c.Dispersion.Radius, opacity = c.Dispersion.Particles.Opacity }),
});
return list;

View File

@ -0,0 +1,47 @@
# 仿真评估报告
**任务名称**:喷气拦截
**任务编号**SIM-20260611-004
**仿真耗时**106.4 秒
## 一、仿真前 — 我方配置
| 配置项 | 值 |
|--------|-----|
| 目标数量 | 1 |
| 发射平台 | 6 台 |
| 探测设备 | 1 台 |
| 气溶胶类型 | ActiveMaterial |
## 二、仿真中 — 关键事件时序
| 时间(s) | 事件 | 描述 |
|---------|------|------|
| 92.2 | MunitionLaunched | 计划发射 mun_1 |
| 92.2 | MunitionLaunched | 计划发射 mun_2 |
| 92.2 | MunitionLaunched | 计划发射 mun_3 |
| 92.2 | MunitionLaunched | 计划发射 mun_4 |
| 92.2 | MunitionLaunched | 计划发射 mun_5 |
| 92.2 | MunitionLaunched | 计划发射 mun_6 |
| 101.8 | CloudGenerated | 云团生成 |
| 101.8 | CloudGenerated | 云团生成 |
| 101.8 | CloudGenerated | 云团生成 |
| 101.8 | CloudGenerated | 云团生成 |
| 101.8 | CloudGenerated | 云团生成 |
| 101.8 | CloudGenerated | 云团生成 |
| 106.4 | DroneDestroyed | 无人机 drone_1 被摧毁 |
| 106.4 | SimulationEnd | |
## 三、仿真后 — 数据统计
| 统计项 | 值 |
|--------|-----|
| 无人机总数 | 1 |
| 被摧毁 | 1 |
| 到达目标 | 0 |
| 侵入管控区 | 0 |
| 弹药发射次数 | 6 |
| 云团生成次数 | 6 |
**对抗结果**:成功拦截

View File

@ -0,0 +1,46 @@
# 仿真评估报告
**任务名称**:活塞拦截
**任务编号**SIM-20260611-041
**仿真耗时**185.6 秒
## 一、仿真前 — 我方配置
| 配置项 | 值 |
|--------|-----|
| 目标数量 | 1 |
| 发射平台 | 5 台 |
| 探测设备 | 1 台 |
| 气溶胶类型 | InertGas |
## 二、仿真中 — 关键事件时序
| 时间(s) | 事件 | 描述 |
|---------|------|------|
| 167.4 | MunitionLaunched | 计划发射 mun_1 |
| 167.4 | MunitionLaunched | 计划发射 mun_2 |
| 167.4 | MunitionLaunched | 计划发射 mun_3 |
| 167.4 | MunitionLaunched | 计划发射 mun_4 |
| 167.4 | MunitionLaunched | 计划发射 mun_5 |
| 177.0 | CloudGenerated | 云团生成 |
| 177.0 | CloudGenerated | 云团生成 |
| 177.0 | CloudGenerated | 云团生成 |
| 177.0 | CloudGenerated | 云团生成 |
| 177.0 | CloudGenerated | 云团生成 |
| 185.6 | DroneDestroyed | 无人机 drone_1 被摧毁 |
| 185.6 | DroneDestroyed | 无人机 drone_1 被摧毁 |
| 185.6 | SimulationEnd | |
## 三、仿真后 — 数据统计
| 统计项 | 值 |
|--------|-----|
| 无人机总数 | 1 |
| 被摧毁 | 2 |
| 到达目标 | 0 |
| 侵入管控区 | 0 |
| 弹药发射次数 | 5 |
| 云团生成次数 | 5 |
**对抗结果**:成功拦截

View File

@ -38,8 +38,10 @@ namespace CounterDrone.Core.Tests
public bool IsDissipated => false;
public void Initialize(CounterDrone.Core.Models.AmmunitionSpec ammo,
CounterDrone.Core.Models.CombatScene env, Vector3 releasePos, float releaseTime) { }
CounterDrone.Core.Models.CombatScene env, Vector3 releasePos, float releaseTime)
{ }
public void Tick(float deltaTime, float windSpeed,
CounterDrone.Core.Models.WindDirection windDir) { }
CounterDrone.Core.Models.WindDirection windDir)
{ }
}
}

View File

@ -61,15 +61,18 @@ namespace CounterDrone.Core.Tests
{
_repo.Insert(new AmmunitionSpec
{
Name = "Inert-A", AerosolType = (int)AerosolType.InertGas
Name = "Inert-A",
AerosolType = (int)AerosolType.InertGas
});
_repo.Insert(new AmmunitionSpec
{
Name = "Inert-B", AerosolType = (int)AerosolType.InertGas
Name = "Inert-B",
AerosolType = (int)AerosolType.InertGas
});
_repo.Insert(new AmmunitionSpec
{
Name = "Active-A", AerosolType = (int)AerosolType.ActiveMaterial
Name = "Active-A",
AerosolType = (int)AerosolType.ActiveMaterial
});
var inertSpecs = _repo.GetByAerosolType((int)AerosolType.InertGas);

View File

@ -28,9 +28,13 @@ namespace CounterDrone.Core.Tests
_db.Insert(new AmmunitionSpec
{
AerosolType = (int)AerosolType.InertGas, InitialRadius = 50,
CoreDensity = 1.0, DispersionRateBase = 5, MaxRadius = 500,
MaxDuration = 120, EffectiveConcentration = 0.05,
AerosolType = (int)AerosolType.InertGas,
InitialRadius = 50,
CoreDensity = 1.0,
DispersionRateBase = 5,
MaxRadius = 500,
MaxDuration = 120,
EffectiveConcentration = 0.05,
});
_scenario = new ScenarioService(
@ -55,8 +59,10 @@ namespace CounterDrone.Core.Tests
_scenario.SaveScene(_taskId, new CombatScene { WindSpeed = 0 });
_scenario.SaveTarget(_taskId, new TargetConfig
{
TargetType = (int)TargetType.Piston, Quantity = 1,
TypicalSpeed = 100, TypicalAltitude = 300,
TargetType = (int)TargetType.Piston,
Quantity = 1,
TypicalSpeed = 100,
TypicalAltitude = 300,
});
_scenario.SaveDeployment(_taskId, new List<EquipmentDeployment>());
_scenario.SaveCloudDispersal(_taskId, new CloudDispersal());
@ -95,7 +101,8 @@ namespace CounterDrone.Core.Tests
});
_scenario.SaveTarget(_taskId, new TargetConfig
{
TargetType = (int)TargetType.Piston, Quantity = 1,
TargetType = (int)TargetType.Piston,
Quantity = 1,
TypicalSpeed = 600, // 高速对抗强风
});
_scenario.SaveDeployment(_taskId, new List<EquipmentDeployment>());
@ -132,7 +139,8 @@ namespace CounterDrone.Core.Tests
_scenario.SaveScene(_taskId, new CombatScene { WindSpeed = 0 });
_scenario.SaveTarget(_taskId, new TargetConfig
{
TargetType = (int)TargetType.HighSpeed, Quantity = 1,
TargetType = (int)TargetType.HighSpeed,
Quantity = 1,
TypicalSpeed = 500,
});
_scenario.SaveDeployment(_taskId, new List<EquipmentDeployment>());

View File

@ -32,23 +32,38 @@ namespace CounterDrone.Core.Tests
_mainDb.Insert(new AmmunitionSpec
{
Id = "ammo-inert", AerosolType = (int)AerosolType.InertGas,
Name = "惰性气体弹", InitialRadius = 50, CoreDensity = 1.0,
DispersionRateBase = 5, MaxRadius = 500, MaxDuration = 120,
Id = "ammo-inert",
AerosolType = (int)AerosolType.InertGas,
Name = "惰性气体弹",
InitialRadius = 50,
CoreDensity = 1.0,
DispersionRateBase = 5,
MaxRadius = 500,
MaxDuration = 120,
EffectiveConcentration = 0.05,
});
_mainDb.Insert(new AmmunitionSpec
{
Id = "ammo-active", AerosolType = (int)AerosolType.ActiveMaterial,
Name = "活性材料弹", InitialRadius = 30, CoreDensity = 2.0,
DispersionRateBase = 3, MaxRadius = 400, MaxDuration = 90,
Id = "ammo-active",
AerosolType = (int)AerosolType.ActiveMaterial,
Name = "活性材料弹",
InitialRadius = 30,
CoreDensity = 2.0,
DispersionRateBase = 3,
MaxRadius = 400,
MaxDuration = 90,
EffectiveConcentration = 0.1,
});
_mainDb.Insert(new AmmunitionSpec
{
Id = "ammo-fuel", AerosolType = (int)AerosolType.ActiveFuel,
Name = "活性燃料弹", InitialRadius = 40, CoreDensity = 1.5,
DispersionRateBase = 4, MaxRadius = 450, MaxDuration = 100,
Id = "ammo-fuel",
AerosolType = (int)AerosolType.ActiveFuel,
Name = "活性燃料弹",
InitialRadius = 40,
CoreDensity = 1.5,
DispersionRateBase = 4,
MaxRadius = 450,
MaxDuration = 100,
EffectiveConcentration = 0.03,
});
@ -150,7 +165,9 @@ namespace CounterDrone.Core.Tests
{
FireTime = fireTime,
PlatformIndex = r % platforms.Count,
TargetX = tx, TargetY = ty, TargetZ = tz,
TargetX = tx,
TargetY = ty,
TargetZ = tz,
MuzzleVelocity = muzzleV,
});
}
@ -193,7 +210,9 @@ namespace CounterDrone.Core.Tests
{
EquipmentRole = (int)EquipmentRole.Detection,
Quantity = d.Quantity,
PositionX = d.Position.X, PositionY = d.Position.Y, PositionZ = d.Position.Z,
PositionX = d.Position.X,
PositionY = d.Position.Y,
PositionZ = d.Position.Z,
DetectionRadius = d.DetectionRadius,
});
foreach (var p in rec.Best.Platforms)
@ -202,7 +221,9 @@ namespace CounterDrone.Core.Tests
EquipmentRole = (int)EquipmentRole.LaunchPlatform,
PlatformType = (int)p.Type,
Quantity = p.Quantity,
PositionX = p.Position.X, PositionY = p.Position.Y, PositionZ = p.Position.Z,
PositionX = p.Position.X,
PositionY = p.Position.Y,
PositionZ = p.Position.Z,
AerosolType = (int)rec.Best.RecommendedAerosolType,
MunitionCount = p.MunitionCount,
Cooldown = p.Cooldown,
@ -243,7 +264,9 @@ namespace CounterDrone.Core.Tests
{
TargetType = (int)TargetType.FixedWing,
PowerType = (int)PowerType.Jet,
Quantity = 1, TypicalSpeed = 600, TypicalAltitude = 400,
Quantity = 1,
TypicalSpeed = 600,
TypicalAltitude = 400,
});
_scenario.SaveRoute(_taskId, new RoutePlan { FormationMode = (int)FormationMode.Single },
new List<Waypoint>
@ -273,7 +296,9 @@ namespace CounterDrone.Core.Tests
{
TargetType = (int)TargetType.Electric,
PowerType = (int)PowerType.Electric,
Quantity = 1, TypicalSpeed = 300, TypicalAltitude = 300,
Quantity = 1,
TypicalSpeed = 300,
TypicalAltitude = 300,
});
_scenario.SaveRoute(_taskId, new RoutePlan { FormationMode = (int)FormationMode.Single },
new List<Waypoint>
@ -309,13 +334,16 @@ namespace CounterDrone.Core.Tests
_scenario.SaveScene(_taskId, new CombatScene
{
WindSpeed = 3, WindDirection = (int)WindDirection.W,
WindSpeed = 3,
WindDirection = (int)WindDirection.W,
});
_scenario.SaveTarget(_taskId, new TargetConfig
{
TargetType = (int)TargetType.Piston,
PowerType = (int)PowerType.Piston,
Quantity = 1, TypicalSpeed = 200, TypicalAltitude = 500,
Quantity = 1,
TypicalSpeed = 200,
TypicalAltitude = 500,
});
_scenario.SaveRoute(_taskId, new RoutePlan { FormationMode = (int)FormationMode.Single },
new List<Waypoint>
@ -380,7 +408,9 @@ namespace CounterDrone.Core.Tests
{
TargetType = (int)TargetType.HighSpeed,
PowerType = (int)PowerType.Jet,
Quantity = 1, TypicalSpeed = 500, TypicalAltitude = 800,
Quantity = 1,
TypicalSpeed = 500,
TypicalAltitude = 800,
});
_scenario.SaveRoute(_taskId, new RoutePlan { FormationMode = (int)FormationMode.Single },
new List<Waypoint>

View File

@ -426,7 +426,9 @@ namespace CounterDrone.Core.Tests
AerosolType = (int)AerosolType.ActiveMaterial,
TriggerMode = (int)TriggerMode.Area,
Duration = 50.0,
PositionX = 3000, PositionY = 0, PositionZ = 300,
PositionX = 3000,
PositionY = 0,
PositionZ = 300,
});
_service.UpdateStep(task.Id, 4);

View File

@ -30,9 +30,14 @@ namespace CounterDrone.Core.Tests
_mainDb.Insert(new AmmunitionSpec
{
AerosolType = (int)AerosolType.InertGas, Name = "Test Ammo",
InitialRadius = 50, CoreDensity = 1.0, DispersionRateBase = 5,
MaxRadius = 500, MaxDuration = 120, EffectiveConcentration = 0.05,
AerosolType = (int)AerosolType.InertGas,
Name = "Test Ammo",
InitialRadius = 50,
CoreDensity = 1.0,
DispersionRateBase = 5,
MaxRadius = 500,
MaxDuration = 120,
EffectiveConcentration = 0.05,
});
_scenarioService = new ScenarioService(
@ -59,8 +64,10 @@ namespace CounterDrone.Core.Tests
_scenarioService.SaveScene(_taskId, new CombatScene { WindSpeed = 0 });
_scenarioService.SaveTarget(_taskId, new TargetConfig
{
TargetType = (int)TargetType.Piston, Quantity = 1,
PowerType = (int)PowerType.Piston, TypicalSpeed = 60,
TargetType = (int)TargetType.Piston,
Quantity = 1,
PowerType = (int)PowerType.Piston,
TypicalSpeed = 60,
});
_scenarioService.SaveDeployment(_taskId, new List<EquipmentDeployment>
{
@ -74,8 +81,13 @@ namespace CounterDrone.Core.Tests
});
_scenarioService.SaveCloudDispersal(_taskId, new CloudDispersal
{
AerosolType = (int)AerosolType.InertGas, DisperseHeight = 300, Duration = 60,
RecommendedTiming = 10, PositionX = 1000, PositionY = 300, PositionZ = 0,
AerosolType = (int)AerosolType.InertGas,
DisperseHeight = 300,
Duration = 60,
RecommendedTiming = 10,
PositionX = 1000,
PositionY = 300,
PositionZ = 0,
PositionMode = (int)PositionMode.AlgorithmRecommended,
});
_scenarioService.SaveRoute(_taskId, new RoutePlan { FormationMode = (int)FormationMode.Single },