/// <summary> /// The entrance locations touching. /// </summary> /// <returns>The locations touching.</returns> /// <param name='voidCluster'>Void cluster.</param> protected List<CellLocation> EntranceLocationsTouching(VoidCluster voidCluster) { // The entrance locations touching List<CellLocation> entranceLocationsTouching = new List<CellLocation> (); foreach (Void voidCell in voidCluster.allVoidCells) { // The northern location CellLocation north = new CellLocation (voidCell.location.x, voidCell.location.y, voidCell.location.z + 1); // The southern location CellLocation south = new CellLocation (voidCell.location.x, voidCell.location.y, voidCell.location.z - 1); // The eastern location CellLocation east = new CellLocation (voidCell.location.x + 1, voidCell.location.y, voidCell.location.z); // The western location CellLocation west = new CellLocation (voidCell.location.x - 1, voidCell.location.y, voidCell.location.z); if (dungeonGenerator.cellTypeGrid[north.x, north.y, north.z] == CellType.Entrance) // Add the northern location to entrances touching entranceLocationsTouching.Add (north); if (dungeonGenerator.cellTypeGrid[south.x, south.y, south.z] == CellType.Entrance) // Add the southern location to entrances touching entranceLocationsTouching.Add (south); if (dungeonGenerator.cellTypeGrid[east.x, east.y, east.z] == CellType.Entrance) // Add the eastern location to entrances touching entranceLocationsTouching.Add (east); if (dungeonGenerator.cellTypeGrid[west.x, west.y, west.z] == CellType.Entrance) // Add the western location to entrances touching entranceLocationsTouching.Add (west); } // Return the entrance locations touching return entranceLocationsTouching; }
/// <summary> /// Alls the void cluster islands. /// </summary> /// <returns>The void cluster islands.</returns> public List<VoidCluster> AllVoidClusterIslands() { // The the void cluster islands List<VoidCluster> allVoidClusterIslands = new List<VoidCluster> (); // The the void clusters List<VoidCluster> allVoidClusters = new List<VoidCluster> (); // The unclustered void cells List<Void> unclusteredVoidCells = new List<Void> (); foreach (Void voidCell in AllVoidCells ()) { // Add void to unclustered void cells unclusteredVoidCells.Add (voidCell); } bool finished = false; while (!finished) { // The void cluster cells List<Void> voidClusterCells = new List<Void> (); // The known existing connections ArrayList knownExistingConnections = new ArrayList(); foreach (Void voidCell in unclusteredVoidCells) { if (VoidConnectedToVoid(voidCell, unclusteredVoidCells[0], ref knownExistingConnections)) { // Add void cell to void cluster cells voidClusterCells.Add (voidCell); } } foreach (Void voidCell in voidClusterCells) { // Remove the void cell from unclustered void cells unclusteredVoidCells.Remove (voidCell); } // The void cluster VoidCluster voidCluster = new VoidCluster (); // Add the void cluster cells to the void clusteres void cells voidCluster.allVoidCells = voidClusterCells; // Add the void cluster to all void clusters allVoidClusters.Add (voidCluster); if (unclusteredVoidCells.Count == 0) { // Finished clustering void cells finished = true; } } foreach (VoidCluster voidCluster in allVoidClusters) { if (VoidClusterIsIsland (voidCluster)) { // Add void cluster to all void cluster islands allVoidClusterIslands.Add (voidCluster); } } // Return all the void cluster islands return allVoidClusterIslands; }
/// <summary> /// The void cluster is an island. /// </summary> /// <returns>Is an island.</returns> /// <param name='voidCluster'>If set to <c>true</c> void cluster.</param> public bool VoidClusterIsIsland(VoidCluster voidCluster) { foreach (Void voidCell in voidCluster.allVoidCells) { if (voidCell.location.x == 1 || voidCell.location.x == dungeonGenerator.numCellsX - 2 || voidCell.location.z == 1 || voidCell.location.z == dungeonGenerator.numCellsZ - 2) { // Void cluster is not island return false; } } // Void cluster is island return true; }