Browse Source

添加医疗三个子任务脚本

liyang 3 months ago
parent
commit
86e13a2e2b

+ 12 - 0
Models/SimulationCommon/FlightPlanEditor.cs

@@ -22,6 +22,8 @@ public class FlightPlanEditor
     public TargetPoint[] targetpoint = new TargetPoint[1];
     [JsonProperty("医疗目标初始点")]
     public MedicalTargetPoint[] medicalTargetPoint = new MedicalTargetPoint[1];
+    [JsonProperty("医疗物品初始点")]
+    public MedicalSuppliesInfo[] medicalSuppliesInfo = new MedicalSuppliesInfo[1];
 
     public static FlightPlanEditor Create(AircraftParameter aircraftparameter, CityWeather cityweather, Base originbase, AirRoute[] airroute, MissionPoint missionpoint, FirePoint[] firepoint)
     {
@@ -64,6 +66,16 @@ public class FlightPlanEditor
         flightPlanEditor.medicalTargetPoint = targetPoints;
         return flightPlanEditor;
     }
+
+    public static FlightPlanEditor Create(AircraftParameter aircraftparameter, CityWeather cityweather, Base originbase, MedicalSuppliesInfo[] targetPoints)
+    {
+        FlightPlanEditor flightPlanEditor = new FlightPlanEditor();
+        flightPlanEditor.aircraftparameter = aircraftparameter;
+        flightPlanEditor.cityweather = cityweather;
+        flightPlanEditor.originbase = originbase;
+        flightPlanEditor.medicalSuppliesInfo = targetPoints;
+        return flightPlanEditor;
+    }
 }
 
 

+ 3 - 0
SimulationServer/Component/TaskComponent.cs

@@ -64,6 +64,7 @@ public class TaskComponent : Component
         ZSJYMissions?.ForEach(r => r.Start());
         JJJYMissions?.ForEach(r => r.Start());
         SHJMissions?.ForEach(r => r.Start());
+
         XCJJMissions?.ForEach(r => r.Start());
         YLZYMissions?.ForEach(r => r.Start());
         YLWPYSMissions?.ForEach(r => r.Start());
@@ -217,6 +218,7 @@ public class TaskComponentAwakeSystem : AwakeSystem<TaskComponent>
         self.ZSJYMissions = new List<ZSJYMission>();
         self.JJJYMissions = new List<JJJYMission>();
         self.SHJMissions = new List<SHJMission>();
+
         self.XCJJMissions = new List<XCJJMission>();
         self.YLZYMissions = new List<YLZYMission>();
         self.YLWPYSMissions = new List<YLWPYSMission>();
@@ -250,6 +252,7 @@ public class TaskComponentUpdateSystem : UpdateSystem<TaskComponent>
     public bool isZSJYMissionsOver = false;
     public bool isJJJYMissionsOver = false;
     public bool isSHJMissionsOver = false;
+
     public bool isXCJJMissionsOver = false;
     public bool isYLZYMissionsOver = false;
     public bool isYLWPYSMissionsOver = false;

+ 1 - 1
SimulationServer/Entity/AircraftEntity.cs

