TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BattlegroundQueue Class Reference

#include <BattlegroundQueue.h>

Classes

class  SelectionPool
 

Public Types

typedef std::map< ObjectGuid,
PlayerQueueInfo
QueuedPlayersMap
 
typedef std::list
< GroupQueueInfo * > 
GroupsQueueType
 

Public Member Functions

 BattlegroundQueue ()
 
 ~BattlegroundQueue ()
 
void BattlegroundQueueUpdate (uint32 diff, BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id, uint8 arenaType=0, bool isRated=false, uint32 minRating=0)
 
void UpdateEvents (uint32 diff)
 
void FillPlayersToBG (Battleground *bg, BattlegroundBracketId bracket_id)
 
bool CheckPremadeMatch (BattlegroundBracketId bracket_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam)
 
bool CheckNormalMatch (Battleground *bg_template, BattlegroundBracketId bracket_id, uint32 minPlayers, uint32 maxPlayers)
 
bool CheckSkirmishForSameFaction (BattlegroundBracketId bracket_id, uint32 minPlayersPerTeam)
 
GroupQueueInfoAddGroup (Player *leader, Group *group, BattlegroundTypeId bgTypeId, PvPDifficultyEntry const *bracketEntry, uint8 ArenaType, bool isRated, bool isPremade, uint32 ArenaRating, uint32 MatchmakerRating, uint32 ArenaTeamId=0)
 
void RemovePlayer (ObjectGuid guid, bool decreaseInvitedCount)
 
bool IsPlayerInvited (ObjectGuid pl_guid, const uint32 bgInstanceGuid, const uint32 removeTime)
 
bool GetPlayerGroupInfoData (ObjectGuid guid, GroupQueueInfo *ginfo)
 
void PlayerInvitedToBGUpdateAverageWaitTime (GroupQueueInfo *ginfo, BattlegroundBracketId bracket_id)
 
uint32 GetAverageQueueWaitTime (GroupQueueInfo *ginfo, BattlegroundBracketId bracket_id) const
 
uint32 GetPlayersInQueue (TeamId id)
 

Public Attributes

QueuedPlayersMap m_QueuedPlayers
 
GroupsQueueType m_QueuedGroups [MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_GROUP_TYPES_COUNT]
 
SelectionPool m_SelectionPools [BG_TEAMS_COUNT]
 

Private Member Functions

bool InviteGroupToBG (GroupQueueInfo *ginfo, Battleground *bg, uint32 side)
 

Private Attributes

uint32 m_WaitTimes [BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS][COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME]
 
