예제 #1
0
 public bool IsLegal(pos p)
 {
     switch(map[p]){
     //case CellType.RoomInterior:
     case CellType.Pillar:
     case CellType.RoomFeature1:
     case CellType.RoomFeature2:
     case CellType.RoomFeature3:
     case CellType.InterestingLocation:
         foreach(pos neighbor in p.AdjacentPositionsClockwise()){
             if(!map[neighbor].IsRoomType()){
                 return false;
             }
         }
         break;
     case CellType.RoomEdge:
     {
         int roomdir = 0;
         foreach(int dir in FourDirections){
             pos neighbor = p.PosInDir(dir);
             if(BoundsCheck(neighbor) && !map[neighbor].IsRoomType()){
                 roomdir = dir.RotateDir(true,4);
                 break;
             }
         }
         if(roomdir == 0){
             return false; //no room found, error - disable this if you want tiny rooms with h/w of 2
             /*char[] rotated = new char[8];
             for(int i=0;i<8;++i){
                 rotated[i] = Map(PosInDir(r,c,RotateDir(8,true,i)));
             }
             int successive_corridors = 0;
             if(IsCorridor(rotated[7])){
                 successive_corridors++;
             }
             for(int i=0;i<8;++i){
                 if(IsCorridor(rotated[i])){
                     successive_corridors++;
                 }
                 else{
                     successive_corridors = 0;
                 }
                 if(successive_corridors == 2){
                     return false;
                 }
             }
             int successive_room_tiles = 0;
             if(IsRoom(rotated[5])){
                 successive_room_tiles++;
             }
             if(IsRoom(rotated[6])){
                 successive_room_tiles++;
             }
             else{
                 successive_room_tiles = 0;
             }
             if(IsRoom(rotated[7])){
                 successive_room_tiles++;
             }
             else{
                 successive_room_tiles = 0;
             }
             for(int i=0;i<8;++i){
                 if(IsRoom(rotated[i])){
                     successive_room_tiles++;
                 }
                 else{
                     successive_room_tiles = 0;
                 }
                 if(successive_room_tiles == 5){
                     return true;
                 }
             }*/
         }
         else{
             List<pos> rotated = p.AdjacentPositionsClockwise(roomdir);
             foreach(int dir in new int[]{0,1,7}){
                 if(!map[rotated[dir]].IsRoomType()){
                     return false;
                 }
             }
             foreach(int dir in new int[]{2,6}){
                 if(!map[rotated[dir]].IsRoomEdgeType()){
                     return false;
                 }
             }
             if((map[rotated[4]].IsWall() || (map[rotated[3]].IsWall() && map[rotated[5]].IsWall())) == false){
                 return false;
             }
         }
         break;
     }
     case CellType.RoomCorner:
     {
         int roomdir = 0;
         foreach(int dir in DiagonalDirections){
             pos neighbor = p.PosInDir(dir);
             if(BoundsCheck(neighbor) && map[neighbor].IsRoomInteriorType()){
                 roomdir = dir;
                 break;
             }
         }
         if(roomdir == 0){
             return false; //no room found, error
         }
         List<pos> rotated = p.AdjacentPositionsClockwise(roomdir);
         foreach(int dir in new int[]{1,7}){
             if(!map[rotated[dir]].IsRoomEdgeType()){
                 return false;
             }
         }
         if(AllowAllCornerConnections){
             if(!map[rotated[2]].IsWall() && !map[rotated[3]].IsWall()){
                 return false;
             }
             if(!map[rotated[6]].IsWall() && !map[rotated[5]].IsWall()){
                 return false;
             }
             if(!map[rotated[4]].IsWall()){ //if the corner isn't a wall...
                 if(!map[rotated[3]].IsWall() && !map[rotated[5]].IsWall()){
                     return false;
                 }
                 if(map[rotated[3]].IsWall() && map[rotated[5]].IsWall()){ //...reject it if there's not exactly 1 adjacent corridor
                     return false;
                 }
             }
         }
         else{
             foreach(int dir in new int[]{3,4,5}){
                 if(!map[rotated[dir]].IsWall()){
                     return false;
                 }
             }
         }
         break;
     }
     case CellType.RoomInteriorCorner:
     {
         List<int> wall_dirs = new List<int>();
         List<int> edge_dirs = new List<int>();
         foreach(int dir in DiagonalDirections){
             pos neighbor = p.PosInDir(dir);
             if(BoundsCheck(neighbor) && map[neighbor].IsWall()){
                 wall_dirs.Add(dir);
                 edge_dirs.AddUnique(dir.RotateDir(true));
                 edge_dirs.AddUnique(dir.RotateDir(false));
             }
         }
         if(wall_dirs.Count == 0){
             return false; //no room found, error
         }
         foreach(int dir in EightDirections){
             if(wall_dirs.Contains(dir)){
                 if(!map[p.PosInDir(dir)].IsWall()){
                     return false;
                 }
             }
             else{
                 if(edge_dirs.Contains(dir)){
                     if(!map[p.PosInDir(dir)].IsRoomEdgeType()){
                         return false;
                     }
                 }
                 else{
                     if(!map[p.PosInDir(dir)].IsRoomType()){
                         return false;
                     }
                 }
             }
         }
         break;
     }
     case CellType.CorridorHorizontal:
         foreach(int dir in new int[]{2,8}){
             pos next = p;
             for(int i=1;i<=MinimumSpaceBetweenCorridors;++i){
                 next = next.PosInDir(dir);
                 if(BoundsCheck(next) && map[next] == CellType.CorridorHorizontal){
                     return false;
                 }
             }
         }
         break;
     case CellType.CorridorVertical:
         foreach(int dir in new int[]{4,6}){
             pos next = p;
             for(int i=1;i<=MinimumSpaceBetweenCorridors;++i){
                 next = next.PosInDir(dir);
                 if(BoundsCheck(next) && map[next] == CellType.CorridorVertical){
                     return false;
                 }
             }
         }
         break;
     case CellType.CorridorIntersection:
         if(p.ConsecutiveAdjacent(x => map[x].IsPassable()) >= 3){
             return false;
         }
         break;
     case CellType.Door:
     {
         int dir_of_wall = 0;
         if(map[p.PosInDir(8)].IsWall()){
             dir_of_wall = 8;
         }
         else{
             dir_of_wall = 4;
         }
         if(!map[p.PosInDir(dir_of_wall)].IsWall() || !map[p.PosInDir(dir_of_wall.RotateDir(true,4))].IsWall()
         || map[p.PosInDir(dir_of_wall.RotateDir(true,2))].IsWall() || map[p.PosInDir(dir_of_wall.RotateDir(false,2))].IsWall()){
             return false; //needs 2 walls on opposite sides, 2 nonwalls on opposite sides
         }
         break;
     }
     }
     return true;
 }
예제 #2
0
 public void SharpenCorners()
 {
     for(int i=1;i<H-1;++i){
         for(int j=1;j<W-1;++j){
             pos p = new pos(i,j);
             if(p.CardinalAdjacentPositions().Where(x=>map[x].IsRoomType()).Count == 2 && p.ConsecutiveAdjacent(x=>!map[x].IsRoomType()) == 5){
                 map[p] = CellType.RoomCorner;
             }
         }
     }
 }
예제 #3
0
 public bool IsCornerFloor(pos p)
 {
     if(p.BoundsCheck(map,false)){
         if(map[p].IsPassable() && p.ConsecutiveAdjacent(x=>map[x].IsWall()) == 5){
             int num_diagonal_walls = 0;
             foreach(int dir in U.DiagonalDirections){
                 if(map[p.PosInDir(dir)].IsWall()){
                     ++num_diagonal_walls;
                 }
             }
             if(num_diagonal_walls == 3){
                 return true;
             }
         }
     }
     return false;
 }