Browse Source

创建机降救援任务和索滑降救援任务相关任务脚本

liyang 6 months ago
parent
commit
0284e1efd6

+ 106 - 0
SimulationServer/Component/SJStaticCapacityComponent.cs

@@ -173,6 +173,56 @@ public class SJStaticCapacityComponent : Component
         SJStaticCapacity.有效探测距离 = 2.ToString();
     }
 
+    public void FillData5(AircraftDB db)
+    {
+        var aircraft = GetParent<AircraftJJ>();
+
+        SJStaticCapacity.初次出动准备时间 = "30";
+        SJStaticCapacity.再次补给时间 = "5";
+        SJStaticCapacity.舱内载荷 = db.fzdnz == null ? "0" : db.fzdnz.ToString();
+        //SJStaticCapacity.机舱容量 = db.fjcrll == null ? "0" : db.fjcrll.ToString();
+        SJStaticCapacity.最大平飞速度 = db.fzdss == null ? "0" : db.fzdss.ToString();
+        SJStaticCapacity.巡航速度 = db.fzdss == null ? "0" : db.fzdss.ToString();
+        //SJStaticCapacity.搜救速度 = db.fsjfxsd == null ? "0" : db.fsjfxsd.ToString();
+        //SJStaticCapacity.单人救助时间 = db.fdrjzsj == null ? "0" : db.fdrjzsj.ToString();
+        SJStaticCapacity.抗风等级 = "八级";
+        SJStaticCapacity.最大起降高度 = "";
+        //SJStaticCapacity.抗浪等级 = db.fkldj == null ? "0" : db.fkldj.ToString();
+        //SJStaticCapacity.起降距离 = db.fjjcdc == null ? "0" : db.fjjcdc.ToString();
+        SJStaticCapacity.夜间作业能力 = 0.ToString();
+        SJStaticCapacity.仪表飞行能力 = 0.ToString();
+        SJStaticCapacity.可靠性 = "0.9";
+        //SJStaticCapacity.航程 = db.fhc == null ? "0" : db.fhc.ToString();
+        SJStaticCapacity.悬停相对耗油率 = FXJHGenerate.GetHoverFuelConsumptionRate(aircraft.FlightPlanEditor, 50).ToString();
+        SJStaticCapacity.搜救相对耗油率 = FXJHGenerate.GetCruisingVelocity(aircraft.FlightPlanEditor, 50).ToString();
+        SJStaticCapacity.有效探测距离 = 2.ToString();
+    }
+
+    public void FillData6(AircraftDB db)
+    {
+        var aircraft = GetParent<AircraftSHJ>();
+
+        SJStaticCapacity.初次出动准备时间 = "30";
+        SJStaticCapacity.再次补给时间 = "5";
+        SJStaticCapacity.舱内载荷 = db.fzdnz == null ? "0" : db.fzdnz.ToString();
+        //SJStaticCapacity.机舱容量 = db.fjcrll == null ? "0" : db.fjcrll.ToString();
+        SJStaticCapacity.最大平飞速度 = db.fzdss == null ? "0" : db.fzdss.ToString();
+        SJStaticCapacity.巡航速度 = db.fzdss == null ? "0" : db.fzdss.ToString();
+        //SJStaticCapacity.搜救速度 = db.fsjfxsd == null ? "0" : db.fsjfxsd.ToString();
+        //SJStaticCapacity.单人救助时间 = db.fdrjzsj == null ? "0" : db.fdrjzsj.ToString();
+        SJStaticCapacity.抗风等级 = "八级";
+        SJStaticCapacity.最大起降高度 = "";
+        //SJStaticCapacity.抗浪等级 = db.fkldj == null ? "0" : db.fkldj.ToString();
+        //SJStaticCapacity.起降距离 = db.fjjcdc == null ? "0" : db.fjjcdc.ToString();
+        SJStaticCapacity.夜间作业能力 = 0.ToString();
+        SJStaticCapacity.仪表飞行能力 = 0.ToString();
+        SJStaticCapacity.可靠性 = "0.9";
+        //SJStaticCapacity.航程 = db.fhc == null ? "0" : db.fhc.ToString();
+        SJStaticCapacity.悬停相对耗油率 = FXJHGenerate.GetHoverFuelConsumptionRate(aircraft.FlightPlanEditor, 50).ToString();
+        SJStaticCapacity.搜救相对耗油率 = FXJHGenerate.GetCruisingVelocity(aircraft.FlightPlanEditor, 50).ToString();
+        SJStaticCapacity.有效探测距离 = 2.ToString();
+    }
+
 
     public Dictionary<string, Dictionary<string, string>> GetReport()
     {
@@ -312,4 +362,60 @@ public class SJStaticCapacityComponent : Component
         };
         return report;
     }
