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 bool IsRated; // rated
43 uint32 ArenaTeamId; // team id if rated match
44 uint32 JoinTime; // time when group was added
45 uint32 RemoveInviteTime; // time when we will remove invite for players in group
46 uint32 IsInvitedToBGInstanceGUID; // was invited to certain BG
47 uint32 ArenaTeamRating; // if rated match, inited to the rating of the team
48 uint32 ArenaMatchmakerRating; // if rated match, inited to the rating of the team
49 uint32 OpponentsTeamRating; // for rated arena matches
50 uint32 OpponentsMatchmakerRating; // for rated arena matches
51 uint32 PreviousOpponentsTeamId; // excluded from the current queue until the timer is met
52};
53
61#define BG_QUEUE_GROUP_TYPES_COUNT 4
62
64{
65 BG_QUEUE_INVITATION_TYPE_NO_BALANCE = 0, // no balance: N+M vs N players
66 BG_QUEUE_INVITATION_TYPE_BALANCED = 1, // teams balanced: N+1 vs N players
67 BG_QUEUE_INVITATION_TYPE_EVEN = 2 // teams even: N vs N players
68};
69
70class Battleground;
72{
73 public:
76
77 void BattlegroundQueueUpdate(uint32 diff, bool isRated = false, uint32 minRating = 0);
78 void UpdateEvents(uint32 diff);
79
80 void FillPlayersToBG(Battleground* bg);
81 bool CheckPremadeMatch(uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam);
82 bool CheckNormalMatch(Battleground* bg_template, uint32 minPlayers, uint32 maxPlayers);
83 bool CheckSkirmishForSameFaction(uint32 minPlayersPerTeam);
84 GroupQueueInfo* AddGroup(Player* leader, Group const* group, PvPDifficultyEntry const* bracketEntry, bool isRated, bool isPremade, uint32 ArenaRating, uint32 MatchmakerRating, uint32 ArenaTeamId = 0, uint32 OpponentsArenaTeamId = 0);
85 void RemovePlayer(ObjectGuid guid, bool decreaseInvitedCount);
86 bool IsPlayerInvited(ObjectGuid pl_guid, const uint32 bgInstanceGuid, const uint32 removeTime);
87 bool GetPlayerGroupInfoData(ObjectGuid guid, GroupQueueInfo* ginfo);
88 void PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo);
89 uint32 GetAverageQueueWaitTime(GroupQueueInfo* ginfo) const;
90
91 typedef std::map<ObjectGuid, PlayerQueueInfo> QueuedPlayersMap;
93
94 //do NOT use deque because deque.erase() invalidates ALL iterators
95 typedef std::list<GroupQueueInfo*> GroupsQueueType;
96
97 /*
98 This two dimensional array is used to store All queued groups
99 First dimension specifies the bgTypeId
100 Second dimension specifies the player's group types -
101 BG_QUEUE_PREMADE_ALLIANCE is used for premade alliance groups and alliance rated arena teams
102 BG_QUEUE_PREMADE_HORDE is used for premade horde groups and horde rated arena teams
103 BG_QUEUE_NORMAL_ALLIANCE is used for normal (or small) alliance groups or non-rated arena matches
104 BG_QUEUE_NORMAL_HORDE is used for normal (or small) horde groups or non-rated arena matches
105 */
107
108 // class to select and invite groups to bg
110 {
111 public:
112 SelectionPool(): PlayerCount(0) { }
113 void Init();
114 bool AddGroup(GroupQueueInfo* ginfo, uint32 desiredCount);
115 bool KickGroup(uint32 size);
116 uint32 GetPlayerCount() const {return PlayerCount;}
117 public:
119 private:
121 };
122
123 //one selection pool for horde, other one for alliance
125 uint32 GetPlayersInQueue(TeamId id);
126
127 BattlegroundQueueTypeId GetQueueId() const { return m_queueId; }
128 private:
129
131
132 bool InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, Team side);
134 uint32 m_WaitTimeLastPlayer[PVP_TEAMS_COUNT];
135 uint32 m_SumOfWaitTimes[PVP_TEAMS_COUNT];
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, uint32 removeTime, BattlegroundQueueTypeId queueId) :
149 m_PlayerGuid(pl_guid), m_BgInstanceGUID(BgInstanceGUID), m_BgTypeId(BgTypeId), m_RemoveTime(removeTime), m_QueueId(queueId)
150 { }
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, BattlegroundQueueTypeId bgQueueTypeId, uint32 removeTime)
172 : m_PlayerGuid(pl_guid), m_BgInstanceGUID(bgInstanceGUID), m_RemoveTime(removeTime), m_BgQueueTypeId(bgQueueTypeId)
173 { }
174
176
177 virtual bool Execute(uint64 e_time, uint32 p_time) override;
178 virtual void Abort(uint64 e_time) override;
179 private:
184};
185
186#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
#define TC_GAME_API
Definition Define.h:114
uint64_t uint64
Definition Define.h:132
uint32_t uint32
Definition Define.h:133
TeamId
uint8 constexpr PVP_TEAMS_COUNT
BattlegroundTypeId
BattlegroundQueueTypeId m_QueueId
BattlegroundTypeId m_BgTypeId
BGQueueInviteEvent(ObjectGuid pl_guid, uint32 BgInstanceGUID, BattlegroundTypeId BgTypeId, uint32 removeTime, BattlegroundQueueTypeId queueId)
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:165
uint32 IsInvitedToBGInstanceGUID
std::map< ObjectGuid, PlayerQueueInfo * > Players
uint32 PreviousOpponentsTeamId
uint32 OpponentsMatchmakerRating
GroupQueueInfo * GroupInfo