uint32 m_WaitTimeLastPlayer [BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
 
uint32 m_SumOfWaitTimes [BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
 
EventProcessor m_events
 

Member Typedef Documentation

Constructor & Destructor Documentation

BattlegroundQueue::BattlegroundQueue ( )
34 {
35  for (uint32 i = 0; i < BG_TEAMS_COUNT; ++i)
36  {
37  for (uint32 j = 0; j < MAX_BATTLEGROUND_BRACKETS; ++j)
38  {
39  m_SumOfWaitTimes[i][j] = 0;
40  m_WaitTimeLastPlayer[i][j] = 0;
41  for (uint32 k = 0; k < COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME; ++k)
42  m_WaitTimes[i][j][k] = 0;
43  }
44  }
45 }
Definition: DBCEnums.h:63
uint32 m_WaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS][COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME]
Definition: BattlegroundQueue.h:133
#define BG_TEAMS_COUNT
Definition: SharedDefines.h:4555
#define COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME
Definition: BattlegroundQueue.h:32
uint32_t uint32
Definition: Define.h:150
uint32 m_SumOfWaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
Definition: BattlegroundQueue.h:135
uint32 m_WaitTimeLastPlayer[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
Definition: BattlegroundQueue.h:134
BattlegroundQueue::~BattlegroundQueue ( )
48 {
49  m_events.KillAllEvents(false);
50 
51  for (int i = 0; i < MAX_BATTLEGROUND_BRACKETS; ++i)
52  {
53  for (uint32 j = 0; j < BG_QUEUE_GROUP_TYPES_COUNT; ++j)
54  {
55  for (GroupsQueueType::iterator itr = m_QueuedGroups[i][j].begin(); itr!= m_QueuedGroups[i][j].end(); ++itr)
56  delete (*itr);
57  }
58  }
59 }
#define BG_QUEUE_GROUP_TYPES_COUNT
Definition: BattlegroundQueue.h:65
void KillAllEvents(bool force)
Definition: EventProcessor.cpp:61
Definition: DBCEnums.h:63
EventProcessor m_events
Definition: BattlegroundQueue.h:138
uint32_t uint32
Definition: Define.h:150
GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_GROUP_TYPES_COUNT]
Definition: BattlegroundQueue.h:110

+ Here is the call graph for this function:

Member Function Documentation

GroupQueueInfo * BattlegroundQueue::AddGroup ( Player leader,
Group group,
BattlegroundTypeId  bgTypeId,
PvPDifficultyEntry const bracketEntry,
uint8  ArenaType,
bool  isRated,
bool  isPremade,
uint32  ArenaRating,
uint32  MatchmakerRating,
uint32  ArenaTeamId = 0 
)
130 {
131  BattlegroundBracketId bracketId = bracketEntry->GetBracketId();
132 
133  // create new ginfo
134  GroupQueueInfo* ginfo = new GroupQueueInfo;
135  ginfo->BgTypeId = BgTypeId;
136  ginfo->ArenaType = ArenaType;
137  ginfo->ArenaTeamId = arenateamid;
138  ginfo->IsRated = isRated;
139  ginfo->IsInvitedToBGInstanceGUID = 0;
140  ginfo->JoinTime = getMSTime();
141  ginfo->RemoveInviteTime = 0;
142  ginfo->Team = leader->GetTeam();
143  ginfo->ArenaTeamRating = ArenaRating;
144  ginfo->ArenaMatchmakerRating = MatchmakerRating;
145  ginfo->OpponentsTeamRating = 0;
146  ginfo->OpponentsMatchmakerRating = 0;
147 
148  ginfo->Players.clear();
149 
150  //compute index (if group is premade or joined a rated match) to queues
151  uint32 index = 0;
152  if (!isRated && !isPremade)
153  index += BG_TEAMS_COUNT;
154  if (ginfo->Team == HORDE)
155  index++;
156  TC_LOG_DEBUG("bg.battleground", "Adding Group to BattlegroundQueue bgTypeId : %u, bracket_id : %u, index : %u", BgTypeId, bracketId, index);
157 
158  uint32 lastOnlineTime = getMSTime();
159 
160  //announce world (this don't need mutex)
161  if (isRated && sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE))
162  {
163  ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(arenateamid);
164  if (team)
165  sWorld->SendWorldText(LANG_ARENA_QUEUE_ANNOUNCE_WORLD_JOIN, team->GetName().c_str(), ginfo->ArenaType, ginfo->ArenaType, ginfo->ArenaTeamRating);
166  }
167 
168  //add players from group to ginfo
169  if (grp)
170  {
171  for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
172  {
173  Player* member = itr->GetSource();
174  if (!member)
175  continue; // this should never happen
176  PlayerQueueInfo& pl_info = m_QueuedPlayers[member->GetGUID()];
177  pl_info.LastOnlineTime = lastOnlineTime;
178  pl_info.GroupInfo = ginfo;
179  // add the pinfo to ginfo's list
180  ginfo->Players[member->GetGUID()] = &pl_info;
181  }
182  }
183  else
184  {
185  PlayerQueueInfo& pl_info = m_QueuedPlayers[leader->GetGUID()];
186  pl_info.LastOnlineTime = lastOnlineTime;
187  pl_info.GroupInfo = ginfo;
188  ginfo->Players[leader->GetGUID()] = &pl_info;
189  }
190 
191  //add GroupInfo to m_QueuedGroups
192  {
193  m_QueuedGroups[bracketId][index].push_back(ginfo);
194 
195  //announce to world, this code needs mutex
196  if (!isRated && !isPremade && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE))
197  {
198  if (Battleground* bg = sBattlegroundMgr->GetBattlegroundTemplate(ginfo->BgTypeId))
199  {
200  uint32 MinPlayers = bg->GetMinPlayersPerTeam();
201  uint32 qHorde = 0;
202  uint32 qAlliance = 0;
203  uint32 q_min_level = bracketEntry->MinLevel;
204  uint32 q_max_level = bracketEntry->MaxLevel;
205  GroupsQueueType::const_iterator itr;
206  for (itr = m_QueuedGroups[bracketId][BG_QUEUE_NORMAL_ALLIANCE].begin(); itr != m_QueuedGroups[bracketId][BG_QUEUE_NORMAL_ALLIANCE].end(); ++itr)
207  if (!(*itr)->IsInvitedToBGInstanceGUID)
208  qAlliance += (*itr)->Players.size();
209  for (itr = m_QueuedGroups[bracketId][BG_QUEUE_NORMAL_HORDE].begin(); itr != m_QueuedGroups[bracketId][BG_QUEUE_NORMAL_HORDE].end(); ++itr)
210  if (!(*itr)->IsInvitedToBGInstanceGUID)
211  qHorde += (*itr)->Players.size();
212 
213  // Show queue status to player only (when joining queue)
215  {
216  ChatHandler(leader->GetSession()).PSendSysMessage(LANG_BG_QUEUE_ANNOUNCE_SELF, bg->GetName().c_str(), q_min_level, q_max_level,
217  qAlliance, (MinPlayers > qAlliance) ? MinPlayers - qAlliance : (uint32)0, qHorde, (MinPlayers > qHorde) ? MinPlayers - qHorde : (uint32)0);
218  }
219  // System message
220  else
221  {
222  sWorld->SendWorldText(LANG_BG_QUEUE_ANNOUNCE_WORLD, bg->GetName().c_str(), q_min_level, q_max_level,
223  qAlliance, (MinPlayers > qAlliance) ? MinPlayers - qAlliance : (uint32)0, qHorde, (MinPlayers > qHorde) ? MinPlayers - qHorde : (uint32)0);
224  }
225  }
226  }
227  //release mutex
228  }
229 
230  return ginfo;
231 }
ArenaType
Definition: Battleground.h:179
uint32 ArenaTeamRating
Definition: BattlegroundQueue.h:52
uint32 OpponentsMatchmakerRating
Definition: BattlegroundQueue.h:55
std::string const & GetName() const
Definition: ArenaTeam.h:130
GroupQueueInfo * GroupInfo
Definition: BattlegroundQueue.h:38
BattlegroundBracketId
Definition: DBCEnums.h:57
uint32 getMSTime()
Definition: Timer.h:24
bool IsRated
Definition: BattlegroundQueue.h:46
arena_t NULL
Definition: jemalloc_internal.h:624
uint32 Team
Definition: BattlegroundQueue.h:44
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
#define sWorld
Definition: World.h:887
#define BG_TEAMS_COUNT
Definition: SharedDefines.h:4555
uint8 ArenaType
Definition: BattlegroundQueue.h:47
Definition: Language.h:713
Definition: Language.h:714
uint32_t uint32
Definition: Define.h:150
Definition: BattlegroundQueue.h:63
uint32 JoinTime
Definition: BattlegroundQueue.h:49
Definition: BattlegroundQueue.h:62
Definition: BattlegroundQueue.h:41
uint32 OpponentsTeamRating
Definition: BattlegroundQueue.h:54
Definition: SharedDefines.h:999
uint32 ArenaMatchmakerRating
Definition: BattlegroundQueue.h:53
Definition: Chat.h:56
Definition: ArenaTeam.h:112
uint32 LastOnlineTime
Definition: BattlegroundQueue.h:37
GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_GROUP_TYPES_COUNT]
Definition: BattlegroundQueue.h:110
#define sBattlegroundMgr
Definition: BattlegroundMgr.h:181
uint32 ArenaTeamId
Definition: BattlegroundQueue.h:48
QueuedPlayersMap m_QueuedPlayers
Definition: BattlegroundQueue.h:96
Definition: Battleground.h:235
#define sArenaTeamMgr
Definition: ArenaTeamMgr.h:53
uint32 RemoveInviteTime
Definition: BattlegroundQueue.h:50
BattlegroundTypeId BgTypeId
Definition: BattlegroundQueue.h:45
Definition: Language.h:720
Definition: BattlegroundQueue.h:35
std::map< ObjectGuid, PlayerQueueInfo * > Players
Definition: BattlegroundQueue.h:43
uint32 IsInvitedToBGInstanceGUID
Definition: BattlegroundQueue.h:51
Definition: GroupReference.h:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlegroundQueue::BattlegroundQueueUpdate ( uint32  diff,
BattlegroundTypeId  bgTypeId,
BattlegroundBracketId  bracket_id,
uint8  arenaType = 0,
bool  isRated = false,
uint32  minRating = 0 
)
771 {
772  //if no players in queue - do nothing
773  if (m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].empty() &&
774  m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].empty() &&
775  m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].empty() &&
776  m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].empty())
777  return;
778 
779  // battleground with free slot for player should be always in the beggining of the queue
780  // maybe it would be better to create bgfreeslotqueue for each bracket_id
781  BGFreeSlotQueueContainer& bgQueues = sBattlegroundMgr->GetBGFreeSlotQueueStore(bgTypeId);
782  for (BGFreeSlotQueueContainer::iterator itr = bgQueues.begin(); itr != bgQueues.end();)
783  {
784  Battleground* bg = *itr; ++itr;
785  // DO NOT allow queue manager to invite new player to rated games
786  if (!bg->isRated() && bg->GetTypeID() == bgTypeId && bg->GetBracketId() == bracket_id &&
788  {
789  // clear selection pools
792 
793  // call a function that does the job for us
794  FillPlayersToBG(bg, bracket_id);
795 
796  // now everything is set, invite players
797  for (GroupsQueueType::const_iterator citr = m_SelectionPools[TEAM_ALLIANCE].SelectedGroups.begin(); citr != m_SelectionPools[TEAM_ALLIANCE].SelectedGroups.end(); ++citr)
798  InviteGroupToBG((*citr), bg, (*citr)->Team);
799 
800  for (GroupsQueueType::const_iterator citr = m_SelectionPools[TEAM_HORDE].SelectedGroups.begin(); citr != m_SelectionPools[TEAM_HORDE].SelectedGroups.end(); ++citr)
801  InviteGroupToBG((*citr), bg, (*citr)->Team);
802 
803  if (!bg->HasFreeSlots())
805  }
806  }
807 
808  // finished iterating through the bgs with free slots, maybe we need to create a new bg
809 
810  Battleground* bg_template = sBattlegroundMgr->GetBattlegroundTemplate(bgTypeId);
811  if (!bg_template)
812  {
813  TC_LOG_ERROR("bg.battleground", "Battleground: Update: bg template not found for %u", bgTypeId);
814  return;
815  }
816 
817  PvPDifficultyEntry const* bracketEntry = GetBattlegroundBracketById(bg_template->GetMapId(), bracket_id);
818  if (!bracketEntry)
819  {
820  TC_LOG_ERROR("bg.battleground", "Battleground: Update: bg bracket entry not found for map %u bracket id %u", bg_template->GetMapId(), bracket_id);
821  return;
822  }
823 
824  // get the min. players per team, properly for larger arenas as well. (must have full teams for arena matches!)
825  uint32 MinPlayersPerTeam = bg_template->GetMinPlayersPerTeam();
826  uint32 MaxPlayersPerTeam = bg_template->GetMaxPlayersPerTeam();
827 
828  if (bg_template->isArena())
829  {
830  MaxPlayersPerTeam = arenaType;
831  MinPlayersPerTeam = sBattlegroundMgr->isArenaTesting() ? 1 : arenaType;
832  }
833  else if (sBattlegroundMgr->isTesting())
834  MinPlayersPerTeam = 1;
835 
838 
839  if (bg_template->isBattleground())
840  {
841  if (CheckPremadeMatch(bracket_id, MinPlayersPerTeam, MaxPlayersPerTeam))
842  {
843  // create new battleground
844  Battleground* bg2 = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, 0, false);
845  if (!bg2)
846  {
847  TC_LOG_ERROR("bg.battleground", "BattlegroundQueue::Update - Cannot create battleground: %u", bgTypeId);
848  return;
849  }
850  // invite those selection pools
851  for (uint32 i = 0; i < BG_TEAMS_COUNT; i++)
852  for (GroupsQueueType::const_iterator citr = m_SelectionPools[TEAM_ALLIANCE + i].SelectedGroups.begin(); citr != m_SelectionPools[TEAM_ALLIANCE + i].SelectedGroups.end(); ++citr)
853  InviteGroupToBG((*citr), bg2, (*citr)->Team);
854 
855  bg2->StartBattleground();
856  //clear structures
859  }
860  }
861 
862  // now check if there are in queues enough players to start new game of (normal battleground, or non-rated arena)
863  if (!isRated)
864  {
865  // if there are enough players in pools, start new battleground or non rated arena
866  if (CheckNormalMatch(bg_template, bracket_id, MinPlayersPerTeam, MaxPlayersPerTeam)
867  || (bg_template->isArena() && CheckSkirmishForSameFaction(bracket_id, MinPlayersPerTeam)))
868  {
869  // we successfully created a pool
870  Battleground* bg2 = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, arenaType, false);
871  if (!bg2)
872  {
873  TC_LOG_ERROR("bg.battleground", "BattlegroundQueue::Update - Cannot create battleground: %u", bgTypeId);
874  return;
875  }
876 
877  // invite those selection pools
878  for (uint32 i = 0; i < BG_TEAMS_COUNT; i++)
879  for (GroupsQueueType::const_iterator citr = m_SelectionPools[TEAM_ALLIANCE + i].SelectedGroups.begin(); citr != m_SelectionPools[TEAM_ALLIANCE + i].SelectedGroups.end(); ++citr)
880  InviteGroupToBG((*citr), bg2, (*citr)->Team);
881  // start bg
882  bg2->StartBattleground();
883  }
884  }
885  else if (bg_template->isArena())
886  {
887  // found out the minimum and maximum ratings the newly added team should battle against
888  // arenaRating is the rating of the latest joined team, or 0
889  // 0 is on (automatic update call) and we must set it to team's with longest wait time
890  if (!arenaRating)
891  {
892  GroupQueueInfo* front1 = NULL;
893  GroupQueueInfo* front2 = NULL;
894  if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].empty())
895  {
896  front1 = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].front();
897  arenaRating = front1->ArenaMatchmakerRating;
898  }
899  if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].empty())
900  {
901  front2 = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].front();
902  arenaRating = front2->ArenaMatchmakerRating;
903  }
904  if (front1 && front2)
905  {
906  if (front1->JoinTime < front2->JoinTime)
907  arenaRating = front1->ArenaMatchmakerRating;
908  }
909  else if (!front1 && !front2)
910  return; //queues are empty
911  }
912 
913  //set rating range
914  uint32 arenaMinRating = (arenaRating <= sBattlegroundMgr->GetMaxRatingDifference()) ? 0 : arenaRating - sBattlegroundMgr->GetMaxRatingDifference();
915  uint32 arenaMaxRating = arenaRating + sBattlegroundMgr->GetMaxRatingDifference();
916  // if max rating difference is set and the time past since server startup is greater than the rating discard time
917  // (after what time the ratings aren't taken into account when making teams) then
918  // the discard time is current_time - time_to_discard, teams that joined after that, will have their ratings taken into account
919  // else leave the discard time on 0, this way all ratings will be discarded
920  // this has to be signed value - when the server starts, this value would be negative and thus overflow
921  int32 discardTime = getMSTime() - sBattlegroundMgr->GetRatingDiscardTimer();
922 
923  // we need to find 2 teams which will play next game
924  GroupsQueueType::iterator itr_teams[BG_TEAMS_COUNT];
925  uint8 found = 0;
926  uint8 team = 0;
927 
929  {
930  // take the group that joined first
931  GroupsQueueType::iterator itr2 = m_QueuedGroups[bracket_id][i].begin();
932  for (; itr2 != m_QueuedGroups[bracket_id][i].end(); ++itr2)
933  {
934  // if group match conditions, then add it to pool
935  if (!(*itr2)->IsInvitedToBGInstanceGUID
936  && (((*itr2)->ArenaMatchmakerRating >= arenaMinRating && (*itr2)->ArenaMatchmakerRating <= arenaMaxRating)
937  || (int32)(*itr2)->JoinTime < discardTime))
938  {
939  itr_teams[found++] = itr2;
940  team = i;
941  break;
942  }
943  }
944  }
945 
946  if (!found)
947  return;
948 
949  if (found == 1)
950  {
951  for (GroupsQueueType::iterator itr3 = itr_teams[0]; itr3 != m_QueuedGroups[bracket_id][team].end(); ++itr3)
952  {
953  if (!(*itr3)->IsInvitedToBGInstanceGUID
954  && (((*itr3)->ArenaMatchmakerRating >= arenaMinRating && (*itr3)->ArenaMatchmakerRating <= arenaMaxRating)
955  || (int32)(*itr3)->JoinTime < discardTime)
956  && (*itr_teams[0])->ArenaTeamId != (*itr3)->ArenaTeamId)
957  {
958  itr_teams[found++] = itr3;
959  break;
960  }
961  }
962  }
963 
964  //if we have 2 teams, then start new arena and invite players!
965  if (found == 2)
966  {
967  GroupQueueInfo* aTeam = *itr_teams[TEAM_ALLIANCE];
968  GroupQueueInfo* hTeam = *itr_teams[TEAM_HORDE];
969  Battleground* arena = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, arenaType, true);
970  if (!arena)
971  {
972  TC_LOG_ERROR("bg.battleground", "BattlegroundQueue::Update couldn't create arena instance for rated arena match!");
973  return;
974  }
975 
976  aTeam->OpponentsTeamRating = hTeam->ArenaTeamRating;
977  hTeam->OpponentsTeamRating = aTeam->ArenaTeamRating;
980  TC_LOG_DEBUG("bg.battleground", "setting oposite teamrating for team %u to %u", aTeam->ArenaTeamId, aTeam->OpponentsTeamRating);
981  TC_LOG_DEBUG("bg.battleground", "setting oposite teamrating for team %u to %u", hTeam->ArenaTeamId, hTeam->OpponentsTeamRating);
982 
983  // now we must move team if we changed its faction to another faction queue, because then we will spam log by errors in Queue::RemovePlayer
984  if (aTeam->Team != ALLIANCE)
985  {
986  m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].push_front(aTeam);
987  m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].erase(itr_teams[TEAM_ALLIANCE]);
988  }
989  if (hTeam->Team != HORDE)
990  {
991  m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].push_front(hTeam);
992  m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].erase(itr_teams[TEAM_HORDE]);
993  }
994 
997  InviteGroupToBG(aTeam, arena, ALLIANCE);
998  InviteGroupToBG(hTeam, arena, HORDE);
999 
1000  TC_LOG_DEBUG("bg.battleground", "Starting rated arena match!");
1001  arena->StartBattleground();
1002  }
1003  }
1004 }
SelectionPool m_SelectionPools[BG_TEAMS_COUNT]
Definition: BattlegroundQueue.h:128
uint32 GetMinPlayersPerTeam() const
Definition: Battleground.h:278
uint32 ArenaTeamRating
Definition: BattlegroundQueue.h:52
uint32 OpponentsMatchmakerRating
Definition: BattlegroundQueue.h:55
PvPDifficultyEntry const * GetBattlegroundBracketById(uint32 mapid, BattlegroundBracketId id)
Definition: DBCStores.cpp:784
std::list< Battleground * > BGFreeSlotQueueContainer
Definition: BattlegroundQueue.h:30
void FillPlayersToBG(Battleground *bg, BattlegroundBracketId bracket_id)
Definition: BattlegroundQueue.cpp:496
BattlegroundStatus GetStatus() const
Definition: Battleground.h:266
uint32 getMSTime()
Definition: Timer.h:24
void SetArenaMatchmakerRating(uint32 Team, uint32 MMR)
Definition: Battleground.h:416
arena_t NULL
Definition: jemalloc_internal.h:624
uint32 Team
Definition: BattlegroundQueue.h:44
void Init()
Definition: BattlegroundQueue.cpp:66
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: Battleground.h:157
#define BG_TEAMS_COUNT
Definition: SharedDefines.h:4555
bool CheckPremadeMatch(BattlegroundBracketId bracket_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam)
Definition: BattlegroundQueue.cpp:601
Definition: SharedDefines.h:1000
bool isRated() const
Definition: Battleground.h:328
bool isArena() const
Definition: Battleground.h:326
Definition: BattlegroundQueue.h:60
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
Definition: BattlegroundQueue.h:63
Definition: SharedDefines.h:992
Definition: BattlegroundQueue.h:61
bool isBattleground() const
Definition: Battleground.h:327
uint32 JoinTime
Definition: BattlegroundQueue.h:49
void RemoveFromBGFreeSlotQueue()
Definition: Battleground.cpp:1241
Definition: BattlegroundQueue.h:62
Definition: BattlegroundQueue.h:41
uint32 OpponentsTeamRating
Definition: BattlegroundQueue.h:54
Definition: SharedDefines.h:999
BattlegroundBracketId GetBracketId() const
Definition: Battleground.h:264
uint32 ArenaMatchmakerRating
Definition: BattlegroundQueue.h:53
bool CheckSkirmishForSameFaction(BattlegroundBracketId bracket_id, uint32 minPlayersPerTeam)
Definition: BattlegroundQueue.cpp:702
Definition: DBCStructure.h:926
uint32 GetMaxPlayersPerTeam() const
Definition: Battleground.h:277
Definition: Battleground.h:160
GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_GROUP_TYPES_COUNT]
Definition: BattlegroundQueue.h:110
bool HasFreeSlots() const
Definition: Battleground.cpp:1317
#define sBattlegroundMgr
Definition: BattlegroundMgr.h:181
GroupsQueueType SelectedGroups
Definition: BattlegroundQueue.h:122
uint32 ArenaTeamId
Definition: BattlegroundQueue.h:48
uint8_t uint8
Definition: Define.h:152
BattlegroundTypeId GetTypeID(bool GetRandom=false) const
Definition: Battleground.h:263
uint32 GetMapId() const
Definition: Battleground.h:352
bool InviteGroupToBG(GroupQueueInfo *ginfo, Battleground *bg, uint32 side)
Definition: BattlegroundQueue.cpp:428
void StartBattleground()
Definition: Battleground.cpp:1063
Definition: Battleground.h:235
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
bool CheckNormalMatch(Battleground *bg_template, BattlegroundBracketId bracket_id, uint32 minPlayers, uint32 maxPlayers)
Definition: BattlegroundQueue.cpp:659
Definition: SharedDefines.h:993

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool BattlegroundQueue::CheckNormalMatch ( Battleground bg_template,
BattlegroundBracketId  bracket_id,
uint32  minPlayers,
uint32  maxPlayers 
)
660 {
661  GroupsQueueType::const_iterator itr_team[BG_TEAMS_COUNT];
662  for (uint32 i = 0; i < BG_TEAMS_COUNT; i++)
663  {
664  itr_team[i] = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].begin();
665  for (; itr_team[i] != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].end(); ++(itr_team[i]))
666  {
667  if (!(*(itr_team[i]))->IsInvitedToBGInstanceGUID)
668  {
669  m_SelectionPools[i].AddGroup(*(itr_team[i]), maxPlayers);
670  if (m_SelectionPools[i].GetPlayerCount() >= minPlayers)
671  break;
672  }
673  }
674  }
675  //try to invite same number of players - this cycle may cause longer wait time even if there are enough players in queue, but we want ballanced bg
676  uint32 j = TEAM_ALLIANCE;
677  if (m_SelectionPools[TEAM_HORDE].GetPlayerCount() < m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount())
678  j = TEAM_HORDE;
681  {
682  //we will try to invite more groups to team with less players indexed by j
683  ++(itr_team[j]); //this will not cause a crash, because for cycle above reached break;
684  for (; itr_team[j] != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + j].end(); ++(itr_team[j]))
685  {
686  if (!(*(itr_team[j]))->IsInvitedToBGInstanceGUID)
687  if (!m_SelectionPools[j].AddGroup(*(itr_team[j]), m_SelectionPools[(j + 1) % BG_TEAMS_COUNT].GetPlayerCount()))
688  break;
689  }
690  // do not allow to start bg with more than 2 players more on 1 faction
692  return false;
693  }
694  //allow 1v0 if debug bg
696  return true;
697  //return true if there are enough players in selection pools - enable to work .debug bg command correctly
698  return m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() >= minPlayers && m_SelectionPools[TEAM_HORDE].GetPlayerCount() >= minPlayers;
699 }
SelectionPool m_SelectionPools[BG_TEAMS_COUNT]
Definition: BattlegroundQueue.h:128
G3D::Matrix abs(const G3D::Matrix &M)
Definition: Matrix.h:632
bool AddGroup(GroupQueueInfo *ginfo, uint32 desiredCount)
Definition: BattlegroundQueue.cpp:109
#define sWorld
Definition: World.h:887
#define BG_TEAMS_COUNT
Definition: SharedDefines.h:4555
GroupQueueInfo * AddGroup(Player *leader, Group *group, BattlegroundTypeId bgTypeId, PvPDifficultyEntry const *bracketEntry, uint8 ArenaType, bool isRated, bool isPremade, uint32 ArenaRating, uint32 MatchmakerRating, uint32 ArenaTeamId=0)
Definition: BattlegroundQueue.cpp:129
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
Definition: SharedDefines.h:992
Definition: BattlegroundQueue.h:62
GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_GROUP_TYPES_COUNT]
Definition: BattlegroundQueue.h:110
#define sBattlegroundMgr
Definition: BattlegroundMgr.h:181
Definition: SharedDefines.h:993
Definition: BattlegroundQueue.h:69
uint32 GetPlayerCount() const
Definition: BattlegroundQueue.h:120

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool BattlegroundQueue::CheckPremadeMatch ( BattlegroundBracketId  bracket_id,
uint32  MinPlayersPerTeam,
uint32  MaxPlayersPerTeam 
)
602 {
603  //check match
604  if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].empty() && !m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].empty())
605  {
606  //start premade match
607  //if groups aren't invited
608  GroupsQueueType::const_iterator ali_group, horde_group;
609  for (ali_group = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].begin(); ali_group != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].end(); ++ali_group)
610  if (!(*ali_group)->IsInvitedToBGInstanceGUID)
611  break;
612  for (horde_group = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].begin(); horde_group != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].end(); ++horde_group)
613  if (!(*horde_group)->IsInvitedToBGInstanceGUID)
614  break;
615 
616  if (ali_group != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].end() && horde_group != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].end())
617  {
618  m_SelectionPools[TEAM_ALLIANCE].AddGroup((*ali_group), MaxPlayersPerTeam);
619  m_SelectionPools[TEAM_HORDE].AddGroup((*horde_group), MaxPlayersPerTeam);
620  //add groups/players from normal queue to size of bigger group
621  uint32 maxPlayers = std::min(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount(), m_SelectionPools[TEAM_HORDE].GetPlayerCount());
622  GroupsQueueType::const_iterator itr;
623  for (uint32 i = 0; i < BG_TEAMS_COUNT; i++)
624  {
625  for (itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].begin(); itr != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].end(); ++itr)
626  {
627  //if itr can join BG and player count is less that maxPlayers, then add group to selectionpool
628  if (!(*itr)->IsInvitedToBGInstanceGUID && !m_SelectionPools[i].AddGroup((*itr), maxPlayers))
629  break;
630  }
631  }
632  //premade selection pools are set
633  return true;
634  }
635  }
636  // now check if we can move group from Premade queue to normal queue (timer has expired) or group size lowered!!
637  // this could be 2 cycles but i'm checking only first team in queue - it can cause problem -
638  // if first is invited to BG and seconds timer expired, but we can ignore it, because players have only 80 seconds to click to enter bg
639  // and when they click or after 80 seconds the queue info is removed from queue
641  for (uint32 i = 0; i < BG_TEAMS_COUNT; i++)
642  {
643  if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].empty())
644  {
645  GroupsQueueType::iterator itr = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].begin();
646  if (!(*itr)->IsInvitedToBGInstanceGUID && ((*itr)->JoinTime < time_before || (*itr)->Players.size() < MinPlayersPerTeam))
647  {
648  //we must insert group to normal queue and erase pointer from premade queue
649  m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].push_front((*itr));
650  m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].erase(itr);
651  }
652  }
653  }
654  //selection pools are not set
655  return false;
656 }
SelectionPool m_SelectionPools[BG_TEAMS_COUNT]
Definition: BattlegroundQueue.h:128
bool AddGroup(GroupQueueInfo *ginfo, uint32 desiredCount)
Definition: BattlegroundQueue.cpp:109
uint32 getMSTime()
Definition: Timer.h:24
#define sWorld
Definition: World.h:887
#define BG_TEAMS_COUNT
Definition: SharedDefines.h:4555
T min(const T &x, const T &y)
Definition: g3dmath.h:305
Definition: BattlegroundQueue.h:60
uint32_t uint32
Definition: Define.h:150
Definition: SharedDefines.h:992
Definition: BattlegroundQueue.h:61
Definition: BattlegroundQueue.h:62
GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_GROUP_TYPES_COUNT]
Definition: BattlegroundQueue.h:110
Definition: SharedDefines.h:993

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool BattlegroundQueue::CheckSkirmishForSameFaction ( BattlegroundBracketId  bracket_id,
uint32  minPlayersPerTeam 
)
703 {
704  if (m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() < minPlayersPerTeam && m_SelectionPools[TEAM_HORDE].GetPlayerCount() < minPlayersPerTeam)
705  return false;
706  uint32 teamIndex = TEAM_ALLIANCE;
707  uint32 otherTeam = TEAM_HORDE;
708  uint32 otherTeamId = HORDE;
709  if (m_SelectionPools[TEAM_HORDE].GetPlayerCount() == minPlayersPerTeam)
710  {
711  teamIndex = TEAM_HORDE;
712  otherTeam = TEAM_ALLIANCE;
713  otherTeamId = ALLIANCE;
714  }
715  //clear other team's selection
716  m_SelectionPools[otherTeam].Init();
717  //store last ginfo pointer
718  GroupQueueInfo* ginfo = m_SelectionPools[teamIndex].SelectedGroups.back();
719  //set itr_team to group that was added to selection pool latest
720  GroupsQueueType::iterator itr_team = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].begin();
721  for (; itr_team != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].end(); ++itr_team)
722  if (ginfo == *itr_team)
723  break;
724  if (itr_team == m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].end())
725  return false;
726  GroupsQueueType::iterator itr_team2 = itr_team;
727  ++itr_team2;
728  //invite players to other selection pool
729  for (; itr_team2 != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].end(); ++itr_team2)
730  {
731  //if selection pool is full then break;
732  if (!(*itr_team2)->IsInvitedToBGInstanceGUID && !m_SelectionPools[otherTeam].AddGroup(*itr_team2, minPlayersPerTeam))
733  break;
734  }
735  if (m_SelectionPools[otherTeam].GetPlayerCount() != minPlayersPerTeam)
736  return false;
737 
738  //here we have correct 2 selections and we need to change one teams team and move selection pool teams to other team's queue
739  for (GroupsQueueType::iterator itr = m_SelectionPools[otherTeam].SelectedGroups.begin(); itr != m_SelectionPools[otherTeam].SelectedGroups.end(); ++itr)
740  {
741  //set correct team
742  (*itr)->Team = otherTeamId;
743  //add team to other queue
744  m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + otherTeam].push_front(*itr);
745  //remove team from old queue
746  GroupsQueueType::iterator itr2 = itr_team;
747  ++itr2;
748  for (; itr2 != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].end(); ++itr2)
749  {
750  if (*itr2 == *itr)
751  {
752  m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].erase(itr2);
753  break;
754  }
755  }
756  }
757  return true;
758 }
SelectionPool m_SelectionPools[BG_TEAMS_COUNT]
Definition: BattlegroundQueue.h:128
bool AddGroup(GroupQueueInfo *ginfo, uint32 desiredCount)
Definition: BattlegroundQueue.cpp:109
void Init()
Definition: BattlegroundQueue.cpp:66
Definition: SharedDefines.h:1000
uint32_t uint32
Definition: Define.h:150
Definition: SharedDefines.h:992
Definition: BattlegroundQueue.h:62
Definition: BattlegroundQueue.h:41
Definition: SharedDefines.h:999
GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_GROUP_TYPES_COUNT]
Definition: BattlegroundQueue.h:110
GroupsQueueType SelectedGroups
Definition: BattlegroundQueue.h:122
Definition: SharedDefines.h:993

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlegroundQueue::FillPlayersToBG ( Battleground bg,
BattlegroundBracketId  bracket_id 
)
497 {
498  int32 hordeFree = bg->GetFreeSlotsForTeam(HORDE);
499  int32 aliFree = bg->GetFreeSlotsForTeam(ALLIANCE);
500  uint32 aliCount = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].size();
501  uint32 hordeCount = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].size();
502 
503  // try to get even teams
505  {
506  // check if the teams are even
507  if (hordeFree == 1 && aliFree == 1)
508  {
509  // if we are here, the teams have the same amount of players
510  // then we have to allow to join the same amount of players
511  int32 hordeExtra = hordeCount - aliCount;
512  int32 aliExtra = aliCount - hordeCount;
513 
514  hordeExtra = std::max(hordeExtra, 0);
515  aliExtra = std::max(aliExtra, 0);
516 
517  if (aliCount != hordeCount)
518  {
519  aliFree -= aliExtra;
520  hordeFree -= hordeExtra;
521 
522  aliFree = std::max(aliFree, 0);
523  hordeFree = std::max(hordeFree, 0);
524  }
525  }
526  }
527 
528  //iterator for iterating through bg queue
529  GroupsQueueType::const_iterator Ali_itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].begin();
530  //count of groups in queue - used to stop cycles
531 
532  //index to queue which group is current
533  uint32 aliIndex = 0;
534  for (; aliIndex < aliCount && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree); aliIndex++)
535  ++Ali_itr;
536  //the same thing for horde
537  GroupsQueueType::const_iterator Horde_itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].begin();
538 
539  uint32 hordeIndex = 0;
540  for (; hordeIndex < hordeCount && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), hordeFree); hordeIndex++)
541  ++Horde_itr;
542 
543  //if ofc like BG queue invitation is set in config, then we are happy
545  return;
546 
547  /*
548  if we reached this code, then we have to solve NP - complete problem called Subset sum problem
549  So one solution is to check all possible invitation subgroups, or we can use these conditions:
550  1. Last time when BattlegroundQueue::Update was executed we invited all possible players - so there is only small possibility
551  that we will invite now whole queue, because only 1 change has been made to queues from the last BattlegroundQueue::Update call
552  2. Other thing we should consider is group order in queue
553  */
554 
555  // At first we need to compare free space in bg and our selection pool
556  int32 diffAli = aliFree - int32(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount());
557  int32 diffHorde = hordeFree - int32(m_SelectionPools[TEAM_HORDE].GetPlayerCount());
558  while (abs(diffAli - diffHorde) > 1 && (m_SelectionPools[TEAM_HORDE].GetPlayerCount() > 0 || m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() > 0))
559  {
560  //each cycle execution we need to kick at least 1 group
561  if (diffAli < diffHorde)
562  {
563  //kick alliance group, add to pool new group if needed
564  if (m_SelectionPools[TEAM_ALLIANCE].KickGroup(diffHorde - diffAli))
565  {
566  for (; aliIndex < aliCount && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), (aliFree >= diffHorde) ? aliFree - diffHorde : 0); aliIndex++)
567  ++Ali_itr;
568  }
569  //if ali selection is already empty, then kick horde group, but if there are less horde than ali in bg - break;
570  if (!m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount())
571  {
572  if (aliFree <= diffHorde + 1)
573  break;
574  m_SelectionPools[TEAM_HORDE].KickGroup(diffHorde - diffAli);
575  }
576  }
577  else
578  {
579  //kick horde group, add to pool new group if needed
580  if (m_SelectionPools[TEAM_HORDE].KickGroup(diffAli - diffHorde))
581  {
582  for (; hordeIndex < hordeCount && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), (hordeFree >= diffAli) ? hordeFree - diffAli : 0); hordeIndex++)
583  ++Horde_itr;
584  }
585  if (!m_SelectionPools[TEAM_HORDE].GetPlayerCount())
586  {
587  if (hordeFree <= diffAli + 1)
588  break;
589  m_SelectionPools[TEAM_ALLIANCE].KickGroup(diffAli - diffHorde);
590  }
591  }
592  //count diffs after small update
593  diffAli = aliFree - int32(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount());
594  diffHorde = hordeFree - int32(m_SelectionPools[TEAM_HORDE].GetPlayerCount());
595  }
596 }
SelectionPool m_SelectionPools[BG_TEAMS_COUNT]
Definition: BattlegroundQueue.h:128
G3D::Matrix abs(const G3D::Matrix &M)
Definition: Matrix.h:632
uint32 GetFreeSlotsForTeam(uint32 Team) const
Definition: Battleground.cpp:1252
bool AddGroup(GroupQueueInfo *ginfo, uint32 desiredCount)
Definition: BattlegroundQueue.cpp:109
#define sWorld
Definition: World.h:887
T max(const T &x, const T &y)
Definition: g3dmath.h:320
Definition: SharedDefines.h:1000
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
Definition: BattlegroundQueue.h:63
Definition: SharedDefines.h:992
Definition: BattlegroundQueue.h:62
Definition: SharedDefines.h:999
GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_GROUP_TYPES_COUNT]
Definition: BattlegroundQueue.h:110
int32_t int32
Definition: g3dmath.h:167
Definition: BattlegroundQueue.h:71
Definition: SharedDefines.h:993
Definition: BattlegroundQueue.h:69
bool KickGroup(uint32 size)
Definition: BattlegroundQueue.cpp:76

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 BattlegroundQueue::GetAverageQueueWaitTime ( GroupQueueInfo ginfo,
BattlegroundBracketId  bracket_id 
) const
262 {
263  uint8 team_index = TEAM_ALLIANCE; //default set to TEAM_ALLIANCE - or non rated arenas!
264  if (!ginfo->ArenaType)
265  {
266  if (ginfo->Team == HORDE)
267  team_index = TEAM_HORDE;
268  }
269  else
270  {
271  if (ginfo->IsRated)
272  team_index = TEAM_HORDE; //for rated arenas use TEAM_HORDE
273  }
274  //check if there is enought values(we always add values > 0)
275  if (m_WaitTimes[team_index][bracket_id][COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME - 1])
276  return (m_SumOfWaitTimes[team_index][bracket_id] / COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME);
277  else
278  //if there aren't enough values return 0 - not available
279  return 0;
280 }
uint32 m_WaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS][COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME]
Definition: BattlegroundQueue.h:133
bool IsRated
Definition: BattlegroundQueue.h:46
uint32 Team
Definition: BattlegroundQueue.h:44
#define COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME
Definition: BattlegroundQueue.h:32
uint8 ArenaType
Definition: BattlegroundQueue.h:47
Definition: SharedDefines.h:992
Definition: SharedDefines.h:999
uint32 m_SumOfWaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
Definition: BattlegroundQueue.h:135
uint8_t uint8
Definition: Define.h:152
Definition: SharedDefines.h:993

