Beispiel #1
0
        private TypedFlags <eBindGameAction> LookupCharacterData(
            RequestCache requestCache)
        {
            TypedFlags <eBindGameAction> actionFlags = new TypedFlags <eBindGameAction>();

            actionFlags.Clear();

            // Get the current state of the character before moving them to another game
            m_character_state = CharacterQueries.GetFullCharacterState(requestCache.DatabaseContext, m_character_id);

            // Get the previous game this character was a part of, if any
            m_previous_game_id = m_character_state.game_id;

            // Only bother doing anything if the character isn't already bound to this game
            if (m_previous_game_id != m_game_id)
            {
                if (m_previous_game_id != -1)
                {
                    actionFlags.Set(eBindGameAction.leaveGame, true);
                }

                actionFlags.Set(eBindGameAction.joinGame, true);
            }

            return(actionFlags);
        }
Beispiel #2
0
        override protected bool ProcessRequestInternal(
            RequestCache requestCache,
            out string result_code)
        {
            bool success = true;

            result_code = SuccessMessages.GENERAL_SUCCESS;
            success     = VerifyGameExists(requestCache, m_game_id, out result_code);

            if (success)
            {
                TypedFlags <eBindGameAction> actionFlags = LookupCharacterData(requestCache);

                if (actionFlags.Test(eBindGameAction.leaveGame))
                {
                    PostCharacterLeftGameEvent(requestCache);
                    LeaveGame(requestCache);
                }

                if (actionFlags.Test(eBindGameAction.joinGame))
                {
                    PostCharacterJoinedGameEvent(requestCache);
                    JoinGame(requestCache);
                }
            }

            return(success);
        }
        public EntityProp(
            Mob ownerMob,
            IEnvironmentEntity entity)
        {
            this.target_object_id = entity.ID;
            RefeshEntityProperties(ownerMob, entity);

            this.propStatus          = EntityProp.ePropStatus.unacknowledged;
            this.propStatusTurnCount = 0;
            this.salience            = 0.0f;
            this.visibilityFlags     = new TypedFlags <EntityProp.ePropVisibilityFlags>();
        }
Beispiel #4
0
 public void GetTemplatesWithPortalBitmask(
     TypedFlags <MathConstants.eSignedDirection> portalBitmask,
     List <RoomTemplate> out_templates)
 {
     foreach (RoomTemplate roomTemplate in m_roomTemplates.Values)
     {
         if (roomTemplate.PortalRoomSideBitmask == portalBitmask)
         {
             out_templates.Add(roomTemplate);
         }
     }
 }
Beispiel #5
0
        public RoomTemplate(string templateName, XmlDocument xmlDoc)
        {
            m_templateName          = templateName;
            m_treasures             = new List <TreasureTemplate>();
            m_traps                 = new List <TrapTemplate>();
            m_mobSpawners           = new List <MobSpawnerTemplate>();
            m_portals               = new List <PortalTemplate>();
            m_energyTanks           = new List <EnergyTankTemplate>();
            m_portalRoomSideBitmask = new TypedFlags <MathConstants.eSignedDirection>();

            m_navMesh = NavMesh.FromNavMeshXML(xmlDoc.SelectSingleNode("/level/NavMesh"));
            ParseEntities(xmlDoc.SelectSingleNode("/level/Entities"));
        }
        private void UpdateEnergyTankPropVisibility(
            MobUpdateContext context)
        {
            Mob     ownerMob = context.mob;
            NavMesh navMesh  = context.moveRequest.Room.runtime_nav_mesh;

            foreach (EntityProp prop in energy_tank_props)
            {
                Point3d oldPropPosition = prop.GetPosition();

                // Find the energy tank associated with the player id
                EnergyTank energyTank = context.moveRequest.EnergyTanks.Find(e => e.ID == prop.target_object_id);

                // Can the mob see the player at their current location
                bool canSee = CanMobSeePoint(navMesh, ownerMob, energyTank.Position);

                TypedFlags <EntityProp.ePropVisibilityFlags> oldVisibilityFlags =
                    new TypedFlags <EntityProp.ePropVisibilityFlags>(prop.visibilityFlags);

                prop.visibilityFlags.Set(EntityProp.ePropVisibilityFlags.canSee, canSee);
                prop.visibilityFlags.Set(EntityProp.ePropVisibilityFlags.caughtGlimpse, canSee);
                prop.visibilityFlags.Set(EntityProp.ePropVisibilityFlags.stationary, true);

                if (canSee)
                {
                    // If so, we get to pull the entity properties
                    prop.RefeshEntityProperties(ownerMob, energyTank);
                    prop.visibilityFlags.Set(EntityProp.ePropVisibilityFlags.seenAtLeastOnce, true);
                }

                // Update the status of the prop based on the current visibility
                UpdatePropStatus(ownerMob, prop);

                // Post an event if we just spotted an energy that we've never seen before
                if (!oldVisibilityFlags.Test(EntityProp.ePropVisibilityFlags.canSee) &&
                    !oldVisibilityFlags.Test(EntityProp.ePropVisibilityFlags.seenAtLeastOnce) &&
                    (prop.visibilityFlags.Test(EntityProp.ePropVisibilityFlags.canSee) ||
                     prop.visibilityFlags.Test(EntityProp.ePropVisibilityFlags.caughtGlimpse)))
                {
                    context.output_game_events.Add(
                        new GameEvent_MobEnergyTankPropSpotted()
                    {
                        mob_id         = ownerMob.ID,
                        energy_tank_id = prop.target_object_id
                    });
                }
            }
        }
        public EntityProp()
        {
            this.target_object_id = -1;

            this.position_x = 0.0;
            this.position_y = 0.0;
            this.position_z = 0.0;
            this.faction    = GameConstants.eFaction.neutral;
            this.energy     = 0;
            this.health     = 0;
            this.distance   = 0.0f;

            this.propStatus          = EntityProp.ePropStatus.unacknowledged;
            this.propStatusTurnCount = 0;
            this.salience            = 0.0f;
            this.visibilityFlags     = new TypedFlags <EntityProp.ePropVisibilityFlags>();
        }