+
+    public Dictionary<string, Dictionary<string, string>> GetReport5()
+    {
+        Dictionary<string, Dictionary<string, string>> report = new Dictionary<string, Dictionary<string, string>>();
+        report["静态能力"] = new Dictionary<string, string>
+        {
+            { "初次出动准备时间/s", SJStaticCapacity.初次出动准备时间.ToString() },
+            { "再次补给时间/s", SJStaticCapacity.再次补给时间.ToString() },
+            { "舱内载荷/kg", SJStaticCapacity.舱内载荷.ToString() },
+            { "机舱容量/kg", SJStaticCapacity.机舱容量.ToString() },
+            { "最大平飞速度/km/h", SJStaticCapacity.最大平飞速度.ToString() },
+            { "巡航速度/km/h", SJStaticCapacity.巡航速度.ToString() },
+            { "搜救速度/km/h", SJStaticCapacity.搜救速度.ToString() },
+            { "单人救助时间/s", SJStaticCapacity.单人救助时间.ToString() },
+            { "抗风等级", SJStaticCapacity.抗风等级.ToString() },
+            { "抗浪等级", SJStaticCapacity.抗浪等级.ToString() },
+            { "起降距离/m", SJStaticCapacity.起降距离.ToString() },
+            { "夜间作业能力", SJStaticCapacity.夜间作业能力.ToString() },
+            { "仪表飞行能力", SJStaticCapacity.仪表飞行能力.ToString() },
+            { "可靠性", SJStaticCapacity.可靠性.ToString() },
+            { "航程/km", SJStaticCapacity.航程.ToString() },
+            { "悬停相对耗油率", SJStaticCapacity.悬停相对耗油率.ToString() },
+            { "搜救相对耗油率", SJStaticCapacity.搜救相对耗油率.ToString() },
+            { "有效探测距离/m", SJStaticCapacity.有效探测距离.ToString() }
+
+        };
+        return report;
+    }
+
+    public Dictionary<string, Dictionary<string, string>> GetReport6()
+    {
+        Dictionary<string, Dictionary<string, string>> report = new Dictionary<string, Dictionary<string, string>>();
+        report["静态能力"] = new Dictionary<string, string>
+        {
+            { "初次出动准备时间/s", SJStaticCapacity.初次出动准备时间.ToString() },
+            { "再次补给时间/s", SJStaticCapacity.再次补给时间.ToString() },
+            { "舱内载荷/kg", SJStaticCapacity.舱内载荷.ToString() },
+            { "机舱容量/kg", SJStaticCapacity.机舱容量.ToString() },
+            { "最大平飞速度/km/h", SJStaticCapacity.最大平飞速度.ToString() },
+            { "巡航速度/km/h", SJStaticCapacity.巡航速度.ToString() },
+            { "搜救速度/km/h", SJStaticCapacity.搜救速度.ToString() },
+            { "单人救助时间/s", SJStaticCapacity.单人救助时间.ToString() },
+            { "抗风等级", SJStaticCapacity.抗风等级.ToString() },
+            { "抗浪等级", SJStaticCapacity.抗浪等级.ToString() },
+            { "起降距离/m", SJStaticCapacity.起降距离.ToString() },
+            { "夜间作业能力", SJStaticCapacity.夜间作业能力.ToString() },
+            { "仪表飞行能力", SJStaticCapacity.仪表飞行能力.ToString() },
+            { "可靠性", SJStaticCapacity.可靠性.ToString() },
+            { "航程/km", SJStaticCapacity.航程.ToString() },
+            { "悬停相对耗油率", SJStaticCapacity.悬停相对耗油率.ToString() },
+            { "搜救相对耗油率", SJStaticCapacity.搜救相对耗油率.ToString() },
+            { "有效探测距离/m", SJStaticCapacity.有效探测距离.ToString() }
+
+        };
+        return report;
+    }
 }

+ 6 - 0
SimulationServer/Component/TaskComponent.cs

@@ -16,6 +16,8 @@ public class TaskComponent : Component
     public List<KZDYMission> KZDYMissions;
     public List<KTKSMission> KTKSMissions;
     public List<ZSJYMission> ZSJYMissions;
+    public List<JJJYMission> JJJYMissions;
+    public List<SHJMission> SHJMissions;
 
     public SJAllTotalTaskPerformanceComponent SSJAllTotalTaskPerformance = new SJAllTotalTaskPerformanceComponent();
     public Dictionary<string, Dictionary<string, List<string>>> alltotalReportSea = new();
@@ -44,6 +46,8 @@ public class TaskComponent : Component
         KZDYMissions?.ForEach(r => r.Start());
         KTKSMissions?.ForEach(r => r.Start());
         ZSJYMissions?.ForEach(r => r.Start());
+        JJJYMissions?.ForEach(r => r.Start());
+        SHJMissions?.ForEach(r => r.Start());
     }
 
     public void SaveSeaSJ(Dictionary<string, Dictionary<string, string>> totalReport)
@@ -188,6 +192,8 @@ public class TaskComponentAwakeSystem : AwakeSystem<TaskComponent>
         self.KZDYMissions = new List<KZDYMission>();
         self.KTKSMissions = new List<KTKSMission>();
         self.ZSJYMissions = new List<ZSJYMission>();
+        self.JJJYMissions = new List<JJJYMission>();
+        self.SHJMissions = new List<SHJMission>();
     }
 }
 

+ 43 - 20
SimulationServer/Entity/AircraftJJ.cs

@@ -14,49 +14,72 @@ public class AircraftJJ : AircraftEntity
     public MHRescueMission mhRescueMission;
 
     public int landingPoint = 0; // 任务文件获取
