diff options
-rw-r--r-- | src/game/BattleGround.cpp | 1 | ||||
-rw-r--r-- | src/game/BattleGround.h | 3 | ||||
-rw-r--r-- | src/game/BattleGroundHandler.cpp | 4 | ||||
-rw-r--r-- | src/game/BattleGroundMgr.cpp | 61 | ||||
-rw-r--r-- | src/game/BattleGroundMgr.h | 7 | ||||
-rw-r--r-- | src/shared/revision_nr.h | 2 |
6 files changed, 63 insertions, 15 deletions
diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp index abef4f823d5..39dc135cffd 100644 --- a/src/game/BattleGround.cpp +++ b/src/game/BattleGround.cpp @@ -130,6 +130,7 @@ BattleGround::BattleGround() m_TypeID = BattleGroundTypeId(0); m_InstanceID = 0; m_Status = STATUS_NONE; + m_ClientInstanceID = 0; m_EndTime = 0; m_LastResurrectTime = 0; m_QueueId = QUEUE_ID_MAX_LEVEL_19; diff --git a/src/game/BattleGround.h b/src/game/BattleGround.h index 857f1c9803e..7d11fc78944 100644 --- a/src/game/BattleGround.h +++ b/src/game/BattleGround.h @@ -305,6 +305,7 @@ class BattleGround BGQueueIdBasedOnLevel GetQueueId() const { return m_QueueId; } uint32 GetInstanceID() const { return m_InstanceID; } BattleGroundStatus GetStatus() const { return m_Status; } + uint32 GetClientInstanceID() const { return m_ClientInstanceID; } uint32 GetStartTime() const { return m_StartTime; } uint32 GetEndTime() const { return m_EndTime; } uint32 GetLastResurrectTime() const { return m_LastResurrectTime; } @@ -335,6 +336,7 @@ class BattleGround } void SetInstanceID(uint32 InstanceID) { m_InstanceID = InstanceID; } void SetStatus(BattleGroundStatus Status) { m_Status = Status; } + void SetClientInstanceID(uint32 InstanceID) { m_ClientInstanceID = InstanceID; } void SetStartTime(uint32 Time) { m_StartTime = Time; } void SetEndTime(uint32 Time) { m_EndTime = Time; } void SetLastResurrectTime(uint32 Time) { m_LastResurrectTime = Time; } @@ -542,6 +544,7 @@ class BattleGround BattleGroundTypeId m_TypeID; uint32 m_InstanceID; //BattleGround Instance's GUID! BattleGroundStatus m_Status; + uint32 m_ClientInstanceID; //the instance-id which is sent to the client and without any other internal use uint32 m_StartTime; uint32 m_EndTime; uint32 m_LastResurrectTime; diff --git a/src/game/BattleGroundHandler.cpp b/src/game/BattleGroundHandler.cpp index ddf747f4401..912c1349d05 100644 --- a/src/game/BattleGroundHandler.cpp +++ b/src/game/BattleGroundHandler.cpp @@ -112,9 +112,9 @@ void WorldSession::HandleBattleGroundJoinOpcode( WorldPacket & recv_data ) return; // get bg instance or bg template if instance not found - BattleGround * bg = 0; + BattleGround * bg = NULL; if(instanceId) - BattleGround *bg = sBattleGroundMgr.GetBattleGround(instanceId, bgTypeId); + BattleGround *bg = sBattleGroundMgr.GetBattleGroundThroughClientInstance(instanceId, bgTypeId, _player->GetBattleGroundQueueIdFromLevel(bgTypeId)); if(!bg && !(bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId))) { diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp index 5b28e226517..44aea47bf8e 100644 --- a/src/game/BattleGroundMgr.cpp +++ b/src/game/BattleGroundMgr.cpp @@ -1150,6 +1150,8 @@ void BattleGroundMgr::DeleteAllBattleGrounds() { BattleGround * bg = itr->second; m_BattleGrounds[i].erase(itr++); + if(!m_ClientBattleGroundIds[i][bg->GetQueueId()].empty()) + m_ClientBattleGroundIds[i][bg->GetQueueId()].erase(bg->GetClientInstanceID()); delete bg; } } @@ -1184,6 +1186,8 @@ void BattleGroundMgr::Update(uint32 diff) { BattleGround * bg = itr->second; m_BattleGrounds[i].erase(itr); + if(!m_ClientBattleGroundIds[i][bg->GetQueueId()].empty()) + m_ClientBattleGroundIds[i][bg->GetQueueId()].erase(bg->GetClientInstanceID()); delete bg; } } @@ -1239,7 +1243,7 @@ void BattleGroundMgr::BuildBattleGroundStatusPacket(WorldPacket *data, BattleGro *data << uint32(QueueSlot); // queue id (0...2) - player can be in 3 queues in time // uint64 in client *data << uint64( uint64(arenatype ? arenatype : bg->GetArenaType()) | (uint64(0x0D) << 8) | (uint64(bg->GetTypeID()) << 16) | (uint64(0x1F90) << 48) ); - *data << uint32(0); // unknown + *data << uint32(bg->GetClientInstanceID()); // alliance/horde for BG and skirmish/rated for Arenas // following displays the minimap-icon 0 = faction icon 1 = arenaicon *data << uint8(bg->isArena()); @@ -1497,6 +1501,25 @@ void BattleGroundMgr::InvitePlayer(Player* plr, uint32 bgInstanceGUID, BattleGro plr->m_Events.AddEvent(removeEvent, plr->m_Events.CalculateTime(INVITE_ACCEPT_WAIT_TIME)); } +BattleGround * BattleGroundMgr::GetBattleGroundThroughClientInstance(uint32 instanceId, BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id) +{ + //cause at HandleBattleGroundJoinOpcode the clients sends the instanceid he gets from + //SMSG_BATTLEFIELD_LIST we need to find the battleground with this clientinstance-id + BattleGround* bg = GetBattleGroundTemplate(bgTypeId); + if( !bg ) + return NULL; + + if(bg->isArena()) + return GetBattleGround(instanceId, bgTypeId); + + for(BattleGroundSet::iterator itr = m_BattleGrounds[bgTypeId].begin(); itr != m_BattleGrounds[bgTypeId].end(); ++itr) + { + if(itr->second->GetClientInstanceID() == instanceId) + return itr->second; + } + return NULL; +} + BattleGround * BattleGroundMgr::GetBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId) { //search if needed @@ -1521,6 +1544,28 @@ BattleGround * BattleGroundMgr::GetBattleGroundTemplate(BattleGroundTypeId bgTyp return m_BattleGrounds[bgTypeId].empty() ? NULL : m_BattleGrounds[bgTypeId].begin()->second; } +uint32 BattleGroundMgr::CreateClientVisibleInstanceId(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id) +{ + if( IsArenaType(bgTypeId) ) + return 0; //arenas don't have client-instanceids + + // we create here an instanceid, which is just for + // displaying this to the client and without any other use.. + // the client-instanceIds are unique for each battleground-type + // the instance-id just needs to be as low as possible, beginning with 1 + // the following works, because std::set is default ordered with "<" + // the optimalization would be to use as bitmask std::vector<uint32> - but that would only make code unreadable + uint32 lastId = 0; + for(std::set<uint32>::iterator itr = m_ClientBattleGroundIds[bgTypeId][queue_id].begin(); itr != m_ClientBattleGroundIds[bgTypeId][queue_id].end();) + { + if( (++lastId) != *itr) //if there is a gap between the ids, we will break.. + break; + lastId = *itr; + } + m_ClientBattleGroundIds[bgTypeId][queue_id].insert(lastId + 1); + return lastId + 1; +} + // create a new battleground that will really be used to play BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id, uint8 arenaType, bool isRated) { @@ -1590,6 +1635,7 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI // generate a new instance id bg->SetInstanceID(MapManager::Instance().GenerateInstanceId()); // set instance id + bg->SetClientInstanceID(CreateClientVisibleInstanceId(bgTypeId, queue_id)); // reset the new bg (set status to status_wait_queue from status_none) bg->Reset(); @@ -1864,16 +1910,11 @@ void BattleGroundMgr::BuildBattleGroundListPacket(WorldPacket *data, const uint6 uint32 count = 0; *data << uint32(0x00); // number of bg instances - for(BattleGroundSet::iterator itr = m_BattleGrounds[bgTypeId].begin(); itr != m_BattleGrounds[bgTypeId].end(); ++itr) + uint32 queue_id = plr->GetBattleGroundQueueIdFromLevel(bgTypeId); + for(std::set<uint32>::iterator itr = m_ClientBattleGroundIds[bgTypeId][queue_id].begin(); itr != m_ClientBattleGroundIds[bgTypeId][queue_id].end();++itr) { - // skip sending battleground template - if( itr == m_BattleGrounds[bgTypeId].begin() ) - continue; - if( PlayerLevel >= itr->second->GetMinLevel() && PlayerLevel <= itr->second->GetMaxLevel() ) - { - *data << uint32(itr->second->GetInstanceID()); - ++count; - } + *data << uint32(*itr); + ++count; } data->put<uint32>( count_pos , count); } diff --git a/src/game/BattleGroundMgr.h b/src/game/BattleGroundMgr.h index 16ed1517922..8cbc0e9b88c 100644 --- a/src/game/BattleGroundMgr.h +++ b/src/game/BattleGroundMgr.h @@ -195,15 +195,17 @@ class BattleGroundMgr void InvitePlayer(Player* plr, uint32 bgInstanceGUID, BattleGroundTypeId bgTypeId, uint32 team); /* Battlegrounds */ + BattleGround* GetBattleGroundThroughClientInstance(uint32 instanceId, BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id); BattleGround* GetBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId); //there must be uint32 because MAX_BATTLEGROUND_TYPE_ID means unknown - BattleGround * GetBattleGroundTemplate(BattleGroundTypeId bgTypeId); - BattleGround * CreateNewBattleGround(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id, uint8 arenaType, bool isRated); + BattleGround* GetBattleGroundTemplate(BattleGroundTypeId bgTypeId); + BattleGround* CreateNewBattleGround(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id, uint8 arenaType, bool isRated); uint32 CreateBattleGround(BattleGroundTypeId bgTypeId, bool IsArena, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam, uint32 LevelMin, uint32 LevelMax, char* BattleGroundName, uint32 MapID, float Team1StartLocX, float Team1StartLocY, float Team1StartLocZ, float Team1StartLocO, float Team2StartLocX, float Team2StartLocY, float Team2StartLocZ, float Team2StartLocO); void AddBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId, BattleGround* BG) { m_BattleGrounds[bgTypeId][InstanceID] = BG; }; void RemoveBattleGround(uint32 instanceID, BattleGroundTypeId bgTypeId) { m_BattleGrounds[bgTypeId].erase(instanceID); } + uint32 CreateClientVisibleInstanceId(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id); void CreateInitialBattleGrounds(); void DeleteAllBattleGrounds(); @@ -248,6 +250,7 @@ class BattleGroundMgr /* Battlegrounds */ BattleGroundSet m_BattleGrounds[MAX_BATTLEGROUND_TYPE_ID]; + std::set<uint32> m_ClientBattleGroundIds[MAX_BATTLEGROUND_TYPE_ID][MAX_BATTLEGROUND_QUEUES]; //the instanceids just visible for the client uint32 m_NextRatingDiscardUpdate; uint64 m_NextAutoDistributionTime; uint32 m_AutoDistributionTimeChecker; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 0b5e9b21256..c95ed0d3933 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7436" + #define REVISION_NR "7437" #endif // __REVISION_NR_H__ |