AircraftYLWPYS.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using KYFramework;
  2. using MathNet.Numerics.Distributions;
  3. using Model;
  4. using MongoDB.Bson;
  5. using SimulationCommon;
  6. using SimulationServer.Utils;
  7. namespace SimulationServer;
  8. public class AircraftYLWPYS : AircraftEntity
  9. {
  10. public YLWPYSTask taskContent;
  11. public MissionEndPoint MissionEndPoint;
  12. public bool IsOver;
  13. public bool Success;
  14. public TaskParameter taskParameter;
  15. public GetNCData getNCData;
  16. public double resulttime;
  17. public bool isReadNC;
  18. Text_readNC text_ReadNC;
  19. public override void End()
  20. {
  21. TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
  22. }
  23. public override void Reset()
  24. {
  25. base.Reset();
  26. IsOver = false;
  27. Success = false;
  28. TotalTime = 0;
  29. }
  30. public override void Start()
  31. {
  32. if (!isReadNC)
  33. {
  34. getNCData = new GetNCData();
  35. getNCData.initlatitudes = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLatitude;
  36. getNCData.initlongitudes = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLongitude;
  37. bool isSuccess3 = false;
  38. while (!isSuccess3)
  39. {
  40. isSuccess3 = getNCData.GetData();
  41. }
  42. text_ReadNC = new Text_readNC();
  43. text_ReadNC.initlatitudes = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLatitude;
  44. text_ReadNC.initlongitudes = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLongitude;
  45. bool isSuccess = false;
  46. while (!isSuccess)
  47. {
  48. isSuccess = text_ReadNC.GetNCData();
  49. }
  50. isReadNC = true;
  51. }
  52. int hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
  53. int Day = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].Split("日")[0]);
  54. ////Console.WriteLine("hour:" + hour);
  55. //double windSpeed = Convert.ToDouble(TargetQiXiangInfoSave("风速", hour));
  56. ////Console.WriteLine("windSpeed:" + windSpeed);
  57. //double vis = Convert.ToDouble(TargetQiXiangInfoSave("能见度", hour));
  58. ////Console.WriteLine("vis:" + vis);
  59. FlightPlanEditor.missionpoint.MissionPointLatitude = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLatitude;
  60. FlightPlanEditor.missionpoint.MissionPointLongitude = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointLongitude;
  61. FlightPlanEditor.missionpoint.MissionPointHeight = FlightPlanEditor.medicalSuppliesInfo[0].TargetPointHeight;
  62. Console.WriteLine("Latitude:" + FlightPlanEditor.missionpoint.MissionPointLatitude + "_" + "Longitude:" + FlightPlanEditor.missionpoint.MissionPointLongitude + "_" + "Height:" + FlightPlanEditor.missionpoint.MissionPointHeight);
  63. FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
  64. //// 吊运上升速度 吊运下降速度 Task文件读取 // Editor里读天气根据时间
  65. //resulttime = get_result_time_rope(taskParameter.Height, taskParameter.liftPersonnel, windSpeed, vis, taskParameter.liftUpSpeed, taskParameter.liftDownSpeed).time;//索滑降模型输出的索滑降时间
  66. //Console.WriteLine("resulttime:" + resulttime);
  67. //FXJHGenerate.SuoHuaJiang(resulttime, FlightPlanEditor, ref TurningPoints);
  68. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, FXJHGenerate.SuoHuaJiangMissionEndPoint(FlightPlanEditor), ref TurningPoints);
  69. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
  70. // 飞到目标点时间与人员存活时间做对比 有一个人活着,整个任务成功
  71. double time = 0;
  72. for (int i = 0; i < TurningPoints.Count - 1; i++)
  73. {
  74. time += TurningPoints[i].SegmentFlightTime; // 判断幸存-1
  75. }
  76. //Console.WriteLine("time:" + time);
  77. for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
  78. {
  79. TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间 //仿真轮次1 数值1
  80. }
  81. Console.WriteLine("TotalTime:" + TotalTime);
  82. IsOver = true;
  83. End();
  84. }
  85. // 吊运函数
  86. public static handling_result get_result_time_rope(double H, int person_number, double windspeed, double vis, double upspeed, double downspeed)
  87. {
  88. handling_result result = new handling_result();
  89. if (windspeed < 8 && vis > 3)
  90. {
  91. result.time = (person_number * H) / downspeed + (person_number * H) / upspeed;
  92. result.success = true;
  93. }
  94. else
  95. {
  96. result.success = false;
  97. }
  98. return result;
  99. }
  100. public string TargetQiXiangInfoSave(string s, int hour)
  101. {
  102. string result = hour.ToString() + "-" + s;
  103. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetQiXiangInfos.Length; i++)
  104. {
  105. }
  106. switch (s)
  107. {
  108. case "温度":
  109. break;
  110. case "湿度":
  111. break;
  112. case "能见度":
  113. break;
  114. case "风速":
  115. break;
  116. case "风向":
  117. break;
  118. case "天气":
  119. break;
  120. }
  121. return result;
  122. }
  123. public static int GetDaysInYear(int year, int month, int day)
  124. {
  125. int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  126. if (IsLeapYear(year))
  127. {
  128. daysInMonths[1] = 29;
  129. }
  130. int days = day;
  131. for (int i = 0; i < month - 1; i++)
  132. {
  133. days += daysInMonths[i];
  134. }
  135. return days;
  136. }
  137. public static bool IsLeapYear(int year)
  138. {
  139. return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
  140. }
  141. }
  142. [ObjectSystem]
  143. public class AircraftYLWPYSAwakeSystem : AwakeSystem<AircraftYLWPYS, FlightPlanEditor>
  144. {
  145. public override void Awake(AircraftYLWPYS self, FlightPlanEditor flightPlanEditor)
  146. {
  147. self.FlightPlanEditor = flightPlanEditor;
  148. self.Awake();
  149. }
  150. }