-    
+
+    public JJJYTask taskContent;
+    public TaskParameter taskParameter;
+    public RescueDemandInfo rescueDemandInfo;
+    public bool IsOver;
+    public bool Success;
+
     public override void End()
     {
-        
+        TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
     }
 
     public override void Reset()
     {
-        base.Reset();       
+        base.Reset();
+        IsOver = false;
+        Success = false;
+        TotalTime = 0;
     }
     public override void Start()
     {
-        FXJHGenerate.FromStartToMission(FlightPlanEditor,ref TurningPoints);//生成从起点到任务段起点的航路点
-        
+        FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
+
+        FlightPlanEditor.missionpoint.MissionPointLatitude = rescueDemandInfo.TargetPointLatitude;
+        FlightPlanEditor.missionpoint.MissionPointLongitude = rescueDemandInfo.TargetPointLongitude;
+        FlightPlanEditor.missionpoint.MissionPointHeight = rescueDemandInfo.TargetPointHeight;
+
         missionEndPoint.MissionEndPointLatitude = FlightPlanEditor.missionpoint.MissionPointLatitude;
         missionEndPoint.MissionEndPointLongitude = FlightPlanEditor.missionpoint.MissionPointLongitude;
         missionEndPoint.MissionEndPointHeight = FlightPlanEditor.missionpoint.MissionPointHeight;
-        
-        int TransportNumber = (int)Math.Ceiling(LandingPersonnel / FlightPlanEditor.aircraftparameter.MaxPassengerNumber);
+
+        int TransportNumber = (int)Math.Ceiling(taskParameter.LandingPersonnel / FlightPlanEditor.aircraftparameter.MaxPassengerNumber);
 
         int j = 0;
-        
-        
-        for (int i = 0; i < TransportNumber; i ++)
+
+
+        for (int i = 0; i < TransportNumber; i++)
         {
             if (i == 0)
             {
-                FXJHGenerate.JijiangJiuYuan1(FlightPlanEditor,ref TurningPoints);
+                FXJHGenerate.JijiangJiuYuan1(FlightPlanEditor, ref TurningPoints);
             }
             else
             {
-                FXJHGenerate.JijiangJiuYuan(FlightPlanEditor,ref TurningPoints);
+                FXJHGenerate.JijiangJiuYuan(FlightPlanEditor, ref TurningPoints);
                 j += 2;
             }
-            
+
         }
         // FXJHGenerate.InitializeVelocities(FlightPlanEditor, TurningPoints, ref Velocitys);
         // FXJHGenerate.InitializeFuelConsumptions(FlightPlanEditor, TurningPoints,ref FuelConsumptions);
-        
-        FXJHGenerate.FromMissionToEnd(FlightPlanEditor, missionEndPoint,ref TurningPoints);
-        FXJHGenerate.FXJHTPDiedai(FlightPlanEditor,ref TurningPoints, Velocitys, FuelConsumptions); // 更新了 计算油耗的方法
+
+        FXJHGenerate.FromMissionToEnd(FlightPlanEditor, missionEndPoint, ref TurningPoints);
+        FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions); // 更新了 计算油耗的方法
+
+        for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
+        {
+            TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间   //仿真轮次1 数值1
+            //Console.WriteLine("TotalTime:" + TotalTime);
+        }
+
+        IsOver = true;
+        Success = true; //需要判断
+        End();
     }
-    
+
     //private double GetDistance(double lon1, double lon2, double lat1, double lat2)
     //{
     //    double R = 6371; // 地球的半径(公里)
@@ -70,7 +93,7 @@ public class AircraftJJ : AircraftEntity
 
     //    return distance;
     //}
