public WaypointLink AddLink(Waypoint destination, LinkStyle stlye, string script) { WaypointLink result = new WaypointLink(this, destination, stlye, script); Links.Add(destination.Id, result); return(result); }
public void SetNearestTypeWaypoint(GameObjectType gameType, WaypointLink link) { if (NearestTypeLinks.ContainsKey(gameType)) { NearestTypeLinks.Remove(gameType); } NearestTypeLinks.Add(gameType, link); }
private static bool FindNearest(GameObjectType gameObjectType, List <WaypointLink> path, List <Waypoint> visitedList, List <WaypointLink> currentShortestPath, WaypointLink waypointLink) { if ((currentShortestPath.Count > 0) && (_getPathLength(path) >= _getPathLength(currentShortestPath))) { string s = _pathToString(path) + "." + waypointLink.Destination.Name; s = "Path longer than current path: " + s; Debug.WriteLine(s); return(false); } if (waypointLink.Destination.SupportsObjectType.Contains(gameObjectType)) { UpdatePath(currentShortestPath, path); currentShortestPath.Add(waypointLink); string s = _pathToString(currentShortestPath); s = "Found new shortest path: " + s; Debug.WriteLine(s); return(false); } if (visitedList.Contains(waypointLink.Destination)) { return(false); } if ((waypointLink.Destination.NearestTypeLinks.ContainsKey(gameObjectType) && (waypointLink.Destination.NearestTypeLinks[gameObjectType].Destination != waypointLink.Source))) { path.Add(waypointLink); string s = _pathToString(currentShortestPath); s = "Found preexisting route at: " + s; Debug.WriteLine(s); //follow links to end int iPathDepth = 1; WaypointLink link = waypointLink.Destination.NearestTypeLinks[gameObjectType]; do { path.Add(link); iPathDepth++; if (link.Destination.NearestTypeLinks.ContainsKey(gameObjectType)) { link = link.Destination.NearestTypeLinks[gameObjectType]; } else { link = null; } } while (link != null); if ((currentShortestPath.Count < 1) || (_getPathLength(path) < _getPathLength(currentShortestPath))) { s = _pathToString(path); s = "Used existing route, path is now: " + s; Debug.WriteLine(s); UpdatePath(currentShortestPath, path); for (int i = 0; i < iPathDepth; i++) { path.RemoveAt(path.Count - 1); //back out of path } return(false); } for (int i = 0; i == iPathDepth; i++) { path.RemoveAt(path.Count - 1); //remove 1 extra as we will add it backin below } Debug.WriteLine("Existing route is longer than current shortest"); } visitedList.Add(waypointLink.Destination); path.Add(waypointLink); foreach (KeyValuePair <int, WaypointLink> pair in waypointLink.Destination.Links) { FindNearest(gameObjectType, path, visitedList, currentShortestPath, pair.Value); } path.Remove(waypointLink); visitedList.Remove(waypointLink.Destination); return(false); }