OregonCore  revision fb2a440-git
Your Favourite TBC server
BattlegroundMgr.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 __BATTLEGROUNDMGR_H
19 #define __BATTLEGROUNDMGR_H
20 
21 #include "Battleground.h"
22 #include "Policies/Singleton.h"
23 
25 
26 //TODO it is not possible to have this structure, because we should have BattlegroundSet for each queue
27 //so i propose to change this type to array 1..MAX_BATTLEGROUND_TYPES of sets or maps..
28 typedef std::map<uint32, Battleground*> BattlegroundSet;
29 //typedef std::map<uint32, BattlegroundQueue*> BattlegroundQueueSet;
30 typedef std::list<Battleground*> BGFreeSlotQueueType;
31 
32 #define MAX_BATTLEGROUND_QUEUES 7 // for level ranges 10-19, 20-29, 30-39, 40-49, 50-59, 60-69, 70+
33 
34 #define MAX_BATTLEGROUND_TYPES 9 // each BG type will be in array
35 
36 #define MAX_BATTLEGROUND_QUEUE_TYPES 8
37 
38 #define BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY 86400 // seconds in a day
39 
40 struct GroupQueueInfo; // type predefinition
41 struct PlayerQueueInfo // stores information for players in queue
42 {
43  uint32 InviteTime; // first invite time
44  uint32 LastInviteTime; // last invite time
45  uint32 LastOnlineTime; // for tracking and removing offline players from queue after 5 minutes
46  GroupQueueInfo* GroupInfo; // pointer to the associated groupqueueinfo
47 };
48 
49 struct GroupQueueInfo // stores information about the group in queue (also used when joined as solo!)
50 {
51  std::map<uint64, PlayerQueueInfo*> Players; // player queue info map
52  uint32 Team; // Player team (ALLIANCE/HORDE)
53  uint32 BgTypeId; // battleground type id
54  bool IsRated; // rated
55  uint8 ArenaType; // 2v2, 3v3, 5v5 or 0 when BG
56  uint32 ArenaTeamId; // team id if rated match
57  uint32 JoinTime; // time when group was added
58  uint32 IsInvitedToBGInstanceGUID; // was invited to certain BG
59  uint32 ArenaTeamRating; // if rated match, inited to the rating of the team
60  uint32 OpponentsTeamRating; // for rated arena matches
61 };
62 
63 class Battleground;
65 {
66  public:
69 
70  void Update(uint32 bgTypeId, uint32 queue_id, uint8 arenatype = 0, bool isRated = false, uint32 minRating = 0);
71 
72  GroupQueueInfo* AddGroup(Player* leader, uint32 BgTypeId, uint8 ArenaType, bool isRated, uint32 ArenaRating, uint32 ArenaTeamId = 0);
73  void AddPlayer(Player* plr, GroupQueueInfo* ginfo);
74  void RemovePlayer(uint64 guid, bool decreaseInvitedCount);
75  void DecreaseGroupLength(uint32 queueId, uint32 AsGroup);
76  void BGEndedRemoveInvites(Battleground* bg);
77 
78  typedef std::map<uint64, PlayerQueueInfo> QueuedPlayersMap;
79  QueuedPlayersMap m_QueuedPlayers[MAX_BATTLEGROUND_QUEUES];
80 
81  typedef std::list<GroupQueueInfo*> QueuedGroupsList;
82  QueuedGroupsList m_QueuedGroups[MAX_BATTLEGROUND_QUEUES];
83 
84  // class to hold pointers to the groups eligible for a specific selection pool building mode
85  class EligibleGroups : public std::list<GroupQueueInfo*>
86  {
87  public:
88  void Init(QueuedGroupsList* source, uint32 BgTypeId, uint32 side, uint32 MaxPlayers, uint8 ArenaType = 0, bool IsRated = false, uint32 MinRating = 0, uint32 MaxRating = 0, uint32 DisregardTime = 0, uint32 excludeTeam = 0);
89  };
90 
92 
93  // class to select and invite groups to bg
95  {
96  public:
97  void Init(EligibleGroups* curr);
98  void AddGroup(GroupQueueInfo* group);
99  void RemoveGroup(GroupQueueInfo* group);
101  {
102  return PlayerCount;
103  }
104  bool Build(uint32 MinPlayers, uint32 MaxPlayers, EligibleGroups::iterator startitr);
105  public:
106  std::list<GroupQueueInfo*> SelectedGroups;
107  private:
110  };
111 
113  {
120 
121  NUM_SELECTION_POOL_TYPES
122  };
123 
124  SelectionPool m_SelectionPools[NUM_SELECTION_POOL_TYPES];
125 
126  bool BuildSelectionPool(uint32 bgTypeId, uint32 queue_id, uint32 MinPlayers, uint32 MaxPlayers, SelectionPoolBuildMode mode, uint8 ArenaType = 0, bool isRated = false, uint32 MinRating = 0, uint32 MaxRating = 0, uint32 DisregardTime = 0, uint32 excludeTeam = 0);
127 
128  private:
129 
130  bool InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, uint32 side);
131 };
132 
133 /*
134  This class is used to invite player to BG again, when minute lasts from his first invitation
135  it is capable to solve all possibilities
136 */
138 {
139  public:
140  BGQueueInviteEvent(uint64 pl_guid, uint32 BgInstanceGUID) : m_PlayerGuid(pl_guid), m_BgInstanceGUID(BgInstanceGUID) {};
141  virtual ~BGQueueInviteEvent() {};
142 
143  virtual bool Execute(uint64 e_time, uint32 p_time);
144  virtual void Abort(uint64 e_time);
145  private:
148 };
149 
150 /*
151  This class is used to remove player from BG queue after 2 minutes from first invitation
152 */
154 {
155  public:
156  BGQueueRemoveEvent(uint64 pl_guid, uint32 bgInstanceGUID, uint32 playersTeam) : m_PlayerGuid(pl_guid), m_BgInstanceGUID(bgInstanceGUID), m_PlayersTeam(playersTeam) {};
157  virtual ~BGQueueRemoveEvent() {};
158 
159  virtual bool Execute(uint64 e_time, uint32 p_time);
160  virtual void Abort(uint64 e_time);
161  private:
165 };
166 
168 {
169  public:
170  /* Construction */
171  BattlegroundMgr();
172  ~BattlegroundMgr();
173  void Update(uint32 diff);
174 
175  /* Packet Building */
176  void BuildPlayerJoinedBattlegroundPacket(WorldPacket* data, Player* plr);
177  void BuildPlayerLeftBattlegroundPacket(WorldPacket* data, const uint64& guid);
178  void BuildBattlegroundListPacket(WorldPacket* data, uint64 guid, Player* plr, uint32 bgTypeId);
179  void BuildGroupJoinedBattlegroundPacket(WorldPacket* data, uint32 bgTypeId);
180  void BuildUpdateWorldStatePacket(WorldPacket* data, uint32 field, uint32 value);
181  void BuildPvpLogDataPacket(WorldPacket* data, Battleground* bg);
182  void BuildBattlegroundStatusPacket(WorldPacket* data, Battleground* bg, uint32 team, uint8 QueueSlot, uint8 StatusID, uint32 Time1, uint32 Time2, uint32 arenatype = 0, uint8 israted = 0);
183  void BuildPlaySoundPacket(WorldPacket* data, uint32 soundid);
184 
185  /* Player invitation */
186  // called from Queue update, or from Addplayer to queue
187  void InvitePlayer(Player* plr, uint32 bgInstanceGUID, uint32 team);
188 
189  /* Battlegrounds */
190  BattlegroundSet::iterator GetBattlegroundsBegin()
191  {
192  return m_Battlegrounds.begin();
193  };
194  BattlegroundSet::iterator GetBattlegroundsEnd()
195  {
196  return m_Battlegrounds.end();
197  };
198 
200  {
201  if (!InstanceID)
202  return NULL;
203  BattlegroundSet::iterator i = m_Battlegrounds.find(InstanceID);
204  if (i != m_Battlegrounds.end())
205  return i->second;
206  else
207  return NULL;
208  };
209 
210  Battleground* GetBattlegroundTemplate(uint32 bgTypeId);
211  Battleground* CreateNewBattleground(uint32 bgTypeId, uint8 arenaType, bool isRated);
212 
213  uint32 CreateBattleground(uint32 bgTypeId, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam, uint32 LevelMin, uint32 LevelMax, char* BattlegroundName, uint32 MapID, float Team1StartLocX, float Team1StartLocY, float Team1StartLocZ, float Team1StartLocO, float Team2StartLocX, float Team2StartLocY, float Team2StartLocZ, float Team2StartLocO, float StartMaxDist);
214 
216  {
217  m_Battlegrounds[ID] = BG;
218  };
219  void RemoveBattleground(uint32 instanceID);
220 
221  void CreateInitialBattlegrounds();
222  void DeleteAlllBattlegrounds();
223 
224  void SendToBattleground(Player* pl, uint32 bgTypeId);
225 
226  /* Battleground queues */
227  //these queues are instantiated when creating BattlegroundMrg
228  BattlegroundQueue m_BattlegroundQueues[MAX_BATTLEGROUND_QUEUE_TYPES]; // public, because we need to access them in BG handler code
229 
231 
232  void SendAreaSpiritHealerQueryOpcode(Player* pl, Battleground* bg, uint64 guid);
233 
234  bool IsArenaType(uint32 bgTypeId) const;
235  bool IsBattlegroundType(uint32 bgTypeId) const;
236  static uint32 BGQueueTypeId(uint32 bgTypeId, uint8 arenaType);
237  uint32 BGTemplateId(uint32 bgQueueTypeId) const;
238  uint8 BGArenaType(uint32 bgQueueTypeId) const;
239 
241  {
242  return m_MaxRatingDifference;
243  }
245  {
246  return m_RatingDiscardTimer;
247  }
248 
249  void InitAutomaticArenaPointDistribution();
250  void DistributeArenaPoints();
252  {
253  return m_PrematureFinishTimer;
254  }
255  void ToggleArenaTesting();
256  void ToggleTesting();
257  bool isArenaTesting() const
258  {
259  return m_ArenaTesting;
260  }
261  bool isTesting() const
262  {
263  return m_Testing;
264  }
265 
266  void SetHolidayWeekends(uint32 mask);
267  private:
268 
269  /* Battlegrounds */
279  bool m_Testing;
280 };
281 
282 #define sBattlegroundMgr Oregon::Singleton<BattlegroundMgr>::Instance()
283 #endif
284 
ArenaType
Definition: Battleground.h:189
Battleground * GetBattleground(uint32 InstanceID)
uint32 ArenaTeamRating
#define MAX_BATTLEGROUND_QUEUES
std::map< uint64, PlayerQueueInfo > QueuedPlayersMap
GroupQueueInfo * GroupInfo
uint32 m_RatingDiscardTimer
uint32 m_MaxRatingDifference
#define MAX_BATTLEGROUND_TYPES
std::list< GroupQueueInfo * > QueuedGroupsList
bool isArenaTesting() const
std::list< Battleground * > BGFreeSlotQueueType
std::list< GroupQueueInfo * > SelectedGroups
ACE_UINT8 uint8
Definition: Define.h:73
virtual ~BGQueueRemoveEvent()
#define MAX_BATTLEGROUND_QUEUE_TYPES
uint32 m_PrematureFinishTimer
void AddBattleground(uint32 ID, Battleground *BG)
EligibleGroups m_EligibleGroups
etc mysql my cnf *Then change max_allowed_packet to a bigger value
BGQueueRemoveEvent(uint64 pl_guid, uint32 bgInstanceGUID, uint32 playersTeam)
std::map< uint64, PlayerQueueInfo * > Players
std::map< uint32, Battleground * > BattlegroundSet
uint32 GetRatingDiscardTimer() const
uint32 OpponentsTeamRating
ACE_UINT64 uint64
Definition: Define.h:70
uint32 m_NextRatingDiscardUpdate
BattlegroundSet::iterator GetBattlegroundsEnd()
BattlegroundSet::iterator GetBattlegroundsBegin()
uint32 GetPrematureFinishTime() const
bool isTesting() const
virtual ~BGQueueInviteEvent()
ACE_UINT32 uint32
Definition: Define.h:71
uint64 m_NextAutoDistributionTime
BattlegroundSet m_Battlegrounds
uint32 GetMaxRatingDifference() const
BGQueueInviteEvent(uint64 pl_guid, uint32 BgInstanceGUID)
Definition: Player.h:922
uint32 m_AutoDistributionTimeChecker
uint32 IsInvitedToBGInstanceGUID