@@ -38,7 +38,7 @@ public class AircraftEntity : Entity
     public void Awake()
     {
         Db = Util.GetAircraftDefine(FlightPlanEditor.aircraftparameter.AircraftType, FlightPlanEditor.aircraftparameter.AircraftSubType, FlightPlanEditor.aircraftparameter.AircraftID);
-        ylDb = Util.GetYL(FlightPlanEditor.aircraftparameter.AircraftType, FlightPlanEditor.aircraftparameter.AircraftSubType, FlightPlanEditor.aircraftparameter.AircraftID);
+        //ylDb = Util.GetYL(FlightPlanEditor.aircraftparameter.AircraftType, FlightPlanEditor.aircraftparameter.AircraftSubType, FlightPlanEditor.aircraftparameter.AircraftID);
 
         if (Db.f_zdqfzl != null)
             FlightPlanEditor.aircraftparameter.MaxTakeoffWeight = double.Parse(Db.f_zdqfzl.ToString());

+ 179 - 0
SimulationServer/Entity/AircraftYLWPYS.cs

@@ -0,0 +1,179 @@
+using KYFramework;
+using MathNet.Numerics.Distributions;
+using Model;
+using MongoDB.Bson;
+using SimulationCommon;
+using SimulationServer.Utils;
+
+namespace SimulationServer;
+
+public class AircraftYLWPYS : AircraftEntity
+{
+    public YLWPYSTask taskContent;
+    public MissionEndPoint MissionEndPoint;
+    public bool IsOver;
+    public bool Success;
+    public TaskParameter taskParameter;
+    public GetNCData getNCData;
+    public double resulttime;
+
+    public bool isReadNC;
+
+    Text_readNC text_ReadNC;
+
+    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()
+    {
+        if (!isReadNC)
+        {
+            getNCData = new GetNCData();
+            getNCData.initlatitudes = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLatitude;
+            getNCData.initlongitudes = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLongitude;
+            bool isSuccess3 = false;
+            while (!isSuccess3)
+            {
+                isSuccess3 = getNCData.GetData();
+            }
+            text_ReadNC = new Text_readNC();
+            text_ReadNC.initlatitudes = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLatitude;
+            text_ReadNC.initlongitudes = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLongitude;
+            bool isSuccess = false;
+            while (!isSuccess)
+            {
+                isSuccess = text_ReadNC.GetNCData();
+            }
+            isReadNC = true;
+        }
+
+        int hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
+        int Day = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].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);
+
+        FlightPlanEditor.missionpoint.MissionPointLatitude = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLatitude;
+        FlightPlanEditor.missionpoint.MissionPointLongitude = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLongitude;
+        FlightPlanEditor.missionpoint.MissionPointHeight = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointHeight;
+        Console.WriteLine("Latitude:" + FlightPlanEditor.missionpoint.MissionPointLatitude + "_" + "Longitude:" + FlightPlanEditor.missionpoint.MissionPointLongitude + "_" + "Height:" + FlightPlanEditor.missionpoint.MissionPointHeight);
+
+        FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
+
+        //// 吊运上升速度  吊运下降速度 Task文件读取 // Editor里读天气根据时间
+        //resulttime = get_result_time_rope(taskParameter.Height, taskParameter.liftPersonnel, windSpeed, vis, taskParameter.liftUpSpeed, taskParameter.liftDownSpeed).time;//索滑降模型输出的索滑降时间
+        //Console.WriteLine("resulttime:" + resulttime);
+        //FXJHGenerate.SuoHuaJiang(resulttime, FlightPlanEditor, ref TurningPoints);
+
+        FXJHGenerate.FromMissionToEnd(FlightPlanEditor, FXJHGenerate.SuoHuaJiangMissionEndPoint(FlightPlanEditor), ref TurningPoints);
+        FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
+
+        // 飞到目标点时间与人员存活时间做对比  有一个人活着,整个任务成功
+        double time = 0;
+        for (int i = 0; i < TurningPoints.Count - 1; i++)
+        {
+            time += TurningPoints[i].SegmentFlightTime; // 判断幸存-1
+        }
+        //Console.WriteLine("time:" + time); 
+
+        for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
+        {
+            TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间   //仿真轮次1 数值1
+        }
+        Console.WriteLine("TotalTime:" + TotalTime);
+
+        IsOver = true;
+        End();
+    }
+
+    // 吊运函数
+    public static handling_result get_result_time_rope(double H, int person_number, double windspeed, double vis, double upspeed, double downspeed)
+    {
+
+        handling_result result = new handling_result();
+
+        if (windspeed < 8 && vis > 3)
+        {
+            result.time = (person_number * H) / downspeed + (person_number * H) / upspeed;
+            result.success = true;
+        }
+        else
+        {
+            result.success = false;
+        }
+        return result;
+    }
+
+    public string TargetQiXiangInfoSave(string s, int hour)
+    {
+        string result = hour.ToString() + "-" + s;
+        for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetQiXiangInfos.Length; i++)
+        {
+
+        }
+        switch (s)
+        {
+            case "温度":
+
+                break;
+            case "湿度":
+
+                break;
+            case "能见度":
+
+                break;
+            case "风速":
+
+                break;
+            case "风向":
+
+                break;
+            case "天气":
+
+                break;
+        }
+        return result;
+    }
+
+    public static int GetDaysInYear(int year, int month, int day)
+    {
+        int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+        if (IsLeapYear(year))
+        {
+            daysInMonths[1] = 29;
+        }
+        int days = day;
+        for (int i = 0; i < month - 1; i++)
+        {
+            days += daysInMonths[i];
+        }
+        return days;
+    }
+
+    public static bool IsLeapYear(int year)
+    {
+        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
+    }
+}
+
+[ObjectSystem]
+public class AircraftYLWPYSAwakeSystem : AwakeSystem<AircraftYLWPYS, FlightPlanEditor>
+{
+    public override void Awake(AircraftYLWPYS self, FlightPlanEditor flightPlanEditor)
+    {
+        self.FlightPlanEditor = flightPlanEditor;
+        self.Awake();
+    }
+}