Beispiel #8
0
        public Point3d world_position; // World space coordinates of the lower-left hand corner (min corner)

        #endregion Fields

        #region Constructors

        public Room(RoomKey rk)
        {
            room_key = rk;
            random_seed = rk.GetHashCode();
            world_position.Set(
                (float)room_key.x * WorldConstants.ROOM_X_SIZE,
                (float)room_key.y * WorldConstants.ROOM_Y_SIZE,
                (float)room_key.z * WorldConstants.ROOM_Z_SIZE);
            portalRoomSideBitmask = new TypedFlags<MathConstants.eSignedDirection>();
            connectivity_id= -1;

            portals = new List<Portal>();
            mobSpawners = new List<MobSpawner>();
            static_room_data = new StaticRoomData();
            static_room_data.room_template_name = "";
            static_room_data.objects = null;
            runtime_nav_mesh = new NavMesh();
        }
Beispiel #9
0
        public Room(RoomKey rk)
        {
            room_key    = rk;
            random_seed = rk.GetHashCode();
            world_position.Set(
                (float)room_key.x * WorldConstants.ROOM_X_SIZE,
                (float)room_key.y * WorldConstants.ROOM_Y_SIZE,
                (float)room_key.z * WorldConstants.ROOM_Z_SIZE);
            portalRoomSideBitmask = new TypedFlags <MathConstants.eSignedDirection>();
            connectivity_id       = -1;

            portals          = new List <Portal>();
            mobSpawners      = new List <MobSpawner>();
            static_room_data = new StaticRoomData();
            static_room_data.room_template_name = "";
            static_room_data.objects            = null;
            runtime_nav_mesh = new NavMesh();
        }
Beispiel #10
0
 public void GetTemplatesWithPortalBitmask(
     TypedFlags<MathConstants.eSignedDirection> portalBitmask, 
     List<RoomTemplate> out_templates)
 {
     foreach (RoomTemplate roomTemplate in m_roomTemplates.Values)
     {
         if (roomTemplate.PortalRoomSideBitmask == portalBitmask)
         {
             out_templates.Add(roomTemplate);
         }
     }
 }
