Пример #1
0
        public DungeonDomainBuilder AddDecoration(DungeonTheme theme, TextAsset textAsset)
        {
            if (textAsset == null)
            {
                return(this);
            }

            Action($"Add decoration");
            {
                Do((context) =>
                {
                    var parentRoom = context.RoomStack.Peek();
                    if (parentRoom != null)
                    {
                        Debug.Log($"Spawn decoration {textAsset.name} in room {parentRoom.Id}\n");
                        var decorationMeta = new DungeonRoomDecorationMeta();
                        decorationMeta.GenerateGround(theme, textAsset);
                        parentRoom.DecorationMeta.Add(decorationMeta);
                        return(TaskStatus.Success);
                    }

                    Debug.Log($"Error! Can't spawn decoration in the void!\n");
                    return(TaskStatus.Failure);
                });
            }
            End();

            return(this);
        }
        public void GenerateGround(DungeonTheme theme, TextAsset textAsset)
        {
            if (textAsset == null)
            {
                return;
            }

            using (var reader = new StringReader(textAsset.text))
            {
                int    y = 0;
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var x     = 0;
                    var split = line.Split(',');
                    foreach (var tile in split)
                    {
                        var key = new int2(x, y);
                        WriteToGround(key, theme, tile);
                        x++;
                    }

                    y++;
                }
            }
        }
Пример #3
0
        public DungeonDomainBuilder AddDecoration(DungeonTheme theme, DecorationInfo info)
        {
            if (info == null)
            {
                return(this);
            }

            Action($"Add decoration");
            {
                Do((context) =>
                {
                    var parentRoom = context.RoomStack.Peek();
                    if (parentRoom != null)
                    {
                        var decorationName = info.Ground != null ? info.Ground.name :
                                             info.Items != null ? info.Items.name :
                                             info.Characters != null ? info.Characters.name : "";
                        Debug.Log($"Spawn decoration {decorationName} in room {parentRoom.Id}\n");


                        var decorationMeta = new DungeonRoomDecorationMeta();
                        decorationMeta.Generate(theme, info);
                        parentRoom.DecorationMeta.Add(decorationMeta);

                        return(TaskStatus.Success);
                    }

                    Debug.Log($"Error! Can't spawn decoration in the void!\n");
                    return(TaskStatus.Failure);
                });
            }
            End();

            return(this);
        }
Пример #4
0
        private static void TryWallIn(Dungeon dungeon, DungeonRoom room, DungeonTheme theme, int2 key, BuilderDirection direction)
        {
            var value = dungeon.ValueMap[key];

            if (value.Theme != theme)
            {
                return;
            }

            var adjacentKey = GetAdjacentKey(dungeon, key, direction);

            if (dungeon.ValueMap.ContainsKey(adjacentKey) == false)
            {
                var tile = new Dungeon.MapValue
                {
                    Theme = theme,
                    Index = DungeonTile.Index.Wall,
                    Room  = room,
                };
                dungeon.ValueMap.Add(adjacentKey, tile);
                room.ValueMap.Add(adjacentKey, value);
            }

            var adjacent = dungeon.ValueMap[adjacentKey];

            if (adjacent.Theme != theme)
            {
                // If we're at a forest tile and the adjacent tile is already a wall, we don't always want to place a forest wall tile.
                if (adjacent.Index == DungeonTile.Index.Wall && value.Theme == DungeonTheme.Forest)
                {
                    if (Random.value < 0.4f)
                    {
                        dungeon.ValueMap[key].Index = DungeonTile.Index.Wall;
                    }
                }
                else
                {
                    dungeon.ValueMap[key].Index = DungeonTile.Index.Wall;
                }

                if (room.ConnectionMap.ContainsKey(key) == false)
                {
                    var adjacentRoom = dungeon.GetRoom(adjacentKey);
                    if (adjacentRoom != null)
                    {
                        room.ConnectionMap.Add(key, new Tuple <int2, DungeonRoom>(
                                                   adjacentKey,
                                                   adjacentRoom));

                        if (adjacentRoom.ConnectionMap.ContainsKey(adjacentKey) == false)
                        {
                            adjacentRoom.ConnectionMap.Add(adjacentKey, new Tuple <int2, DungeonRoom>(
                                                               key,
                                                               room));
                        }
                    }
                }
            }
        }
 private void WriteToGround(int2 key, DungeonTheme theme, string tile)
 {
     ValueMap.Add(key, new Dungeon.MapValue
     {
         Theme     = theme,
         Index     = (DungeonTile.Index)Convert.ToInt32(tile),
         IsSpecial = true,
     });
 }
        public void GenerateGround(DungeonTheme theme, string textFilePath)
        {
            var textAsset = Resources.Load <TextAsset>(textFilePath);

            if (textAsset == null)
            {
                return;
            }

            GenerateGround(theme, textAsset);
        }