+ Here is the caller graph for this function:

bool BattlegroundQueue::GetPlayerGroupInfoData ( ObjectGuid  guid,
GroupQueueInfo ginfo 
)
415 {
416  QueuedPlayersMap::const_iterator qItr = m_QueuedPlayers.find(guid);
417  if (qItr == m_QueuedPlayers.end())
418  return false;
419  *ginfo = *(qItr->second.GroupInfo);
420  return true;
421 }
QueuedPlayersMap m_QueuedPlayers
Definition: BattlegroundQueue.h:96

+ Here is the caller graph for this function:

uint32 BattlegroundQueue::GetPlayersInQueue ( TeamId  id)
424 {
425  return m_SelectionPools[id].GetPlayerCount();
426 }
SelectionPool m_SelectionPools[BG_TEAMS_COUNT]
Definition: BattlegroundQueue.h:128
uint32 GetPlayerCount() const
Definition: BattlegroundQueue.h:120

+ Here is the call graph for this function:

bool BattlegroundQueue::InviteGroupToBG ( GroupQueueInfo ginfo,
Battleground bg,
uint32  side 
)
private
429 {
430  // set side if needed
431  if (side)
432  ginfo->Team = side;
433 
434  if (!ginfo->IsInvitedToBGInstanceGUID)
435  {
436  // not yet invited
437  // set invitation
439  BattlegroundTypeId bgTypeId = bg->GetTypeID();
441  BattlegroundBracketId bracket_id = bg->GetBracketId();
442 
443  // set ArenaTeamId for rated matches
444  if (bg->isArena() && bg->isRated())
445  bg->SetArenaTeamIdForTeam(ginfo->Team, ginfo->ArenaTeamId);
446 
448 
449  // loop through the players
450  for (std::map<ObjectGuid, PlayerQueueInfo*>::iterator itr = ginfo->Players.begin(); itr != ginfo->Players.end(); ++itr)
451  {
452  // get the player
453  Player* player = ObjectAccessor::FindConnectedPlayer(itr->first);
454  // if offline, skip him, this should not happen - player is removed from queue when he logs out
455  if (!player)
456  continue;
457 
458  // invite the player
459  PlayerInvitedToBGUpdateAverageWaitTime(ginfo, bracket_id);
460  //sBattlegroundMgr->InvitePlayer(player, bg, ginfo->Team);
461 
462  // set invited player counters
463  bg->IncreaseInvitedCount(ginfo->Team);
464 
465  player->SetInviteForBattlegroundQueueType(bgQueueTypeId, ginfo->IsInvitedToBGInstanceGUID);
466 
467  // create remind invite events
468  BGQueueInviteEvent* inviteEvent = new BGQueueInviteEvent(player->GetGUID(), ginfo->IsInvitedToBGInstanceGUID, bgTypeId, ginfo->ArenaType, ginfo->RemoveInviteTime);
470  // create automatic remove events
471  BGQueueRemoveEvent* removeEvent = new BGQueueRemoveEvent(player->GetGUID(), ginfo->IsInvitedToBGInstanceGUID, bgTypeId, ginfo->ArenaType, bgQueueTypeId, ginfo->RemoveInviteTime);
473 
474  WorldPacket data;
475 
476  uint32 queueSlot = player->GetBattlegroundQueueIndex(bgQueueTypeId);
477 
478  TC_LOG_DEBUG("bg.battleground", "Battleground: invited player %s (%s) to BG instance %u queueindex %u bgtype %u",
479  player->GetName().c_str(), player->GetGUID().ToString().c_str(), bg->GetInstanceID(), queueSlot, bg->GetTypeID());
480 
482  sBattlegroundMgr->BuildBattlegroundStatusNeedConfirmation(&battlefieldStatus, bg, player, queueSlot, player->GetBattlegroundQueueJoinTime(bgQueueTypeId), INVITE_ACCEPT_WAIT_TIME, ginfo->ArenaType);
483  player->SendDirectMessage(battlefieldStatus.Write());
484  }
485  return true;
486  }
487 
488  return false;
489 }
BattlegroundTypeId
Definition: SharedDefines.h:4558
Definition: Battleground.h:125
void AddEvent(BasicEvent *Event, uint64 e_time, bool set_addtime=true)
Definition: EventProcessor.cpp:88
BattlegroundBracketId
Definition: DBCEnums.h:57
uint32 getMSTime()
Definition: Timer.h:24
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType)
Definition: BattlegroundMgr.cpp:623
uint32 Team
Definition: BattlegroundQueue.h:44
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: BattlegroundQueue.h:168
bool isRated() const
Definition: Battleground.h:328
bool isArena() const
Definition: Battleground.h:326
Definition: BattlegroundQueue.h:145
uint8 GetArenaType() const
Definition: Battleground.h:281
EventProcessor m_events
Definition: BattlegroundQueue.h:138
uint8 ArenaType
Definition: BattlegroundQueue.h:47
uint32_t uint32
Definition: Define.h:150
uint64 CalculateTime(uint64 t_offset) const
Definition: EventProcessor.cpp:95
uint32 GetInstanceID() const
Definition: Battleground.h:265
BattlegroundBracketId GetBracketId() const
Definition: Battleground.h:264
void PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo *ginfo, BattlegroundBracketId bracket_id)
Definition: BattlegroundQueue.cpp:233
void IncreaseInvitedCount(uint32 team)
Definition: Battleground.h:319
BattlegroundQueueTypeId
Definition: SharedDefines.h:4732
Definition: Battleground.h:124
#define sBattlegroundMgr
Definition: BattlegroundMgr.h:181
uint32 ArenaTeamId
Definition: BattlegroundQueue.h:48
void SetArenaTeamIdForTeam(uint32 Team, uint32 ArenaTeamId)
Definition: Battleground.h:413
BattlegroundTypeId GetTypeID(bool GetRandom=false) const
Definition: Battleground.h:263
uint32 RemoveInviteTime
Definition: BattlegroundQueue.h:50
std::map< ObjectGuid, PlayerQueueInfo * > Players
Definition: BattlegroundQueue.h:43
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215
Definition: WorldPacket.h:26
uint32 IsInvitedToBGInstanceGUID
Definition: BattlegroundQueue.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool BattlegroundQueue::IsPlayerInvited ( ObjectGuid  pl_guid,
const uint32  bgInstanceGuid,
const uint32  removeTime 
)
407 {
408  QueuedPlayersMap::const_iterator qItr = m_QueuedPlayers.find(pl_guid);
409  return (qItr != m_QueuedPlayers.end()
410  && qItr->second.GroupInfo->IsInvitedToBGInstanceGUID == bgInstanceGuid
411  && qItr->second.GroupInfo->RemoveInviteTime == removeTime);
412 }
QueuedPlayersMap m_QueuedPlayers
Definition: BattlegroundQueue.h:96