Beispiel #11
0
        public RoomTemplate(string templateName, XmlDocument xmlDoc, byte[] compressedNavCells, byte[] compressedPVS)
        {
            m_templateName = templateName;
            m_treasures = new List<TreasureTemplate>();
            m_traps = new List<TrapTemplate>();
            m_mobSpawners = new List<MobSpawnerTemplate>();
            m_portals = new List<PortalTemplate>();
            m_energyTanks = new List<EnergyTankTemplate>();
            m_portalRoomSideBitmask = new TypedFlags<MathConstants.eSignedDirection>();

            m_navMesh = NavMesh.FromCompressedNavMeshData(compressedNavCells, compressedPVS);
            ParseEntities(xmlDoc.SelectSingleNode("/level/Entities"));
        }
        private TypedFlags<eBindGameAction> LookupCharacterData(
            RequestCache requestCache)
        {
            TypedFlags<eBindGameAction> actionFlags = new TypedFlags<eBindGameAction>();

            actionFlags.Clear();

            // Get the current state of the character before moving them to another game
            m_character_state = CharacterQueries.GetFullCharacterState(requestCache.DatabaseContext, m_character_id);

            // Get the previous game this character was a part of, if any
            m_previous_game_id = m_character_state.game_id;

            // Only bother doing anything if the character isn't already bound to this game
            if (m_previous_game_id != m_game_id)
            {
                if (m_previous_game_id != -1)
                {
                    actionFlags.Set(eBindGameAction.leaveGame, true);
                }

                actionFlags.Set(eBindGameAction.joinGame, true);
            }

            return actionFlags;
        }
        private void UpdateAIPropVisibility(
            MobUpdateContext context)
        {
            Mob     ownerMob = context.mob;
            NavMesh navMesh  = context.moveRequest.Room.runtime_nav_mesh;

            foreach (EntityProp prop in ai_props)
            {
                Point3d oldPropPosition = prop.GetPosition();

                // Find the player associated with the player id
                MobUpdateContext otherMobContext = context.moveRequest.MobContexts.Find(m => m.mob.ID == prop.target_object_id);
                Mob otherMob = otherMobContext.mob;

                // Can the mob see the other mob at their current location
                bool canSee = CanMobSeePoint(navMesh, ownerMob, otherMob.Position);

                TypedFlags <EntityProp.ePropVisibilityFlags> oldVisibilityFlags =
                    new TypedFlags <EntityProp.ePropVisibilityFlags>(prop.visibilityFlags);

                prop.visibilityFlags.Set(EntityProp.ePropVisibilityFlags.canSee, canSee);
                prop.visibilityFlags.Set(EntityProp.ePropVisibilityFlags.caughtGlimpse, canSee);

                if (canSee)
                {
                    // If so, we get to pull the entity properties
                    prop.RefeshEntityProperties(ownerMob, otherMob);
                    prop.visibilityFlags.Set(EntityProp.ePropVisibilityFlags.seenAtLeastOnce, true);
                }
                else
                {
                    EntityPath entityPath = otherMobContext.path;

                    if (entityPath != null)
                    {
                        // Find the last place we saw the player along their path, if at all
                        for (int pathStepIndex = entityPath.path.Count - 1; pathStepIndex >= 0; pathStepIndex--)
                        {
                            PathStep pathStep = entityPath.path[pathStepIndex];

                            if (CanMobSeePoint(navMesh, ownerMob, pathStep.StepPoint))
                            {
                                prop.position_x = pathStep.StepPoint.x;
                                prop.position_y = pathStep.StepPoint.y;
                                prop.position_z = pathStep.StepPoint.z;
                                prop.visibilityFlags.Set(EntityProp.ePropVisibilityFlags.caughtGlimpse, true);
                                prop.visibilityFlags.Set(EntityProp.ePropVisibilityFlags.seenAtLeastOnce, true);
                                break;
                            }
                        }
                    }
                }

                // Post an event if we just spotted another mob that we've never seen before
                if (!oldVisibilityFlags.Test(EntityProp.ePropVisibilityFlags.canSee) &&
                    !oldVisibilityFlags.Test(EntityProp.ePropVisibilityFlags.seenAtLeastOnce) &&
                    (prop.visibilityFlags.Test(EntityProp.ePropVisibilityFlags.canSee) ||
                     prop.visibilityFlags.Test(EntityProp.ePropVisibilityFlags.caughtGlimpse)))
                {
                    context.output_game_events.Add(
                        new GameEvent_MobAIPropSpotted()
                    {
                        mob_id         = ownerMob.ID,
                        spotted_mob_id = prop.target_object_id,
                        x = prop.position_x,
                        y = prop.position_y,
                        z = prop.position_z
                    });
                }
            }
        }
