Пример #1
0
 /// <summary>
 /// Link all adjacent walkable areas to the area a given tile belongs to.
 /// For example, link the end of a path to the room belonging to a door.
 /// </summary>
 /// <param name="tile"></param>
 public void ConnectAreas(Tile tile)
 {
     foreach (Tile adj in Dungeon.GetAdjacentTiles(tile))
     {
         if (Tile.IsWalkable(adj.Space))
         {
             tile.Area.ConnectTo(adj.Area);
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Commits a stack of wrapped corridor tiles to the dungeon.
        /// </summary>
        /// <param name="path"></param>
        public void CarveCorridor(Stack <CorridorTile> path)
        {
            // Unwrap the tiles in the stack to populate a set

            HashSet <Tile> tiles = new HashSet <Tile>();

            foreach (CorridorTile wrappedTile in path)
            {
                tiles.Add(wrappedTile.Tile);
            }

            // Get an existing Path object if there is one; otherwise make a new object

            Area        area;
            List <Tile> adjacentPaths = Dungeon.GetAdjacentTilesOfType(path.Peek().Tile, Space.Path);

            if (adjacentPaths.Count > 0)
            {
                area = adjacentPaths[0].Area;
            }
            else
            {
                area = new Path();
                area.InitializeArea();
            }

            // Connect the *end* of the path to any adjacent Area objects

            Tile end = path.Peek().Tile;

            end.Area = area;
            ConnectAreas(end);

            // Finally begin carving the corridor

            CorridorTile head = null;

            while (path.Count > 0)
            {
                head = path.Pop();
                tiles.Remove(head.Tile);
                List <Tile> adjacents = Dungeon.GetAdjacentTiles(head.Tile, head.From.Tile);
                foreach (Tile adjacent in adjacents)
                {
                    if (tiles.Contains(adjacent))
                    {
                        // Loops exists, trim it

                        while (path.Peek().Tile != adjacent)
                        {
                            Tile remove = path.Pop().Tile;
                            tiles.Remove(remove);
                        }
                    }
                }
                head.Tile.Space = Space.Path;
                head.Tile.Area  = area;
            }

            // Connect the *start* of the path to the room it came from

            ConnectAreas(head.Tile);
        }