Skip to content

Commit

Permalink
[7338] Little cleanup in battleground queues code.
Browse files Browse the repository at this point in the history
* Moved counts and maxs out of enums.
* Added some linebreaks to better code reading.
* Little bit tuned up BattleGroundQueue::RemovePlayer.

Signed-off-by: ApoC <apoc@nymfe.net>
  • Loading branch information
apoc committed Feb 25, 2009
1 parent 0271bf5 commit e6d7b49
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/game/BattleGround.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
26 changes: 17 additions & 9 deletions src/game/BattleGroundMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/game/BattleGroundMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "7337"
#define REVISION_NR "7338"
#endif // __REVISION_NR_H__

0 comments on commit e6d7b49

Please sign in to comment.