using KYFramework; using Model; using MongoDB.Bson; using MuShiApp; using SimulationCommon; using SimulationSingleServer.Utils; using Unity.Mathematics; using Define = SimulationServer.Utils.Define; using Point = SimulationCommon.Point; using Random = System.Random; namespace SimulationServer; public class AircraftSJ : AircraftEntity { public bool IsOver; private MissionEndPoint MissionEndPoint; private CurrentLocation currentLocation; private double temptime = 0; private double probability = 0; private double finalProbability = 1.0; private Random random = new Random(); private bool isseefire = false; private int fireIndex = -1; // 记录发现火点的位置 public EquationHelper helper; public override void Start() { //TODO 计算 AirRoute[] double[] initialPosition = { FlightPlanEditor.targetpoint[0].TargetPointLatitude, FlightPlanEditor.targetpoint[0].TargetPointLongitude }; double dt = 1; double totalTime = 24.0; Text_readNC text_ReadNC = new Text_readNC(); text_ReadNC.GetNCData(); var nCread = text_ReadNC.windNCread; //漂移轨迹 List trajectory = SeaSJ.CalculateDriftTrajectory(nCread, initialPosition,dt, totalTime); // 生成任务终点 MissionEndPoint = new MissionEndPoint { MissionEndPointLongitude = trajectory[trajectory.Count - 1][1], MissionEndPointLatitude = trajectory[trajectory.Count - 1][0], MissionEndPointHeight = 0 }; var temp = SeaSJ.getminEnclosingRect(trajectory); // temp 转成 List List points = new List(); foreach (var item in temp) { points.Add(new Point(item[0], item[1])); } Point basePoint = new Point(FlightPlanEditor.originbase.BaseLatitude, FlightPlanEditor.originbase.BaseLongitude); double sweepWidth = 0.2; // 生成航路点 List waypoints = ParallellineSearch.parallellineSearch(basePoint, points, sweepWidth); // List 转成 List List airRoutes = new List(); foreach (var item in waypoints) { airRoutes.Add(new AirRoute { AirRouteLatitude = item.lat, AirRouteLongitude = item.lon }); } FlightPlanEditor.airroute = airRoutes.ToArray(); FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints); //生成从起点到任务段起点的航路点 FXJHGenerate.SeaSouJiu(FlightPlanEditor, ref TurningPoints); FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions); Task.Run(() => { bool isseefire = false; double temptime = 0; // 自增时间,每次增加1s CurrentLocation currentLocation = new CurrentLocation(); double probability = 0; double finalProbability = 1.0; Random random = new Random(); int fireIndex = -1; // 记录发现火点的位置 do { (currentLocation, _) = FXJHGenerate.GetCurrentLocation(TurningPoints, FlightPlanEditor, temptime); // 获取飞机当前位置 double3 aricraftPoint = new double3(currentLocation.CurrentLon, currentLocation.CurrentLat, currentLocation.CurrentHei); double3 targetPoint = new double3(FlightPlanEditor.targetpoint[0].TargetPointLongitude, FlightPlanEditor.targetpoint[0].TargetPointLatitude, FlightPlanEditor.targetpoint[0].TargetPointHeight); //******* probability = helper.getProbability(aricraftPoint, targetPoint, currentLocation.CurrentCourse, Define.WIND, 1, "落水人员", "陆地"); // 计算发现概率,需要其他模型输入 // 计算发现概率,需要其他模型输入 finalProbability *= (1 - probability); Console.WriteLine($"海上任务: {Name} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},最终概率:{1 -finalProbability},是否看到落水人员:{isseefire}"); double randomValue = random.NextDouble(); // 生成随机数比较概率 if (randomValue < (1 - finalProbability)) { isseefire = true; fireIndex = currentLocation.Currentsegnum; // 记录当前航路点位置 IsOver = true; } else { isseefire = false; } if (temptime >= 7200) IsOver = true; temptime += 1; } while (!isseefire && IsOver == false); finalProbability = 1 - finalProbability; 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); } FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions); Log.Info(TurningPoints.ToJson()); End(); }); } public override void End() { for (int i = 0; i < currentLocation.Currentsegnum + 2; i++) { EffMisTime += TurningPoints[i].SegmentFlightTime; } TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[currentLocation.Currentsegnum + 1].RemainingFuel; } } [ObjectSystem] public class AircraftSJAwakeSystem : AwakeSystem { public override void Awake(AircraftSJ self, FlightPlanEditor flightPlanEditor) { self.FlightPlanEditor = flightPlanEditor; self.helper = new EquationHelper(HttpInterface.baseUrl); self.Awake(); } }