TrinityCore
Loading...
Searching...
No Matches
BattlegroundQueue.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __BATTLEGROUNDQUEUE_H
19#define __BATTLEGROUNDQUEUE_H
20
21#include "Common.h"
22#include "DBCEnums.h"
23#include "Battleground.h"
24#include "EventProcessor.h"
25
26//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
27typedef std::list<Battleground*> BGFreeSlotQueueContainer;
28
29#define COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME 10
30
31struct GroupQueueInfo; // type predefinition
32struct PlayerQueueInfo // stores information for players in queue
33{
34 uint32 LastOnlineTime; // for tracking and removing offline players from queue after 5 minutes
35 GroupQueueInfo* GroupInfo; // pointer to the associated groupqueueinfo
36};
37
38struct GroupQueueInfo // stores information about the group in queue (also used when joined as solo!)
39{
40 std::map<ObjectGuid, PlayerQueueInfo*> Players; // player queue info map
41 ::Team Team; // Player team (ALLIANCE/HORDE)
42 uint32 JoinTime; // time when group was added
43 uint32 RemoveInviteTime; // time when we will remove invite for players in group
44 uint32 IsInvitedToBGInstanceGUID; // was invited to certain BG
45 uint32 ArenaTeamRating; // if rated match, inited to the rating of the team
46 uint32 ArenaMatchmakerRating; // if rated match, inited to the rating of the team
47 uint32 OpponentsTeamRating; // for rated arena matches
48 uint32 OpponentsMatchmakerRating; // for rated arena matches
49};
50
58#define BG_QUEUE_GROUP_TYPES_COUNT 4
59
61{
62 BG_QUEUE_INVITATION_TYPE_NO_BALANCE = 0, // no balance: N+M vs N players
63 BG_QUEUE_INVITATION_TYPE_BALANCED = 1, // teams balanced: N+1 vs N players
64 BG_QUEUE_INVITATION_TYPE_EVEN = 2 // teams even: N vs N players
65};
66
67class Battleground;
69{
70 public:
73
74 void BattlegroundQueueUpdate(uint32 diff, BattlegroundBracketId bracket_id, uint32 minRating = 0);
75 void UpdateEvents(uint32 diff);
76
77 void FillPlayersToBG(Battleground* bg, BattlegroundBracketId bracket_id);
78 bool CheckPremadeMatch(BattlegroundBracketId bracket_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam);
79 bool CheckNormalMatch(BattlegroundBracketId bracket_id, uint32 minPlayers, uint32 maxPlayers);
80 bool CheckSkirmishForSameFaction(BattlegroundBracketId bracket_id, uint32 minPlayersPerTeam);
81 GroupQueueInfo* AddGroup(Player const* leader, Group const* group, Team team, PVPDifficultyEntry const* bracketEntry, bool isPremade, uint32 ArenaRating, uint32 MatchmakerRating);
82 void RemovePlayer(ObjectGuid guid, bool decreaseInvitedCount);
83 bool IsPlayerInvited(ObjectGuid pl_guid, const uint32 bgInstanceGuid, const uint32 removeTime);
84 bool GetPlayerGroupInfoData(ObjectGuid guid, GroupQueueInfo* ginfo);
85 void PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, BattlegroundBracketId bracket_id);
86 uint32 GetAverageQueueWaitTime(GroupQueueInfo* ginfo, BattlegroundBracketId bracket_id) const;
87
88 typedef std::map<ObjectGuid, PlayerQueueInfo> QueuedPlayersMap;
90
91 //do NOT use deque because deque.erase() invalidates ALL iterators
92 typedef std::list<GroupQueueInfo*> GroupsQueueType;
93
94 /*
95 This two dimensional array is used to store All queued groups
96 First dimension specifies the bgTypeId
97 Second dimension specifies the player's group types -
98 BG_QUEUE_PREMADE_ALLIANCE is used for premade alliance groups and alliance rated arena teams
99 BG_QUEUE_PREMADE_HORDE is used for premade horde groups and horde rated arena teams
100 BG_QUEUE_NORMAL_ALLIANCE is used for normal (or small) alliance groups or non-rated arena matches
101 BG_QUEUE_NORMAL_HORDE is used for normal (or small) horde groups or non-rated arena matches
102 */
104
105 // class to select and invite groups to bg
107 {
108 public:
109 SelectionPool(): PlayerCount(0) { }
110 void Init();
111 bool AddGroup(GroupQueueInfo* ginfo, uint32 desiredCount);
112 bool KickGroup(uint32 size);
113 uint32 GetPlayerCount() const {return PlayerCount;}
114 public:
116 private:
118 };
119
120 //one selection pool for horde, other one for alliance
122 uint32 GetPlayersInQueue(TeamId id);
123
124 BattlegroundQueueTypeId GetQueueId() const { return m_queueId; }
125 private:
126
128
129 bool InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, Team side);
133
134 // Event handler
136};
137
138/*
139 This class is used to invite player to BG again, when minute lasts from his first invitation
140 it is capable to solve all possibilities
141*/
143{
144 public:
145 BGQueueInviteEvent(ObjectGuid pl_guid, uint32 BgInstanceGUID, BattlegroundTypeId BgTypeId, uint32 removeTime, BattlegroundQueueTypeId queueId)
146 : m_PlayerGuid(pl_guid), m_BgInstanceGUID(BgInstanceGUID), m_BgTypeId(BgTypeId), m_RemoveTime(removeTime), m_QueueId(queueId)
147 { }
148
149 virtual bool Execute(uint64 e_time, uint32 p_time) override;
150 virtual void Abort(uint64 e_time) override;
151 private:
157};
158
159/*
160 This class is used to remove player from BG queue after 1 minute 20 seconds from first invitation
161 We must store removeInvite time in case player left queue and joined and is invited again
162 We must store bgQueueTypeId, because battleground can be deleted already, when player entered it
163*/
165{
166 public:
167 BGQueueRemoveEvent(ObjectGuid pl_guid, uint32 bgInstanceGUID, BattlegroundQueueTypeId bgQueueTypeId, uint32 removeTime)
168 : m_PlayerGuid(pl_guid), m_BgInstanceGUID(bgInstanceGUID), m_RemoveTime(removeTime), m_BgQueueTypeId(bgQueueTypeId)
169 { }
170
171 virtual bool Execute(uint64 e_time, uint32 p_time) override;
172 virtual void Abort(uint64 e_time) override;
173 private:
178};
179
180#endif
BattlegroundQueueInvitationType
@ BG_QUEUE_INVITATION_TYPE_NO_BALANCE
@ BG_QUEUE_INVITATION_TYPE_EVEN
@ BG_QUEUE_INVITATION_TYPE_BALANCED
BattlegroundQueueGroupTypes
@ BG_QUEUE_PREMADE_HORDE
@ BG_QUEUE_NORMAL_ALLIANCE
@ BG_QUEUE_PREMADE_ALLIANCE
@ BG_QUEUE_NORMAL_HORDE
#define BG_QUEUE_GROUP_TYPES_COUNT
#define COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME
std::list< Battleground * > BGFreeSlotQueueContainer
BattlegroundBracketId
Definition DBCEnums.h:53
@ MAX_BATTLEGROUND_BRACKETS
Definition DBCEnums.h:58
#define TC_GAME_API
Definition Define.h:129
uint64_t uint64
Definition Define.h:153
uint32_t uint32
Definition Define.h:154
uint8 constexpr PVP_TEAMS_COUNT
BattlegroundTypeId
virtual void Abort(uint64 e_time) override
BattlegroundQueueTypeId m_QueueId
virtual bool Execute(uint64 e_time, uint32 p_time) override
BattlegroundTypeId m_BgTypeId
BGQueueInviteEvent(ObjectGuid pl_guid, uint32 BgInstanceGUID, BattlegroundTypeId BgTypeId, uint32 removeTime, BattlegroundQueueTypeId queueId)
virtual bool Execute(uint64 e_time, uint32 p_time) override
virtual void Abort(uint64 e_time) override
BattlegroundQueueTypeId m_BgQueueTypeId
BGQueueRemoveEvent(ObjectGuid pl_guid, uint32 bgInstanceGUID, BattlegroundQueueTypeId bgQueueTypeId, uint32 removeTime)
BattlegroundQueueTypeId GetQueueId() const
QueuedPlayersMap m_QueuedPlayers
BattlegroundQueueTypeId m_queueId
std::list< GroupQueueInfo * > GroupsQueueType
std::map< ObjectGuid, PlayerQueueInfo > QueuedPlayersMap
EventProcessor m_events
Definition Group.h:205
uint32 IsInvitedToBGInstanceGUID
std::map< ObjectGuid, PlayerQueueInfo * > Players
uint32 OpponentsMatchmakerRating
GroupQueueInfo * GroupInfo