private bool diagonalRoomConnected(RoomNodes nextNode) { RoomNodes badConnector; // current node above next node, could lead to possible conflict from node below this one. if (ID / RoomPathGenerator.LEVELS > nextNode.getID() / RoomPathGenerator.LEVELS) { if ((badConnector = map.getNeighbors(nextNode.getID() + RoomPathGenerator.LEVELS)) != null) { if (badConnector.isNodeConnected(map.getNeighbors(ID - RoomPathGenerator.LEVELS))) { return(true); } } } // current node below next node, could lead to possible conflict from node above this one. else if (ID / RoomPathGenerator.LEVELS < nextNode.getID() / RoomPathGenerator.LEVELS) { if ((badConnector = map.getNeighbors(nextNode.getID() - RoomPathGenerator.LEVELS)) != null) { if (badConnector.isNodeConnected(map.getNeighbors(ID + RoomPathGenerator.LEVELS))) { return(true); } } } // straight corridor, no problems. (due to corridor generation, if that changes this will too) // also if diagonals dont interfer with each other. return(false); }
private void createDungeonPath() { // begin algorithm get first node of graph current = (RoomNodes)notInPath [Random.Range(0, notInPath.Count)]; notInPath.Remove(current); inPath.Add(current); // keep connecting nodes -- ends when reaches node with no unconnected neighbors that are not already in the path RoomNodes previous = current; previousNodeID = previous.getID(); while ((current = current.getRandomUnconnectedNeighbor(previousNodeID)) != null) { previousNodeID = previous.getID(); if (previous.connectTwoNeighbors(current)) { current.connectTwoNeighbors(previous); notInPath.Remove(current); inPath.Add(current); previous = current; } else { break; } } // some nodes may still be unconnected, the next stage is to connect them to a neighbor whom is attached until all remaining nodes are connected. connectUnconnectedNodes(2); }
// to use in hash table, one must override hash code method as well public override bool Equals(object other) { if (other is RoomNodes) { RoomNodes r = (RoomNodes)other; return(this.ID == r.getID()); } return(false); }
// checks if this node is connected to nextNode's verticle neighbors public bool notConnectedToVerticleNodes(RoomNodes nextNode) { int verticleID = nextNode.getID() % RoomPathGenerator.LEVELS; // gives 0 - 8. for (int i = 0; i < 3; ++i) { if (this.isNodeConnected(map.getNeighbors(verticleID + (RoomPathGenerator.LEVELS * i)))) { return(false); } } return(true); }
// newConnect must be in the unconnected list // also connects given neighbor to this public bool connectTwoNeighbors(RoomNodes newConnect) { int count = unconnectedNeighbors.Count; unconnectedNeighbors.Remove(newConnect); if (count > unconnectedNeighbors.Count) { connectedNeighbors.Add(newConnect); enableCorridor(newConnect.getID()); // activates gameobject inPath = true; newConnect.setInPath(); return(true); } return(false); }