AircraftXH.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. public double[] Velocitys = new double[5]{220,220,220,110,0}; // 速度
  31. public double[] FuelConsumptions = new double[5]{2800,2800,2800,1000,132}; // 燃油消耗
  32. public void Awake()
  33. {
  34. FXJHGenerate.FromStartToMission(FlightPlanEditor,ref turningPoints);//生成从起点到任务段起点的航路点
  35. FXJHGenerate.XunHu(FlightPlanEditor,ref turningPoints);//生成巡航航路点
  36. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor,ref turningPoints, Velocitys,FuelConsumptions);//生成从任务段终点到结束点的航路点
  37. }
  38. public void End()
  39. {
  40. for (int i = 0; i < currentLocation.Currentsegnum + 2; i++)
  41. {
  42. TotalTime += turningPoints[i].SegmentFlightTime;
  43. }
  44. TotalFuelConsumption = turningPoints[0].RemainingFuel - turningPoints[currentLocation.Currentsegnum + 1].RemainingFuel;
  45. }
  46. public void Update()
  47. {
  48. if (isOver)
  49. {
  50. finalProbability = 1 - finalProbability;
  51. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, new MissionEndPoint
  52. {
  53. MissionEndPointLongitude = currentLocation.CurrentLon,
  54. MissionEndPointLatitude = currentLocation.CurrentLat,
  55. MissionEndPointHeight = currentLocation.CurrentHei
  56. }, ref turningPoints);
  57. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor,ref turningPoints, Velocitys, FuelConsumptions);
  58. End();
  59. isOver = false;
  60. mission.EndMission();
  61. return;
  62. }
  63. if (!isSeeFire) // 发现火情
  64. {
  65. var location = FXJHGenerate.GetCurrentLocation(turningPoints, FlightPlanEditor, temptime);
  66. currentLocation = location.Item1;
  67. double3 aricraftPoint = new double3(currentLocation.CurrentLon,currentLocation.CurrentLat,currentLocation.CurrentHei);
  68. double3 targetPoint = new double3(FlightPlanEditor.firepoint[0].FirePointLongitude,FlightPlanEditor.firepoint[0].FirePointLatitude, FlightPlanEditor.firepoint[0].FirePointHeight);
  69. probability = helper.getProbability(aricraftPoint,targetPoint,currentLocation.CurrentCourse,"");
  70. finalProbability *= (1 - probability);
  71. Console.WriteLine($"巡护任务: {Name} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},最终概率:{1 -finalProbability},是否看到火点:{isSeeFire}");
  72. var randomValue = random.NextDouble();
  73. if (randomValue < (1 - finalProbability))
  74. {
  75. isSeeFire = true;
  76. isOver = true;
  77. Log.Info("发现火情");
  78. }
  79. else
  80. {
  81. isSeeFire = false;
  82. }
  83. if (temptime >= 7200)
  84. {
  85. isOver = true;
  86. }
  87. temptime++;
  88. }
  89. }
  90. }
  91. [ObjectSystem]
  92. public class AircraftXHAwakeSystem : AwakeSystem<AircraftXH,FlightPlanEditor,string,string>
  93. {
  94. public override void Awake(AircraftXH self,FlightPlanEditor planEditor,string name,string aircraftId)
  95. {
  96. self.FlightPlanEditor = planEditor;
  97. self.Name = name;
  98. self.AircraftId = aircraftId;
  99. // 读取数据库
  100. self.Db = Util.GetAircraftDefine(self.FlightPlanEditor.aircraftparameter.AircraftType,self.FlightPlanEditor.aircraftparameter.AircraftSubType,self.FlightPlanEditor.aircraftparameter.AircraftID);
  101. self.helper = new EquationHelper(HttpInterface.baseUrl);
  102. self.Awake();
  103. }
  104. }