AircraftXH.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using KYFramework;
  2. using Model;
  3. using MuShiApp;
  4. using SimulationServer.Utils;
  5. using SimulationSingleServer.Utils;
  6. using Unity.Mathematics;
  7. using Random = System.Random;
  8. namespace SimulationServer;
  9. public class AircraftXH : Entity
  10. {
  11. public string Name; // 飞机名称
  12. public string AircraftId;
  13. public string NextMissionId; // 下一个任务ID
  14. public AircraftDB Db;
  15. public FlightPlanEditor? FlightPlanEditor; // 飞行计划编辑器
  16. public List<TurningPoint> turningPoints = new List<TurningPoint>();
  17. public CurrentLocation currentLocation;
  18. public EquationHelper helper;
  19. public XHRescueMission mission;
  20. public double TotalTime;// 单机总效任务时长
  21. public double TotalFuelConsumption;
  22. private Random random = new Random();
  23. private double temptime = 0;
  24. private double probability = 0;
  25. private double finalProbability = 1.0;
  26. private bool isSeeFire = false;
  27. public bool isOver = false;
  28. public double TaskReadyTime;
  29. public bool SyncOver;
  30. // 火情入场时间
  31. public double FireEnterTime;
  32. public double[] Velocitys = new double[5]{220,220,220,110,0}; // 速度
  33. public double[] FuelConsumptions = new double[5]{2800,2800,2800,1000,132}; // 燃油消耗
  34. public void Start()
  35. {
  36. FXJHGenerate.FromStartToMission(FlightPlanEditor,ref turningPoints);//生成从起点到任务段起点的航路点
  37. FXJHGenerate.MieHuo1(FlightPlanEditor,ref turningPoints);//生成从任务段起点到任务段终点的航路点
  38. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor,ref turningPoints, Velocitys,FuelConsumptions);//生成从任务段终点到结束点的航路点
  39. // 火情入场时间
  40. foreach (TurningPoint turningPoint in turningPoints)
  41. {
  42. FireEnterTime += turningPoint.SegmentFlightTime;
  43. }
  44. FireEnterTime += 1800;
  45. turningPoints.Clear();
  46. FXJHGenerate.FromStartToMission(FlightPlanEditor,ref turningPoints);//生成从起点到任务段起点的航路点
  47. FXJHGenerate.XunHu(FlightPlanEditor,ref turningPoints);//生成巡航航路点
  48. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor,ref turningPoints, Velocitys,FuelConsumptions);//生成从任务段终点到结束点的航路点
  49. Task.Run(() =>
  50. {
  51. do
  52. {
  53. var location = FXJHGenerate.GetCurrentLocation(turningPoints, FlightPlanEditor, temptime);
  54. currentLocation = location.Item1;
  55. double3 aricraftPoint = new double3(currentLocation.CurrentLon,currentLocation.CurrentLat,currentLocation.CurrentHei);
  56. double3 targetPoint = new double3(FlightPlanEditor.firepoint[0].FirePointLongitude,FlightPlanEditor.firepoint[0].FirePointLatitude, FlightPlanEditor.firepoint[0].FirePointHeight);
  57. probability = helper.getProbability(aricraftPoint,targetPoint,currentLocation.CurrentCourse);
  58. finalProbability *= (1 - probability);
  59. Console.WriteLine($"巡护任务: {Name} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},最终概率:{1 -finalProbability},是否看到火点:{isSeeFire}");
  60. var randomValue = random.NextDouble();
  61. if (randomValue < (1 - finalProbability))
  62. {
  63. isSeeFire = true;
  64. isOver = true;
  65. Log.Info("发现火情");
  66. }
  67. else
  68. {
  69. isSeeFire = false;
  70. }
  71. if (temptime >= 7200)
  72. {
  73. isOver = true;
  74. }
  75. temptime++;
  76. } while (!isSeeFire && isOver==false);
  77. finalProbability = 1 - finalProbability;
  78. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, new MissionEndPoint
  79. {
  80. MissionEndPointLongitude = currentLocation.CurrentLon,
  81. MissionEndPointLatitude = currentLocation.CurrentLat,
  82. MissionEndPointHeight = currentLocation.CurrentHei
  83. }, ref turningPoints);
  84. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor,ref turningPoints, Velocitys, FuelConsumptions);
  85. End();
  86. });
  87. }
  88. public void End()
  89. {
  90. for (int i = 0; i < currentLocation.Currentsegnum + 2; i++)
  91. {
  92. TotalTime += turningPoints[i].SegmentFlightTime;
  93. }
  94. TotalFuelConsumption = turningPoints[0].RemainingFuel - turningPoints[currentLocation.Currentsegnum + 1].RemainingFuel;
  95. }
  96. }
  97. [ObjectSystem]
  98. public class AircraftXHAwakeSystem : AwakeSystem<AircraftXH,FlightPlanEditor,string,string>
  99. {
  100. public override void Awake(AircraftXH self,FlightPlanEditor planEditor,string name,string aircraftId)
  101. {
  102. self.FlightPlanEditor = planEditor;
  103. self.Name = name;
  104. self.AircraftId = aircraftId;
  105. // 读取数据库
  106. self.Db = Util.GetAircraftDefine(self.FlightPlanEditor.aircraftparameter.AircraftType,self.FlightPlanEditor.aircraftparameter.AircraftSubType,self.FlightPlanEditor.aircraftparameter.AircraftID);
  107. self.helper = new EquationHelper(HttpInterface.baseUrl);
  108. }
  109. }