+ 358 - 0
SimulationServer/Entity/AircraftYLZY.cs

@@ -0,0 +1,358 @@
+using KYFramework;
+using MathNet.Numerics.Distributions;
+using Model;
+using MongoDB.Bson;
+using SimulationCommon;
+using SimulationServer.Utils;
+
+namespace SimulationServer;
+
+public class AircraftYLZY : AircraftEntity
+{
+    public YLZYTask taskContent;
+    public MissionEndPoint MissionEndPoint;
+    public bool IsOver;
+    public bool Success;
+    public TaskParameter taskParameter;
+    public GetNCData getNCData;
+    public double resulttime;
+
+    public bool isReadNC;
+
+    Text_readNC text_ReadNC;
+
+    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()
+    {
+        if (!isReadNC)
+        {
+            getNCData = new GetNCData();
+            getNCData.initlatitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
+            getNCData.initlongitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
+            bool isSuccess3 = false;
+            while (!isSuccess3)
+            {
+                isSuccess3 = getNCData.GetData();
+            }
+            text_ReadNC = new Text_readNC();
+            text_ReadNC.initlatitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
+            text_ReadNC.initlongitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
+            bool isSuccess = false;
+            while (!isSuccess)
+            {
+                isSuccess = text_ReadNC.GetNCData();
+            }
+            isReadNC = true;
+        }
+
+        int hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
+        int Day = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].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);
+
+        FlightPlanEditor.missionpoint.MissionPointLatitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
+        FlightPlanEditor.missionpoint.MissionPointLongitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
+        FlightPlanEditor.missionpoint.MissionPointHeight = FlightPlanEditor.medicalTargetPoint[0].TargetPointHeight;
+        Console.WriteLine("Latitude:" + FlightPlanEditor.missionpoint.MissionPointLatitude + "_" + "Longitude:" + FlightPlanEditor.missionpoint.MissionPointLongitude + "_" + "Height:" + FlightPlanEditor.missionpoint.MissionPointHeight);
+
+        FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
+
+        //// 吊运上升速度  吊运下降速度 Task文件读取 // Editor里读天气根据时间
+        //resulttime = get_result_time_rope(taskParameter.Height, taskParameter.liftPersonnel, windSpeed, vis, taskParameter.liftUpSpeed, taskParameter.liftDownSpeed).time;//索滑降模型输出的索滑降时间
+        //Console.WriteLine("resulttime:" + resulttime);
+        //FXJHGenerate.SuoHuaJiang(resulttime, FlightPlanEditor, ref TurningPoints);
+
+        FXJHGenerate.FromMissionToEnd(FlightPlanEditor, FXJHGenerate.SuoHuaJiangMissionEndPoint(FlightPlanEditor), ref TurningPoints);
+        FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
+
+        // 飞到目标点时间与人员存活时间做对比  有一个人活着,整个任务成功
+        double time = 0;
+        for (int i = 0; i < TurningPoints.Count - 1; i++)
+        {
+            time += TurningPoints[i].SegmentFlightTime; // 判断幸存-1
+        }
+        //Console.WriteLine("time:" + time); 
+
+        int patientCount = FlightPlanEditor.medicalTargetPoint[0].TargetType.Count; // 伤患人数
+        List<string> diseaseTypes = new List<string>();
+        for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes.Length; i++)
+        {
+            diseaseTypes.Add(FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes[i]);
+        }
+        int medicCount = taskParameter.doctorPersonnel + taskParameter.nursePersonnel + taskParameter.nurseSeverePersonnel; // 医护人员数量  
+
+        // 交接时间为5分钟  
+        double handoverTime = 5;
+
+        // 计算总急救时间  
+        double totalEmergencyTime = CalculateTotalEmergencyTime(diseaseTypes);
+
+        // 计算平均急救时间(每个医护人员分担的时间)  
+        double averageEmergencyTimePerMedic = totalEmergencyTime / medicCount;
+
+        // 计算总时间(平均急救时间 + 交接时间)  
+        double totalTime = averageEmergencyTimePerMedic + handoverTime;
+
+        Console.WriteLine($"总急救时间(平均每个医护人员): {averageEmergencyTimePerMedic} 分钟");
+        Console.WriteLine($"总时间(包括交接时间): {totalTime} 分钟");
+
+        Random rand = new Random();
+        List<Patient> patients = new List<Patient>();
+        for (int i = 0; i < patientCount; i++)
+        {
+            patients.Add(new Patient()
+            {
+                Id = i + 1,
+                DiseaseType = diseaseTypes[i],
+                GoldenHour = 0
+            });
+        }
+
+        patients = MedicalRescue.ProcessPatients(patients, rand);
+
+        // 对患者进行排序  
+        var sortedPatients = patients.OrderBy(p => DiseasePriorityService.GetPriority(p.DiseaseType))
+                                    .ThenBy(p => p.GoldenHour)
+                                    .ToList();
+
+        // 输出排序后的患者列表    // 从是事故点到医院的飞行时间 + 5分钟的交接时间 < 黄金时间 ? 成功:失败
+        foreach (var patient in sortedPatients)
+        {
+            Console.WriteLine($"sortedPatients ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {patient.GoldenHour:F2}");
+        }
+
+        // 注意:实际项目中,每次转运一名伤员的操作可能涉及更多的逻辑,比如更新数据库中的转运状态等。  
+
+
+        for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
+        {
+            TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间   //仿真轮次1 数值1
+        }
+        Console.WriteLine("TotalTime:" + TotalTime);
+
+        IsOver = true;
+        End();
+    }
+
+    static double CalculateTotalEmergencyTime(List<string> diseaseTypes)
+    {
+        double totalTime = 0;
+
+        // 这里假设有一个方法GetEmergencyTimeFromDatabase,它根据疾病类型从数据库获取急救时间,此处应为从数据库中读取
+        foreach (var diseaseType in diseaseTypes)
+        {
+            double emergencyTime = GetEmergencyTimeFromDatabase(diseaseType);
+            totalTime += emergencyTime;
+        }
+
+        return totalTime;
+    }
+
+    // 模拟从数据库获取急救时间的方法  
+    static double GetEmergencyTimeFromDatabase(string diseaseType)
+    {
+        // 这里应该是实际的数据库查询逻辑  
+        // 但为了示例,我们直接返回一个模拟值  
+        switch (diseaseType)
+        {
+            case "aa": //HeartAttack
+                return 2; // 心脏病急救时间为2分钟  
+            case "bb": //Stroke
+                return 5; // 中风急救时间为5分钟  
+            case "cc": //Trauma
+                return 10; // 创伤急救时间为10分钟  
+            case "dd":
+                return 15;
+            case "ee":
+                return 20;
+            default:
+                return 0;
+        }
+    }
+
+    // 假设从前端接收到的数据结构  
+    public class Patient
+    {
+        public int Id { get; set; }
+        public string DiseaseType { get; set; }
+        public double GoldenHour { get; set; } // 患者的黄金救援时间应由黄金救援时间程序获得
+    }
+
+    public class DiseaseInfo
+    {
+        public string DiseaseType { get; set; }
+        public double MinGoldenHour { get; set; }
+        public double MaxGoldenHour { get; set; }
+    }
+
+    public class MedicalRescue
+    {
+        private static Dictionary<string, DiseaseInfo> diseaseDatabase = new Dictionary<string, DiseaseInfo>
+        {
+            { "aa", new DiseaseInfo { DiseaseType = "aa", MinGoldenHour = 1, MaxGoldenHour = 3 } },
+            { "bb", new DiseaseInfo { DiseaseType = "bb", MinGoldenHour = 2, MaxGoldenHour = 4 } },
+            { "cc", new DiseaseInfo { DiseaseType = "cc", MinGoldenHour = 3, MaxGoldenHour = 5 } },
+            { "dd", new DiseaseInfo { DiseaseType = "dd", MinGoldenHour = 4, MaxGoldenHour = 6 } },
+            { "ee", new DiseaseInfo { DiseaseType = "ee", MinGoldenHour = 5, MaxGoldenHour = 7 } },  
+        // 添加更多疾病类型
+        };
+
+        public static List<Patient> ProcessPatients(List<Patient> patients, Random rand)
+        {
+            foreach (var patient in patients)
+            {
+                var diseaseInfo = GetDiseaseInfo(patient.DiseaseType); // MinGoldenHour MaxGoldenHour 数据库读取
+                double goldenHour = GenerateRandomGoldenHour(rand, diseaseInfo.MinGoldenHour, diseaseInfo.MaxGoldenHour);
+                Console.WriteLine($"Patient ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {goldenHour:F2}");
+                patient.GoldenHour = goldenHour;
+            }
+            return patients;
+        }
+
+        public static DiseaseInfo GetDiseaseInfo(string diseaseType)
+        {
+            if (diseaseDatabase.ContainsKey(diseaseType))
+            {
+                return diseaseDatabase[diseaseType];
+            }
+            throw new ArgumentException("Unknown disease type.");
+        }
+
+        public static double GenerateRandomGoldenHour(Random rand, double min, double max)
+        {
+            double mu = (max + min) / 2;
+            double sigma = (max - min) / 6;
+            var normal = new Normal(mu, sigma);
+            return normal.Sample();
+        }
+    }
+
+    // 假设数据库中的疾病优先级信息  
+    public class DiseasePriority
+    {
+        public string DiseaseType { get; set; }
+        public int Priority { get; set; } // 优先级,数字越小优先级越高  
+    }
+
+    // 静态类,包含与疾病优先级相关的静态方法  
+    public static class DiseasePriorityService
+    {
+        // 数据库查询(实际项目中应该是从数据库读取)  
+        public static List<DiseasePriority> GetDiseasePriorities()
+        {
+            return new List<DiseasePriority>
+            {
+                new DiseasePriority { DiseaseType = "aa", Priority = 5 },
+                new DiseasePriority { DiseaseType = "bb", Priority = 4 },
+                new DiseasePriority { DiseaseType = "cc", Priority = 3 },
+                new DiseasePriority { DiseaseType = "dd", Priority = 2 },
+                new DiseasePriority { DiseaseType = "ee", Priority = 5 },
+            };
+        }
+
+        // 根据疾病类型获取优先级  
+        public static int GetPriority(string diseaseType)
+        {
+            var priorities = GetDiseasePriorities().ToDictionary(dp => dp.DiseaseType, dp => dp.Priority);
+            if (priorities.TryGetValue(diseaseType, out int priority))
+            {
+                return priority;
+            }
+            return int.MaxValue; // 如果没有找到,返回一个很大的数作为默认优先级  
+        }
+    }
+
+    // 吊运函数
+    public static handling_result get_result_time_rope(double H, int person_number, double windspeed, double vis, double upspeed, double downspeed)
+    {
+
+        handling_result result = new handling_result();
+
+        if (windspeed < 8 && vis > 3)
+        {
+            result.time = (person_number * H) / downspeed + (person_number * H) / upspeed;
+            result.success = true;
+        }
+        else
+        {
+            result.success = false;
+        }
+        return result;
+    }
+
+    public string TargetQiXiangInfoSave(string s, int hour)
+    {
+        string result = hour.ToString() + "-" + s;
+        for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetQiXiangInfos.Length; i++)
+        {
+
+        }
+        switch (s)
+        {
+            case "温度":
+
+                break;
+            case "湿度":
+
+                break;
+            case "能见度":
+
+                break;
+            case "风速":
+
+                break;
+            case "风向":
+
+                break;
+            case "天气":
+
+                break;
+        }
+        return result;
+    }
+
+    public static int GetDaysInYear(int year, int month, int day)
+    {
+        int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+        if (IsLeapYear(year))
+        {
+            daysInMonths[1] = 29;
+        }
+        int days = day;
+        for (int i = 0; i < month - 1; i++)
+        {
+            days += daysInMonths[i];
+        }
+        return days;
+    }
+
+    public static bool IsLeapYear(int year)
+    {
+        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
+    }
+}
+
+[ObjectSystem]
+public class AircraftYLZYAwakeSystem : AwakeSystem<AircraftYLZY, FlightPlanEditor>
+{
+    public override void Awake(AircraftYLZY self, FlightPlanEditor flightPlanEditor)
+    {
+        self.FlightPlanEditor = flightPlanEditor;
+        self.Awake();
+    }
+}

