TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BattlegroundQueue.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __BATTLEGROUNDQUEUE_H
20 #define __BATTLEGROUNDQUEUE_H
21 
22 #include "Common.h"
23 #include "DBCEnums.h"
24 #include "Battleground.h"
25 #include "EventProcessor.h"
26 
27 #include <deque>
28 
29 //this container can't be deque, because deque doesn't like removing the last element - if you remove it, it invalidates next iterator and crash appears
30 typedef std::list<Battleground*> BGFreeSlotQueueContainer;
31 
32 #define COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME 10
33 
34 struct GroupQueueInfo; // type predefinition
35 struct PlayerQueueInfo // stores information for players in queue
36 {
37  uint32 LastOnlineTime; // for tracking and removing offline players from queue after 5 minutes
38  GroupQueueInfo* GroupInfo; // pointer to the associated groupqueueinfo
39 };
40 
41 struct GroupQueueInfo // stores information about the group in queue (also used when joined as solo!)
42 {
43  std::map<ObjectGuid, PlayerQueueInfo*> Players; // player queue info map
44  uint32 Team; // Player team (ALLIANCE/HORDE)
45  BattlegroundTypeId BgTypeId; // battleground type id
46  bool IsRated; // rated
47  uint8 ArenaType; // 2v2, 3v3, 5v5 or 0 when BG
48  uint32 ArenaTeamId; // team id if rated match
49  uint32 JoinTime; // time when group was added
50  uint32 RemoveInviteTime; // time when we will remove invite for players in group
51  uint32 IsInvitedToBGInstanceGUID; // was invited to certain BG
52  uint32 ArenaTeamRating; // if rated match, inited to the rating of the team
53  uint32 ArenaMatchmakerRating; // if rated match, inited to the rating of the team
54  uint32 OpponentsTeamRating; // for rated arena matches
55  uint32 OpponentsMatchmakerRating; // for rated arena matches
56 };
57 
59 {
64 };
65 #define BG_QUEUE_GROUP_TYPES_COUNT 4
66 
68 {
69  BG_QUEUE_INVITATION_TYPE_NO_BALANCE = 0, // no balance: N+M vs N players
70  BG_QUEUE_INVITATION_TYPE_BALANCED = 1, // teams balanced: N+1 vs N players
71  BG_QUEUE_INVITATION_TYPE_EVEN = 2 // teams even: N vs N players
72 };
73 
74 class Battleground;
76 {
77  public:
80 
81  void BattlegroundQueueUpdate(uint32 diff, BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id, uint8 arenaType = 0, bool isRated = false, uint32 minRating = 0);
82  void UpdateEvents(uint32 diff);
83 
84  void FillPlayersToBG(Battleground* bg, BattlegroundBracketId bracket_id);
85  bool CheckPremadeMatch(BattlegroundBracketId bracket_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam);
86  bool CheckNormalMatch(Battleground* bg_template, BattlegroundBracketId bracket_id, uint32 minPlayers, uint32 maxPlayers);
87  bool CheckSkirmishForSameFaction(BattlegroundBracketId bracket_id, uint32 minPlayersPerTeam);
88  GroupQueueInfo* AddGroup(Player* leader, Group* group, BattlegroundTypeId bgTypeId, PvPDifficultyEntry const* bracketEntry, uint8 ArenaType, bool isRated, bool isPremade, uint32 ArenaRating, uint32 MatchmakerRating, uint32 ArenaTeamId = 0);
89  void RemovePlayer(ObjectGuid guid, bool decreaseInvitedCount);
90  bool IsPlayerInvited(ObjectGuid pl_guid, const uint32 bgInstanceGuid, const uint32 removeTime);
91  bool GetPlayerGroupInfoData(ObjectGuid guid, GroupQueueInfo* ginfo);
92  void PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, BattlegroundBracketId bracket_id);
93  uint32 GetAverageQueueWaitTime(GroupQueueInfo* ginfo, BattlegroundBracketId bracket_id) const;
94 
95  typedef std::map<ObjectGuid, PlayerQueueInfo> QueuedPlayersMap;
96  QueuedPlayersMap m_QueuedPlayers;
97 
98  //do NOT use deque because deque.erase() invalidates ALL iterators
99  typedef std::list<GroupQueueInfo*> GroupsQueueType;
100 
101  /*
102  This two dimensional array is used to store All queued groups
103  First dimension specifies the bgTypeId
104  Second dimension specifies the player's group types -
105  BG_QUEUE_PREMADE_ALLIANCE is used for premade alliance groups and alliance rated arena teams
106  BG_QUEUE_PREMADE_HORDE is used for premade horde groups and horde rated arena teams
107  BG_QUEUE_NORMAL_ALLIANCE is used for normal (or small) alliance groups or non-rated arena matches
108  BG_QUEUE_NORMAL_HORDE is used for normal (or small) horde groups or non-rated arena matches
109  */
110  GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_GROUP_TYPES_COUNT];
111 
112  // class to select and invite groups to bg
114  {
115  public:
116  SelectionPool(): PlayerCount(0) { }
117  void Init();
118  bool AddGroup(GroupQueueInfo* ginfo, uint32 desiredCount);
119  bool KickGroup(uint32 size);
120  uint32 GetPlayerCount() const {return PlayerCount;}
121  public:
122  GroupsQueueType SelectedGroups;
123  private:
125  };
126 
127  //one selection pool for horde, other one for alliance
128  SelectionPool m_SelectionPools[BG_TEAMS_COUNT];
129  uint32 GetPlayersInQueue(TeamId id);
130  private:
131 
132  bool InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, uint32 side);
136 
137  // Event handler
139 };
140 
141 /*
142  This class is used to invite player to BG again, when minute lasts from his first invitation
143  it is capable to solve all possibilities
144 */
146 {
147  public:
148  BGQueueInviteEvent(ObjectGuid pl_guid, uint32 BgInstanceGUID, BattlegroundTypeId BgTypeId, uint8 arenaType, uint32 removeTime) :
149  m_PlayerGuid(pl_guid), m_BgInstanceGUID(BgInstanceGUID), m_BgTypeId(BgTypeId), m_ArenaType(arenaType), m_RemoveTime(removeTime)
150  { }
151  virtual ~BGQueueInviteEvent() { }
152 
153  virtual bool Execute(uint64 e_time, uint32 p_time) override;
154  virtual void Abort(uint64 e_time) override;
155  private:
161 };
162 
163 /*
164  This class is used to remove player from BG queue after 1 minute 20 seconds from first invitation
165  We must store removeInvite time in case player left queue and joined and is invited again
166  We must store bgQueueTypeId, because battleground can be deleted already, when player entered it
167 */
169 {
170  public:
171  BGQueueRemoveEvent(ObjectGuid pl_guid, uint32 bgInstanceGUID, BattlegroundTypeId BgTypeId, uint8 arenaType, BattlegroundQueueTypeId bgQueueTypeId, uint32 removeTime)
172  : m_PlayerGuid(pl_guid), m_BgInstanceGUID(bgInstanceGUID), m_ArenaType(arenaType), m_RemoveTime(removeTime), m_BgTypeId(BgTypeId), m_BgQueueTypeId(bgQueueTypeId)
173  { }
174 
175  virtual ~BGQueueRemoveEvent() { }
176 
177  virtual bool Execute(uint64 e_time, uint32 p_time) override;
178  virtual void Abort(uint64 e_time) override;
179  private:
186 };
187 
188 #endif
#define BG_QUEUE_GROUP_TYPES_COUNT
Definition: BattlegroundQueue.h:65
ArenaType
Definition: Battleground.h:179
Definition: DBCEnums.h:63
BattlegroundTypeId
Definition: SharedDefines.h:4558
BattlegroundTypeId m_BgTypeId
Definition: BattlegroundQueue.h:158
uint32 ArenaTeamRating
Definition: BattlegroundQueue.h:52
std::map< ObjectGuid, PlayerQueueInfo > QueuedPlayersMap
Definition: BattlegroundQueue.h:95
BGQueueRemoveEvent(ObjectGuid pl_guid, uint32 bgInstanceGUID, BattlegroundTypeId BgTypeId, uint8 arenaType, BattlegroundQueueTypeId bgQueueTypeId, uint32 removeTime)
Definition: BattlegroundQueue.h:171
uint32 OpponentsMatchmakerRating
Definition: BattlegroundQueue.h:55
uint32 m_BgInstanceGUID
Definition: BattlegroundQueue.h:157
std::list< Battleground * > BGFreeSlotQueueContainer
Definition: BattlegroundQueue.h:30
GroupQueueInfo * GroupInfo
Definition: BattlegroundQueue.h:38
BGQueueInviteEvent(ObjectGuid pl_guid, uint32 BgInstanceGUID, BattlegroundTypeId BgTypeId, uint8 arenaType, uint32 removeTime)
Definition: BattlegroundQueue.h:148
uint32 m_BgInstanceGUID
Definition: BattlegroundQueue.h:181
BattlegroundBracketId
Definition: DBCEnums.h:57
uint32 PlayerCount
Definition: BattlegroundQueue.h:124
bool IsRated
Definition: BattlegroundQueue.h:46
uint32 Team
Definition: BattlegroundQueue.h:44
virtual void Abort(uint64)
Definition: EventProcessor.h:46
Definition: BattlegroundQueue.h:70
Definition: BattlegroundQueue.h:168
#define BG_TEAMS_COUNT
Definition: SharedDefines.h:4555
Definition: BattlegroundQueue.h:145
#define COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME
Definition: BattlegroundQueue.h:32
virtual ~BGQueueRemoveEvent()
Definition: BattlegroundQueue.h:175
EventProcessor m_events
Definition: BattlegroundQueue.h:138
Definition: BattlegroundQueue.h:60
uint8 ArenaType
Definition: BattlegroundQueue.h:47
uint32 m_RemoveTime
Definition: BattlegroundQueue.h:183
Definition: BattlegroundQueue.h:113
ObjectGuid m_PlayerGuid
Definition: BattlegroundQueue.h:156
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
Definition: BattlegroundQueue.h:63
std::list< GroupQueueInfo * > GroupsQueueType
Definition: BattlegroundQueue.h:99
Definition: BattlegroundQueue.h:61
uint32 JoinTime
Definition: BattlegroundQueue.h:49
ObjectGuid m_PlayerGuid
Definition: BattlegroundQueue.h:180
Definition: BattlegroundQueue.h:62
TeamId
Definition: SharedDefines.h:990
Definition: BattlegroundQueue.h:41
uint32 OpponentsTeamRating
Definition: BattlegroundQueue.h:54
virtual bool Execute(uint64, uint32)
Definition: EventProcessor.h:42
uint32 ArenaMatchmakerRating
Definition: BattlegroundQueue.h:53
uint8 m_ArenaType
Definition: BattlegroundQueue.h:159
Definition: EventProcessor.h:28
uint8 m_ArenaType
Definition: BattlegroundQueue.h:182
Definition: BattlegroundQueue.h:75
BattlegroundQueueTypeId
Definition: SharedDefines.h:4732
uint32 LastOnlineTime
Definition: BattlegroundQueue.h:37
Definition: DBCStructure.h:926
#define TC_GAME_API
Definition: Define.h:134
BattlegroundQueueTypeId m_BgQueueTypeId
Definition: BattlegroundQueue.h:185
Definition: EventProcessor.h:58
GroupsQueueType SelectedGroups
Definition: BattlegroundQueue.h:122
uint32 ArenaTeamId
Definition: BattlegroundQueue.h:48
QueuedPlayersMap m_QueuedPlayers
Definition: BattlegroundQueue.h:96
Definition: BattlegroundQueue.h:71
uint8_t uint8
Definition: Define.h:152
BattlegroundTypeId m_BgTypeId
Definition: BattlegroundQueue.h:184
Definition: Battleground.h:235
virtual ~BGQueueInviteEvent()
Definition: BattlegroundQueue.h:151
Definition: ObjectGuid.h:189
uint32 RemoveInviteTime
Definition: BattlegroundQueue.h:50
BattlegroundQueueGroupTypes
Definition: BattlegroundQueue.h:58
BattlegroundQueueInvitationType
Definition: BattlegroundQueue.h:67
BattlegroundTypeId BgTypeId
Definition: BattlegroundQueue.h:45
Definition: BattlegroundQueue.h:69
Definition: BattlegroundQueue.h:35
uint32 GetPlayerCount() const
Definition: BattlegroundQueue.h:120
std::map< ObjectGuid, PlayerQueueInfo * > Players
Definition: BattlegroundQueue.h:43
SelectionPool()
Definition: BattlegroundQueue.h:116
uint32 m_RemoveTime
Definition: BattlegroundQueue.h:160
uint32 IsInvitedToBGInstanceGUID
Definition: BattlegroundQueue.h:51
Definition: Group.h:191