Example #1
0
 private void Awake()
 {
     m_dungeonNav     = GetComponent <DungeonNavigation>();
     m_gridTestAgent  = GetComponent <DungeonNavigation_Agent>();
     m_occupiedSpaces = new List <Vector2>();
     m_playerInput    = m_playerObject.GetComponent <Input_Base>();
 }
 public abstract List <DungeonGridCell> CreateDungeon(DungeonManager p_gen, DungeonTheme p_dungeonTheme, DungeonNavigation p_dungeonNav);
Example #3
0
 private void Start()
 {
     navGrid = DungeonManager.Instance.GetComponent <DungeonNavigation>();
 }
Example #4
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);
    }
Example #5
0
 public List <DungeonGridCell> CreateNewFloor(DungeonManager p_gen, DungeonNavigation p_dungeonNav)
 {
     p_gen.m_dungeonGenTypeIndex = Random.Range(0, m_generationTypes.Count);
     p_gen.m_currentDungeonType  = m_generationTypes[p_gen.m_dungeonGenTypeIndex];
     return(m_generationTypes[p_gen.m_dungeonGenTypeIndex].CreateDungeon(p_gen, this, p_dungeonNav));
 }