Example #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>	Merge two rooms. </summary>
        ///
        /// <remarks>	Named as though dir was vertical.  Darrellp, 9/22/2011. </remarks>
        ///
        /// <param name="topRoomsGridLocation">	The location of the top room in the grid. </param>
        /// <param name="dir">					The direction of the merge. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        private void MergeTwoRooms(MapCoordinates topRoomsGridLocation, Dir dir)
        {
            // Get grid coordinates of the other room
            MapCoordinates bottomRoomsGridLocation = topRoomsGridLocation.NextLarger(dir);
            Dir            otherDir = MapCoordinates.OtherDirection(dir);

            // Retrieve both rooms
            RectangularRoom topRoom    = RoomAt(topRoomsGridLocation);
            RectangularRoom bottomRoom = RoomAt(bottomRoomsGridLocation);

            // Are the rooms unmergable?
            if (!CheckMergeForOverlap(topRoom, bottomRoom, otherDir))
            {
                // Return and don't merge them - use normal corridors
                return;
            }

            // Remove their generic counterparts
            _mapRoomToGenericRooms.Remove(topRoom);
            _mapRoomToGenericRooms.Remove(bottomRoom);

            // Get their current coordinates, etc.
            int topRoomsBottom    = topRoom.LargeCoord(dir);
            int topRoomsTop       = topRoom.SmallCoord(dir);
            int bottomRoomsTop    = bottomRoom.SmallCoord(dir);
            int bottomRoomsHeight = bottomRoom.Size(dir);
            int topRoomsWidth     = topRoom.Size(otherDir);
            int bottomRoomsWidth  = bottomRoom.Size(otherDir);

            // Pick a random spot between the rooms to merge them
            // This will be the new inside coord of the small coordinate room
            int mergeRow = _rnd.Next(topRoomsBottom, bottomRoomsTop);

            // Determine all the new coordinates
            int            topRoomsNewHeight    = mergeRow - topRoomsTop + 1;
            int            bottomRoomsNewHeight = bottomRoomsTop - mergeRow + bottomRoomsHeight - 1;
            MapCoordinates bottomRoomsLocation  = bottomRoom.Location;

            bottomRoomsLocation[dir] = mergeRow + 1;

            // Create our new expanded rooms
            RectangularRoom roomTopNew = RectangularRoom.CreateUndirectional(
                topRoom.Location,
                topRoomsNewHeight,
                topRoomsWidth,
                topRoomsGridLocation[dir],
                topRoomsGridLocation[otherDir],
                dir);
            RectangularRoom roomBottomNew = RectangularRoom.CreateUndirectional(
                bottomRoomsLocation,
                bottomRoomsNewHeight,
                bottomRoomsWidth,
                bottomRoomsGridLocation[dir],
                bottomRoomsGridLocation[otherDir],
                dir);

            // Install the new rooms
            SetRoomAt(topRoomsGridLocation, roomTopNew);
            SetRoomAt(bottomRoomsGridLocation, roomBottomNew);

            // Create the new generic rooms
            // We don't create the single merged generic room until we excavate because we don't know
            // the layout until then.
            _mapRoomToGenericRooms[roomTopNew]    = roomTopNew.ToGeneric();
            _mapRoomToGenericRooms[roomBottomNew] = roomBottomNew.ToGeneric();

            // Mark this in our merges structure
            _merges.Connect(topRoomsGridLocation, bottomRoomsGridLocation);
        }