Beispiel #14
0
        public bool RunTest()
        {
            bool success = true;

            {
                TypedFlags <TestEnum> flags = new TypedFlags <TestEnum>();

                Debug.Assert(flags.IsEmpty());
                success &= flags.IsEmpty();

                for (TestEnum bitIndex = TestEnum._flag0; bitIndex <= TestEnum._flag31; ++bitIndex)
                {
                    Debug.Assert(!flags.Test(bitIndex));
                    success &= !flags.Test(bitIndex);

                    flags.Set(bitIndex, true);
                    Debug.Assert(flags.Test(bitIndex));
                    success &= flags.Test(bitIndex);

                    flags.Set(bitIndex, false);
                    Debug.Assert(!flags.Test(bitIndex));
                    success &= !flags.Test(bitIndex);
                }
            }


            {
                TypedFlags <TestEnum> flagsA = new TypedFlags <TestEnum>();
                TypedFlags <TestEnum> flagsB = new TypedFlags <TestEnum>();

                flagsB.Set(TestEnum._flag10, true);

                TypedFlags <TestEnum> flagsC = new TypedFlags <TestEnum>(flagsB);

                Debug.Assert(flagsA != flagsB);
                success &= flagsA != flagsB;

                Debug.Assert(flagsB == flagsC);
                success &= flagsB == flagsC;
            }

            {
                TypedFlags <TestEnum> flags = new TypedFlags <TestEnum>(
                    TypedFlags <TestEnum> .FLAG(TestEnum._flag4) |
                    TypedFlags <TestEnum> .FLAG(TestEnum._flag9));


                for (TestEnum bitIndex = TestEnum._flag0; bitIndex <= TestEnum._flag31; ++bitIndex)
                {
                    if (bitIndex == TestEnum._flag4 || bitIndex == TestEnum._flag9)
                    {
                        Debug.Assert(flags.Test(bitIndex));
                        success &= flags.Test(bitIndex);
                    }
                    else
                    {
                        Debug.Assert(!flags.Test(bitIndex));
                        success &= !flags.Test(bitIndex);
                    }
                }
            }

            return(success);
        }