+ Here is the caller graph for this function:

void BattlegroundQueue::PlayerInvitedToBGUpdateAverageWaitTime ( GroupQueueInfo ginfo,
BattlegroundBracketId  bracket_id 
)
234 {
235  uint32 timeInQueue = getMSTimeDiff(ginfo->JoinTime, getMSTime());
236  uint8 team_index = TEAM_ALLIANCE; //default set to TEAM_ALLIANCE - or non rated arenas!
237  if (!ginfo->ArenaType)
238  {
239  if (ginfo->Team == HORDE)
240  team_index = TEAM_HORDE;
241  }
242  else
243  {
244  if (ginfo->IsRated)
245  team_index = TEAM_HORDE; //for rated arenas use TEAM_HORDE
246  }
247 
248  //store pointer to arrayindex of player that was added first
249  uint32* lastPlayerAddedPointer = &(m_WaitTimeLastPlayer[team_index][bracket_id]);
250  //remove his time from sum
251  m_SumOfWaitTimes[team_index][bracket_id] -= m_WaitTimes[team_index][bracket_id][(*lastPlayerAddedPointer)];
252  //set average time to new
253  m_WaitTimes[team_index][bracket_id][(*lastPlayerAddedPointer)] = timeInQueue;
254  //add new time to sum
255  m_SumOfWaitTimes[team_index][bracket_id] += timeInQueue;
256  //set index of last player added to next one
257  (*lastPlayerAddedPointer)++;
258  (*lastPlayerAddedPointer) %= COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME;
259 }
uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
Definition: Timer.h:33
uint32 m_WaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS][COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME]
Definition: BattlegroundQueue.h:133
uint32 getMSTime()
Definition: Timer.h:24
bool IsRated
Definition: BattlegroundQueue.h:46
uint32 Team
Definition: BattlegroundQueue.h:44
#define COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME
Definition: BattlegroundQueue.h:32
uint8 ArenaType
Definition: BattlegroundQueue.h:47
uint32_t uint32
Definition: Define.h:150
Definition: SharedDefines.h:992
uint32 JoinTime
Definition: BattlegroundQueue.h:49
Definition: SharedDefines.h:999
uint32 m_SumOfWaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
Definition: BattlegroundQueue.h:135
uint8_t uint8
Definition: Define.h:152
uint32 m_WaitTimeLastPlayer[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
Definition: BattlegroundQueue.h:134
Definition: SharedDefines.h:993

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlegroundQueue::RemovePlayer ( ObjectGuid  guid,
bool  decreaseInvitedCount 
)
284 {
285  int32 bracket_id = -1; // signed for proper for-loop finish
286  QueuedPlayersMap::iterator itr;
287 
288  //remove player from map, if he's there
289  itr = m_QueuedPlayers.find(guid);
290  if (itr == m_QueuedPlayers.end())
291  {
292  //This happens if a player logs out while in a bg because WorldSession::LogoutPlayer() notifies the bg twice
293  std::string playerName = "Unknown";
294  if (Player* player = ObjectAccessor::FindPlayer(guid))
295  playerName = player->GetName();
296  TC_LOG_DEBUG("bg.battleground", "BattlegroundQueue: couldn't find player %s (%s)", playerName.c_str(), guid.ToString().c_str());
297  return;
298  }
299 
300  GroupQueueInfo* group = itr->second.GroupInfo;
301  GroupsQueueType::iterator group_itr;
302  // mostly people with the highest levels are in battlegrounds, thats why
303  // we count from MAX_BATTLEGROUND_QUEUES - 1 to 0
304 
306 
307  for (int32 bracket_id_tmp = MAX_BATTLEGROUND_BRACKETS - 1; bracket_id_tmp >= 0 && bracket_id == -1; --bracket_id_tmp)
308  {
309  //we must check premade and normal team's queue - because when players from premade are joining bg,
310  //they leave groupinfo so we can't use its players size to find out index
311  for (uint32 j = index; j < BG_QUEUE_GROUP_TYPES_COUNT; j += BG_TEAMS_COUNT)
312  {
313  GroupsQueueType::iterator k = m_QueuedGroups[bracket_id_tmp][j].begin();
314  for (; k != m_QueuedGroups[bracket_id_tmp][j].end(); ++k)
315  {
316  if ((*k) == group)
317  {
318  bracket_id = bracket_id_tmp;
319  group_itr = k;
320  //we must store index to be able to erase iterator
321  index = j;
322  break;
323  }
324  }
325  }
326  }
327 
328  //player can't be in queue without group, but just in case
329  if (bracket_id == -1)
330  {
331  TC_LOG_ERROR("bg.battleground", "BattlegroundQueue: ERROR Cannot find groupinfo for %s", guid.ToString().c_str());
332  return;
333  }
334  TC_LOG_DEBUG("bg.battleground", "BattlegroundQueue: Removing %s, from bracket_id %u", guid.ToString().c_str(), (uint32)bracket_id);
335 
336  // ALL variables are correctly set
337  // We can ignore leveling up in queue - it should not cause crash
338  // remove player from group
339  // if only one player there, remove group
340 
341  // remove player queue info from group queue info
342  std::map<ObjectGuid, PlayerQueueInfo*>::iterator pitr = group->Players.find(guid);
343  if (pitr != group->Players.end())
344  group->Players.erase(pitr);
345 
346  // if invited to bg, and should decrease invited count, then do it
347  if (decreaseInvitedCount && group->IsInvitedToBGInstanceGUID)
348  if (Battleground* bg = sBattlegroundMgr->GetBattleground(group->IsInvitedToBGInstanceGUID, group->BgTypeId))
349  bg->DecreaseInvitedCount(group->Team);
350 
351  // remove player queue info
352  m_QueuedPlayers.erase(itr);
353 
354  // announce to world if arena team left queue for rated match, show only once
355  if (group->ArenaType && group->IsRated && group->Players.empty() && sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE))
356  if (ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(group->ArenaTeamId))
357  sWorld->SendWorldText(LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT, team->GetName().c_str(), group->ArenaType, group->ArenaType, group->ArenaTeamRating);
358 
359  // if player leaves queue and he is invited to rated arena match, then he have to lose
360  if (group->IsInvitedToBGInstanceGUID && group->IsRated && decreaseInvitedCount)
361  {
362  if (ArenaTeam* at = sArenaTeamMgr->GetArenaTeamById(group->ArenaTeamId))
363  {
364  TC_LOG_DEBUG("bg.battleground", "UPDATING memberLost's personal arena rating for %s by opponents rating: %u", guid.ToString().c_str(), group->OpponentsTeamRating);
365  if (Player* player = ObjectAccessor::FindConnectedPlayer(guid))
366  at->MemberLost(player, group->OpponentsMatchmakerRating);
367  else
368  at->OfflineMemberLost(guid, group->OpponentsMatchmakerRating);
369  at->SaveToDB();
370  }
371  }
372 
373  // remove group queue info if needed
374  if (group->Players.empty())
375  {
376  m_QueuedGroups[bracket_id][index].erase(group_itr);
377  delete group;
378  return;
379  }
380 
381  // if group wasn't empty, so it wasn't deleted, and player have left a rated
382  // queue -> everyone from the group should leave too
383  // don't remove recursively if already invited to bg!
384  if (!group->IsInvitedToBGInstanceGUID && group->IsRated)
385  {
386  // remove next player, this is recursive
387  // first send removal information
388  if (Player* plr2 = ObjectAccessor::FindConnectedPlayer(group->Players.begin()->first))
389  {
391  uint32 queueSlot = plr2->GetBattlegroundQueueIndex(bgQueueTypeId);
392 
393  plr2->RemoveBattlegroundQueueId(bgQueueTypeId); // must be called this way, because if you move this call to
394  // queue->removeplayer, it causes bugs
395 
397  sBattlegroundMgr->BuildBattlegroundStatusNone(&battlefieldStatus, plr2, queueSlot, plr2->GetBattlegroundQueueJoinTime(bgQueueTypeId), group->ArenaType);
398  plr2->SendDirectMessage(battlefieldStatus.Write());
399  }
400  // then actually delete, this may delete the group as well!
401  RemovePlayer(group->Players.begin()->first, decreaseInvitedCount);
402  }
403 }
#define BG_QUEUE_GROUP_TYPES_COUNT
Definition: BattlegroundQueue.h:65
Definition: BattlegroundPackets.h:147
Definition: DBCEnums.h:63
uint32 ArenaTeamRating
Definition: BattlegroundQueue.h:52
uint32 OpponentsMatchmakerRating
Definition: BattlegroundQueue.h:55
WorldPacket const * Write() override
Definition: BattlegroundPackets.cpp:150
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType)
Definition: BattlegroundMgr.cpp:623
Definition: Language.h:721
bool IsRated
Definition: BattlegroundQueue.h:46
uint32 Team
Definition: BattlegroundQueue.h:44
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
#define sWorld
Definition: World.h:887
#define BG_TEAMS_COUNT
Definition: SharedDefines.h:4555
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:209
Definition: BattlegroundQueue.h:60
uint8 ArenaType
Definition: BattlegroundQueue.h:47
void RemovePlayer(ObjectGuid guid, bool decreaseInvitedCount)
Definition: BattlegroundQueue.cpp:283
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
Definition: BattlegroundQueue.h:61
Definition: BattlegroundQueue.h:41
uint32 OpponentsTeamRating
Definition: BattlegroundQueue.h:54
Definition: SharedDefines.h:999
Definition: ArenaTeam.h:112
BattlegroundQueueTypeId
Definition: SharedDefines.h:4732
GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_GROUP_TYPES_COUNT]
Definition: BattlegroundQueue.h:110
#define sBattlegroundMgr
Definition: BattlegroundMgr.h:181
uint32 ArenaTeamId
Definition: BattlegroundQueue.h:48
QueuedPlayersMap m_QueuedPlayers
Definition: BattlegroundQueue.h:96
Definition: Battleground.h:235
#define sArenaTeamMgr
Definition: ArenaTeamMgr.h:53
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32_t uint32
Definition: g3dmath.h:168
BattlegroundTypeId BgTypeId
Definition: BattlegroundQueue.h:45
std::map< ObjectGuid, PlayerQueueInfo * > Players
Definition: BattlegroundQueue.h:43
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215
std::string ToString() const
Definition: ObjectGuid.cpp:99
uint32 IsInvitedToBGInstanceGUID
Definition: BattlegroundQueue.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlegroundQueue::UpdateEvents ( uint32  diff)
761 {
762  m_events.Update(diff);
763 }
EventProcessor m_events
Definition: BattlegroundQueue.h:138
void Update(uint32 p_time)
Definition: EventProcessor.cpp:32

+ Here is the call graph for this function:

Member Data Documentation

EventProcessor BattlegroundQueue::m_events
private
QueuedPlayersMap BattlegroundQueue::m_QueuedPlayers
SelectionPool BattlegroundQueue::m_SelectionPools[BG_TEAMS_COUNT]
uint32 BattlegroundQueue::m_SumOfWaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
private
uint32 BattlegroundQueue::m_WaitTimeLastPlayer[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
private

The documentation for this class was generated from the following files: