void verticesLink(BuildingVertex[] verts) { List <int> linksList; for (int n1 = 0; n1 < verts.Length; n1++) { BuildingVertex v1 = verts[n1]; v1.id = n1; linksList = new List <int>(); for (int n2 = 0; n2 < verts.Length; n2++) { if (n1 != n2) { BuildingVertex v2 = verts[n2]; if (v2.floorIDs[0] == v1.floorIDs[0] || v2.floorIDs[1] == v1.floorIDs[0] || v2.floorIDs[0] == v1.floorIDs[1] || v2.floorIDs[1] == v1.floorIDs[1]) { linksList.Add(n2); } } } Debug.Log("Found Connections: " + linksList.Count); v1.accessibleVertices = linksList.ToArray(); linksList.Clear(); /*GameObject o = GameObject.Instantiate(pfMarking, v1.position, Quaternion.identity); * o.GetComponent<DebugInfo>().integer = n1; * o.GetComponent<DebugInfo>().listOfInts = v1.accessibleVertices;*/ } }
BuildingVertex[] verticesProcess(List <BuildingVertex> vertsList) { Debug.Log("YOWZA, size of list: " + vertsList.Count.ToString()); List <BuildingVertex> vNew = new List <BuildingVertex>(); for (int n = 0; n < vertsList.Count; n++) { BuildingVertex v = vertsList[n]; BuildingVertex opp = null; //find the vertex's opposite "partner" if (v != null) { for (var n2 = 0; n2 < vertsList.Count; n2++) { BuildingVertex v2 = vertsList[n2]; if (v2 != null && n != n2) { if (v.floorIDs[0] == v2.floorIDs[1] && v.floorIDs[1] == v2.floorIDs[0]) { opp = v2; vNew.Add(new BuildingVertex(v.floorIDs, (v.position + v2.position) * 0.5f)); int index = vNew.Count - 1; vertsList[n2] = null; } } } } } return(vNew.ToArray()); }
List <int> routeRun(BuildingGraph graph, List <int> route, int roomTo, int[] vertShortestAccess, bool[] viability) { BuildingVertex v = graph.vertices[route[route.Count - 1]]; vertShortestAccess[v.id] = route.Count; for (int n = 0; n < v.floorIDs.Length; n++) { if (graph.floorsRoomIds[v.floorIDs[n]] == roomTo) //If in target room { return(route); } } List <int>[] lists = new List <int> [v.accessibleVertices.Length]; for (int n = 0; n < v.accessibleVertices.Length; n++) { if (vertShortestAccess[v.accessibleVertices[n]] > route.Count - 1 && viability[v.accessibleVertices[n]]) { List <int> copy = listCopy(route); copy.Add(v.accessibleVertices[n]); lists[n] = routeRun(graph, copy, roomTo, vertShortestAccess, viability); } else { lists[n] = null; } } int shortestLength = int.MaxValue; int shortestIndex = -1; for (int n = 0; n < lists.Length; n++) { List <int> rCurrent = lists[n]; if (rCurrent != null) { if (rCurrent.Count < shortestLength) { shortestIndex = n; shortestLength = rCurrent.Count; } } } if (shortestIndex >= 0) { return(lists[shortestIndex]); } else { viability[v.id] = false; //DONT GO HERE EVER AGAIN! return(null); } }
int findVertex(int floor) { BuildingGraph graph = building.GetComponent <BuildingGraph>(); for (int n = 0; n < graph.vertices.Length; n++) { BuildingVertex v = graph.vertices[n]; for (int n2 = 0; n2 < v.floorIDs.Length; n2++) { if (v.floorIDs[n2] == floor) { return(n); } } } return(-1); }