Пример #7
0
        public DecorationInfo Find(DungeonTheme theme, DecorationType decorationType)
        {
            foreach (var entry in _dbs)
            {
                if (entry.Theme == theme)
                {
                    return(entry.Db.Find(decorationType));
                }
            }

            return(null);
        }
Пример #8
0
        private static bool IsValid(Dungeon dungeon, DungeonTheme theme, int2 key)
        {
            if (dungeon.ValueMap.ContainsKey(key))
            {
                var tile = dungeon.ValueMap[key];
                if (tile.Theme == theme && tile.Index == DungeonTile.Index.Floor)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #9
0
        public Sprite Find(DungeonTheme theme, DungeonTile.Index index, bool isEdge, bool isBorder, out Color color)
        {
            foreach (var db in _dbs)
            {
                if (db.Theme == theme)
                {
                    return(db.Database.Find(index, isEdge, isBorder, out color));
                }
            }

            color = Color.white;
            return(default(Sprite));
        }
Пример #10
0
 public DungeonDomainBuilder SetTheme(DungeonTheme theme)
 {
     Action($"Set theme");
     {
         Do((context) =>
         {
             Debug.Log($"Set theme {theme}\n");
             context.CurrentTheme = theme;
             return(TaskStatus.Success);
         });
     }
     End();
     return(this);
 }
 /// <summary>
 /// Generate a value map from a double array.
 /// Dimension 0 is read as Column
 /// Dimension 1 is read as Row
 /// </summary>
 /// <param name="valueMap"></param>
 public void GenerateGround(DungeonTheme theme, int[,] valueMap)
 {
     for (var x = 0; x < valueMap.GetLength(0); x++)
     {
         for (var y = 0; y < valueMap.GetLength(1); y++)
         {
             var key = new int2(x, y);
             ValueMap.Add(key, new Dungeon.MapValue
             {
                 Theme     = theme,
                 Index     = (DungeonTile.Index)valueMap[y, x],
                 IsSpecial = true,
             });
         }
     }
 }
Пример #12
0
        public static void WallIn(Dungeon dungeon, DungeonTheme theme)
        {
            var map = new Dictionary <int2, Dungeon.MapValue>(dungeon.ValueMap);

            foreach (var kvp in map)
            {
                if (kvp.Value.Room == null)
                {
                    Debug.LogError($"{kvp.Value} has no room!");
                    continue;
                }

                TryWallIn(dungeon, kvp.Value.Room, theme, kvp.Key, BuilderDirection.North);
                TryWallIn(dungeon, kvp.Value.Room, theme, kvp.Key, BuilderDirection.East);
                TryWallIn(dungeon, kvp.Value.Room, theme, kvp.Key, BuilderDirection.South);
                TryWallIn(dungeon, kvp.Value.Room, theme, kvp.Key, BuilderDirection.West);
            }
        }
Пример #13
0
        private static bool Floodfill(Dungeon dungeon, DungeonTheme theme, int2 start, int2 end, List <int2> closed)
        {
            if (FloodFillInDirection(dungeon, theme, start, end, closed, BuilderDirection.North))
            {
                return(true);
            }
            if (FloodFillInDirection(dungeon, theme, start, end, closed, BuilderDirection.East))
            {
                return(true);
            }
            if (FloodFillInDirection(dungeon, theme, start, end, closed, BuilderDirection.South))
            {
                return(true);
            }
            if (FloodFillInDirection(dungeon, theme, start, end, closed, BuilderDirection.West))
            {
                return(true);
            }

            return(false);
        }
        public void Generate(DungeonTheme theme, DecorationInfo info)
        {
            if (info == null)
            {
                return;
            }

            if (info.Ground != null)
            {
                GenerateGround(theme, info.Ground);
            }

            if (info.Items != null)
            {
                WriteItems(info.Items);
            }

            if (info.Characters != null)
            {
                WriteCharacters(info.Characters);
            }
        }
Пример #15
0
        private static bool FloodFillInDirection(Dungeon dungeon, DungeonTheme theme, int2 start, int2 end, List <int2> closed,
                                                 BuilderDirection dir)
        {
            var key = DungeonRoom.GetAdjacentKey(dungeon, start, dir);

            if (key.x == end.x && key.y == end.y)
            {
                return(true);
            }

            if (closed.Contains(key))
            {
                return(false);
            }

            closed.Add(key);

            if (IsValid(dungeon, theme, key))
            {
                return(Floodfill(dungeon, theme, key, end, closed));
            }

            return(false);
        }
Пример #16
0
    void PopulateRoomWithItems(DungeonManager p_gen, DungeonTheme p_dungeonTheme, List <Vector2> p_floorTilesLocations, List <ItemStruct> p_itemList)
    {
        int            numberOfItems  = Random.Range(p_dungeonTheme.m_minItemsPerRoom, p_dungeonTheme.m_maxItemsPerRoom);
        List <Vector2> itemPlacements = new List <Vector2>();

        for (int i = 0; i < numberOfItems; i++)
        {
            int randomPlace = Random.Range(0, p_floorTilesLocations.Count);
            itemPlacements.Add(p_floorTilesLocations[randomPlace]);
            p_floorTilesLocations.RemoveAt(randomPlace);
        }

        foreach (Vector2 itemPlace in itemPlacements)
        {
            float randomItem     = Random.Range(0f, 1f);
            float currentRate    = 0;
            int   itemSpawnIndex = 0;
            foreach (ItemStruct item in p_itemList)
            {
                if (randomItem < item.m_itemRarity + currentRate)
                {
                    itemSpawnIndex = p_itemList.IndexOf(item);
                    break;
                }
                else
                {
                    currentRate += item.m_itemRarity;
                }
            }

            Vector3            itemPos = new Vector3(itemPlace.x + .5f, itemPlace.y + .5f, 0);
            Item_MapObjectBase newItem = ObjectPooler.instance.NewObject(p_itemList[itemSpawnIndex].m_itemType.m_itemGameWorldPrefab.gameObject, itemPos, Quaternion.identity).GetComponent <Item_MapObjectBase>();
            p_gen.m_itemsOnFloor.Add(newItem.gameObject);
            newItem.AssignObjectType(p_itemList[itemSpawnIndex].m_itemType);
        }
    }
Пример #17
0
    public override List <DungeonGridCell> CreateDungeon(DungeonManager p_gen, DungeonTheme p_dungeonTheme, DungeonNavigation p_dungeonNav)
    {
        p_gen.m_allCells = new DungeonGridCell[m_cellsInDungeon.x, m_cellsInDungeon.y];

        ///Generates a random amount of room cells
        #region Room Cell Generation
        int numOfRooms = Random.Range(m_minRooms, m_maxRooms);

        List <int> roomCells  = new List <int>();
        List <int> emptyCells = new List <int>();


        List <DungeonGridCell> returningRoomCells = new List <DungeonGridCell>();
        int cellCount = m_cellsInDungeon.x * m_cellsInDungeon.y;
        for (int z = 0; z < cellCount; z++)
        {
            roomCells.Add(z);
        }


        //Create the number of rooms
        for (int i = 0; i < cellCount - numOfRooms; i++)
        {
            int currentCellIndex = Random.Range(0, roomCells.Count);
            emptyCells.Add(roomCells[currentCellIndex]);
            roomCells.RemoveAt(currentCellIndex);
        }
        #endregion


        #region Hallway Cell Generation
        //The hallways
        int currentCorridors = Random.Range((int)((float)emptyCells.Count * m_minEmptyPercent), (int)((float)emptyCells.Count * m_maxEmptyPercent));

        for (int c = 0; c < cellCount - numOfRooms; c++)
        {
            if (c >= currentCorridors)
            {
                int currentCellIndex = Random.Range(0, emptyCells.Count);
                emptyCells.RemoveAt(currentCellIndex);
            }
        }

        #endregion


        #region Creates the connections between cells
        int currentIndex = 0;
        for (int x = 0; x < m_cellsInDungeon.x; x++)
        {
            for (int y = 0; y < m_cellsInDungeon.y; y++)
            {
                p_gen.m_allCells[x, y] = new DungeonGridCell();
                p_gen.m_allCells[x, y].m_connectionPoints = new List <ConnectionPoint>();
                p_gen.m_allCells[x, y].m_connectedTo      = new List <Vector2Int>();


                //Create the rooms
                if (roomCells.Contains(currentIndex))
                {
                    p_gen.m_allCells[x, y].ChangeCellType(DungeonGridCell.CellType.Room);
                }
                else if (emptyCells.Contains(currentIndex))
                {
                    p_gen.m_allCells[x, y].ChangeCellType(DungeonGridCell.CellType.None);
                }

                //The connection points
                else
                {
                    p_gen.m_allCells[x, y].ChangeCellType(DungeonGridCell.CellType.Hallway);
                    Vector2Int bounds = new Vector2Int(m_cellSize.x - m_cellBoarder, m_cellSize.y - m_cellBoarder);
                    Vector3Int newPos = new Vector3Int(Random.Range(2, bounds.x) + (x * m_cellSize.x), Random.Range(2, bounds.y) + (y * m_cellSize.y), 0);

                    p_gen.m_allCells[x, y].AddConnectionPoint(newPos, ConnectionPoint.ConnectionType.Node);
                }


                currentIndex++;
            }
        }

        #endregion

        int[,] dungeonGrid = new int[m_cellsInDungeon.x * m_cellSize.x, m_cellsInDungeon.y *m_cellSize.y];
        //Draw the boarder

        /*for (int x = -m_dungeonMapBounds.x; x < m_cellsInDungeon.x * m_cellSize.x + m_dungeonMapBounds.x; x++)
         * {
         *  for (int y = -m_dungeonMapBounds.y; y < m_cellsInDungeon.y * m_cellSize.y + m_dungeonMapBounds.y; y++)
         *  {
         *      if(x > dungeonGrid.GetLength(0))
         *      {
         *          Debug.LogError("X Too big: " + x);
         *      }
         *      else if (y > dungeonGrid.GetLength(1))
         *      {
         *          Debug.LogError("Y Too big: " + y);
         *      }
         *      dungeonGrid[x, y] = 0;
         *
         *  }
         * }*/


        //Get the items structs
        p_dungeonTheme.FixRates();
        List <ItemStruct> itemsInDungeon = p_dungeonTheme.ItemsInDungeon();

        //Assign the tiles to the 2d array grid
        for (int x = 0; x < m_cellsInDungeon.x; x++)
        {
            for (int y = 0; y < m_cellsInDungeon.y; y++)
            {
                p_gen.m_allCells[x, y].SetGridPosition(new Vector2Int(x, y));
                switch (p_gen.m_allCells[x, y].m_currentCellType)
                {
                case DungeonGridCell.CellType.Room:

                    DungeonGridCell roomCell = CreateRoom(p_gen, p_dungeonTheme, new Vector3Int(x * m_cellSize.x, y * m_cellSize.y, 0), p_gen.m_allCells[x, y], p_gen.m_allCells, ref dungeonGrid);
                    PopulateRoomWithItems(p_gen, p_dungeonTheme, roomCell.m_floorTiles, itemsInDungeon);
                    roomCell.m_roomIndex = returningRoomCells.Count;
                    returningRoomCells.Add(roomCell);
                    break;

                case DungeonGridCell.CellType.HallwayOneWay:
                    break;

                case DungeonGridCell.CellType.Hallway:
                    CreateCorridor(p_gen, p_dungeonTheme, Vector3Int.zero, p_gen.m_allCells[x, y].m_connectionPoints[0].m_connectionPos, p_gen.m_allCells[x, y], ref dungeonGrid);
                    break;

                case DungeonGridCell.CellType.None:
                    break;
                }
            }
        }


        //Create the room connections
        for (int x = 0; x < m_cellsInDungeon.x; x++)
        {
            for (int y = 0; y < m_cellsInDungeon.y; y++)
            {
                p_gen.m_allRooms.Add(p_gen.m_allCells[x, y]);
                foreach (ConnectionPoint connectedPoint in p_gen.m_allCells[x, y].m_connectionPoints)
                {
                    RoomConnections(p_gen, p_dungeonTheme, p_gen.m_allCells, p_gen.m_allCells[x, y], connectedPoint, ref dungeonGrid);
                }
            }
        }

        Vector2Int gridLength = new Vector2Int(dungeonGrid.GetLength(0), dungeonGrid.GetLength(1));

        //Draw the tiles on the tilemaps
        for (int x = -m_dungeonMapBounds.x; x < dungeonGrid.GetLength(0) + m_dungeonMapBounds.x; x++)
        {
            for (int y = -m_dungeonMapBounds.y; y < dungeonGrid.GetLength(1) + m_dungeonMapBounds.y; y++)
            {
                if (x < 0 || x > gridLength.x - 1 || y < 0 || y > gridLength.y - 1)
                {
                    p_gen.m_wallTiles.SetTile(new Vector3Int(x, y, 0), p_dungeonTheme.m_wallTile);
                    continue;
                }
                ///Wall


                if (dungeonGrid[x, y] == 0)
                {
                    p_gen.m_wallTiles.SetTile(new Vector3Int(x, y, 0), p_dungeonTheme.m_wallTile);
                }

                ///Floor
                else if (dungeonGrid[x, y] == 1)
                {
                    p_gen.m_floorTiles.SetTile(new Vector3Int(x, y, 0), p_dungeonTheme.m_floorTile);
                    p_gen.m_miniMapTiles.SetTile(new Vector3Int(x, y, 0), p_gen.m_miniMapTile);
                }
            }
        }

        p_dungeonNav.m_gridWorldSize = new Vector2(m_cellSize.x * m_cellsInDungeon.x, m_cellSize.y * m_cellsInDungeon.y);
        p_dungeonNav.m_gridOrigin    = p_dungeonNav.m_gridWorldSize / 2;
        p_dungeonNav.CreateGrid();
        return(returningRoomCells);
    }
Пример #18
0
 public abstract void CreateHallway(DungeonManager p_gen, DungeonTheme p_dungeonTheme, Vector3Int p_startPos, Vector3Int p_endPos, ref int[,] p_dungeonGrid);
Пример #19
0
 public abstract void RoomConnections(DungeonManager p_gen, DungeonTheme p_dungeonTheme, DungeonGridCell[,] p_allCells, DungeonGridCell p_currentCell, ConnectionPoint p_currentConnectionPoint, ref int[,] p_dungeonGrid);
Пример #20
0
 public abstract void CreateCorridor(DungeonManager p_gen, DungeonTheme p_dungeonTheme, Vector3Int p_startPos, Vector3Int p_endPos, DungeonGridCell p_currentCell, ref int[,] p_dungeonGrid);
Пример #21
0
 public abstract DungeonGridCell CreateRoom(DungeonManager p_gen, DungeonTheme p_dungeonTheme, Vector3Int p_roomPosition, DungeonGridCell p_currentCell, DungeonGridCell[,] p_allCells, ref int[,] p_dungeonGrid);
Пример #22
0
 public abstract List <DungeonGridCell> CreateDungeon(DungeonManager p_gen, DungeonTheme p_dungeonTheme, DungeonNavigation p_dungeonNav);
Пример #23
0
    public override void RoomConnections(DungeonManager p_gen, DungeonTheme p_dungeonTheme, DungeonGridCell[,] p_allCells, DungeonGridCell p_currentCell, ConnectionPoint p_currentConnectionPoint, ref int[,] p_dungeonGrid)
    {
        Vector2Int neighbourIndex = new Vector2Int();

        if (p_currentConnectionPoint.currentConnectionType != ConnectionPoint.ConnectionType.Node)
        {
            if (p_currentConnectionPoint.currentConnectionType == ConnectionPoint.ConnectionType.Left)
            {
                neighbourIndex = new Vector2Int(p_currentCell.m_gridPosition.x - 1, p_currentCell.m_gridPosition.y);
                if (p_allCells[neighbourIndex.x, neighbourIndex.y].m_connectedTo.Contains(p_currentCell.m_gridPosition))
                {
                    return;
                }

                foreach (ConnectionPoint neighbour in p_allCells[neighbourIndex.x, neighbourIndex.y].m_connectionPoints)
                {
                    if (neighbour.currentConnectionType == ConnectionPoint.ConnectionType.Right || neighbour.currentConnectionType == ConnectionPoint.ConnectionType.Node)
                    {
                        CreateHallway(p_gen, p_dungeonTheme, p_currentConnectionPoint.m_connectionPos, neighbour.m_connectionPos, ref p_dungeonGrid);
                    }
                }
            }

            else if (p_currentConnectionPoint.currentConnectionType == ConnectionPoint.ConnectionType.Right)
            {
                neighbourIndex = new Vector2Int(p_currentCell.m_gridPosition.x + 1, p_currentCell.m_gridPosition.y);
                if (p_allCells[neighbourIndex.x, neighbourIndex.y].m_connectedTo.Contains(p_currentCell.m_gridPosition))
                {
                    return;
                }

                foreach (ConnectionPoint neighbour in p_allCells[neighbourIndex.x, neighbourIndex.y].m_connectionPoints)
                {
                    if (neighbour.currentConnectionType == ConnectionPoint.ConnectionType.Left || neighbour.currentConnectionType == ConnectionPoint.ConnectionType.Node)
                    {
                        CreateHallway(p_gen, p_dungeonTheme, p_currentConnectionPoint.m_connectionPos, neighbour.m_connectionPos, ref p_dungeonGrid);
                    }
                }
            }

            else if (p_currentConnectionPoint.currentConnectionType == ConnectionPoint.ConnectionType.Up)
            {
                neighbourIndex = new Vector2Int(p_currentCell.m_gridPosition.x, p_currentCell.m_gridPosition.y + 1);
                if (p_allCells[neighbourIndex.x, neighbourIndex.y].m_connectedTo.Contains(p_currentCell.m_gridPosition))
                {
                    return;
                }

                foreach (ConnectionPoint neighbour in p_allCells[neighbourIndex.x, neighbourIndex.y].m_connectionPoints)
                {
                    if (neighbour.currentConnectionType == ConnectionPoint.ConnectionType.Down || neighbour.currentConnectionType == ConnectionPoint.ConnectionType.Node)
                    {
                        CreateHallway(p_gen, p_dungeonTheme, p_currentConnectionPoint.m_connectionPos, neighbour.m_connectionPos, ref p_dungeonGrid);
                    }
                }
            }

            else if (p_currentConnectionPoint.currentConnectionType == ConnectionPoint.ConnectionType.Down)
            {
                neighbourIndex = new Vector2Int(p_currentCell.m_gridPosition.x, p_currentCell.m_gridPosition.y - 1);
                if (p_allCells[neighbourIndex.x, neighbourIndex.y].m_connectedTo.Contains(p_currentCell.m_gridPosition))
                {
                    return;
                }

                foreach (ConnectionPoint neighbour in p_allCells[neighbourIndex.x, neighbourIndex.y].m_connectionPoints)
                {
                    if (neighbour.currentConnectionType == ConnectionPoint.ConnectionType.Up || neighbour.currentConnectionType == ConnectionPoint.ConnectionType.Node)
                    {
                        CreateHallway(p_gen, p_dungeonTheme, p_currentConnectionPoint.m_connectionPos, neighbour.m_connectionPos, ref p_dungeonGrid);
                    }
                }
            }


            p_allCells[neighbourIndex.x, neighbourIndex.y].m_connectedTo.Add(p_currentCell.m_gridPosition);
            p_currentCell.m_connectedTo.Add(p_allCells[neighbourIndex.x, neighbourIndex.y].m_gridPosition);
        }
        else
        {
            for (int x = -1; x < 1; x++)
            {
                for (int y = -1; y < 1; y++)
                {
                    if (x == 0 && y == 0 || x == -1 && y != 0 || x == 1 && y != 0 || x != 0 && y == -1 || x != 0 && y == 1)
                    {
                        continue;
                    }
                    if (x + p_currentCell.m_gridPosition.x < 0 || x + p_currentCell.m_gridPosition.x > m_cellsInDungeon.x - 1)
                    {
                        continue;
                    }
                    if (y + p_currentCell.m_gridPosition.y < 0 || y + p_currentCell.m_gridPosition.y > m_cellsInDungeon.y - 1)
                    {
                        continue;
                    }



                    DungeonGridCell neighbourCell = p_allCells[p_currentCell.m_gridPosition.x + x, p_currentCell.m_gridPosition.y + y];
                    if (neighbourCell.m_currentCellType == DungeonGridCell.CellType.Hallway)
                    {
                        if (!neighbourCell.m_connectedTo.Contains(p_currentCell.m_gridPosition))
                        {
                            neighbourCell.m_connectedTo.Add(p_currentCell.m_gridPosition);
                            p_currentCell.m_connectedTo.Add(neighbourCell.m_gridPosition);
                            CreateHallway(p_gen, p_dungeonTheme, p_currentConnectionPoint.m_connectionPos, neighbourCell.m_connectionPoints[0].m_connectionPos, ref p_dungeonGrid);
                        }
                    }
                }
            }
        }
    }
Пример #24
0
        public static bool IsConnected(Dungeon dungeon, DungeonTheme theme, int2 start, int2 end)
        {
            List <int2> closed = new List <int2>();

            return(Floodfill(dungeon, theme, start, end, closed));
        }
Пример #25
0
    public override void CreateHallway(DungeonManager p_gen, DungeonTheme p_dungeonTheme, Vector3Int p_startPos, Vector3Int p_endPos, ref int[,] p_dungeonGrid)
    {
        bool travelX = (p_endPos.x - p_startPos.x > p_endPos.y - p_startPos.y) ? true : false;

        int amountOfTiles = Mathf.Abs(p_endPos.x - p_startPos.x) + Mathf.Abs(p_endPos.y - p_startPos.y);


        int xDir, yDir;

        if (p_endPos.x > p_startPos.x)
        {
            xDir = 1;
        }
        else if (p_endPos.x < p_startPos.x)
        {
            xDir = -1;
        }
        else
        {
            xDir = 0;
        }

        if (p_endPos.y > p_startPos.y)
        {
            yDir = 1;
        }
        else if (p_endPos.y < p_startPos.y)
        {
            yDir = -1;
        }
        else
        {
            yDir = 0;
        }

        Vector3Int currentPos        = p_startPos;
        int        currentTurnAmount = m_hallwayTurnAount;

        for (int t = 0; t < amountOfTiles; t++)
        {
            if (travelX)
            {
                currentPos = new Vector3Int(currentPos.x + 1 * xDir, currentPos.y, 0);

                if (currentPos.x == p_endPos.x)
                {
                    travelX = false;
                }
                else
                {
                    if (currentTurnAmount > 1)
                    {
                        float turnPercent = (float)t / (float)amountOfTiles;

                        if (Random.Range(0f, 1f) > 1 - turnPercent && currentPos.y != p_endPos.y)
                        {
                            currentTurnAmount -= 1;

                            travelX = false;
                        }
                    }
                }
            }
            else
            {
                currentPos = new Vector3Int(currentPos.x, currentPos.y + 1 * yDir, 0);
                if (currentPos.y == p_endPos.y)
                {
                    travelX = true;
                }
                else
                {
                    if (currentTurnAmount > 1)
                    {
                        float turnPercent = (float)t / (float)amountOfTiles;
                        if (Random.Range(0f, 1f) > 1 - turnPercent && currentPos.x != p_endPos.x)
                        {
                            currentTurnAmount -= 1;

                            travelX = true;
                        }
                    }
                }
            }

            p_dungeonGrid[currentPos.x, currentPos.y] = 1;
        }
    }
Пример #26
0
 public override void CreateCorridor(DungeonManager p_gen, DungeonTheme p_dungeonTheme, Vector3Int p_startPos, Vector3Int p_endPos, DungeonGridCell p_currentCell, ref int[,] p_dungeonGrid)
 {
     p_currentCell.m_worldPos = (Vector3)p_endPos + new Vector3(.5f, .5f, 0f);
     p_gen.m_hallwayPoints.Add(p_currentCell);
     p_dungeonGrid[p_endPos.x, p_endPos.y] = 1;
 }
Пример #27
0
    public override DungeonGridCell CreateRoom(DungeonManager p_gen, DungeonTheme p_dungeonTheme, Vector3Int p_roomPosition, DungeonGridCell p_currentCell, DungeonGridCell[,] p_allCells, ref int[,] p_dungeonGrid)
    {
        Vector2Int bounds = new Vector2Int(m_cellSize.x - m_cellBoarder, m_cellSize.y - m_cellBoarder);

        Vector2Int roomSize = new Vector2Int(Random.Range(m_minRoomSize.x, m_maxRoomSize.x), Random.Range(m_minRoomSize.y, m_maxRoomSize.y));

        Vector2Int randomStart = new Vector2Int(Random.Range(m_cellBoarder, bounds.x - roomSize.x), Random.Range(m_cellBoarder, bounds.y - roomSize.y));


        //p_currentCell.m_worldPos = new Vector3(randomStart.x + p_roomPosition.x + .5f, randomStart.y + p_roomPosition.y + .5f);
        p_currentCell.m_worldPos = new Vector3(randomStart.x + p_roomPosition.x + ((float)roomSize.x / 2), randomStart.y + p_roomPosition.y + ((float)roomSize.y / 2));
        p_currentCell.m_roomSize = roomSize;
        Vector3 pos = p_currentCell.m_worldPos;
        //GameObject.Instantiate(m_debugCube, pos - Vector3.forward*3, Quaternion.identity);
        List <Vector2> floorTiles = new List <Vector2>();

        for (int x = randomStart.x; x < roomSize.x + randomStart.x; x++)
        {
            for (int y = randomStart.y; y < roomSize.y + randomStart.y; y++)
            {
                p_dungeonGrid[x + p_roomPosition.x, y + p_roomPosition.y] = 1;
                //GameObject.Instantiate(m_debugCube2, new Vector3(p_roomPosition.x + x + .5f, p_roomPosition.y +y + .5f), Quaternion.identity);
                if (x > randomStart.x && x < roomSize.x + randomStart.x - 1 && y > randomStart.y && y < roomSize.y + randomStart.y - 1)
                {
                    floorTiles.Add(new Vector2(x + p_roomPosition.x, y + p_roomPosition.y));
                }
            }
        }

        p_currentCell.m_floorTiles = floorTiles;

        for (int x = -1; x < 2; x++)
        {
            for (int y = -1; y < 2; y++)
            {
                if (x == 0 && y == 0 || x == -1 && y != 0 || x == 1 && y != 0 || x != 0 && y == -1 || x != 0 && y == 1)
                {
                    continue;
                }
                if (x + p_currentCell.m_gridPosition.x < 0 || x + p_currentCell.m_gridPosition.x > m_cellsInDungeon.x - 1)
                {
                    continue;
                }
                if (y + p_currentCell.m_gridPosition.y < 0 || y + p_currentCell.m_gridPosition.y > m_cellsInDungeon.y - 1)
                {
                    continue;
                }
                if (p_allCells[x + p_currentCell.m_gridPosition.x, y + p_currentCell.m_gridPosition.y].m_connectedTo.Contains(p_currentCell.m_gridPosition))
                {
                    continue;
                }
                if (p_allCells[x + p_currentCell.m_gridPosition.x, y + p_currentCell.m_gridPosition.y].m_currentCellType == DungeonGridCell.CellType.Hallway || p_allCells[x + p_currentCell.m_gridPosition.x, y + p_currentCell.m_gridPosition.y].m_currentCellType == DungeonGridCell.CellType.Room)
                {
                    Vector3Int connectionPos = new Vector3Int();
                    ConnectionPoint.ConnectionType connectType = ConnectionPoint.ConnectionType.Node;
                    if (y > 0)
                    {
                        connectionPos = new Vector3Int(Random.Range(0, roomSize.x) + p_roomPosition.x + randomStart.x, roomSize.y + p_roomPosition.y + randomStart.y, 0);
                        connectType   = ConnectionPoint.ConnectionType.Up;
                    }

                    else if (y < 0)
                    {
                        connectionPos = new Vector3Int(Random.Range(0, roomSize.x) + p_roomPosition.x + randomStart.x, p_roomPosition.y + randomStart.y - 1, 0);
                        connectType   = ConnectionPoint.ConnectionType.Down;
                    }

                    else if (x > 0)
                    {
                        connectionPos = new Vector3Int(roomSize.x + p_roomPosition.x + randomStart.x, Random.Range(0, roomSize.y) + p_roomPosition.y + randomStart.y, 0);
                        connectType   = ConnectionPoint.ConnectionType.Right;
                    }
                    else if (x < 0)
                    {
                        connectionPos = new Vector3Int(p_roomPosition.x + randomStart.x - 1, Random.Range(0, roomSize.y) + p_roomPosition.y + randomStart.y, 0);
                        connectType   = ConnectionPoint.ConnectionType.Left;
                    }

                    p_dungeonGrid[connectionPos.x, connectionPos.y] = 1;
                    p_currentCell.AddConnectionPoint(connectionPos, connectType);
                }
            }
        }

        return(p_currentCell);
    }