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); }
public EntranceEdges(OverworldNodes overworldNodes, RoomNodes roomNodes, RawEntranceCollection rawEntranceCollection, RawItemLocationCollection itemLocations) { this._overworldNodes = overworldNodes; this._roomNodes = roomNodes; this._rawEntranceCollection = rawEntranceCollection; this._itemLocations = itemLocations; FillEntranceEdges(); }
public ExitEdges(OverworldNodes overworldNodes, RoomNodes roomNodes, RawExitCollection rawExitCollection) { this._overworldNodes = overworldNodes; this._roomNodes = roomNodes; this._rawExitCollection = rawExitCollection; FillExitEdges(); }
public RoomEdges(RoomNodes roomNodes, OverworldNodes overworldNodes, BossNodes bossNodes, RawRoomEdgeCollection rawRoomEdges) { this._roomNodes = roomNodes; this._overworldNodes = overworldNodes; this._bossNodes = bossNodes; this._rawRoomEdges = rawRoomEdges; this.Edges = new List <Edge>(); FillRoomEdges(); }
// 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); }
public bool isNodeConnected(RoomNodes nodeToTest) { foreach (RoomNodes RN in connectedNeighbors) { if (RN == nodeToTest) { return(true); } } 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); }
void FillNodesAndEdges(RawEntranceCollection rawEntranceCollection, RawExitCollection rawExitCollection, RawItemLocationCollection rawItemLocationCollection, RawItemEdgeCollection rawItemEdges, RawRoomEdgeCollection rawRoomEdges) { _overworldNodes = new Data.OverworldNodes(); _roomNodes = new Data.RoomNodes(); _bossNodes = new Data.BossNodes(); _itemNodes = new Data.ItemLocations(rawItemLocationCollection); FillAllNodes(); _areaEdges = new Data.AreaEdges(_overworldNodes); _roomEdges = new Data.RoomEdges(_roomNodes, _overworldNodes, _bossNodes, rawRoomEdges); _itemEdges = new ItemEdges(this, rawItemEdges); _entranceEdges = new EntranceEdges(_overworldNodes, _roomNodes, rawEntranceCollection, rawItemLocationCollection); _exitEdges = new ExitEdges(_overworldNodes, _roomNodes, rawExitCollection); FillAllEdges(); }
// 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); }