private bool CheckInsideRoomTile(VirtualMap map, CellLocation loc) { CellLocation[] neigh_locs = map.GetAllNeighbours(loc); int countRoomFloors = 0; foreach (CellLocation nl in neigh_locs) { if (!map.LocationIsOutsideBounds(nl) && map.GetCell(nl).IsRoomFloor()) { countRoomFloors++; } } return(countRoomFloors == 4); }
public void ConvertDirectionalRoomColumn(VirtualMap map, VirtualCell conversion_cell) { CellLocation l = conversion_cell.location; if (behaviour.useDirectionalFloors) { CellLocation[] border_neighs; bool considerDoorsAsWalls = true; // Count how many border neighbours are room walls int countWallNeighs = 0; bool[] validIndices = new bool[4]; // This was a 'tile', check neigh walls border_neighs = map.GetAllNeighbours(l); for (int i = 0; i < border_neighs.Length; i++) { CellLocation other_l = border_neighs[i]; if (!map.LocationIsOutsideBounds(other_l) && (((behaviour.isolateDirectionalWallsForRooms && map.GetCell(other_l).IsRoomWall()) || (!behaviour.isolateDirectionalWallsForRooms && map.GetCell(other_l).IsWall())) || (considerDoorsAsWalls && map.GetCell(other_l).IsDoor())) && !map.IsPassageRemovable(other_l) // Make sure the wall is not being removed! ) { //Debug.Log(l + " - " + other_l + " " + map.GetCell(other_l).Type); countWallNeighs++; validIndices[i] = true; } } // Define the adbvanced tiles //Debug.Log ("Cell " + l + " has neigh walls " + countWallNeighs); if (countWallNeighs == 0) { conversion_cell.Type = VirtualCell.CellType.RoomWallO; } else if (countWallNeighs == 1) { conversion_cell.Type = VirtualCell.CellType.RoomWallU; } else if (countWallNeighs == 2) { // Wall I conversion_cell.Type = VirtualCell.CellType.RoomWallI; //Debug.Log("SETTING " + l + " TO I"); for (int i = 0; i < 4; i++) { if (validIndices[i]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)]; break; } } // Wall L for (int i = 0; i < 4; i++) { if (validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { // This and the next are valid: left turn (we consider all of them to be left turns( conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)]; conversion_cell.Type = VirtualCell.CellType.RoomWallL; break; } } } else if (countWallNeighs == 3) { conversion_cell.Type = VirtualCell.CellType.RoomWallT; for (int i = 0; i < 4; i++) { if (validIndices[(int)Mathf.Repeat(i - 1, 4)] && validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)]; break; } } } else if (countWallNeighs == 4) { conversion_cell.Type = VirtualCell.CellType.RoomWallX; } } }
public void ConvertDirectionalCorridorColumn(VirtualMap map, VirtualCell conversion_cell) { CellLocation l = conversion_cell.location; if (behaviour.useDirectionalFloors) { // Count how many border neighbours are walls int countWallNeighs = 0; bool[] validIndices = new bool[4]; // This was a 'tile', check neigh walls CellLocation[] border_neighs = map.GetAllNeighbours(l); for (int i = 0; i < border_neighs.Length; i++) { CellLocation other_l = border_neighs[i]; if (!map.LocationIsOutsideBounds(other_l) // && other_l.isValid() ) // TODO: Maybe isValid is not needed! { VirtualCell other_cell = map.GetCell(other_l); if (other_cell.IsWall() && !map.IsPassageRemovable(other_cell.location)) { countWallNeighs++; validIndices[i] = true; } } } // Define the advanced tile to use // TODO: merge this with the one for directional floors somehow! if (countWallNeighs == 0) { conversion_cell.Type = VirtualCell.CellType.CorridorWallO; } else if (countWallNeighs == 1) { conversion_cell.Type = VirtualCell.CellType.CorridorWallU; for (int i = 0; i < 4; i++) { if (validIndices[i]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)]; break; } } } else if (countWallNeighs == 2) { // Corridor I conversion_cell.Type = VirtualCell.CellType.CorridorWallI; for (int i = 0; i < 4; i++) { if (validIndices[i]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)]; break; } } // Corridor L for (int i = 0; i < 4; i++) { if (validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { // This and the next are valid: left turn (we consider all of them to be left turns( conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)]; conversion_cell.Type = VirtualCell.CellType.CorridorWallL; break; } } } else if (countWallNeighs == 3) { conversion_cell.Type = VirtualCell.CellType.CorridorWallT; for (int i = 0; i < 4; i++) { if (validIndices[(int)Mathf.Repeat(i - 1, 4)] && validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { // This, the one before and the next are valid: T cross (with this being the middle road) conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)]; break; } } } else if (countWallNeighs == 4) { conversion_cell.Type = VirtualCell.CellType.CorridorWallX; } } }
public void ConvertDirectionalRoomFloor(VirtualMap map, VirtualCell conversion_cell) { CellLocation l = conversion_cell.location; if (behaviour.useDirectionalFloors) { if (conversion_cell.IsRoomFloor()) { CellLocation[] border_neighs; CellLocation[] floor_neighs; bool considerDoorsAsWalls = true; // Count how many border neighbours are non-walls int countFloorNeighs = 0; bool[] validIndices = new bool[4]; if (conversion_cell.IsTile()) { // This was a tile, check neigh walls border_neighs = map.GetAllNeighbours(l); for (int i = 0; i < border_neighs.Length; i++) { CellLocation other_l = border_neighs[i]; if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() && !(map.GetCell(other_l).IsWall()) && !(considerDoorsAsWalls && map.GetCell(other_l).IsDoor()) ) { countFloorNeighs++; validIndices[i] = true; } } } else { // This was a border, check neigh floors instead floor_neighs = map.GetAllNeighbours(l); // Debug.Log ("From " + l);None for (int i = 0; i < floor_neighs.Length; i++) { CellLocation other_l = floor_neighs[i]; // Debug.Log ("At " + other_l + " is " + map.GetCell(other_l).Type); bool insideRoomTile = CheckInsideRoomTile(map, other_l); // We need this to be checked now, or we cannot know if a tile is inside a room reliably if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() && (map.GetCell(other_l).IsFloor() || //|| map.GetCell(other_l).IsNone() map.GetCell(other_l).IsInsideRoomColumn() || // Treat inside room columns as floors here insideRoomTile // || map.GetCell(other_l).IsNone() )) { countFloorNeighs++; validIndices[i] = true; } } } // Define the adbvanced floors // Debug.Log (countFloorNeighs); if (countFloorNeighs == 2) { bool adjacentFloors = false; // This is a room corner for (int i = 0; i < 4; i++) { if (validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)]; adjacentFloors = true; break; } } if (adjacentFloors) { conversion_cell.Type = VirtualCell.CellType.RoomFloorCorner; } else { conversion_cell.Type = VirtualCell.CellType.RoomFloorInside; } } else if (countFloorNeighs == 3) { conversion_cell.Type = VirtualCell.CellType.RoomFloorBorder; for (int i = 0; i < 4; i++) { if (validIndices[(int)Mathf.Repeat(i - 1, 4)] && validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 2, 4)]; break; } } } else if (countFloorNeighs == 4) { conversion_cell.Type = VirtualCell.CellType.RoomFloorInside; } else { // Wrong number of floor neighs, may happen if we have too small rooms. We always use the INSIDE one, then. conversion_cell.Type = VirtualCell.CellType.RoomFloorInside; } } } }
public void ConvertDirectionalCorridorFloor(VirtualMap map, VirtualCell conversion_cell) { CellLocation l = conversion_cell.location; if (behaviour.useDirectionalFloors) { if (conversion_cell.IsCorridorFloor()) { // Count how many border neighbours are non-walls int countFloorNeighs = 0; bool[] validIndices = new bool[4]; if (conversion_cell.IsTile()) { // This was a tile, check neigh walls CellLocation[] border_neighs = map.GetAllNeighbours(l); for (int i = 0; i < border_neighs.Length; i++) { CellLocation other_l = border_neighs[i]; if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() && !(map.GetCell(other_l).IsWall())) // TODO: Maybe isValid is not needed! { countFloorNeighs++; validIndices[i] = true; } } } else { // This was a border, check neigh floors instead CellLocation[] floor_neighs = map.GetAllNeighbours(l); for (int i = 0; i < floor_neighs.Length; i++) { CellLocation other_l = floor_neighs[i]; if (!map.LocationIsOutsideBounds(other_l) && other_l.isValid() && map.GetCell(other_l).IsFloor()) // TODO: Maybe isValid is not needed! { countFloorNeighs++; validIndices[i] = true; } } } // Define the adbvanced floors if (countFloorNeighs == 1) { conversion_cell.Type = VirtualCell.CellType.CorridorFloorU; for (int i = 0; i < 4; i++) { if (validIndices[i]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)]; break; } } } else if (countFloorNeighs == 2) { // Corridor I conversion_cell.Type = VirtualCell.CellType.CorridorFloorI; for (int i = 0; i < 4; i++) { if (validIndices[i]) { conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)]; break; } } // Corridor L for (int i = 0; i < 4; i++) { if (validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { // This and the next are valid: left turn (we consider all of them to be left turns( conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 3, 4)]; conversion_cell.Type = VirtualCell.CellType.CorridorFloorL; break; } } } else if (countFloorNeighs == 3) { conversion_cell.Type = VirtualCell.CellType.CorridorFloorT; for (int i = 0; i < 4; i++) { if (validIndices[(int)Mathf.Repeat(i - 1, 4)] && validIndices[i] && validIndices[(int)Mathf.Repeat(i + 1, 4)]) { // This, the one before and the next are valid: T cross (with this being the middle road) conversion_cell.Orientation = map.directions[(int)Mathf.Repeat(i + 1, 4)]; break; } } } else if (countFloorNeighs == 4) { conversion_cell.Type = VirtualCell.CellType.CorridorFloorX; } } } }