コード例 #1
0
ファイル: csDungeonRoomGenerator.cs プロジェクト: akokulu/FQ
    public int CalculateRoomPlacementScore(Vector2 location, csDungeonRoom room, csDungeon dungeon)
    {
        // Check if the room at the given location will fit inside the bounds of the map

        //if (dungeon.Bounds.Contains(new Rect(location.x, location.y, (float)room.Width + 1, (float)room.Height + 1)))
        if (dungeon.Bounds.Contains(location) &&
            dungeon.Bounds.Contains(new Vector2(location.x + room.Width + 1, location.y + room.Height + 1)))
        {
            int roomPlacementScore = 0;

            // Loop for each cell in the room
            foreach (Vector2 roomLocation in room.CellLocations)
            {
                // Translate the room cell location to its location in the dungeon
                Vector2 dungeonLocation = new Vector2(location.x + roomLocation.x, location.y + roomLocation.y);

                // Add 1 point for each adjacent corridor to the cell
                if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, csDungeonCell.DirectionType.North))
                {
                    roomPlacementScore++;
                }
                if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, csDungeonCell.DirectionType.South))
                {
                    roomPlacementScore++;
                }
                if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, csDungeonCell.DirectionType.West))
                {
                    roomPlacementScore++;
                }
                if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, csDungeonCell.DirectionType.East))
                {
                    roomPlacementScore++;
                }

                // Add 3 points if the cell overlaps an existing corridor
                if (dungeon[dungeonLocation].IsCorridor)
                {
                    roomPlacementScore += 3;
                }

                // Do not allow rooms to overlap!
                foreach (csDungeonRoom dungeonRoom in dungeon.Rooms)
                {
                    if (dungeonRoom.Bounds.Contains(dungeonLocation))
                    {
                        return(0);
                    }
                }
            }

            return(roomPlacementScore);
        }
        else
        {
            return(0);
        }
    }
コード例 #2
0
ファイル: csDungeonRoomGenerator.cs プロジェクト: akokulu/FQ
    public csDungeonRoom CreateRoom(bool forceSmall)
    {
        csDungeonRoom room = new csDungeonRoom();

        room.Constructor(
            csRandom.Instance.Next(forceSmall == true ? 1 : minRoomWidth, forceSmall == true ? 1 : maxRoomWidth),
            csRandom.Instance.Next(forceSmall == true ? 1 : minRoomHeight, forceSmall == true ? 1 : maxRoomHeight)
            );

        room.InitializeRoomCells();
        return(room);
    }
コード例 #3
0
ファイル: csDungeonRoomGenerator.cs プロジェクト: akokulu/FQ
    public void PlaceRooms(csDungeon dungeon)
    {
        int roomsPlaced = 0;

        for (int roomCounter = 0; roomCounter < noOfRoomsToPlace; roomCounter++)
        {
            csDungeonRoom room = null;

            // Ensure that at least half the rooms placed are small rooms to avoid "empty" dungeons
            if (maxRoomWidth > 1 || maxRoomHeight > 1)
            {
                if (roomCounter < noOfRoomsToPlace / 2)
                {
                    room = CreateRoom(true);
                }
                else
                {
                    room = CreateRoom(false);
                }
            }
            else
            {
                room = CreateRoom(false);
            }

            int     bestRoomPlacementScore    = 0;              // int.MaxValue;
            Vector2?bestRoomPlacementLocation = null;

            foreach (Vector2 currentRoomPlacementLocation in dungeon.CorridorCellLocations)
            {
                int currentRoomPlacementScore = CalculateRoomPlacementScore(currentRoomPlacementLocation, room, dungeon);

                if (currentRoomPlacementScore > bestRoomPlacementScore)
                {
                    bestRoomPlacementScore    = currentRoomPlacementScore;
                    bestRoomPlacementLocation = currentRoomPlacementLocation;
                }
            }

            // Create room at best room placement cell
            if (bestRoomPlacementLocation != null)
            {
                PlaceRoom(bestRoomPlacementLocation.Value, room, dungeon);
                roomsPlaced++;
            }
        }
    }
コード例 #4
0
ファイル: csDungeonRoomGenerator.cs プロジェクト: akokulu/FQ
    public void PlaceRoom(Vector2 location, csDungeonRoom room, csDungeon dungeon)
    {
        // Offset the room origin to the new location
        room.SetLocation(location);

        // Loop for each cell in the room
        foreach (Vector2 roomLocation in room.CellLocations)
        {
            // Translate the room cell location to its location in the dungeon
            Vector2 dungeonLocation = new Vector2(location.x + roomLocation.x, location.y + roomLocation.y);
            dungeon[dungeonLocation].NorthSide = room[roomLocation].NorthSide;
            dungeon[dungeonLocation].SouthSide = room[roomLocation].SouthSide;
            dungeon[dungeonLocation].WestSide  = room[roomLocation].WestSide;
            dungeon[dungeonLocation].EastSide  = room[roomLocation].EastSide;

            // Create room walls on map (either side of the wall)
            if ((roomLocation.x == 0) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, csDungeonCell.DirectionType.West)))
            {
                dungeon.CreateWall(dungeonLocation, csDungeonCell.DirectionType.West);
            }
            if ((roomLocation.x == room.Width - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, csDungeonCell.DirectionType.East)))
            {
                dungeon.CreateWall(dungeonLocation, csDungeonCell.DirectionType.East);
            }
            if ((roomLocation.y == 0) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, csDungeonCell.DirectionType.North)))
            {
                dungeon.CreateWall(dungeonLocation, csDungeonCell.DirectionType.North);
            }
            if ((roomLocation.y == room.Height - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, csDungeonCell.DirectionType.South)))
            {
                dungeon.CreateWall(dungeonLocation, csDungeonCell.DirectionType.South);
            }
        }

        dungeon.AddRoom(room);
    }
コード例 #5
0
 internal void AddRoom(csDungeonRoom room)
 {
     rooms.Add(room);
 }