AircraftMH.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using KYFramework;
  2. using Model;
  3. using MongoDB.Bson;
  4. using Define = SimulationServer.Utils.Define;
  5. namespace SimulationServer;
  6. public class AircraftMH : AircraftEntity
  7. {
  8. public double SprinklerArea = 1500; // 飞机速度
  9. public string NextMissionId; // 下一个任务ID
  10. public FireGround fireGround;
  11. public MHRescueMission mhRescueMission;
  12. private int waterInterval = 4; // 洒水间隔
  13. public int waterTimes = 1; // 洒水次数
  14. public List<Fire.FireGrid> FireGrids = new List<Fire.FireGrid>();
  15. //任务重置
  16. public override void Reset()
  17. {
  18. waterTimes = 1;
  19. waterInterval = 4;
  20. base.Reset();
  21. }
  22. // 任务开始
  23. public override void Start()
  24. {
  25. FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
  26. // 计算出第一次洒水的时间
  27. FXJHGenerate.MieHuo1(FlightPlanEditor,ref TurningPoints);
  28. // FXJHGenerate.InitializeVelocities(FlightPlanEditor, TurningPoints, ref Velocitys);
  29. // FXJHGenerate.InitializeFuelConsumptions(FlightPlanEditor, TurningPoints,ref FuelConsumptions);
  30. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
  31. for (int i = 0; i < waterInterval; i++)
  32. {
  33. T += TurningPoints[i].SegmentFlightTime;
  34. }
  35. TaskResponseTime = T;
  36. if (FirstTime == 0) FirstTime = T;
  37. }
  38. // 任务结束
  39. public override void End()
  40. {
  41. MissionEndPoint missionEndPoint = new MissionEndPoint();
  42. missionEndPoint.MissionEndPointLatitude = fireGround.FirePoint.Latitude;
  43. missionEndPoint.MissionEndPointLongitude = fireGround.FirePoint.Longitude;
  44. missionEndPoint.MissionEndPointHeight = fireGround.FirePoint.Altitude;
  45. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, missionEndPoint, ref TurningPoints);
  46. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor,ref TurningPoints, Velocitys, FuelConsumptions);
  47. EffMisTime = mhRescueMission.tn - TaskResponseTime;
  48. TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
  49. }
  50. // 更新
  51. public override void Update(double time)
  52. {
  53. if (fireGround.countArea.burnarea > 0) // 灭火完成
  54. {
  55. if (time > T)
  56. {
  57. // 开始洒水
  58. fireGround.countArea = Fire.burnCalculate(Define.WIND, mhRescueMission.slope, T, fireGround.countArea.burnarea, T, mhRescueMission.tn , fireGround.countArea.burnarea);
  59. // T 洒水的时间
  60. // 正在燃烧的网格数 向下取整
  61. double fireGrids = Math.Floor(fireGround.countArea.burnarea/400);
  62. // 已经燃尽的网格数
  63. double firedGrids = Math.Floor((mhRescueMission.area - fireGround.countArea.burnarea)/400);
  64. //记录洒水之前的火场
  65. FireGrids.Add(new Fire.FireGrid
  66. {
  67. Time = T,
  68. FireGrids = fireGrids,
  69. FiredGrids = firedGrids
  70. });
  71. var currentArea = Fire.SprinklerArea(Type, SprinklerArea/2, fireGround.FirePoint.Altitude) ; // 本次有效洒水面积
  72. fireGround.countArea.burnarea -= currentArea;
  73. mhRescueMission.area += currentArea; // 有效洒水面积
  74. Log.Info($"任务 {TaskName } {Name} 洒水{waterTimes} 次 本次有效洒水面积 {currentArea} 用时 {T} area {mhRescueMission.area} burnarea {fireGround.countArea.burnarea}");
  75. mhRescueMission.tn = T;
  76. waterTimes++;
  77. // 计算出下一次洒水的时间
  78. FXJHGenerate.MieHuo1(FlightPlanEditor, ref TurningPoints);
  79. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor,ref TurningPoints, Velocitys, FuelConsumptions);
  80. for (int i = waterInterval - 2; i < waterInterval; i++)
  81. {
  82. T += TurningPoints[i].SegmentFlightTime;
  83. }
  84. waterInterval += 2;
  85. }
  86. }
  87. }
  88. }
  89. [ObjectSystem]
  90. public class AircraftAwakeSystem : AwakeSystem<AircraftMH,FlightPlanEditor>
  91. {
  92. public override void Awake(AircraftMH self, FlightPlanEditor flightPlanEditor)
  93. {
  94. self.FlightPlanEditor = flightPlanEditor;
  95. // 读取数据库
  96. self.Awake();
  97. if (self.Db != null)
  98. {
  99. self.Type = self.Db?.fConcreateType.ToString();
  100. self.SprinklerArea = (double)self.Db?.fpsmj;
  101. }
  102. self.Reset();
  103. }
  104. }