Example #1
0
 public void RoomFlagPortalOnSide(MathConstants.eSignedDirection side, bool flag)
 {
     portalRoomSideBitmask.Set(side, flag);
 }
Example #2
0
 public bool RoomHasPortalOnSide(MathConstants.eSignedDirection side)
 {
     return portalRoomSideBitmask.Test(side);
 }
Example #3
0
        public static Portal CreatePortal(Room room, MathConstants.eSignedDirection roomSide)
        {
            Portal newPortal = new Portal();

            newPortal.portal_id = -1; // portal ID not set until this portal gets saved into the DB
            newPortal.target_portal_id = -1;
            newPortal.room_side = roomSide;
            newPortal.room_x = room.room_key.x;
            newPortal.room_y = room.room_key.y;
            newPortal.room_z = room.room_key.z;

            switch (roomSide)
            {
                case MathConstants.eSignedDirection.positive_x:
                    {
                        Point3d p1= WorldConstants.ROOM_BOUNDS.Max;
                        Point3d p0= p1 - Vector3d.I*WorldConstants.PORTAL_WIDTH - Vector3d.J*WorldConstants.ROOM_Y_SIZE;

                        newPortal.bounding_box= new AABB3d(p0, p1);
                    }
                    break;
                case MathConstants.eSignedDirection.negative_x:
                    {
                        Point3d p0 = WorldConstants.ROOM_BOUNDS.Min;
                        Point3d p1 = p0 + Vector3d.I * WorldConstants.PORTAL_WIDTH + Vector3d.J * WorldConstants.ROOM_Y_SIZE;

                        newPortal.bounding_box= new AABB3d(p0, p1);
                    }
                    break;
                case MathConstants.eSignedDirection.positive_y:
                    {
                        Point3d p1 = WorldConstants.ROOM_BOUNDS.Max;
                        Point3d p0 = p1 - Vector3d.I * WorldConstants.ROOM_X_SIZE - Vector3d.J * WorldConstants.PORTAL_WIDTH;

                        newPortal.bounding_box= new AABB3d(p0, p1);
                    }
                    break;
                case MathConstants.eSignedDirection.negative_y:
                    {
                        Point3d p0 = WorldConstants.ROOM_BOUNDS.Min;
                        Point3d p1 = p0 + Vector3d.I * WorldConstants.ROOM_X_SIZE + Vector3d.J * WorldConstants.PORTAL_WIDTH;

                        newPortal.bounding_box= new AABB3d(p0, p1);
                    }
                    break;
                case MathConstants.eSignedDirection.positive_z:
                case MathConstants.eSignedDirection.negative_z:
                    {
                        int column = RNGUtilities.RandomInt(WorldConstants.ROOM_X_TILES / 3, 2 * WorldConstants.ROOM_X_TILES / 3);
                        int row = RNGUtilities.RandomInt(WorldConstants.ROOM_Y_TILES / 3, 2 * WorldConstants.ROOM_Y_TILES / 3);
                        Point3d p0 = WorldConstants.GetTilePosition(column, row);
                        Point3d p1 = p0 + Vector3d.I * WorldConstants.ROOM_TILE_SIZE + Vector3d.J * WorldConstants.ROOM_TILE_SIZE;

                        newPortal.bounding_box = new AABB3d(p0, p1);
                    }
                    break;
            }

            return newPortal;
        }
Example #4
0
        private static bool TryGetValidNeighborNavCellIndex(
            NavCell[] navCells,
            uint colomnCount,
            uint rowCount,
            uint navCellIndex,
            MathConstants.eDirection direction,
            out uint neighborCellIndex)
        {
            bool hasNeighbor = false;

            neighborCellIndex = 0;

            if (navCells.Length > 1)
            {
                uint colomn = GetNavCellColomn(colomnCount, navCellIndex);
                uint row = GetNavCellRow(colomnCount, navCellIndex);

                switch (direction)
                {
                    case MathConstants.eDirection.down:
                        if ((row + 1) < rowCount)
                        {
                            neighborCellIndex = GetNavCellIndex(colomnCount, row + 1, colomn);
                            hasNeighbor = true;
                        }
                        break;
                    case MathConstants.eDirection.up:
                        if ((row - 1) > 0)
                        {
                            neighborCellIndex = GetNavCellIndex(colomnCount, row - 1, colomn);
                            hasNeighbor = true;
                        }
                        break;
                    case MathConstants.eDirection.left:
                        if ((colomn - 1) >= 0)
                        {
                            neighborCellIndex = GetNavCellIndex(colomnCount, row, colomn - 1);
                            hasNeighbor = true;
                        }
                        break;
                    case MathConstants.eDirection.right:
                        if ((colomn + 1) >= 0)
                        {
                            neighborCellIndex = GetNavCellIndex(colomnCount, row, colomn + 1);
                            hasNeighbor = true;
                        }
                        break;
                }

                if (hasNeighbor && navCells[neighborCellIndex].connectivityId == EMPTY_NAV_CELL)
                {
                    neighborCellIndex = 0;
                    hasNeighbor = false;
                }
            }

            return hasNeighbor;
        }
Example #5
0
 public bool TryGetValidNeighborNavCellIndex(
     uint navCellIndex,
     MathConstants.eDirection direction,
     out uint neighborCellIndex)
 {
     return NavMesh.TryGetValidNeighborNavCellIndex(
         m_navCells,
         m_colomnCount,
         m_rowCount,
         navCellIndex,
         direction,
         out neighborCellIndex);
 }
Example #6
0
        public bool NavCellHasNeighbor(uint navCellIndex, MathConstants.eDirection direction)
        {
            uint neighborNavCellIndex;

            return TryGetValidNeighborNavCellIndex(navCellIndex, direction, out neighborNavCellIndex);
        }
Example #7
0
        public bool ComputePointsOnNavCellSide(
            uint navCellIndex,
            MathConstants.eDirection direction,
            out Point3d portalLeft,
            out Point3d portalRight)
        {
            bool validPortal = false;

            if (m_navCells.Length > 1)
            {
                float halfCellSize = GameConstants.NAV_MESH_WORLD_UNITS_SIZE * 0.5F;

                portalLeft = ComputeNavCellCenter(navCellIndex);
                portalRight = new Point3d(portalLeft);

                // toNavRef is to the right of the fromNavRef (+X)
                switch (direction)
                {
                    // (+X)
                    case MathConstants.eDirection.right:
                        {
                            portalLeft.x += halfCellSize;
                            portalLeft.y -= halfCellSize;
                            portalRight.x += halfCellSize;
                            portalRight.y += halfCellSize;

                            validPortal = true;
                        } break;
                    // (-X)
                    case MathConstants.eDirection.left:
                        {
                            portalLeft.x -= halfCellSize;
                            portalLeft.y += halfCellSize;
                            portalRight.x -= halfCellSize;
                            portalRight.y -= halfCellSize;

                            validPortal = true;
                        } break;
                    // (-Y)
                    case MathConstants.eDirection.down:
                        {
                            portalLeft.x += halfCellSize;
                            portalLeft.y -= halfCellSize;
                            portalRight.x -= halfCellSize;
                            portalRight.y -= halfCellSize;

                            validPortal = true;
                        } break;
                    // (+Y)
                    case MathConstants.eDirection.up:
                        {
                            portalLeft.x -= halfCellSize;
                            portalLeft.y += halfCellSize;
                            portalRight.x += halfCellSize;
                            portalRight.y += halfCellSize;

                            validPortal = true;
                        } break;
                }
            }
            else
            {
                portalLeft = new Point3d();
                portalRight = new Point3d();
            }

            return validPortal;
        }