-    
+
     public override void Update(double time)
     {
 
@@ -79,9 +102,9 @@ public class AircraftJJ : AircraftEntity
 
 
 [ObjectSystem]
-public class AircraftJJAwakeSystem : AwakeSystem<AircraftJJ,FlightPlanEditor>
+public class AircraftJJAwakeSystem : AwakeSystem<AircraftJJ, FlightPlanEditor>
 {
-    public override void Awake(AircraftJJ self,FlightPlanEditor flightPlanEditor)
+    public override void Awake(AircraftJJ self, FlightPlanEditor flightPlanEditor)
     {
         self.FlightPlanEditor = flightPlanEditor;
         self.Awake();

+ 95 - 4
SimulationServer/Entity/AircraftSHJ.cs

@@ -7,19 +7,54 @@ namespace SimulationServer;
 public class AircraftSHJ : AircraftEntity
 {
     public SHJTask content;
+
     public TaskParameter SHJParameter;
+
+    public MissionEndPoint missionEndPoint;
+
+    public bool IsOver;
+    public bool Success;
     public override void End()
     {
         TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
     }
 
+    public override void Reset()
+    {
+        base.Reset();
+        IsOver = false;
+        Success = false;
+        TotalTime = 0;
+    }
+
     public override void Start()
     {
+        FlightPlanEditor.missionpoint.MissionPointLatitude = missionEndPoint.MissionEndPointLatitude;
+        FlightPlanEditor.missionpoint.MissionPointLongitude = missionEndPoint.MissionEndPointLongitude;
+        FlightPlanEditor.missionpoint.MissionPointHeight = missionEndPoint.MissionEndPointHeight;
+
+        int hour = Convert.ToInt32(content.missionInformation.StartTime.Split("时")[0]);
+        //Console.WriteLine("hour:" + hour);
+        double windSpeed = Convert.ToDouble(TargetQiXiangInfoSave("风速", hour));
+        //Console.WriteLine("windSpeed:" + windSpeed);
+        double vis = Convert.ToDouble(TargetQiXiangInfoSave("能见度", hour));
+        //Console.WriteLine("vis:" + vis);
+
         FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
-        double resulttime = get_result_time_rope(SHJParameter.H, SHJParameter.person_number, SHJParameter.windspeed, SHJParameter.vis, SHJParameter.descendspeed).time;//索滑降模型输出的索滑降时间
+        double resulttime = get_result_time_rope(SHJParameter.H, SHJParameter.person_number, windSpeed, vis, SHJParameter.descendspeed).time;//索滑降模型输出的索滑降时间
         FXJHGenerate.SuoHuaJiang(resulttime, FlightPlanEditor, ref TurningPoints);
         FXJHGenerate.FromMissionToEnd(FlightPlanEditor, FXJHGenerate.SuoHuaJiangMissionEndPoint(FlightPlanEditor), ref TurningPoints);
         FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
+
+
+        for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
+        {
+            TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间   //仿真轮次1 数值1
+            //Console.WriteLine("TotalTime:" + TotalTime);
+        }
+        IsOver = true;
+        Success = true;
+        End();
     }
 
     // --接口
@@ -60,6 +95,63 @@ public class AircraftSHJ : AircraftEntity
         }
         return result;
     }
+
+    public string TargetQiXiangInfoSave(string s, int hour)
+    {
+        string result = hour.ToString() + "-" + s;
+        switch (s)
+        {
+            case "温度":
+                if (hour >= 0 && hour < 8)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Temperature_00_08.ToString();
+                else if (hour >= 8 && hour < 19)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Temperature_08_19.ToString();
+                else if (hour >= 19 && hour <= 24)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Temperature_19_24.ToString();
+                break;
+            case "湿度":
+                if (hour >= 0 && hour < 8)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Humidity_00_08.ToString();
+                else if (hour >= 8 && hour < 19)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Humidity_08_19.ToString();
+                else if (hour >= 19 && hour <= 24)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Humidity_19_24.ToString();
+                break;
+            case "能见度":
+                if (hour >= 0 && hour < 8)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Visibility_00_08.ToString();
+                else if (hour >= 8 && hour < 19)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Visibility_08_19.ToString();
+                else if (hour >= 19 && hour <= 24)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Visibility_19_24.ToString();
+                break;
+            case "风速":
+                if (hour >= 0 && hour < 8)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindSpeed_00_08.ToString();
+                else if (hour >= 8 && hour < 19)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindSpeed_08_19.ToString();
+                else if (hour >= 19 && hour <= 24)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindSpeed_19_24.ToString();
+                break;
+            case "风向":
+                if (hour >= 0 && hour < 8)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindDirection_00_08.ToString();
+                else if (hour >= 8 && hour < 19)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindDirection_08_19.ToString();
+                else if (hour >= 19 && hour <= 24)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.WindDirection_19_24.ToString();
+                break;
+            case "天气":
+                if (hour >= 0 && hour < 8)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Weather_00_08;
+                else if (hour >= 8 && hour < 19)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Weather_08_19;
+                else if (hour >= 19 && hour <= 24)
+                    result = FlightPlanEditor.targetpoint[0].TargetQiXiangInfo.Weather_19_24;
+                break;
+        }
+        return result;
+    }
 }
 
 public class Cable_result
@@ -69,11 +161,10 @@ public class Cable_result
 }
 
 [ObjectSystem]
-public class AircraftSHJAwakeSystem : AwakeSystem<AircraftSHJ, FlightPlanEditor, SHJTask>
+public class AircraftSHJAwakeSystem : AwakeSystem<AircraftSHJ, FlightPlanEditor>
 {
-    public override void Awake(AircraftSHJ self, FlightPlanEditor flightPlanEditor, SHJTask shjTask)
+    public override void Awake(AircraftSHJ self, FlightPlanEditor flightPlanEditor)
     {
-        self.content = shjTask;
         self.FlightPlanEditor = flightPlanEditor;
         self.Awake();
     }

+ 1 - 1
SimulationServer/Entity/AircraftZS.cs

@@ -156,6 +156,6 @@ public class AircraftZSAwakeSystem : AwakeSystem<AircraftZS, FlightPlanEditor>
     {
         self.FlightPlanEditor = flightPlanEditor;
         self.Awake();
-        self.Reset();
+        //self.Reset();
     }
 }

+ 177 - 0
SimulationServer/Entity/JJJYMission.cs

