public AvidWindow[] GetPossibleLaunchWindows(int courseOffset, AvidWindow targetWindow, AvidWindow crossingVector) { if (AvidWindow.IsNullOrZero(targetWindow)) { return(new[] { GetOppositeWindow(crossingVector) }); //This may still result in undefined vector if both are zero. // This is fine. If both ships aren't moving and sit in the same hex, launch window can't be determined. This situation should // not arise in any real scenario, but we still need to handle it. } if (courseOffset == 0 || targetWindow.Equals(crossingVector) || AvidWindow.IsNullOrZero(crossingVector)) { return(new [] { targetWindow }); } var pathingResult = _avidPathfinder.GetShortestPaths(_avidModel, targetWindow, crossingVector, AvidPathingOptions.DiagonalTransitionsLimitWithPolar); if (!pathingResult.PathExists) { return(new AvidWindow[] { }); } return(pathingResult.AllShortestPaths.Select(pi => pi.PathNodes[courseOffset]) .Where(lan => lan.Window.MinDistance >= lan.NodeDistance) // This is to exclude windows, that could be reached through diagonal transition // but can also reached by two non-diagonal transitions. So, in the final result for course offset = 2, it would look like two windows .Select(lan => (AvidWindow)lan.Window).Distinct().ToArray()); }
public int GetCourseOffset(AvidWindow targetVector, AvidWindow crossingVector) { if (AvidWindow.IsNullOrZero(targetVector) || AvidWindow.IsNullOrZero(crossingVector)) { return(6); } return(CountWindows(targetVector, crossingVector)); }
public void UpdateVector(AvidVector vector, bool isVisible) { IsVisible = !AvidWindow.IsNullOrZero(vector) && isVisible; Magnitude = vector != null ? vector.Magnitude : 0; Window = vector; OnPropertyChanged(Properties.IsVisible); OnPropertyChanged(Properties.Magnitude); OnPropertyChanged(Properties.Window); }
private void CreateOrUpdateVector(AvidVector originalVector, ref IAvidMark targetVector, int categoryId, bool underlined) { string markText = originalVector != null?originalVector.Magnitude.ToString("D") : string.Empty; AvidWindow position = originalVector ?? new AvidWindow(); if (targetVector == null) { targetVector = _elementBoard.AddMark(categoryId, markText, originalVector != null, underlined, position); } else { targetVector.Text = markText; targetVector.Window = position; targetVector.Visible = !AvidWindow.IsNullOrZero(position); } }
public void UpdateDirections(AvidWindow launchWindow, AvidDirection referenceDirection) { if (AvidWindow.IsNullOrZero(launchWindow) || (launchWindow.Ring == AvidRing.Magenta && referenceDirection == AvidDirection.Undefined)) { ResetEvasionInfo(); return; } var impactWindow = _avidCalculator.GetOppositeWindow(launchWindow); var axis = _avidCalculator.GetOrientationWithoutRoll(impactWindow, referenceDirection); ImpactWindow = axis.Nose; EvasionUp = axis.Top; EvasionDown = axis.Bottom; EvasionLeft = axis.Port; EvasionRight = axis.Starboard; OnEvasionChanged(); }
public int CountWindows(AvidWindow start, AvidWindow destination) { if (start.Equals(destination) || AvidWindow.IsNullOrZero(start) || AvidWindow.IsNullOrZero(destination)) { return(0); } var pathingResult = _avidPathfinder.GetShortestPaths(_avidModel, start, destination, AvidPathingOptions.DiagonalTransitionsLimitWithPolar); if (!pathingResult.PathExists) { throw new Exception("Failed to find path from start to destination. That must be the problem with the algorithm."); } if (Math.Abs(pathingResult.MinimalDistance - GetDistanceFromAngle(start, destination) * 2) > 1) { //throw new Exception("Distance inconsistent."); } // Since all normal transitions on the avid are two points, we need to halve the result. return(pathingResult.MinimalDistance / 2); }
public static bool IsNullOrZero(AvidVector vector) { return(AvidWindow.IsNullOrZero(vector) || vector.Magnitude == 0); }