/// <summary> /// Compress the road array - remove any null roads /// </summary> public void CompressRoads() { for (int i = 0; i < Roads.Count - 1; i++) { if (Roads[i] == null) { if (Roads[i + 1] != null) { Roads[i] = Roads[i + 1]; Roads[i + 1] = null; Modified = true; } } } int numberOfRoads = 0; for (int i = 0; i < Roads.Count; i++) { if (Roads[i] != null) { numberOfRoads++; } } int roadsFromUnion = UnionHelper.GetRoadCount(Union); if (roadsFromUnion == numberOfRoads) { return; } Union = UnionHelper.SetRoadUnionTypeFromRoadCount(numberOfRoads); UpdateLinksnumber(numberOfRoads); }
/// <summary> /// Add a road /// </summary> /// <param name="node">The node to add the road too</param> /// <param name="nodeToAdd">The node to add</param> public static void AddRoadToNode(RoadNetworkNode node, RoadNetworkNode nodeToAdd) { if (node.HasLinksToNode(nodeToAdd)) { return; } int roadCount = UnionHelper.GetRoadCount(node.Details.Union) + 1; node.Details.Union = UnionHelper.SetRoadUnionTypeFromRoadCount(roadCount); node.CreateRoadArray(); for (int r = 0; r < node.Details.Roads.Count; r++) { if (node.Details.Roads[r] == null) { node.Details.Roads[r] = nodeToAdd; node.Details.Modified = true; return; } } }