@@ -0,0 +1,177 @@
+using KYFramework;
+using NPOI.SS.Formula.PTG;
+using SimulationServer.Utils;
+
+namespace SimulationServer;
+
+public class JJJYMission : Entity
+{
+    public string MissionId; // 任务ID
+    public bool Success; // 任务是否成功
+    public List<AircraftJJ> aircrafts = new List<AircraftJJ>();
+
+    public bool IsRunning;
+    public double SimulationTime;
+
+    public Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>> singleReport = new();
+
+    public Dictionary<string, Dictionary<string, List<string>>> aircraftSJDatas = new();
+
+    public bool IsOver = false;
+
+    private int currentExecuteCount = 1;
+    public int ExecutionContext = 0;
+    public void Start()
+    {
+        IsRunning = true;
+        aircrafts.ForEach(a => a.Start());
+        Log.Info($"{MissionId} 任务开始!");
+    }
+
+    public void Reset()
+    {
+        SimulationTime = 0;
+        aircrafts?.ForEach(a => a.Reset());
+    }
+
+    public void EndMission()
+    {
+        IsRunning = false;
+        Log.Info($"{MissionId} 任务结束!");
+
+        if (currentExecuteCount > ExecutionContext)
+        {
+            return;
+        }
+
+        if (currentExecuteCount < ExecutionContext)
+        {
+            SaveSJ();
+            SaveAircraftSJDatas();
+        }
+
+        if (currentExecuteCount == ExecutionContext)
+        {
+            SaveSJ();
+            SaveAircraftSJDatas();
+            ReportSJ();
+            IsOver = true;
+            return;
+        }
+
+        this.Reset();
+        this.Start();
+        currentExecuteCount++;
+    }
+
+    public void SaveAircraftSJDatas()
+    {
+        foreach (AircraftJJ aircraftEntity in aircrafts)
+        {
+            string key = aircraftEntity.AircraftId;
+            if (!aircraftSJDatas.ContainsKey(key))
+            {
+                aircraftSJDatas[key] = new Dictionary<string, List<string>>();
+            }
+            if (!aircraftSJDatas[key].ContainsKey("识别成功率"))
+                aircraftSJDatas[key]["识别成功率"] = new List<string>();
+            aircraftSJDatas[key]["识别成功率"].Add("0");
+            if (!aircraftSJDatas[key].ContainsKey("任务准备时间"))
+                aircraftSJDatas[key]["任务准备时间"] = new List<string>();
+            aircraftSJDatas[key]["任务准备时间"].Add(aircraftEntity.TaskReadyTime.ToString());
+            if (!aircraftSJDatas[key].ContainsKey("平均搜索时间"))
+                aircraftSJDatas[key]["平均搜索时间"] = new List<string>();
+            aircraftSJDatas[key]["平均搜索时间"].Add("0");
+            if (!aircraftSJDatas[key].ContainsKey("总飞行时间"))
+                aircraftSJDatas[key]["总飞行时间"] = new List<string>();
+            aircraftSJDatas[key]["总飞行时间"].Add(aircraftEntity.TotalTime.ToString());
+            if (!aircraftSJDatas[key].ContainsKey("人员存活率"))
+                aircraftSJDatas[key]["人员存活率"] = new List<string>();
+            aircraftSJDatas[key]["人员存活率"].Add(aircraftEntity.Success ? "1" : "0");
+        }
+    }
+
+    public void SaveSJ()
+    {
+        foreach (AircraftJJ aircraftEntity in aircrafts)
+        {
+            var staticCapacity = aircraftEntity.GetComponent<SJStaticCapacityComponent>();
+
+            if (staticCapacity == null) continue;
+
+            staticCapacity.FillData5(aircraftEntity.Db);
+
+            string key = aircraftEntity.AircraftId;
+
+            if (!singleReport.ContainsKey(key))
+            {
+                singleReport[key] = new Dictionary<string, Dictionary<string, List<string>>>();
+            }
+
+            Dictionary<string, Dictionary<string, string>> staticReport = staticCapacity.GetReport5();
+            foreach (var kv in staticReport)
+            {
+                if (!singleReport[key].ContainsKey(kv.Key)) singleReport[key][kv.Key] = new Dictionary<string, List<string>>();
+                foreach (var kv2 in kv.Value)
+                {
+                    if (!singleReport[key][kv.Key].ContainsKey(kv2.Key)) singleReport[key][kv.Key][kv2.Key] = new List<string>();
+                    singleReport[key][kv.Key][kv2.Key].Add(kv2.Value);
+                }
+            }
+        }
+        if (currentExecuteCount == ExecutionContext)
+        {
+            foreach (var kv in singleReport)
+            {
+                foreach (var kv2 in kv.Value)
+                {
+                    foreach (var kv3 in kv2.Value)
+                    {
+                        var sum = 0f;
+                        foreach (var kv4 in kv3.Value)
+                        {
+                            bool isfloat = float.TryParse(kv4, out float f);
+                            if (isfloat)
+                                sum += float.Parse(kv4);
+                            else
+                                sum = -1f;
+                        }
+                        if (sum != -1f)
+                            kv3.Value.Add((sum / kv3.Value.Count).ToString());
+                        else
+                            kv3.Value.Add("");
+                    }
+                }
+            }
+        }
+    }
+
+    public void ReportSJ()
+    {
+        string data = DateTime.Now.ToString("yyyy-MM-dd");
+        string path = $"Reports/机降救援任务/{data}/{MissionId}"; //作为海上/陆上搜救子任务需生成实验报告,路径不确定,需判断跟随谁
+        if (!Directory.Exists(path)) Directory.CreateDirectory(path);
+        foreach (var kv in singleReport)
+        {
+            string filePath = $"{path}/{kv.Key}搜救任务单机指标报告.xls";
+            DataTableExtensions.SaveToExcel(filePath, kv.Value, true);
+        }
+    }
+}
+
+
+[ObjectSystem]
+public class JJJYMissionUpdateSystem : UpdateSystem<JJJYMission>
+{
+    public override void Update(JJJYMission self)
+    {
+        if (!self.IsRunning) return;
+
+        self.aircrafts?.ForEach(a => a.Update(self.SimulationTime));
+
+        if (self.aircrafts.All(a => a.IsOver))
+        {
+            self.EndMission();
+        }
+    }
+}

+ 177 - 0
SimulationServer/Entity/SHJMission.cs

