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 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 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 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(); }