private void RecalculateAllPaths() { PathCollection.Clear(); foreach (var start in StructureManager) { if (!PathCollection.ContainsKey(start.Position)) { PathCollection.Add(start.Position, new Dictionary <HexagonNode, Path>()); } foreach (var destination in StructureManager) { try { if (!PathCollection[start.Position].ContainsKey(destination.Position)) { Path path = new Path(PathFinding.AStar(start.Position, destination.Position).ToArray()); AddPath(path); if (path.AllHops.Count > 2) { var containedPaths = path.GetContainedPaths(); foreach (var containedPath in containedPaths) { AddPath(containedPath); } } } } catch (NoPathFoundException <HexagonNode> ) { } } } }
private void AddPath(Path path) { if (!PathCollection.ContainsKey(path.Start)) { PathCollection.Add(path.Start, new Dictionary <HexagonNode, Path>()); } if (!PathCollection[path.Start].ContainsKey(path.Destination)) { PathCollection[path.Start].Add(path.Destination, path); } }
public Path GetPath(HexagonNode start, HexagonNode destination) { if (PathCollection.ContainsKey(start) && PathCollection[start].ContainsKey(destination)) { return(PathCollection[start][destination]); } if (PathCollection.ContainsKey(destination) && PathCollection[destination].ContainsKey(start)) { return(PathCollection[destination][start].Reverse()); } return(null); }