@@ -0,0 +1,177 @@
+using KYFramework;
+using NPOI.SS.Formula.PTG;
+using SimulationServer.Utils;
+
+namespace SimulationServer;
+
+public class SHJMission : Entity
+{
+    public string MissionId; // 任务ID
+    public bool Success; // 任务是否成功
+    public List<AircraftSHJ> aircrafts = new List<AircraftSHJ>();
+
+    public bool IsRunning;
+    public double SimulationTime;
+
+    public Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>> singleReport = new();
+
+    public Dictionary<string, Dictionary<string, List<string>>> aircraftSJDatas = new();
+
+    public bool IsOver = false;
+
+    private int currentExecuteCount = 1;
+    public int ExecutionContext = 0;
+    public void Start()
+    {
+        IsRunning = true;
+        aircrafts.ForEach(a => a.Start());
+        Log.Info($"{MissionId} 任务开始!");
+    }
+
+    public void Reset()
+    {
+        SimulationTime = 0;
+        aircrafts?.ForEach(a => a.Reset());
+    }
+
+    public void EndMission()
+    {
+        IsRunning = false;
+        Log.Info($"{MissionId} 任务结束!");
+
+        if (currentExecuteCount > ExecutionContext)
+        {
+            return;
+        }
+
+        if (currentExecuteCount < ExecutionContext)
+        {
+            SaveSJ();
+            SaveAircraftSJDatas();
+        }
+
+        if (currentExecuteCount == ExecutionContext)
+        {
+            SaveSJ();
+            SaveAircraftSJDatas();
+            ReportSJ();
+            IsOver = true;
+            return;
+        }
+
+        this.Reset();
+        this.Start();
+        currentExecuteCount++;
+    }
+
+    public void SaveAircraftSJDatas()
+    {
+        foreach (AircraftSHJ aircraftEntity in aircrafts)
+        {
+            string key = aircraftEntity.AircraftId;
+            if (!aircraftSJDatas.ContainsKey(key))
+            {
+                aircraftSJDatas[key] = new Dictionary<string, List<string>>();
+            }
+            if (!aircraftSJDatas[key].ContainsKey("识别成功率"))
+                aircraftSJDatas[key]["识别成功率"] = new List<string>();
+            aircraftSJDatas[key]["识别成功率"].Add("0");
+            if (!aircraftSJDatas[key].ContainsKey("任务准备时间"))
+                aircraftSJDatas[key]["任务准备时间"] = new List<string>();
+            aircraftSJDatas[key]["任务准备时间"].Add(aircraftEntity.TaskReadyTime.ToString());
+            if (!aircraftSJDatas[key].ContainsKey("平均搜索时间"))
+                aircraftSJDatas[key]["平均搜索时间"] = new List<string>();
+            aircraftSJDatas[key]["平均搜索时间"].Add("0");
+            if (!aircraftSJDatas[key].ContainsKey("总飞行时间"))
+                aircraftSJDatas[key]["总飞行时间"] = new List<string>();
+            aircraftSJDatas[key]["总飞行时间"].Add(aircraftEntity.TotalTime.ToString());
+            if (!aircraftSJDatas[key].ContainsKey("人员存活率"))
+                aircraftSJDatas[key]["人员存活率"] = new List<string>();
+            aircraftSJDatas[key]["人员存活率"].Add(aircraftEntity.Success ? "1" : "0");
+        }
+    }
+
+    public void SaveSJ()
+    {
+        foreach (AircraftSHJ aircraftEntity in aircrafts)
+        {
+            var staticCapacity = aircraftEntity.GetComponent<SJStaticCapacityComponent>();
+
+            if (staticCapacity == null) continue;
+
+            staticCapacity.FillData6(aircraftEntity.Db);
+
+            string key = aircraftEntity.AircraftId;
+
+            if (!singleReport.ContainsKey(key))
+            {
+                singleReport[key] = new Dictionary<string, Dictionary<string, List<string>>>();
+            }
+
+            Dictionary<string, Dictionary<string, string>> staticReport = staticCapacity.GetReport6();
+            foreach (var kv in staticReport)
+            {
+                if (!singleReport[key].ContainsKey(kv.Key)) singleReport[key][kv.Key] = new Dictionary<string, List<string>>();
+                foreach (var kv2 in kv.Value)
+                {
+                    if (!singleReport[key][kv.Key].ContainsKey(kv2.Key)) singleReport[key][kv.Key][kv2.Key] = new List<string>();
+                    singleReport[key][kv.Key][kv2.Key].Add(kv2.Value);
+                }
+            }
+        }
+        if (currentExecuteCount == ExecutionContext)
+        {
+            foreach (var kv in singleReport)
+            {
+                foreach (var kv2 in kv.Value)
+                {
+                    foreach (var kv3 in kv2.Value)
+                    {
+                        var sum = 0f;
+                        foreach (var kv4 in kv3.Value)
+                        {
+                            bool isfloat = float.TryParse(kv4, out float f);
+                            if (isfloat)
+                                sum += float.Parse(kv4);
+                            else
+                                sum = -1f;
+                        }
+                        if (sum != -1f)
+                            kv3.Value.Add((sum / kv3.Value.Count).ToString());
+                        else
+                            kv3.Value.Add("");
+                    }
+                }
+            }
+        }
+    }
+
+    public void ReportSJ()
+    {
+        string data = DateTime.Now.ToString("yyyy-MM-dd");
+        string path = $"Reports/索滑降救援任务/{data}/{MissionId}"; //作为海上/陆上搜救子任务需生成实验报告,路径不确定,需判断跟随谁
+        if (!Directory.Exists(path)) Directory.CreateDirectory(path);
+        foreach (var kv in singleReport)
+        {
+            string filePath = $"{path}/{kv.Key}搜救任务单机指标报告.xls";
+            DataTableExtensions.SaveToExcel(filePath, kv.Value, true);
+        }
+    }
+}
+
+
+[ObjectSystem]
+public class SHJMissionUpdateSystem : UpdateSystem<SHJMission>
+{
+    public override void Update(SHJMission self)
+    {
+        if (!self.IsRunning) return;
+
+        self.aircrafts?.ForEach(a => a.Update(self.SimulationTime));
+
+        if (self.aircrafts.All(a => a.IsOver))
+        {
+            self.EndMission();
+        }
+    }
+}

+ 107 - 1
SimulationServer/EventHandler/CreateTaskEventHandler.cs

