refactor: 删除 SimulationRunner.BuildFireSchedule fallback
- Planner 输出直接传给 Engine.SetFireSchedule - ManagerVerification/SimulationBootstrap 在 LoadAndStart 前设置 fire schedule - 引擎不再需要从 CloudDispersal 反推发射计划
This commit is contained in:
parent
317f47280b
commit
3a2f68b02b
@ -91,6 +91,7 @@ namespace CounterDrone.Unity
|
||||
|
||||
var runner = gameObject.AddComponent<SimulationRunner>();
|
||||
runner.Awake();
|
||||
runner.Engine.SetFireSchedule(plan.MergedSchedule);
|
||||
runner.LoadAndStart(taskId);
|
||||
runner.Engine.TimeScale = 10f;
|
||||
|
||||
|
||||
@ -110,6 +110,7 @@ namespace CounterDrone.Unity
|
||||
Runner = GetComponent<SimulationRunner>();
|
||||
if (Runner == null) Runner = gameObject.AddComponent<SimulationRunner>();
|
||||
else Runner.enabled = true;
|
||||
Runner.Engine.SetFireSchedule(plan.MergedSchedule);
|
||||
Runner.LoadAndStart(taskId);
|
||||
|
||||
// 设置倍速
|
||||
|
||||
@ -55,16 +55,6 @@ namespace CounterDrone.Unity
|
||||
var detail = _scenario.GetTaskDetail(taskId);
|
||||
if (detail == null) { Debug.LogError("Task not found"); return; }
|
||||
|
||||
var cloud = detail.Cloud;
|
||||
if (cloud.RecommendedTiming > 0)
|
||||
{
|
||||
var db = new DatabaseManager(_paths).OpenMainDb();
|
||||
var ammoCatalog = db.Table<AmmunitionSpec>().ToList();
|
||||
db.Close();
|
||||
var schedule = BuildFireSchedule(detail, ammoCatalog);
|
||||
_engine.SetFireSchedule(schedule);
|
||||
}
|
||||
|
||||
_engine.Initialize(taskId);
|
||||
|
||||
foreach (var drone in _engine.Drones)
|
||||
@ -205,41 +195,5 @@ namespace CounterDrone.Unity
|
||||
catch { }
|
||||
return 1f;
|
||||
}
|
||||
|
||||
private List<FireEvent> BuildFireSchedule(TaskFullConfig detail, List<AmmunitionSpec> ammoCatalog)
|
||||
{
|
||||
var schedule = new List<FireEvent>();
|
||||
var cloud = detail.Cloud;
|
||||
if (!cloud.RecommendedTiming.HasValue || cloud.RecommendedTiming <= 0) return schedule;
|
||||
|
||||
var platforms = detail.Equipment.FindAll(e => e.EquipmentRole == (int)EquipmentRole.LaunchPlatform);
|
||||
if (platforms.Count == 0) return schedule;
|
||||
|
||||
var releaseAlt = (float)cloud.DisperseHeight;
|
||||
if (releaseAlt < 10) releaseAlt = 300f;
|
||||
|
||||
var spacing = (float)cloud.SalvoSpacing;
|
||||
if (spacing <= 0) spacing = 50f;
|
||||
|
||||
for (int i = 0; i < platforms.Count; i++)
|
||||
{
|
||||
var p = platforms[i];
|
||||
var mv = (float)(p.MuzzleVelocity ?? 800);
|
||||
var offset = (i - (platforms.Count - 1) / 2f) * spacing;
|
||||
var tx = (float)cloud.PositionX + offset; var ty = (float)cloud.PositionY; var tz = (float)cloud.PositionZ;
|
||||
var dx = tx - (float)p.PositionX; var dz = tz - (float)p.PositionZ;
|
||||
var dist = Mathf.Sqrt(dx * dx + dz * dz);
|
||||
var angle = Kinematics.CalculateLaunchAngle(dist, mv, releaseAlt);
|
||||
var sinA = Mathf.Sin(angle);
|
||||
var tUp = mv * sinA / 9.81f;
|
||||
var peakH = mv * mv * sinA * sinA / (2f * 9.81f);
|
||||
var dropH = Mathf.Max(0, peakH - releaseAlt);
|
||||
var ft = tUp + Mathf.Sqrt(2f * dropH / 9.81f);
|
||||
var fireTime = (float)cloud.RecommendedTiming.Value - ft;
|
||||
if (fireTime < 0) fireTime = 0.1f;
|
||||
schedule.Add(new FireEvent { FireTime = fireTime, PlatformIndex = i, TargetX = tx, TargetY = ty, TargetZ = tz, MuzzleVelocity = mv });
|
||||
}
|
||||
return schedule;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user