123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- using KYFramework;
- using Model;
- using MongoDB.Bson;
- using MuShiApp;
- using SimulationCommon;
- using SimulationSingleServer.Utils;
- using Unity.Mathematics;
- using Point = SimulationCommon.Point;
- using Random = System.Random;
- using QuYuSaoMiao;
- using System.Threading;
- namespace SimulationServer;
- public class AircraftLandSJ : AircraftEntity
- {
- public bool IsOver;
- public LandSouXunTask taskContent;
- public EquationHelper helper;
- public GetNCData getNCData;
- public bool isseePerson = false;
- public MissionEndPoint MissionEndPoint;
- public SearchMissionMode SearchMissionMode;
- public bool Success = false;
- public SearchMissionPayload searchMissionPayload;
- public double resulttime;
- int Days;
- int Hour;
- public bool isEndWhile;
- public int targetCount;
- public int sbCount;
- public double landArea;
- public bool isReadNC;
- Text_readNC text_ReadNC;
- public override void Reset()
- {
- base.Reset();
- IsOver = false;
- isseePerson = false;
- Success = false;
- SearchTime = 0;
- TotalTime = 0;
- isEndWhile = false;
- resulttime = 0;
- targetCount = 0;
- sbCount = 0;
- landArea = 0;
- }
- public override void Start()
- {
- if (FlightPlanEditor.targetpoint[0].TargetType.Type == "遇险人员")
- {
- targetCount = FlightPlanEditor.targetpoint[0].TargetType.Count;
- sbCount = targetCount;
- }
- else
- sbCount = 1;
- landArea = SearchMissionMode.LandArea;
- int Year = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[0]);
- int Month = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[0]);
- int Day = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].Split("日")[0]);
- Hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
- Days = GetDaysInYear(Year, Month, Day);
- Velocitys = new double[5] { 220, 220, 60, 110, 0 };
- List<double[]> route = new List<double[]>();
- if (SearchMissionMode.SearchMode == "扇形搜索")
- {
- List<double[]> trajectory = new List<double[]>();
- foreach (var item in SearchMissionMode.Poly)
- {
- trajectory.Add(new double[]
- {
- item[1],item[0]
- });
- }
- var points = SeaSJ.getminEnclosingRect(trajectory);
- var startPoint1 = new Point
- {
- lat = points[0][0] / 2 + points[1][0] / 2,
- lon = points[0][1] / 2 + points[1][1] / 2
- };
- var startPoint2 = new Point
- {
- lat = points[2][0] / 2 + points[3][0] / 2,
- lon = points[2][1] / 2 + points[3][1] / 2
- };
- var centerPoint = new Point
- {
- lat = startPoint1.lat / 2 + startPoint2.lat / 2,
- lon = startPoint1.lon / 2 + startPoint2.lon / 2
- };
- List<Point> temp = SectorSearch.sectorSearch(centerPoint, 30, SearchMissionMode.SearchWidth);
- foreach (Point point in temp)
- {
- route.Add(new double[]
- {
- point.lon, point.lat,3500
- });
- }
- }
- else if (SearchMissionMode.SearchMode == "等高线搜索")
- {
- route = ContourSearch.ContourSearch1(SearchMissionMode.Poly, SearchMissionMode.interval, SearchMissionMode.MinLength, SearchMissionMode.TrueH, SearchMissionMode.JG, ContourSearch.DemHelper());
- }
-
- List<AirRoute> airRoutes = new List<AirRoute>();
- foreach (var item in route)
- {
- airRoutes.Add(new AirRoute
- {
- AirRouteLatitude = item[1],
- AirRouteLongitude = item[0],
- AirRouteHeight = item[2]
- });
- }
- FlightPlanEditor.airroute = airRoutes.ToArray();
- FlightPlanEditor.missionpoint = new MissionPoint()
- {
- MissionPointLongitude = FlightPlanEditor.airroute[0].AirRouteLongitude,
- MissionPointLatitude = FlightPlanEditor.airroute[0].AirRouteLatitude,
- MissionPointHeight = FlightPlanEditor.airroute[0].AirRouteHeight
- };
- FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);
-
- FXJHGenerate.LandSouJiu(FlightPlanEditor, ref TurningPoints);
- FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
- double time = 0;
- for (int i = 0; i < TurningPoints.Count - 2; i++)
- {
- time += TurningPoints[i].SegmentFlightTime;
- }
- double3 targetPoint = new double3(FlightPlanEditor.targetpoint[0].TargetPointLongitude,
- FlightPlanEditor.targetpoint[0].TargetPointLatitude,
- FlightPlanEditor.targetpoint[0].TargetPointHeight);
- string cityName = helper.getCityName(targetPoint.x, targetPoint.y);
-
- string year = taskContent.missionInformation.StartDate.Split("年")[0];
- string month = taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[0];
- if (Convert.ToInt32(month) < 10) month = "0" + month;
- string day = taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].Split("日")[0];
- if (Convert.ToInt32(day) < 10) day = "0" + day;
-
- string date = year + "-" + month + "-" + day;
-
-
- var visibility = helper.getVisibilityByDb(targetPoint.x, targetPoint.y, date);
-
-
-
-
- Task.Run(() =>
- {
- bool isseePerson = false;
- double temptime = 0;
- CurrentLocation currentLocation = new CurrentLocation();
- double probability = 0;
- double finalProbability = 1.0;
- Random random = new Random();
- int fireIndex = -1;
-
- do
- {
- if (!isseePerson && temptime >= time)
- {
- FXJHGenerate.LandSouJiu(FlightPlanEditor, ref TurningPoints);
- FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
- time = 0;
- for (int i = 0; i < TurningPoints.Count - 2; i++)
- {
- time += TurningPoints[i].SegmentFlightTime;
- }
- Log.Info($"+++++++++++搜寻结束 TurningPoints Count: {TurningPoints.Count} 下次结束的时间 {time}++++++++++++++++");
- }
- (currentLocation, _) =
- FXJHGenerate.GetAllCurrentLocation(TurningPoints, temptime);
- double3 aricraftPoint = new double3(currentLocation.CurrentLon, currentLocation.CurrentLat,
- currentLocation.CurrentHei);
- var distance = Utils.Util.GetDistance(currentLocation.CurrentLon, targetPoint.x,
- currentLocation.CurrentLat,
- targetPoint.y);
- Log.Info("距离:====================" + distance);
- if (searchMissionPayload.SearchPayload == "雷达搜索")
- {
-
- probability = helper.GetRadarPossibility(0.5, Math.Pow(10, -6), Math.Pow(10, -6), 23645, aricraftPoint, FlightPlanEditor.targetpoint[0], FlightPlanEditor.targetpoint[0].TargetType.RadarArea, 5000, visibility);
- }
- else if (searchMissionPayload.SearchPayload == "目视搜索")
- {
- probability = helper.GetMushiLandProbability(aricraftPoint, visibility, FlightPlanEditor.targetpoint[0]);
- }
- else if (searchMissionPayload.SearchPayload == "光电(红外)搜索")
- {
-
- probability = helper.GetInfraredDetectionProbability(FlightPlanEditor.targetpoint[0].TargetType.TargetBrightness, FlightPlanEditor.targetpoint[0].TargetType.TargetArea, 1, 3, 1, aricraftPoint, FlightPlanEditor.targetpoint[0], 0.075, 3, 0.8, 0073728, 0.125, 0.5, Math.Pow(10, -6));
- }
-
-
-
- if (probability > 0.8)
- {
- probability -= 0.5f;
- probability *= random.NextDouble();
- double random1 = random.NextInt64(8000, 9200);
- random1 /= 10000;
- probability += (0.5 * random1);
- }
- double randomValue = random.NextInt64(9006, 10000);
- randomValue /= 10000;
- Log.Info(
- $"陆上任务:{taskContent.missionInformation.MissionName} 机型: {AircraftId} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},是否看到遇险人员:{isseePerson}");
- if (randomValue < probability)
- {
- isseePerson = true;
- this.isseePerson = true;
- fireIndex = currentLocation.Currentsegnum;
-
- isEndWhile = true;
-
-
-
- }
- else
- {
- isseePerson = false;
- }
- temptime += 10;
- if (temptime >= taskContent.missionInformation.TaskEndConditions.TaskTime)
- {
-
- isEndWhile = true;
- isseePerson = false;
- fireIndex = currentLocation.Currentsegnum;
- }
- } while (!isseePerson && isEndWhile == false);
-
- if (fireIndex != -1)
- {
-
- TurningPoints.RemoveRange(fireIndex + 1, TurningPoints.Count - fireIndex - 1);
- MissionPoint missionPoint = new MissionPoint
- {
- MissionPointLongitude = currentLocation.CurrentLon,
- MissionPointLatitude = currentLocation.CurrentLat,
- MissionPointHeight = currentLocation.CurrentHei
- };
- FXJHGenerate.SeaSouJiu2(FlightPlanEditor, missionPoint, ref TurningPoints);
-
- FXJHGenerate.FromMissionToEnd(FlightPlanEditor, MissionEndPoint, ref TurningPoints);
- }
- if (isseePerson)
- {
- double seeTime = 0;
- if (FlightPlanEditor.targetpoint[0].TargetType.Type == "遇险人员")
- {
- if (!isReadNC)
- {
- text_ReadNC = new Text_readNC();
- text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
- text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
-
- bool isSuccess = false;
- while (!isSuccess)
- {
- isSuccess = text_ReadNC.GetNCData();
- }
- isReadNC = true;
- }
- var nCread = text_ReadNC.windNCread;
- var wind = SeaSJ.GetWindVelocityFromAPI(nCread, currentLocation.CurrentLat, currentLocation.CurrentLon,
- temptime, text_ReadNC.times, text_ReadNC.latitudes, text_ReadNC.longitudes, text_ReadNC.times1, text_ReadNC.latitudes1, text_ReadNC.longitudes1, Days, Hour);
- double windSpeed = Math.Sqrt(wind[0] * wind[0] + wind[1] * wind[1]);
- for (int i = 0; i < TurningPoints.Count - 1; i++)
- {
- seeTime += TurningPoints[i].SegmentFlightTime;
- }
- double latitude = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
- double longitude = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
- double survivalTime = FlightPlanEditor.targetpoint[0].TargetType.LiveTime;
-
- resulttime = get_result_time_rope(30, FlightPlanEditor.targetpoint[0].TargetType.Count, windSpeed, visibility, 0.75, 1.38).time;
- Console.WriteLine("resulttime:" + resulttime);
-
- if (survivalTime * 3600 > seeTime)
- {
- Success = true;
- }
-
-
- }
- }
-
-
- Log.Info(
- $"陆上任务:{taskContent.missionInformation.MissionName} 机型: {AircraftId} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},是否看到遇险人员:{isseePerson}");
- FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
- End();
- });
- }
- public static handling_result get_result_time_rope(double H, int person_number, double windspeed, double vis, double upspeed, double downspeed)
- {
- handling_result result = new handling_result();
- if (windspeed < 8 && vis > 3)
- {
- result.time = (person_number * H) / downspeed + (person_number * H) / upspeed;
- result.success = true;
- }
- else
- {
- result.success = false;
- }
- return result;
- }
- public static int GetDaysInYear(int year, int month, int day)
- {
- int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- if (IsLeapYear(year))
- {
- daysInMonths[1] = 29;
- }
- int days = day;
- for (int i = 0; i < month - 1; i++)
- {
- days += daysInMonths[i];
- }
- return days;
- }
- public static bool IsLeapYear(int year)
- {
- return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
- }
- public override void End()
- {
- for (int i = 0; i < TurningPoints.Count - 2; i++)
- {
- EffMisTime += TurningPoints[i].SegmentFlightTime;
- }
- for (int i = 0; i < TurningPoints.Count - 3; i++)
- {
- SearchTime += TurningPoints[i].SegmentFlightTime;
- }
- for (int i = 0; i < TurningPoints.Count; i++)
- {
- TotalTime += TurningPoints[i].SegmentFlightTime;
- }
- TotalFuelConsumption = TurningPoints[0].RemainingFuel -
- TurningPoints[TurningPoints.Count - 1].RemainingFuel;
- IsOver = true;
- }
- }
- [ObjectSystem]
- public class AircraftLandSJAwakeSystem : AwakeSystem<AircraftLandSJ, FlightPlanEditor>
- {
- public override void Awake(AircraftLandSJ self, FlightPlanEditor flightPlanEditor)
- {
- self.FlightPlanEditor = flightPlanEditor;
- self.helper = new EquationHelper(HttpInterface.baseUrl);
- self.Awake();
- }
- }
|