@@ -176,7 +176,7 @@ public class CreateZCTaskEventHandler : AEvent<CreateZCTask>
             aircraft.AircraftId = config.ZCTask.aircraftInfos[i].AircraftId;
             foreach (var item in config.ZCTask.ZCMethods)
             {
-                if(aircraft.AircraftId == item.AircraftId)
+                if (aircraft.AircraftId == item.AircraftId)
                 {
                     aircraft.ZCMethod = item;
                 }
@@ -518,4 +518,110 @@ public class CreateLandSJEventHandler : AEvent<CreateLandSXTask>
             return UniTask.CompletedTask;
         }
     }
+
+    [Event]
+    public class CreateJJJYEventHandler : AEvent<CreateJJJYTask>
+    {
+        protected override UniTask Run(CreateJJJYTask config)
+        {
+            var taskSys = Game.Scene.GetComponent<TaskComponent>();
+            JJJYMission mission = ComponentFactory.Create<JJJYMission>();
+            taskSys.JJJYMissions.Add(mission);
+            mission.MissionId = $"机降救援任务 {config.JJJYTask.missionInformation.MissionName}";
+            mission.ExecutionContext = config.EditorConfig.runCounts;
+            //mission.AddComponent<SJTotalTaskPerformanceComponent>();
+            for (int i = 0; i < config.JJJYTask.aircraftInfos.Length; i++)
+            {
+                //飞机参数
+                var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
+                    a => a.AircraftID == config.JJJYTask.aircraftInfos[i].AircraftType);
+                //基地
+                var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
+
+                TargetPoint targetPoint = config.EditorConfig.targetPoints.Find(t => t.TargetPointId == config.JJJYTask.missionInformation.TargetPointId);
+
+                //创建飞行计划编辑器
+                var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, new TargetPoint[] { targetPoint });
+
+                AircraftJJ aircraft = ComponentFactory.Create<AircraftJJ, FlightPlanEditor>(flightPlanEditor);
+                aircraft.Name = config.JJJYTask.aircraftInfos[i].AircraftType;
+                aircraft.TaskReadyTime = config.JJJYTask.missionInformation.TakeoffPreparationTime;
+                mission.aircrafts.Add(aircraft);
+                aircraft.taskContent = config.JJJYTask;
+                aircraft.AircraftId = config.JJJYTask.aircraftInfos[i].AircraftId;
+                aircraft.rescueDemandInfo = config.EditorConfig.rescueDemandInfos.Find(t => t.DemandPointName == config.JJJYTask.missionInformation.TargetPoint);
+                //aircraft.MissionEndPoint = new MissionEndPoint
+                //{
+                //    MissionEndPointLongitude = targetPoint.TargetPointLongitude,
+                //    MissionEndPointLatitude = targetPoint.TargetPointLatitude,
+                //    MissionEndPointHeight = targetPoint.TargetPointHeight
+                //};
+
+                foreach (var item in config.JJJYTask.JJJYParameters)
+                {
+                    if (item.AircraftId == aircraft.AircraftId)
+                    {
+                        aircraft.taskParameter = item;
+                    }
+                }
+
+                aircraft.AddComponent<SJStaticCapacityComponent>();
+                Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
+            }
+
+            return UniTask.CompletedTask;
+        }
+    }
+
+    [Event]
+    public class CreateSHJEventHandler : AEvent<CreateSHJTask>
+    {
+        protected override UniTask Run(CreateSHJTask config)
+        {
+            var taskSys = Game.Scene.GetComponent<TaskComponent>();
+            SHJMission mission = ComponentFactory.Create<SHJMission>();
+            taskSys.SHJMissions.Add(mission);
+            mission.MissionId = $"索滑降救援任务 {config.SHJTask.missionInformation.MissionName}";
+            mission.ExecutionContext = config.EditorConfig.runCounts;
+            //mission.AddComponent<SJTotalTaskPerformanceComponent>();
+            for (int i = 0; i < config.SHJTask.aircraftInfos.Length; i++)
+            {
+                //飞机参数
+                var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
+                    a => a.AircraftID == config.SHJTask.aircraftInfos[i].AircraftType);
+                //基地
+                var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
+
+                TargetPoint targetPoint = config.EditorConfig.targetPoints.Find(t => t.TargetPointId == config.SHJTask.missionInformation.TargetPointId);
+
+                //创建飞行计划编辑器
+                var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, new TargetPoint[] { targetPoint });
+                AircraftSHJ aircraft = ComponentFactory.Create<AircraftSHJ, FlightPlanEditor>(flightPlanEditor);
+                aircraft.Name = config.SHJTask.aircraftInfos[i].AircraftType;
+                aircraft.TaskReadyTime = config.SHJTask.missionInformation.TakeoffPreparationTime;
+                mission.aircrafts.Add(aircraft);
+                aircraft.content = config.SHJTask;
+                aircraft.AircraftId = config.SHJTask.aircraftInfos[i].AircraftId;
+                aircraft.missionEndPoint = new MissionEndPoint
+                {
+                    MissionEndPointLongitude = targetPoint.TargetPointLongitude,
+                    MissionEndPointLatitude = targetPoint.TargetPointLatitude,
+                    MissionEndPointHeight = targetPoint.TargetPointHeight
+                };
+
+                foreach (var item in config.SHJTask.SHJParameters)
+                {
+                    if (item.AircraftId == aircraft.AircraftId)
+                    {
+                        aircraft.SHJParameter = item;
+                    }
+                }
+
+                aircraft.AddComponent<SJStaticCapacityComponent>();
+                Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
+            }
+
+            return UniTask.CompletedTask;
+        }
+    }
 }

