123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- using KYFramework;
- using KYFramework.Network;
- using Model;
- using SimulationServer.Utils;
- using Define = SimulationServer.Utils.Define;
- namespace SimulationServer;
- public class AircraftZS : AircraftEntity
- {
- public string NextMissionId; // 下一个任务ID
- public MissionEndPoint missionEndPoint = new MissionEndPoint();
- public int LandingPersonnel; //personCount
- public MHRescueMission mhRescueMission;
- public int 单次救援人数 = 80; // 任务文件读取
- public int 观察盘旋圈数 = 3; //任务文件读取
- public int landingPoint = 0;
- public List<Model.AirRoute> airRoutes = new List<Model.AirRoute>();
- public ZSJYTask taskContent;
- public TaskParameter taskParameter;
- public bool IsOver;
- public bool Success;
- 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()
- {
- FlightPlanEditor.missionpoint.MissionPointLatitude = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
- FlightPlanEditor.missionpoint.MissionPointLongitude = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
- FlightPlanEditor.missionpoint.MissionPointHeight = FlightPlanEditor.targetpoint[0].TargetPointHeight;
- //Console.WriteLine("MissionPointLatitude:" + FlightPlanEditor.missionpoint.MissionPointLatitude);
- int count = 0;
- foreach (var item in taskContent.ZSJYParameters)
- {
- //Console.WriteLine("item.AircraftId:" + item.AircraftId);
- //Console.WriteLine("FlightPlanEditor.aircraftparameter.AircraftID:" + FlightPlanEditor.aircraftparameter.Id);
- if (item.AircraftId == FlightPlanEditor.aircraftparameter.Id)
- {
- double a = (double)taskContent.missionInformation.TaskEndConditions.person_number_Rescue;
- double b = (double)item.RescuePersonnel;
- count = (int)Math.Ceiling(a / b);
- //Console.WriteLine("count:" + count);
- }
- }
- for (int j = 0; j < count; j++)
- {
- FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
- missionEndPoint.MissionEndPointLatitude = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
- missionEndPoint.MissionEndPointLongitude = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
- missionEndPoint.MissionEndPointHeight = FlightPlanEditor.targetpoint[0].TargetPointHeight;
- airRoutes.Clear();
- List<double> list = GenerateCircleTrajectory(FlightPlanEditor.targetpoint[0].TargetPointLatitude, FlightPlanEditor.targetpoint[0].TargetPointLongitude, 1, 360);
- //airRoutes = list
- Model.AirRoute airRoute = new Model.AirRoute();
- for (int i = 0; i < list.Count; i++)
- {
- if (i % 2 == 0)
- {
- //Console.WriteLine("i0:" + list[i]);
- airRoute = new Model.AirRoute();
- airRoute.AirRouteLongitude = list[i];
- }
- else
- {
- //Console.WriteLine("i1:" + list[i]);
- airRoute.AirRouteLatitude = list[i];
- airRoutes.Add(airRoute);
- }
- }
- for (int i = 0; i < taskParameter.TurnsNumber; i++)
- {
- FXJHGenerate.ZhaoShuiJiuYuan(airRoutes, ref TurningPoints);
- }
- FXJHGenerate.ZhaoShuiJiuYuan1(airRoutes, ref TurningPoints);
- FXJHGenerate.FromMissionToEnd(FlightPlanEditor, missionEndPoint, ref TurningPoints);
- }
- // FXJHGenerate.InitializeVelocities(FlightPlanEditor, TurningPoints, ref Velocitys);
- // FXJHGenerate.InitializeFuelConsumptions(FlightPlanEditor, TurningPoints,ref FuelConsumptions);
- FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions); // 更新了 计算油耗的方法
- for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
- {
- TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间 //仿真轮次1 数值1
- //Console.WriteLine("TotalTime:" + TotalTime);
- }
- Console.WriteLine("TotalTime:" + TotalTime);
- IsOver = true;
- //Success = true; //需要判断
- End();
- }
- // centerLat centerLon 想定里目标点的经纬度 radiusKm = 1 numPoints = 360 返回的airRoutes //
- // 生成圆形轨迹点,并以 double 列表形式返回(按经度-纬度顺序存储)
- public static List<double> GenerateCircleTrajectory(double centerLat, double centerLon, double radiusKm, int numPoints)
- {
- var points = new List<double>();
- double earthRadius = 6371.0; // 地球半径,单位:公里
- for (int i = 0; i < numPoints; i++)
- {
- double angle = 2 * Math.PI * i / numPoints; // 当前点的角度(弧度)
- // 计算偏移量
- double offsetLat = radiusKm / earthRadius; // 纬度的偏移量(弧度)
- double offsetLon = offsetLat / Math.Cos(ToRadians(centerLat)); // 经度的偏移量(弧度)
- // 计算该角度下的点的经纬度
- double newLat = centerLat + ToDegrees(offsetLat * Math.Cos(angle));
- double newLon = centerLon + ToDegrees(offsetLon * Math.Sin(angle));
- // 按经度在前,纬度在后顺序存储
- points.Add(newLon);
- points.Add(newLat);
- }
- return points;
- }
- // 弧度转换为角度
- static double ToDegrees(double radians)
- {
- return radians * 180.0 / Math.PI;
- }
- // 角度转换为弧度
- static double ToRadians(double degrees)
- {
- return degrees * Math.PI / 180.0;
- }
- //private double GetDistance(double lon1, double lon2, double lat1, double lat2)
- //{
- // double R = 6371; // 地球的半径(公里)
- // double dLat = (lat2 - lat1) * Math.PI / 180.0;
- // double dLon = (lon2 - lon1) * Math.PI / 180.0;
- // double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
- // Math.Cos(lat1 * Math.PI / 180.0) * Math.Cos(lat2 * Math.PI / 180.0) *
- // Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
- // double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
- // double distance = R * c;
- // return distance;
- //}
- public override void Update(double time)
- {
- }
- }
- [ObjectSystem]
- public class AircraftZSAwakeSystem : AwakeSystem<AircraftZS, FlightPlanEditor>
- {
- public override void Awake(AircraftZS self, FlightPlanEditor flightPlanEditor)
- {
- self.FlightPlanEditor = flightPlanEditor;
- self.Awake();
- //self.Reset();
- }
- }
|