From f35ffca03efc1a5800ccbbd47161083ecb38390b Mon Sep 17 00:00:00 2001 From: ApoC Date: Wed, 25 Feb 2009 23:28:21 +0100 Subject: [PATCH] [7338] Little cleanup in battleground queues code. * Moved counts and maxs out of enums. * Added some linebreaks to better code reading. * Little bit tuned up BattleGroundQueue::RemovePlayer. Signed-off-by: ApoC --- src/game/BattleGround.h | 4 ++-- src/game/BattleGroundMgr.cpp | 26 +++++++++++++++++--------- src/game/BattleGroundMgr.h | 4 ++-- src/shared/revision_nr.h | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/game/BattleGround.h b/src/game/BattleGround.h index 1d5e5ef4b..696ef84b5 100644 --- a/src/game/BattleGround.h +++ b/src/game/BattleGround.h @@ -210,9 +210,9 @@ enum BattleGroundWinner enum BattleGroundTeamId { BG_TEAM_ALLIANCE = 0, - BG_TEAM_HORDE = 1, - BG_TEAMS_COUNT = 2 + BG_TEAM_HORDE = 1 }; +#define BG_TEAMS_COUNT 2 enum BattleGroundJoinError { diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp index 8931c407b..af56787db 100644 --- a/src/game/BattleGroundMgr.cpp +++ b/src/game/BattleGroundMgr.cpp @@ -203,19 +203,21 @@ void BattleGroundQueue::RemovePlayer(const uint64& guid, bool decreaseInvitedCou // we count from MAX_BATTLEGROUND_QUEUES - 1 to 0 // variable index removes useless searching in other team's queue uint32 index = (group->Team == HORDE) ? BG_TEAM_HORDE : BG_TEAM_ALLIANCE; - for (int32 queue_id_tmp = MAX_BATTLEGROUND_QUEUES - 1; queue_id_tmp >= 0 && queue_id == -1; queue_id_tmp--) + + for (int32 queue_id_tmp = MAX_BATTLEGROUND_QUEUES - 1; queue_id_tmp >= 0 && queue_id == -1; --queue_id_tmp) { - //we must check premade and normal team's queue - because when players from premade are joining bg, they leave groupinfo so we can't use its players size to find out index - for (uint32 j = 0; j < 3; j += BG_QUEUE_NORMAL_ALLIANCE) + //we must check premade and normal team's queue - because when players from premade are joining bg, + //they leave groupinfo so we can't use its players size to find out index + for (uint32 j = index; j < BG_QUEUE_GROUP_TYPES_COUNT - 1; j += BG_QUEUE_NORMAL_ALLIANCE) { - for(group_itr_tmp = m_QueuedGroups[queue_id_tmp][index + j].begin(); group_itr_tmp != m_QueuedGroups[queue_id_tmp][index + j].end(); ++group_itr_tmp) + for(group_itr_tmp = m_QueuedGroups[queue_id_tmp][j].begin(); group_itr_tmp != m_QueuedGroups[queue_id_tmp][j].end(); ++group_itr_tmp) { if( (*group_itr_tmp) == group ) { queue_id = queue_id_tmp; group_itr = group_itr_tmp; //we must store index to be able to erase iterator - index += j; + index = j; break; } } @@ -260,7 +262,8 @@ void BattleGroundQueue::RemovePlayer(const uint64& guid, bool decreaseInvitedCou m_QueuedGroups[queue_id][index].erase(group_itr); delete group; } - // if group wasn't empty, so it wasn't deleted, and player have left a rated queue -> everyone from the group should leave too + // if group wasn't empty, so it wasn't deleted, and player have left a rated + // queue -> everyone from the group should leave too // don't remove recursively if already invited to bg! else if( !group->IsInvitedToBGInstanceGUID && group->IsRated ) { @@ -271,7 +274,8 @@ void BattleGroundQueue::RemovePlayer(const uint64& guid, bool decreaseInvitedCou BattleGround * bg = sBattleGroundMgr.GetBattleGroundTemplate(group->BgTypeId); BattleGroundQueueTypeId bgQueueTypeId = BattleGroundMgr::BGQueueTypeId(group->BgTypeId, group->ArenaType); uint32 queueSlot = plr2->GetBattleGroundQueueIndex(bgQueueTypeId); - plr2->RemoveBattleGroundQueueId(bgQueueTypeId); // must be called this way, because if you move this call to queue->removeplayer, it causes bugs + plr2->RemoveBattleGroundQueueId(bgQueueTypeId); // must be called this way, because if you move this call to + // queue->removeplayer, it causes bugs WorldPacket data; sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, plr2->GetTeam(), queueSlot, STATUS_NONE, 0, 0); plr2->GetSession()->SendPacket(&data); @@ -629,7 +633,10 @@ void BattleGroundQueue::Update(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLeve return; //if no players in queue ... do nothing - if( m_QueuedGroups[queue_id][BG_QUEUE_PREMADE_ALLIANCE].empty() && m_QueuedGroups[queue_id][BG_QUEUE_PREMADE_HORDE].empty() && m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE].empty() && m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_HORDE].empty() ) + if( m_QueuedGroups[queue_id][BG_QUEUE_PREMADE_ALLIANCE].empty() && + m_QueuedGroups[queue_id][BG_QUEUE_PREMADE_HORDE].empty() && + m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE].empty() && + m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_HORDE].empty() ) return; BattleGroundQueueTypeId bgQueueTypeId = BattleGroundMgr::BGQueueTypeId(bgTypeId, arenaType); @@ -642,7 +649,8 @@ void BattleGroundQueue::Update(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLeve next = itr; ++next; // DO NOT allow queue manager to invite new player to arena - if( (*itr)->isBattleGround() && (*itr)->GetTypeID() == bgTypeId && (*itr)->GetQueueId() == queue_id && (*itr)->GetStatus() > STATUS_WAIT_QUEUE && (*itr)->GetStatus() < STATUS_WAIT_LEAVE ) + if( (*itr)->isBattleGround() && (*itr)->GetTypeID() == bgTypeId && (*itr)->GetQueueId() == queue_id && + (*itr)->GetStatus() > STATUS_WAIT_QUEUE && (*itr)->GetStatus() < STATUS_WAIT_LEAVE ) { BattleGround* bg = *itr; //we have to store battleground pointer here, because when battleground is full, it is removed from free queue (not yet implemented!!) // and iterator is invalid diff --git a/src/game/BattleGroundMgr.h b/src/game/BattleGroundMgr.h index 7910462f3..30ab006e1 100644 --- a/src/game/BattleGroundMgr.h +++ b/src/game/BattleGroundMgr.h @@ -60,9 +60,9 @@ enum BattleGroundQueueGroupTypes BG_QUEUE_PREMADE_ALLIANCE = 0, BG_QUEUE_PREMADE_HORDE = 1, BG_QUEUE_NORMAL_ALLIANCE = 2, - BG_QUEUE_NORMAL_HORDE = 3, - BG_QUEUE_GROUP_TYPES_COUNT = 4 + BG_QUEUE_NORMAL_HORDE = 3 }; +#define BG_QUEUE_GROUP_TYPES_COUNT 4 class BattleGround; class BattleGroundQueue diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index eb685b899..d791b16d7 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 "7337" + #define REVISION_NR "7338" #endif // __REVISION_NR_H__