Beispiel #1
0
        private void RemoveRoomFromGrid(RoomIndex roomIndex)
        {
            RoomLayout room = GetRoomByIndex(roomIndex);

            // Neighbor on the +x side
            if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.positive_x))
            {
                RoomLayout posXRoom = GetRoomByIndex(roomIndex.Offset(1, 0, 0));

                // No more room on the -x side
                posXRoom.RoomFlagPortalOnSide(MathConstants.eSignedDirection.negative_x, false);
            }

            // Neighbor on the -x side
            if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.negative_x))
            {
                RoomLayout negXRoom = GetRoomByIndex(roomIndex.Offset(-1, 0, 0));

                // No more room on the +x side
                negXRoom.RoomFlagPortalOnSide(MathConstants.eSignedDirection.positive_x, false);
            }

            // Neighbor on the +y side
            if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.positive_y))
            {
                RoomLayout posYRoom = GetRoomByIndex(roomIndex.Offset(0, 1, 0));

                // No more room on the -y side
                posYRoom.RoomFlagPortalOnSide(MathConstants.eSignedDirection.negative_y, false);
            }

            // Neighbor on the -y side
            if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.negative_y))
            {
                RoomLayout negYRoom = GetRoomByIndex(roomIndex.Offset(0, -1, 0));

                // No more room on the +y side
                negYRoom.RoomFlagPortalOnSide(MathConstants.eSignedDirection.positive_y, false);
            }

            // Stomp this room
            m_roomGrid[roomIndex.X, roomIndex.Y, roomIndex.Z] = null;
        }
Beispiel #2
0
        private bool CanRemoveRoomFromGrid(RoomIndex roomIndex)
        {
            RoomLayout room          = GetRoomByIndex(roomIndex);
            bool       canRemoveRoom = true;

            // Can't remove this room if it contains stairs
            // Or we are neighboring a room that contains stairs
            if (!room.RoomHasStairs)
            {
                RoomKey roomKey = GetRoomKeyForRoomIndex(roomIndex);

                // Can't remove the origin room because that's where the player is spawned in a new game
                canRemoveRoom = !(roomKey.x == 0 && roomKey.y == 0 && roomKey.z == 0);

                if (canRemoveRoom && room.RoomHasPortalOnSide(MathConstants.eSignedDirection.positive_x))
                {
                    canRemoveRoom &= !GetRoomByIndex(roomIndex.Offset(1, 0, 0)).RoomHasStairs;
                }

                if (canRemoveRoom && room.RoomHasPortalOnSide(MathConstants.eSignedDirection.negative_x))
                {
                    canRemoveRoom &= !GetRoomByIndex(roomIndex.Offset(-1, 0, 0)).RoomHasStairs;
                }

                if (canRemoveRoom && room.RoomHasPortalOnSide(MathConstants.eSignedDirection.positive_y))
                {
                    canRemoveRoom &= !GetRoomByIndex(roomIndex.Offset(0, 1, 0)).RoomHasStairs;
                }

                if (canRemoveRoom && room.RoomHasPortalOnSide(MathConstants.eSignedDirection.negative_y))
                {
                    canRemoveRoom &= !GetRoomByIndex(roomIndex.Offset(0, -1, 0)).RoomHasStairs;
                }
            }
            else
            {
                canRemoveRoom = false;
            }

            return(canRemoveRoom);
        }
Beispiel #3
0
        private void ComputeRoomConnectivity(UnionFind <RoomIndex> roomUnion)
        {
            IList <RoomIndex> roomIndices = GetRoomIndexList();

            roomUnion = new UnionFind <RoomIndex>();

            // Add all of the rooms into the union
            foreach (RoomIndex roomIndex in roomIndices)
            {
                roomUnion.AddElement(roomIndex);
            }

            // Start connecting to our neighbors
            foreach (RoomIndex roomIndex in roomIndices)
            {
                RoomLayout room = GetRoomByIndex(roomIndex);

                // Union with the neighbor on the +x side
                if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.positive_x))
                {
                    roomUnion.Union(roomIndex, roomIndex.Offset(1, 0, 0));
                }

                // Union with the neighbor on the -x side
                if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.negative_x))
                {
                    roomUnion.Union(roomIndex, roomIndex.Offset(-1, 0, 0));
                }

                // Union with the neighbor on the +y side
                if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.positive_y))
                {
                    roomUnion.Union(roomIndex, roomIndex.Offset(0, 1, 0));
                }

                // Union with the neighbor on the -y side
                if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.negative_y))
                {
                    roomUnion.Union(roomIndex, roomIndex.Offset(0, -1, 0));
                }

                // Union with the neighbor on the +z side
                if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.positive_z))
                {
                    roomUnion.Union(roomIndex, roomIndex.Offset(0, 0, 1));
                }

                // Union with the neighbor on the -z side
                if (room.RoomHasPortalOnSide(MathConstants.eSignedDirection.negative_z))
                {
                    roomUnion.Union(roomIndex, roomIndex.Offset(0, 0, -1));
                }
            }

            // Store the final connectivity id on the room
            foreach (RoomIndex roomIndex in roomIndices)
            {
                RoomLayout room = GetRoomByIndex(roomIndex);

                room.connectivity_id = roomUnion.FindRootIndex(roomIndex);
            }
        }