public CheckPointDescriptor(Vehicle _ThisVehicle, World.Objects.Path._Point _CheckPoint) { CheckPoint = _CheckPoint; Vehicle = _ThisVehicle; World.Objects.Path._Point ThisPoint = _CheckPoint; Math3D.Point3 Previous = new Math3D.Point3(_ThisVehicle.Prev_PosX, _ThisVehicle.Prev_PosY, _ThisVehicle.Prev_PosZ); Math3D.Point3 Current = new Math3D.Point3(_ThisVehicle.PosX, _ThisVehicle.PosY, _ThisVehicle.PosZ); Math3D.Segment3 Segment = new Math3D.Segment3(Previous, Current); Math3D.Point3 Point = new Math3D.Point3(ThisPoint.X, ThisPoint.Y, ThisPoint.Z); double Tolerance = Math3D.Distance(Previous, Current); Tolerance /= (_ThisVehicle.TimeStamp - _ThisVehicle.Prev_TimeStamp); float HitRadius = (float)_ThisVehicle.CachedAircraft.HTRADIUS; if (Tolerance < HitRadius * 5) { Tolerance = HitRadius * 5; } if (Math3D.DoesSegmentPassNearPoint(Segment, Point, Tolerance)) { Math3D.Point3 ClosestPoint = Math3D.GetPointSegmentClosestPointIfIntersecting(Point, Segment); if (ClosestPoint == null) { //Doesn't even intersect! Let's say it crossed this point at the last second! TimeStamp = _ThisVehicle.TimeStamp; } else { //Does intersect! find the exact millisecond the intersection took place! double Numerator = Math3D.Distance(Previous, ClosestPoint); double Denominator = Math3D.Distance(Previous, Current); float TimeSpanDifference = _ThisVehicle.TimeStamp - _ThisVehicle.Prev_TimeStamp; TimeStamp = _ThisVehicle.Prev_TimeStamp + (float)((Numerator / Denominator) * TimeSpanDifference); } } }
public static void CheckIntersections(Client ThisClient) { Vehicle ThisVehicle = ThisClient.Vehicle; if (ThisVehicle == Vehicles.NoVehicle) { return; } for (int j = 0; j < World.Objects.PathList.Count; j++) { World.Objects.Path ThisPath = World.Objects.PathList[j]; for (int k = ThisPath.Points.Count - 1; k >= 0; k--) { #region Segment Testings Maths... World.Objects.Path._Point ThisPoint = ThisPath.Points[k]; if (!ActiveCheckPoints.Select(x => x.CheckPoint).Contains(ThisPath.Points[0]) & ThisPoint != ThisPath.Points[0]) { continue; } Math3D.Point3 Previous = new Math3D.Point3(ThisVehicle.Prev_PosX, ThisVehicle.Prev_PosY, ThisVehicle.Prev_PosZ); Math3D.Point3 Current = new Math3D.Point3(ThisVehicle.PosX, ThisVehicle.PosY, ThisVehicle.PosZ); Math3D.Segment3 Segment = new Math3D.Segment3(Previous, Current); Math3D.Point3 Point = new Math3D.Point3(ThisPoint.X, ThisPoint.Y, ThisPoint.Z); double Tolerance = Math3D.Distance(Previous, Current); Tolerance /= (ThisVehicle.TimeStamp - ThisVehicle.Prev_TimeStamp); float HitRadius = (float)ThisVehicle.CachedAircraft.HTRADIUS; if (Tolerance < HitRadius * 5) { Tolerance = HitRadius * 5; } #endregion if (Math3D.DoesSegmentPassNearPoint(Segment, Point, Tolerance)) { lock (ActiveCheckPoints) { List <World.Objects.Path._Point> Intersection = ActiveCheckPoints.Select(x => x.CheckPoint).Intersect(ThisPath.Points).ToList(); if (ThisPath.Points.Count > Intersection.Count) { if (ThisPath.Points[Intersection.Count] == ThisPoint) //Allow to go forwards or backwards on the track! { #region Add the new point. ActiveCheckPoints.Add(new CheckPointDescriptor(ThisVehicle, ThisPoint)); #endregion #region Update the data-set intersection Intersection = ActiveCheckPoints.Select(x => x.CheckPoint).Intersect(ThisPath.Points).ToList(); #endregion #region GET SPLIT TIME string SplitTimeResult = "<ERROR>"; try { float starttime = 0; float endtime = 0; if (ActiveCheckPoints.Count > 0) { starttime = ActiveCheckPoints.Where(x => x.Vehicle == ThisVehicle).Where(y => y.CheckPoint == Intersection[0]).ToArray()[0].TimeStamp; endtime = ActiveCheckPoints.Where(x => x.Vehicle == ThisVehicle).Where(y => y.CheckPoint == ThisPoint).ToArray()[0].TimeStamp; } else { starttime = ThisVehicle.TimeStamp; endtime = ThisVehicle.TimeStamp; } TimeSpan StartTimeSpan = new TimeSpan(0, 0, 0, 0, (int)(starttime * 1000)); TimeSpan EndTimeSpan = new TimeSpan(0, 0, 0, 0, (int)(endtime * 1000)); TimeSpan LapTime = EndTimeSpan - StartTimeSpan; string Hours = LapTime.Hours.ToString(); while (Hours.Length < 2) { Hours = "0" + Hours; } if (Hours.Length > 2) { Hours = "99"; } string Minutes = LapTime.Minutes.ToString(); while (Minutes.Length < 2) { Minutes = "0" + Minutes; } if (Minutes.Length > 2) { Minutes = "99"; } string Seconds = LapTime.Seconds.ToString(); while (Seconds.Length < 2) { Seconds = "0" + Seconds; } if (Seconds.Length > 2) { Seconds = "99"; } string Milliseconds = LapTime.Milliseconds.ToString(); while (Milliseconds.Length < 3) { Milliseconds = "0" + Milliseconds; } if (Milliseconds.Length > 3) { Milliseconds = "999"; } SplitTimeResult = Hours + ":" + Minutes + ":" + Seconds + "." + Milliseconds; } catch { } #endregion if (SplitTimeResult == "00:00:00.000") { continue; //ThisClient.SendMessage(ThisPath.Identify + " Split " + (k - 1) + " - " + SplitTimeResult); } else { if (ThisPoint == ThisPath.Points[ThisPath.Points.Count - 1] & Intersection.Count == ThisPath.Points.Count) //Finish Line! { ThisClient.SendMessage("[" + ThisPath.Identify + "]" + " Lap - " + SplitTimeResult); } else { ThisClient.SendMessage("[" + ThisPath.Identify + "]" + " Split " + k + " - " + SplitTimeResult); } } } } if (ThisPoint == ThisPath.Points[ThisPath.Points.Count - 1] & Intersection.Count == ThisPath.Points.Count) { ActiveCheckPoints.OrderBy(x => x.TimeStamp); foreach (World.Objects.Path._Point ThisUnionPoint in Intersection) { CheckPointDescriptor CheckPointToRemove = ActiveCheckPoints.Where(x => x.CheckPoint == ThisUnionPoint).Where(y => y.Vehicle == ThisVehicle).ToArray()[0]; ActiveCheckPoints.Remove(CheckPointToRemove); } Intersection = ActiveCheckPoints.Select(x => x.CheckPoint).Intersect(ThisPath.Points).ToList(); //need to update this! } if (ThisPoint == ThisPath.Points[0] & Intersection.Count == 1) { //ThisClient.SendMessage("START LAP" + ActiveCheckPoints.Count.ToString()); //ActiveCheckPoints.Add(new CheckPointDescriptor(ThisVehicle, ThisPoint)); //continue; //k = 0; //Restart the check, we may have passed another checkpoint a second ago! } } } } } }
public void CheckIntersections(_Racer ThisRacer) { List <Client> NONRACING = Clients.AllClients.Except(ThisRacer.Race.Racers.Select(x => x.Client)).ToList(); List <Client> RACING = ThisRacer.Race.Racers.Select(x => x.Client).ToList(); if (RaceEnds <= DateTime.Now & Status.IsInProgress() & RaceEnds > RaceStarted) { //The session has timed out! lock (Threads.GenericThreadSafeLock) { if (!Status.IsFinished()) { Status.SetFinished(); } foreach (_Racer DNFRacer in Racers.Where(x => x.CurrentCheckpoint / (Path.Points.Count) < TotalLapCount)) { DNFRacer.Client.SendMessage("RACE OVER ##" + " P" + GetPositionOfRacer(DNFRacer) + " ## RACE OVER"); } } } if (ThisRacer.CurrentLap > TotalLapCount && TotalLapCount > 0) { //stop counting for this racer, they finished the race! return; } Client ThisClient = ThisRacer.Client; Vehicle ThisVehicle = ThisRacer.Client.Vehicle; if (ThisVehicle == Vehicles.NoVehicle) { return; } World.Objects.Path ThisPath = Path; World.Objects.Path._Point ThisPoint; try { ThisPoint = ThisPath.Points[(ThisRacer.CurrentCheckpoint + 1) % ThisPath.Points.Count]; } catch { return; } //Target point will be the next checkpoint the vehicle has to pass! #region Set up the 3D Maths required. //if (!ActiveCheckPoints.Select(x => x.CheckPoint).Contains(ThisPath.Points[0]) & ThisPoint != ThisPath.Points[0]) continue; Math3D.Point3 Previous = new Math3D.Point3(ThisVehicle.Prev_PosX, ThisVehicle.Prev_PosY, ThisVehicle.Prev_PosZ); Math3D.Point3 Current = new Math3D.Point3(ThisVehicle.PosX, ThisVehicle.PosY, ThisVehicle.PosZ); Math3D.Segment3 Segment = new Math3D.Segment3(Previous, Current); Math3D.Point3 Point = new Math3D.Point3(ThisPoint.X, ThisPoint.Y, ThisPoint.Z); double Tolerance = Math3D.Distance(Previous, Current); Tolerance /= (ThisVehicle.TimeStamp - ThisVehicle.Prev_TimeStamp); float HitRadius = (float)ThisVehicle.CachedAircraft.HTRADIUS; if (Tolerance < HitRadius * 5) { Tolerance = HitRadius * 5; } #endregion if (Math3D.DoesSegmentPassNearPoint(Segment, Point, Tolerance)) { int ModulatedCheckPointCount = (ThisRacer.CurrentCheckpoint + 1) % ThisPath.Points.Count; //increment point count! ThisRacer.CurrentCheckpoint++; string CurrentLapTime = "<ERROR>"; string CurrentSplitTime = "<ERROR>"; #region GET SPLIT/LAP TIME //float starttime = ThisRacer.TimeStamp_LastCheckpoint; float endtime = ThisRacer.TimeStamp_LastCheckpoint; float laptime = 0; float splittime = 0; try { double Distance = Math3D.GetPointSegmentDistanceIfIntersecting(Point, Segment); if (Distance == Double.PositiveInfinity | Distance == Double.NegativeInfinity) { //no intersection??? return; } double FractionOfTime = Distance / Segment.Length(); endtime = (float)(FractionOfTime * (ThisVehicle.TimeStamp - ThisVehicle.Prev_TimeStamp)) + ThisVehicle.Prev_TimeStamp; TimeSpan StartLapTimeSpan = new TimeSpan(0, 0, 0, 0, (int)(ThisRacer.TimeStamp_LapStarted * 1000)); TimeSpan StartSplitTimeSpan = new TimeSpan(0, 0, 0, 0, (int)(ThisRacer.TimeStamp_LastCheckpoint * 1000)); TimeSpan EndTimeSpan = new TimeSpan(0, 0, 0, 0, (int)(endtime * 1000)); CurrentLapTime = StartLapTimeSpan.GetTimeDifference(EndTimeSpan); laptime = (float)((EndTimeSpan - StartLapTimeSpan).TotalSeconds); splittime = (float)((EndTimeSpan - StartSplitTimeSpan).TotalSeconds); CurrentSplitTime = StartSplitTimeSpan.GetTimeDifference(EndTimeSpan); } catch { } #endregion if (ThisRacer.CumulativeSectorTimeStamps.Count > 0) { ThisRacer.CumulativeSectorTimeStamps.Add(splittime + ThisRacer.CumulativeSectorTimeStamps.Last()); } else { ThisRacer.CumulativeSectorTimeStamps.Add(splittime); } ThisRacer.SectorTimeStamps.Add(splittime); if (ModulatedCheckPointCount == 0) { //just passed the start/finish line! bool YellowLap = false; bool RedLap = false; if (CurrentLapTime == "00:00:00.000") { return; } float ThisLapTime = laptime; float LapTimeDifference = ThisLapTime - FastestLap; if (ThisRacer.FastestLap == 0) { ThisRacer.FastestLap = ThisLapTime; if (FastestLap == 0) { LapTimeDifference = 0; } else { LapTimeDifference = ThisLapTime - FastestLap; } } string PositionDifference = "<ERROR>"; string LapCountString = "<ERROR>"; if (FastestLap == 0) { //No fastest lap set yet! FastestLap = ThisLapTime; LapTimeDifference = 0; RedLap = true; } if (LapTimeDifference < 0) { //New Circuit Record! FastestLap = ThisLapTime; RedLap = true; NONRACING.SendMessage("&a" + ThisRacer.Client.Username + " Just set a new lap record on " + Path.Identify); NONRACING.SendMessage("&a Using a &3" + ThisRacer.Client.Vehicle.Identify); NONRACING.SendMessage("&a LapTime: &e" + ThisLapTime.AsFormattedTimeDifference().Substring(1) + "&c!"); RACING.Exclude(ThisRacer.Client).SendMessage("&a" + ThisRacer.Client.Username + " New lap record: &e" + ThisLapTime.AsFormattedTimeDifference().Substring(1) + "&c!"); } if (ThisRacer.FastestLap > ThisLapTime) { //New Personal Best! ThisRacer.FastestLap = ThisLapTime; YellowLap = true; } string LapBonusMarker = ""; if (YellowLap) { LapBonusMarker = "[&e+&f]"; } if (RedLap) { LapBonusMarker = "[&c#&f]"; } if (RaceTypeIsTimeTrial()) { LapCountString = "L" + ThisRacer.CurrentLap.ToString() + " P" + GetPositionOfRacer(ThisRacer); PositionDifference = LapTimeDifference.AsFormattedTimeDifference(); ThisClient.SendMessage(LapCountString + " - " + CurrentLapTime + " (" + PositionDifference + ")" + LapBonusMarker); } if (RaceTypeIsRace()) { string LapsRemaining = (TotalLapCount - ThisRacer.CurrentLap).ToString(); if (ThisRacer.CurrentLap < TotalLapCount) { LapCountString = "L" + LapsRemaining + " P" + GetPositionOfRacer(ThisRacer); } else { LapCountString = "P" + GetPositionOfRacer(ThisRacer); } int CurrentPosition = GetPositionOfRacer(ThisRacer); string PosAhead = ""; string PosBehind = ""; if (CurrentPosition != Racers.Count()) //Not Last { PosAhead = ThisRacer.RaceTimeGetTimeAheadString(); } if (CurrentPosition != 1) //Not First { PosBehind = ThisRacer.RaceTimeGetTimeBehindString(); } if (ThisRacer.CurrentLap < TotalLapCount) { ThisClient.SendMessage(LapCountString + " - " + CurrentLapTime + LapBonusMarker); } else { if (GetPositionOfRacer(ThisRacer) == 1) { ThisClient.SendMessage("RACE OVER ## " + LapCountString + " - " + ThisRacer.RaceTimeGetTotalTime() + LapBonusMarker + " ## RACE OVER"); } else { float Time = RacersSortedByPosition[0].RaceTimeGetTotalTime(); float Difference = ThisRacer.RaceTimeGetTotalTime() - Time; string StrDiff = Difference.AsFormattedTimeDifference(); ThisClient.SendMessage("RACE OVER ## " + LapCountString + " - " + ThisRacer.RaceTimeGetTotalTime() + LapBonusMarker + "(" + StrDiff + ")" + " ## RACE OVER"); } } if (PosAhead != "") { ThisClient.SendMessage(" " + PosAhead); } if (PosBehind != "") { ThisClient.SendMessage(" " + PosBehind); } } ThisRacer.TimeStamp_LapStarted = endtime; ThisRacer.TimeStamp_LastCheckpoint = endtime; if (GetPositionOfRacer(ThisRacer) == 1 & ThisRacer.CurrentLap == TotalLapCount & TotalLapCount != 0) { //coming first //completed the last lap //not a 0 lap race... //... Means this racer WON the race! RaceEnds = DateTime.Now + new TimeSpan(0, 0, 0, 0, (int)(FastestLap * 1000 * 2)); //double the fastest lap time of the race should be plenty of time for the stragglers to catch up! } ThisRacer.CurrentLap++; } else { //normal checkpoint. bool YellowSector = false; bool RedSector = false; #region FastestSectors if (FastestSectors[ModulatedCheckPointCount] == 0) { //no time set for this sector, set it now! FastestSectors[ModulatedCheckPointCount] = splittime; } if (splittime < FastestSectors[ModulatedCheckPointCount]) { //New circuit record sector! FastestSectors[ModulatedCheckPointCount] = splittime; } if (splittime < ThisRacer.FastestSectors[ModulatedCheckPointCount]) { //New personal best sector! ThisRacer.FastestSectors[ModulatedCheckPointCount] = splittime; } #endregion #region CumulativeSectors float Difference = laptime - CumulativeSectors[ModulatedCheckPointCount]; if (CumulativeSectors[ModulatedCheckPointCount] == 0) { //no time set for this sector, set it now! CumulativeSectors[ModulatedCheckPointCount] = laptime; RedSector = true; Difference = 0; } if (laptime < CumulativeSectors[ModulatedCheckPointCount]) { //New circuit record sector! CumulativeSectors[ModulatedCheckPointCount] = laptime; RedSector = true; } if (laptime < ThisRacer.CumulativeSectors[ModulatedCheckPointCount]) { //New personal best sector! ThisRacer.CumulativeSectors[ModulatedCheckPointCount] = laptime; YellowSector = true; } #endregion string StrDiff = Difference.AsFormattedTimeDifference(); string SectorBonusMarker = ""; if (YellowSector) { SectorBonusMarker = "[&e+&f]"; } if (RedSector) { SectorBonusMarker = "[&c#&f]"; } ThisClient.SendMessage("Split " + ModulatedCheckPointCount + " - " + CurrentSplitTime + "(" + StrDiff + ")" + SectorBonusMarker); ThisRacer.TimeStamp_LastCheckpoint = endtime; } } }
public static Aircraft Cache(this MetaData.Aircraft ThisAircraft) { Aircraft Output = CachedData._Aircraft.None; #region DAT File Exists? if (!Files.FileExists(Settings.Loading.YSFlightDirectory + ThisAircraft.AircraftPath0Dat)) { Log.Warning("Can't find .DAT File: \"" + Settings.Loading.YSFlightDirectory + ThisAircraft.AircraftPath0Dat + "\". Can't Cache!"); return(Output); } #endregion #region Load DAT File string[] DatFileContents = Files.FileReadAllLines(Settings.Loading.YSFlightDirectory + ThisAircraft.AircraftPath0Dat); List <string[]> SplitLines = new List <string[]>(); #endregion #region Process DAT File into Arguments foreach (string ThisLine in DatFileContents) { string[] ReadyToAdd = ThisLine.SplitPreservingQuotes(' '); if (ReadyToAdd.Length < 1) { continue; } if (ReadyToAdd[0].ToUpperInvariant() == "REM") { if (ReadyToAdd.Length < 2) { continue; } if (ReadyToAdd[1].ToUpperInvariant() != "OPENYS") { continue; } if (ReadyToAdd.Length < 4) { continue; } ReadyToAdd = ReadyToAdd.Skip(2).ToArray(); } List <string> Out = new List <string>(); foreach (string ThisString in ReadyToAdd) { if (ThisString.StartsWith("#")) { break; } if (ThisString.StartsWith(";")) { break; } Out.Add(ThisString); } SplitLines.Add(Out.ToArray()); } #endregion #region Set Cached Values from Arguments Output = new Aircraft(); foreach (FieldInfo ThisField in typeof(Aircraft).GetFields()) { //Foreach Field in Class... foreach (string[] ThisArgumentStack in SplitLines) { //compare against each line in dat file... if (ThisArgumentStack[0].ToUpperInvariant() == ThisField.Name) { //If DAT file command = field name... //2 VALUES: if (ThisArgumentStack.Length < 2) { Log.Warning("Bad .DAT Line in .DAT File: " + Settings.Loading.YSFlightDirectory + ThisAircraft.AircraftPath0Dat + ". " + ThisArgumentStack.ToStringList()); Debug.WriteLine("Bad .DAT Line - Break here to investigate."); } #region String if (ThisField.FieldType == typeof(string)) { ThisField.SetValue(Output, ThisArgumentStack[1]); continue; } #endregion #region Bool if (ThisField.FieldType == typeof(bool)) { bool Value = false; bool Failed = !Boolean.TryParse(ThisArgumentStack[1].ToUpperInvariant(), out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Int if (ThisField.FieldType == typeof(int)) { int Value = 0; bool Failed = !Int32.TryParse(ThisArgumentStack[1].ToUpperInvariant(), out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Double if (ThisField.FieldType == typeof(double)) { double Value = 0; bool Failed = !Double.TryParse(ThisArgumentStack[1].ToUpperInvariant(), out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.Knots if (ThisField.FieldType == typeof(Numbers.Velocity.Knots)) { Numbers.Velocity.Knots Value = 0; bool Failed = !ThisArgumentStack[1].AsKnots(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.MetersPerSecond if (ThisField.FieldType == typeof(Numbers.Velocity.MetersPerSecond)) { Numbers.Velocity.MetersPerSecond Value = 0; bool Failed = !ThisArgumentStack[1].AsMetersPerSecond(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.MilesPerHour if (ThisField.FieldType == typeof(Numbers.Velocity.MilesPerHour)) { Numbers.Velocity.MilesPerHour Value = 0; bool Failed = !ThisArgumentStack[1].AsMilesPerHour(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.KilometersPerHour if (ThisField.FieldType == typeof(Numbers.Velocity.KilometersPerHour)) { Numbers.Velocity.KilometersPerHour Value = 0; bool Failed = !ThisArgumentStack[1].AsKilometersPerHour(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.FeetPerSecond if (ThisField.FieldType == typeof(Numbers.Velocity.FeetPerSecond)) { Numbers.Velocity.FeetPerSecond Value = 0; bool Failed = !ThisArgumentStack[1].AsFeetPerSecond(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.MachAtSeaLevel if (ThisField.FieldType == typeof(Numbers.Velocity.MachAtSeaLevel)) { Numbers.Velocity.MachAtSeaLevel Value = 0; bool Failed = !ThisArgumentStack[1].AsMachAtSeaLevel(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Kilometers if (ThisField.FieldType == typeof(Numbers.Length.Kilometers)) { Numbers.Length.Kilometers Value = 0; bool Failed = !ThisArgumentStack[1].AsKilometers(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Meters if (ThisField.FieldType == typeof(Numbers.Length.Meters)) { Numbers.Length.Meters Value = 0; bool Failed = !ThisArgumentStack[1].AsMeters(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Centimeters if (ThisField.FieldType == typeof(Numbers.Length.Centimeters)) { Numbers.Length.Centimeters Value = 0; bool Failed = !ThisArgumentStack[1].AsCentimeters(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Miles if (ThisField.FieldType == typeof(Numbers.Length.Miles)) { Numbers.Length.Miles Value = 0; bool Failed = !ThisArgumentStack[1].AsMiles(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.NauticalMiles if (ThisField.FieldType == typeof(Numbers.Length.NauticalMiles)) { Numbers.Length.NauticalMiles Value = 0; bool Failed = !ThisArgumentStack[1].AsNauticalMiles(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Yards if (ThisField.FieldType == typeof(Numbers.Length.Yards)) { Numbers.Length.Yards Value = 0; bool Failed = !ThisArgumentStack[1].AsYards(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Feet if (ThisField.FieldType == typeof(Numbers.Length.Feet)) { Numbers.Length.Feet Value = 0; bool Failed = !ThisArgumentStack[1].AsFeet(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Inches if (ThisField.FieldType == typeof(Numbers.Length.Inches)) { Numbers.Length.Inches Value = 0; bool Failed = !ThisArgumentStack[1].AsInches(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Tonnes if (ThisField.FieldType == typeof(Numbers.Mass.Tonnes)) { Numbers.Mass.Tonnes Value = 0; bool Failed = !ThisArgumentStack[1].AsTonnes(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Kilograms if (ThisField.FieldType == typeof(Numbers.Mass.Kilograms)) { Numbers.Mass.Kilograms Value = 0; bool Failed = !ThisArgumentStack[1].AsKilograms(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Grams if (ThisField.FieldType == typeof(Numbers.Mass.Grams)) { Numbers.Mass.Grams Value = 0; bool Failed = !ThisArgumentStack[1].AsGrams(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Pounds if (ThisField.FieldType == typeof(Numbers.Mass.Pounds)) { Numbers.Mass.Pounds Value = 0; bool Failed = !ThisArgumentStack[1].AsPounds(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Ounces if (ThisField.FieldType == typeof(Numbers.Mass.Ounces)) { Numbers.Mass.Ounces Value = 0; bool Failed = !ThisArgumentStack[1].AsOunces(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Stones if (ThisField.FieldType == typeof(Numbers.Mass.Stones)) { Numbers.Mass.Stones Value = 0; bool Failed = !ThisArgumentStack[1].AsStones(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Angles.Degrees if (ThisField.FieldType == typeof(Numbers.Angles.Degrees)) { Numbers.Angles.Degrees Value = 0; bool Failed = ThisArgumentStack[1].AsDegrees(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Angles.Radians if (ThisField.FieldType == typeof(Numbers.Angles.Radians)) { Numbers.Angles.Radians Value = 0; bool Failed = ThisArgumentStack[1].AsRadians(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Angles.Gradians if (ThisField.FieldType == typeof(Numbers.Angles.Gradians)) { Numbers.Angles.Gradians Value = 0; bool Failed = ThisArgumentStack[1].AsGradians(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion //3 VALUES: if (ThisArgumentStack.Length < 3) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ": " + ThisArgumentStack.ToArray().ToStringList()); Debug.WriteLine("Bad .DAT Line - Break here to investigate."); } //4 VALUES: if (ThisArgumentStack.Length < 4) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ": " + ThisArgumentStack.ToArray().ToStringList()); Debug.WriteLine("Bad .DAT Line - Break here to investigate."); } #region Math3D.Point3 if (ThisField.FieldType == typeof(Math3D.Point3)) { Math3D.Point3 Value = new Math3D.Point3(0, 0, 0); Numbers.Length.Meters _X = 0; Numbers.Length.Meters _Y = 0; Numbers.Length.Meters _Z = 0; bool Failed = !ThisArgumentStack[1].AsMeters(out _X); Failed |= !ThisArgumentStack[2].AsMeters(out _Y); Failed |= !ThisArgumentStack[3].AsMeters(out _Z); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ": " + ThisArgumentStack.Skip(1).ToArray().ToStringList()); Debug.WriteLine("Failed to convert value."); } Value.X = _X; Value.Y = _Y; Value.Z = _Z; ThisField.SetValue(Output, Value); continue; } #endregion Log.Warning("Dat Variable Not Recognised for " + ThisAircraft.Identify + "?: " + ThisArgumentStack.ToArray().ToStringList()); Debug.WriteLine("Value not recognised."); } } //Debug.WriteLine(ThisField.ToString()); } #endregion #region Post-Conversion Integrity Checks if (Output.WEIGFUEL <= 0) { Log.Warning("Something went wrong in conversion of fuel? " + ThisAircraft.Identify); } #endregion return(Output); }