Beispiel #15
0
        private void JoinAdjacentDisjointRoomSets(
            Dictionary <int, List <RoomIndex> > connectivityIdToRoomIndexMap)
        {
            // Look for any null room that neighboring at least two disjoint sets of rooms
            for (RoomIndexIterator iterator = new RoomIndexIterator(m_roomGrid, RoomIndexIterator.eIterationType.nullRooms);
                 iterator.Valid;
                 iterator.Next())
            {
                RoomIndex   nullRoomIndex      = iterator.Current;
                RoomIndex[] neighboringIndices = new RoomIndex[4] {
                    nullRoomIndex.Offset(1, 0, 0),
                    nullRoomIndex.Offset(-1, 0, 0),
                    nullRoomIndex.Offset(0, 1, 0),
                    nullRoomIndex.Offset(0, -1, 0)
                };
                MathConstants.eSignedDirection[] neighborSideFlags = new MathConstants.eSignedDirection[4] {
                    MathConstants.eSignedDirection.positive_x,
                    MathConstants.eSignedDirection.negative_x,
                    MathConstants.eSignedDirection.positive_y,
                    MathConstants.eSignedDirection.negative_y
                };

                bool createNewRoom = false;
                TypedFlags <MathConstants.eSignedDirection> nullRoomNeighborFlags = new TypedFlags <MathConstants.eSignedDirection>();
                int lastConnectivityId = -1;

                for (int side_index = 0; side_index < 4; ++side_index)
                {
                    MathConstants.eSignedDirection neighborSide = neighborSideFlags[side_index];
                    RoomIndex neighborRoomIndex = neighboringIndices[side_index];

                    // See if an adjacent room exists on this side
                    RoomLayout neighborRoom = TryGetRoomByIndex(neighborRoomIndex);

                    if (neighborRoom != null)
                    {
                        // Record that a neighboring room was found in this side
                        nullRoomNeighborFlags.Set(neighborSide, true);

                        // See if the neighboring room is actually disjoint from a previous neighbor
                        // we have found on another side (different connectivity_id)
                        int roomConnectivityId = neighborRoom.connectivity_id;

                        if (lastConnectivityId != -1 &&
                            roomConnectivityId != lastConnectivityId)
                        {
                            List <RoomIndex> roomSet     = connectivityIdToRoomIndexMap[roomConnectivityId];
                            List <RoomIndex> lastRoomSet = connectivityIdToRoomIndexMap[lastConnectivityId];

                            // Make the connectivity ids match for rooms in both sets
                            roomSet.ForEach(rIndex => GetRoomByIndex(rIndex).connectivity_id = lastConnectivityId);

                            // Merge the rooms in the set into the previous set
                            lastRoomSet.AddRange(roomSet);

                            // Remove the set
                            connectivityIdToRoomIndexMap.Remove(roomConnectivityId);

                            // Since we have merged two adjacent sets we now need a new room
                            // to bridge the disjoin sets
                            createNewRoom = true;
                        }

                        // Keep track of the last valid connectivity we found for the next iteration
                        lastConnectivityId = neighborRoom.connectivity_id;
                    }
                }

                if (createNewRoom)
                {
                    // Create a new room at the null room index location
                    RoomLayout newRoom = new RoomLayout(GetRoomKeyForRoomIndex(nullRoomIndex));

                    // Record which neighbors the null room has
                    newRoom.portalRoomSideBitmask = nullRoomNeighborFlags;

                    // All neighbors should have the same connectivity id now
                    // so just get the connectivity id from the last valid neighbor
                    newRoom.connectivity_id = lastConnectivityId;

                    // Finally store the new room in the room grid
                    m_roomGrid[nullRoomIndex.X, nullRoomIndex.Y, nullRoomIndex.Z] = newRoom;

                    // Add the new room to the connectivity set it's helping to bridge
                    {
                        List <RoomIndex> lastRoomSet = connectivityIdToRoomIndexMap[lastConnectivityId];

                        lastRoomSet.Add(new RoomIndex(nullRoomIndex));
                    }

                    // Tell all neighboring rooms about the new room adjacent to it
                    for (int side_index = 0; side_index < 4; ++side_index)
                    {
                        MathConstants.eSignedDirection neighborSide = neighborSideFlags[side_index];
                        RoomIndex neighborRoomIndex = neighboringIndices[side_index];

                        // See if an adjacent room exists on this side
                        if (newRoom.portalRoomSideBitmask.Test(neighborSide))
                        {
                            RoomLayout neighborRoom = GetRoomByIndex(neighborRoomIndex);
                            MathConstants.eSignedDirection opposingNeighborSide = RoomKey.GetOpposingRoomSide(neighborSide);

                            neighborRoom.RoomFlagPortalOnSide(opposingNeighborSide, true);
                        }
                    }
                }
            }
        }
        public bool RunTest()
        {
            bool success = true;

            {
                TypedFlags<TestEnum> flags = new TypedFlags<TestEnum>();

                Debug.Assert(flags.IsEmpty());
                success &= flags.IsEmpty();

                for (TestEnum bitIndex = TestEnum._flag0; bitIndex <= TestEnum._flag31; ++bitIndex)
                {
                    Debug.Assert(!flags.Test(bitIndex));
                    success &= !flags.Test(bitIndex);

                    flags.Set(bitIndex, true);
                    Debug.Assert(flags.Test(bitIndex));
                    success &= flags.Test(bitIndex);

                    flags.Set(bitIndex, false);
                    Debug.Assert(!flags.Test(bitIndex));
                    success &= !flags.Test(bitIndex);
                }
            }

            {
                TypedFlags<TestEnum> flagsA = new TypedFlags<TestEnum>();
                TypedFlags<TestEnum> flagsB = new TypedFlags<TestEnum>();

                flagsB.Set(TestEnum._flag10, true);

                TypedFlags<TestEnum> flagsC = new TypedFlags<TestEnum>(flagsB);

                Debug.Assert(flagsA != flagsB);
                success &= flagsA != flagsB;

                Debug.Assert(flagsB == flagsC);
                success &= flagsB == flagsC;
            }

            {
                TypedFlags<TestEnum> flags = new TypedFlags<TestEnum>(
                    TypedFlags<TestEnum>.FLAG(TestEnum._flag4) |
                    TypedFlags<TestEnum>.FLAG(TestEnum._flag9));

                for (TestEnum bitIndex = TestEnum._flag0; bitIndex <= TestEnum._flag31; ++bitIndex)
                {
                    if (bitIndex == TestEnum._flag4 || bitIndex == TestEnum._flag9)
                    {
                        Debug.Assert(flags.Test(bitIndex));
                        success &= flags.Test(bitIndex);
                    }
                    else
                    {
                        Debug.Assert(!flags.Test(bitIndex));
                        success &= !flags.Test(bitIndex);
                    }
                }
            }

            return success;
        }