+ 34 - 34
SimulationServer/Entity/YLWPYSMission.cs

@@ -9,7 +9,7 @@ public class YLWPYSMission : Entity
 {
     public string MissionId; // 任务ID
     public bool Success; // 任务是否成功
-    public List<AircraftDY> aircrafts = new List<AircraftDY>();
+    public List<AircraftYLWPYS> aircrafts = new List<AircraftYLWPYS>();
 
     public bool IsRunning;
     public double SimulationTime;
@@ -70,43 +70,43 @@ public class YLWPYSMission : Entity
 
     public void SaveAircraftSJDatas()
     {
-        foreach (AircraftDY 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("0");
-            if (!aircraftSJDatas[key].ContainsKey("人员数量"))
-                aircraftSJDatas[key]["人员数量"] = new List<string>();
-            aircraftSJDatas[key]["人员数量"].Add(aircraftEntity.targetCount.ToString());
-            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.resulttime.ToString());
-            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 ? aircraftEntity.targetCount.ToString() : "0");
-        }
+        //foreach (AircraftDY 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("0");
+        //    if (!aircraftSJDatas[key].ContainsKey("人员数量"))
+        //        aircraftSJDatas[key]["人员数量"] = new List<string>();
+        //    aircraftSJDatas[key]["人员数量"].Add(aircraftEntity.targetCount.ToString());
+        //    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.resulttime.ToString());
+        //    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 ? aircraftEntity.targetCount.ToString() : "0");
+        //}
     }
 
     public void SaveSJ()
     {
-        foreach (AircraftDY aircraftEntity in aircrafts)
+        foreach (AircraftYLWPYS aircraftEntity in aircrafts)
         {
             var staticCapacity = aircraftEntity.GetComponent<SJStaticCapacityComponent>();
 

+ 34 - 34
SimulationServer/Entity/YLZYMission.cs

@@ -9,7 +9,7 @@ public class YLZYMission : Entity
 {
     public string MissionId; // 任务ID
     public bool Success; // 任务是否成功
-    public List<AircraftDY> aircrafts = new List<AircraftDY>();
+    public List<AircraftYLZY> aircrafts = new List<AircraftYLZY>();
 
     public bool IsRunning;
     public double SimulationTime;
@@ -70,43 +70,43 @@ public class YLZYMission : Entity
 
     public void SaveAircraftSJDatas()
     {
-        foreach (AircraftDY 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("0");
-            if (!aircraftSJDatas[key].ContainsKey("人员数量"))
-                aircraftSJDatas[key]["人员数量"] = new List<string>();
-            aircraftSJDatas[key]["人员数量"].Add(aircraftEntity.targetCount.ToString());
-            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.resulttime.ToString());
-            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 ? aircraftEntity.targetCount.ToString() : "0");
-        }
+        //foreach (AircraftDY 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("0");
+        //    if (!aircraftSJDatas[key].ContainsKey("人员数量"))
+        //        aircraftSJDatas[key]["人员数量"] = new List<string>();
+        //    aircraftSJDatas[key]["人员数量"].Add(aircraftEntity.targetCount.ToString());
+        //    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.resulttime.ToString());
+        //    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 ? aircraftEntity.targetCount.ToString() : "0");
+        //}
     }
 
     public void SaveSJ()
     {
-        foreach (AircraftDY aircraftEntity in aircrafts)
+        foreach (AircraftYLZY aircraftEntity in aircrafts)
         {
             var staticCapacity = aircraftEntity.GetComponent<SJStaticCapacityComponent>();
 

+ 94 - 0
SimulationServer/EventHandler/CreateTaskEventHandler.cs

@@ -679,4 +679,98 @@ public class CreateLandSJEventHandler : AEvent<CreateLandSXTask>
             return UniTask.CompletedTask;
         }
     }
+
+    [Event]
+    public class CreateYLZYEventHandler : AEvent<CreateYLZYTask>
+    {
+        protected override UniTask Run(CreateYLZYTask config)
+        {
+            var taskSys = Game.Scene.GetComponent<TaskComponent>();
+            YLZYMission mission = ComponentFactory.Create<YLZYMission>();
+            mission.date = taskSys.date;
+            taskSys.YLZYMissions.Add(mission);
+            mission.MissionId = $"医疗转运任务 {config.YLZYTask.missionInformation.MissionName}";
+            mission.ExecutionContext = config.EditorConfig.runCounts;
+            //mission.AddComponent<SJTotalTaskPerformanceComponent>();
+            for (int i = 0; i < config.YLZYTask.aircraftInfos.Length; i++)
+            {
+                //飞机参数
+                var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
+                    a => a.AircraftID == config.YLZYTask.aircraftInfos[i].AircraftType);
+                //基地
+                var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
+
+                MedicalTargetPoint targetPoint = config.EditorConfig.medicalTargetPoints.Find(t => t.TargetPointId == config.YLZYTask.missionInformation.TargetPointId);
+
+                //创建飞行计划编辑器
+                var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, new MedicalTargetPoint[] { targetPoint });
+                AircraftYLZY aircraft = ComponentFactory.Create<AircraftYLZY, FlightPlanEditor>(flightPlanEditor);
+                aircraft.Name = config.YLZYTask.aircraftInfos[i].AircraftType;
+                aircraft.TaskReadyTime = config.YLZYTask.missionInformation.TakeoffPreparationTime;
+                mission.aircrafts.Add(aircraft);
+                aircraft.taskContent = config.YLZYTask;
+                aircraft.AircraftId = config.YLZYTask.aircraftInfos[i].AircraftId;
+
+                foreach (var item in config.YLZYTask.YLZYParameters)
+                {
+                    if (item.AircraftId == aircraft.AircraftId)
+                    {
+                        aircraft.taskParameter = item;
+                    }
+                }
+
+                //aircraft.AddComponent<SJStaticCapacityComponent>();
+                Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
+            }
+
+            return UniTask.CompletedTask;
+        }
+    }
+
+    [Event]
+    public class CreateYLWPYSEventHandler : AEvent<CreateYLWPYSTask>
+    {
+        protected override UniTask Run(CreateYLWPYSTask config)
+        {
+            var taskSys = Game.Scene.GetComponent<TaskComponent>();
+            YLWPYSMission mission = ComponentFactory.Create<YLWPYSMission>();
+            mission.date = taskSys.date;
+            taskSys.YLWPYSMissions.Add(mission);
+            mission.MissionId = $"医疗物品运送 {config.YLWPYSTask.missionInformation.MissionName}";
+            mission.ExecutionContext = config.EditorConfig.runCounts;
+            //mission.AddComponent<SJTotalTaskPerformanceComponent>();
+            for (int i = 0; i < config.YLWPYSTask.aircraftInfos.Length; i++)
+            {
+                //飞机参数
+                var aircraftParameter = config.EditorConfig.aircraftParameters.Find(
+                    a => a.AircraftID == config.YLWPYSTask.aircraftInfos[i].AircraftType);
+                //基地
+                var originBase = config.EditorConfig.bases.Find(b => b.BaseId == aircraftParameter.AirportId);
+
+                MedicalSuppliesInfo targetPoint = config.EditorConfig.medicalSuppliesInfos.Find(t => t.TargetPointName == config.YLWPYSTask.missionInformation.TargetPoint);
+
+                //创建飞行计划编辑器
+                var flightPlanEditor = FlightPlanEditor.Create(aircraftParameter, config.EditorConfig.cityWeather, originBase, new MedicalSuppliesInfo[] { targetPoint });
+                AircraftYLWPYS aircraft = ComponentFactory.Create<AircraftYLWPYS, FlightPlanEditor>(flightPlanEditor);
+                aircraft.Name = config.YLWPYSTask.aircraftInfos[i].AircraftType;
+                aircraft.TaskReadyTime = config.YLWPYSTask.missionInformation.TakeoffPreparationTime;
+                mission.aircrafts.Add(aircraft);
+                aircraft.taskContent = config.YLWPYSTask;
+                aircraft.AircraftId = config.YLWPYSTask.aircraftInfos[i].AircraftId;
+
+                foreach (var item in config.YLWPYSTask.YLWPYSParameters)
+                {
+                    if (item.AircraftId == aircraft.AircraftId)
+                    {
+                        aircraft.taskParameter = item;
+                    }
+                }
+
+                //aircraft.AddComponent<SJStaticCapacityComponent>();
+                Log.Info($"创建机型 : {flightPlanEditor.aircraftparameter.AircraftID}");
+            }
+
+            return UniTask.CompletedTask;
+        }
+    }
 }

+ 1 - 1
SimulationServer/bin/Debug/net7.0/Missions/editor_config.json

@@ -1,5 +1,5 @@
 {
-    "仿真次数": 10,
+    "仿真次数": 1,
     "想定信息": {
         "想定日期": "2024年9月11日",
         "想定时间": "00时00分00秒"

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


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


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


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


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