/// <summary> /// Recalculate heights based on terrain, rebuild visuals if necessary. /// </summary> /// <param name="onLoad">True if this is being called on initial load. False otherwise. Only affects setting of IsLevelDirty flag.</param> public void RecalcHeights(bool onLoad = false) { RecalcAirborne(); if (Road != null) { Road.Rebuild(); } if (!onLoad) { InGame.IsLevelDirty = true; // Force a save. } }
/// <summary> /// Scans through the path ensuring that all the nodes in the path are /// connected by edges. If not, it splits this path into multiple paths /// of the same color. Also checks all edges to make sure that they are /// only connected to nodes in this path. If not, they are just deleted. /// </summary> public void EnsureCoherence() { // Delete any edges that reference nodes not in this path. for (int i = Edges.Count - 1; i >= 0; i--) { Edge e = Edges[i]; if (!Nodes.Contains(e.Node0) || !Nodes.Contains(e.Node1)) { RemoveEdge(e); } } if (Nodes.Count == 0) { // Hmm, degenerate path. What to do? Should never get here. throw new Exception("Degenerate waypoint path found."); } // Sweep through all nodes marking them as "not in". Node n = null; for (int i = 0; i < Nodes.Count; i++) { n = Nodes[i]; n.temp = 0; } // Mark first node as in. n = Nodes[0]; n.temp = 1; // Flood fill this out to the other connected nodes. Flood(n); // At this point, any nodes that are not marked are not connected to this path and // should be removed from this path and given their own path. bool newPaths = false; for (int i = Nodes.Count - 1; i > 0; i--) { n = Nodes[i]; if (n.temp != 1) { ///Note that in this loop, no nodes or edges are created or destroyed, ///just moved from one path to another. So no bookkeeping on counts ///is needed. // Remove this node from the current path. Nodes.RemoveAt(i); // Create a new path for the node in the same color and add the node to the path. Path path = new Path(n.Path.color); n.Path = path; path.Nodes.Add(n); // Move any edges that originate from this node to the new path. for (int j = Edges.Count - 1; j >= 0; j--) { Edge e = Edges[j]; if (e.Node0 == n) { Edges.RemoveAt(j); n.Path.Edges.Add(e); } } newPaths = true; } } // Finally, if we removed any nodes and created new paths for // them we may have multiple paths that need to be merged. if (newPaths) { MergePaths(); } // ***ROAD - nuke the road so we'll rebuild it. if (Road != null) { Road.Rebuild(); } } // end of Path EnsureCoherence()