+ 47 - 47
SimulationServer/EventHandler/ServerStartEventHandler.cs

@@ -96,50 +96,50 @@ public class ServerStartEventHandler : AEvent<ServerStart>
         //    { EditorConfig = editorConfig, XHTask = xhTask });
         //}
         //Console.WriteLine("taskConfig.seaSouJiuTasks.Count:" + taskConfig.seaSouJiuTasks.Count);
-        //创建搜救
-        foreach (var seaSJTask in taskConfig.seaSouJiuTasks)
-        {
-            //Console.WriteLine("seaSJTask.missionInformation.MissionName:" + seaSJTask.missionInformation.MissionName);
-            //Console.WriteLine("TargetPointId:" + seaSJTask.TargetPointId);
-            //Console.WriteLine("SearchPayload:" + seaSJTask.SearchPayload);
-            //Console.WriteLine("SearchMode:" + seaSJTask.SearchMode);
-            //Console.WriteLine("RadarTransmitterPower:" + seaSJTask.RadarTransmitterPower);
-            //Console.WriteLine("仿真次数:" + editorConfig.runCounts);
-            Game.EventSystem.Publish(new CreateSeaSJTask
-            { EditorConfig = editorConfig, SeaSJTask = seaSJTask });
-            //break;
-        }
+        ////创建搜救
+        //foreach (var seaSJTask in taskConfig.seaSouJiuTasks)
+        //{
+        //    //Console.WriteLine("seaSJTask.missionInformation.MissionName:" + seaSJTask.missionInformation.MissionName);
+        //    //Console.WriteLine("TargetPointId:" + seaSJTask.TargetPointId);
+        //    //Console.WriteLine("SearchPayload:" + seaSJTask.SearchPayload);
+        //    //Console.WriteLine("SearchMode:" + seaSJTask.SearchMode);
+        //    //Console.WriteLine("RadarTransmitterPower:" + seaSJTask.RadarTransmitterPower);
+        //    //Console.WriteLine("仿真次数:" + editorConfig.runCounts);
+        //    Game.EventSystem.Publish(new CreateSeaSJTask
+        //    { EditorConfig = editorConfig, SeaSJTask = seaSJTask });
+        //    //break;
+        //}
 
-        foreach (var landSXTask in taskConfig.LandSouXunTasks)
-        {
-            Game.EventSystem.Publish(new CreateLandSXTask
-            { EditorConfig = editorConfig, LandSXTask = landSXTask });
-            //break;
-        }
+        //foreach (var landSXTask in taskConfig.LandSouXunTasks)
+        //{
+        //    Game.EventSystem.Publish(new CreateLandSXTask
+        //    { EditorConfig = editorConfig, LandSXTask = landSXTask });
+        //    //break;
+        //}
 
-        //创建空中吊运救援任务
-        foreach (var KZDYTask in taskConfig.KZDYTasks)
-        {
-            Game.EventSystem.Publish(new CreateKZDYTask
-            { EditorConfig = editorConfig, KZDYTask = KZDYTask });
-            //break;
-        }
+        ////创建空中吊运救援任务
+        //foreach (var KZDYTask in taskConfig.KZDYTasks)
+        //{
+        //    Game.EventSystem.Publish(new CreateKZDYTask
+        //    { EditorConfig = editorConfig, KZDYTask = KZDYTask });
+        //    //break;
+        //}
 
-        //创建空投空送任务
-        foreach (var KTKSTask in taskConfig.KTKSTasks)
-        {
-            Game.EventSystem.Publish(new CreateKTKSTask
-            { EditorConfig = editorConfig, KTKSTask = KTKSTask });
-            //break;
-        }
+        ////创建空投空送任务
+        //foreach (var KTKSTask in taskConfig.KTKSTasks)
+        //{
+        //    Game.EventSystem.Publish(new CreateKTKSTask
+        //    { EditorConfig = editorConfig, KTKSTask = KTKSTask });
+        //    //break;
+        //}
 
-        //创建着水救援任务
-        foreach (var ZSJYTask in taskConfig.ZSJYTasks)
-        {
-            Game.EventSystem.Publish(new CreateZSJYTask
-            { EditorConfig = editorConfig, ZSJYTask = ZSJYTask });
-            //break;
-        }
+        ////创建着水救援任务
+        //foreach (var ZSJYTask in taskConfig.ZSJYTasks)
+        //{
+        //    Game.EventSystem.Publish(new CreateZSJYTask
+        //    { EditorConfig = editorConfig, ZSJYTask = ZSJYTask });
+        //    //break;
+        //}
 
         ////创建机降救援任务
         //foreach (var JJJYTask in taskConfig.JJJYTasks)
@@ -149,13 +149,13 @@ public class ServerStartEventHandler : AEvent<ServerStart>
         //    //break;
         //}
 
-        ////创建索滑降救援任务
-        //foreach (var SHJTask in taskConfig.SHJTasks)
-        //{
-        //    Game.EventSystem.Publish(new CreateSHJTask
-        //    { EditorConfig = editorConfig, SHJTask = SHJTask });
-        //    //break;
-        //}
+        //创建索滑降救援任务
+        foreach (var SHJTask in taskConfig.SHJTasks)
+        {
+            Game.EventSystem.Publish(new CreateSHJTask
+            { EditorConfig = editorConfig, SHJTask = SHJTask });
+            //break;
+        }
 
         taskSys.ExecutionContext = editorConfig.runCounts;
         taskSys.Start();

BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.dll


BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.exe


BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.pdb