public bool UpdateIndirectNeighbours(WaypointObstacle obstacle, Waypoint wp, out Node oldNeighbour) { float oldIndirectPathCost = 0; changed = false; oldNeighbour = null; if (wp.indirectNeighbours.Count > 0) { oldNeighbour = wp.indirectNeighbours[0]; } Waypoint newIndirectNeighbour = (Waypoint)GetClosesNodeViaPhysics(obstacle, wp); //for simplicity let's assume ever node only has one indirect neighour if (newIndirectNeighbour == null) //waypoint had indirect neighbour before, but now doesn't { if (wp.indirectNeighbours.Count == 0) { changed = false; } else { changed = true; foreach (Node node in wp.indirectNeighbours) //remove path costs of all indirect neighbours { wp.pathCosts.Remove(node); } wp.indirectNeighbours.Clear(); } return(changed); } else if (wp.indirectNeighbours.Count == 0 && newIndirectNeighbour != null) //waypoint didn't have indirect neighbour before, but now does { wp.AddNeighbour(newIndirectNeighbour, true); changed = true; } else if (newIndirectNeighbour != null && newIndirectNeighbour != wp.indirectNeighbours[0]) //indirect neighbour has changed { changed = true; foreach (Node node in wp.indirectNeighbours) //remove path costs of all indirect neighbours { wp.pathCosts.Remove(node); } wp.indirectNeighbours.Clear(); wp.AddNeighbour(newIndirectNeighbour, true); } else if (newIndirectNeighbour == wp.indirectNeighbours[0]) //indirect neigbour stayed the same { wp.indirectNeighbours[0].ToWaypoint().indirectPredecessors.Add(wp); oldIndirectPathCost = wp.pathCosts[wp.indirectNeighbours[0]]; float newindirectPathCost = Vector3.Distance(wp.globalPosition, newIndirectNeighbour.globalPosition); if (oldIndirectPathCost != newindirectPathCost) { changed = true; } } return(changed); }
public void Connect(Waypoint other) { if (other == null) throw new ArgumentNullException("other"); this.AddNeighbour(other); other.AddNeighbour(this); }