// FUNCTIONS

        public override void GenerateDungeon(int size, int floor, Point worldIndex)
        {
            DungeonHelper.InitializeMap(dungeonFloor);
            Block[,] room;

            firstRoomPos = floor > 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[floor - 1].GetDownStairPos() : Program.Player.Position;

            for (int c = 0; c < size * 100; c++) /* create all rooms */
            {
                if (rooms.Count >= size)
                {
                    break;
                }
                room = GenerateRoom(); // generate the first room
                if (room != null)
                {
                    PlaceRoom(room);
                }
            }

            DungeonHelper.PlaceStairs(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceItemsAndChests(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceCreatures(dungeonFloor, firstRoomPos, monsterTypes, worldIndex, floor);

            for (int i = 0; i < dungeonFloor.Width; i++)
            {
                for (int j = 0; j < dungeonFloor.Height; j++)
                {
                    if (dungeonFloor.Blocks[i * dungeonFloor.Width + j] == null)
                    {
                        dungeonFloor.Blocks[i * dungeonFloor.Width + j] = new Air();
                    }
                }
            }
        }
Example #2
0
        // FUNCTIONS

        public void GenerateDungeon(int placementAttempts, int maxRoomCount, int floor)
        {
            DungeonHelper.InitializeMap(dungeonFloor);
            Block[,] room;

            firstRoomPos = floor > 0 ? Program.WorldMap.LocalTile.Dungeon.Floors[floor - 1].GetDownStairPos() : Program.Player.Position;

            for (int c = 0; c < placementAttempts; c++) // create all rooms
            {
                if (rooms.Count >= maxRoomCount)
                {
                    break;
                }
                room = GenerateRoom(); // generate the first room
                if (room != null)
                {
                    PlaceRoom(room);
                }
            }

            DungeonHelper.PlaceStairs(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceItemsAndChests(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceCreatures(dungeonFloor, firstRoomPos, monsterTypes);

            for (int i = 0; i < dungeonFloor.Width; i++)
            {
                for (int j = 0; j < dungeonFloor.Height; j++)
                {
                    if (dungeonFloor.Blocks[i * dungeonFloor.Width + j] == null)
                    {
                        dungeonFloor.Blocks[i * dungeonFloor.Width + j] = new Air();
                    }
                }
            }
        }
Example #3
0
        public override void GenerateDungeon(int size, int floor, Point worldIndex)
        {
            firstRoomPos = floor > 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[floor - 1].GetDownStairPos() : Program.Player.Position;

            DungeonHelper.InitializeMap(dungeonFloor);

            // fill the map with random blocks
            for (int i = Math.Max(0, firstRoomPos.X - size / 2); i < Math.Min(dungeonFloor.Width, firstRoomPos.X + size / 2); i++)
            {
                for (int j = Math.Max(0, firstRoomPos.Y - size / 2); j < Math.Min(dungeonFloor.Height, firstRoomPos.Y + size / 2); j++)
                {
                    if ((rng.Next(0, 100) < 40 && (new Point(i, j)).DistFrom(firstRoomPos) > 5))
                    {
                        dungeonFloor.Blocks[i * dungeonFloor.Width + j] = new Wall(Material.Stone);
                    }
                    else
                    {
                        dungeonFloor.Blocks[i * dungeonFloor.Width + j] = new Air();
                    }
                    dungeonFloor.Floor[i * Program.WorldMap.TileWidth + j] = new DirtFloor();
                }
            }
            for (int i = 0; i < 3; i++)
            {
                DoAutomataStep();
            }

            for (int i = 0; i < 15; i++)
            {
                Point pos = new Point(rng.Next(Math.Max(0, firstRoomPos.X - size / 2), Math.Min(dungeonFloor.Width, firstRoomPos.X + size / 2)),
                                      rng.Next(Math.Max(0, firstRoomPos.Y - size / 2), Math.Min(dungeonFloor.Height, firstRoomPos.Y + size / 2)));
                if (dungeonFloor[pos.X, pos.Y] is Air)
                {
                    dungeonFloor.PatrolPoints.Add(pos);
                }
            }

            DungeonHelper.PlaceStairs(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceItemsAndChests(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceCreatures(dungeonFloor, firstRoomPos, monsterTypes, worldIndex, floor);

            for (int i = 0; i < dungeonFloor.Width; i++)
            {
                for (int j = 0; j < dungeonFloor.Height; j++)
                {
                    if (dungeonFloor.Blocks[i * dungeonFloor.Width + j] == null)
                    {
                        dungeonFloor.Blocks[i * dungeonFloor.Width + j] = new Air();
                    }
                }
            }
        }