[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / BattleGroundMgr.h
blobdf5e9668c799ec3c197c0744e701cd668bcbe41e
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef __BATTLEGROUNDMGR_H
20 #define __BATTLEGROUNDMGR_H
22 #include "Common.h"
23 #include "BattleGround.h"
25 //TODO it is not possible to have this structure, because we should have BattlegroundSet for each queue
26 //so i propose to change this type to array 1..MAX_BATTLEGROUND_TYPES of sets or maps..
27 typedef std::map<uint32, BattleGround*> BattleGroundSet;
28 //typedef std::map<uint32, BattleGroundQueue*> BattleGroundQueueSet;
29 typedef std::deque<BattleGround*> BGFreeSlotQueueType;
31 typedef UNORDERED_MAP<uint32, BattleGroundTypeId> BattleMastersMap;
33 #define MAX_BATTLEGROUND_QUEUES 8 // for level ranges 10-19, 20-29, 30-39, 40-49, 50-59, 60-69, 70-79, 80+
35 #define MAX_BATTLEGROUND_QUEUE_TYPES 9
37 #define BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY 86400 // seconds in a day
39 struct GroupQueueInfo; // type predefinition
40 struct PlayerQueueInfo // stores information for players in queue
42 uint32 InviteTime; // first invite time
43 uint32 LastInviteTime; // last invite time
44 uint32 LastOnlineTime; // for tracking and removing offline players from queue after 5 minutes
45 GroupQueueInfo * GroupInfo; // pointer to the associated groupqueueinfo
48 struct GroupQueueInfo // stores information about the group in queue (also used when joined as solo!)
50 std::map<uint64, PlayerQueueInfo*> Players; // player queue info map
51 uint32 Team; // Player team (ALLIANCE/HORDE)
52 BattleGroundTypeId BgTypeId; // battleground type id
53 bool IsRated; // rated
54 uint8 ArenaType; // 2v2, 3v3, 5v5 or 0 when BG
55 uint32 ArenaTeamId; // team id if rated match
56 uint32 JoinTime; // time when group was added
57 uint32 IsInvitedToBGInstanceGUID; // was invited to certain BG
58 uint32 ArenaTeamRating; // if rated match, inited to the rating of the team
59 uint32 OpponentsTeamRating; // for rated arena matches
62 class BattleGround;
63 class BattleGroundQueue
65 public:
66 BattleGroundQueue();
67 ~BattleGroundQueue();
69 void Update(BattleGroundTypeId bgTypeId, uint32 queue_id, uint8 arenatype = 0, bool isRated = false, uint32 minRating = 0);
71 GroupQueueInfo * AddGroup(Player * leader, BattleGroundTypeId bgTypeId, uint8 ArenaType, bool isRated, uint32 ArenaRating, uint32 ArenaTeamId = 0);
72 void AddPlayer(Player *plr, GroupQueueInfo *ginfo);
73 void RemovePlayer(const uint64& guid, bool decreaseInvitedCount);
74 void DecreaseGroupLength(uint32 queueId, uint32 AsGroup);
75 void BGEndedRemoveInvites(BattleGround * bg);
76 void AnnounceWorld(GroupQueueInfo *ginfo, const uint64& playerGUID, bool isAddedToQueue);
78 typedef std::map<uint64, PlayerQueueInfo> QueuedPlayersMap;
79 QueuedPlayersMap m_QueuedPlayers[MAX_BATTLEGROUND_QUEUES];
81 typedef std::list<GroupQueueInfo*> QueuedGroupsList;
82 QueuedGroupsList m_QueuedGroups[MAX_BATTLEGROUND_QUEUES];
84 // class to hold pointers to the groups eligible for a specific selection pool building mode
85 class EligibleGroups : public std::list<GroupQueueInfo *>
87 public:
88 void Init(QueuedGroupsList * source, BattleGroundTypeId BgTypeId, uint32 side, uint32 MaxPlayers, uint8 ArenaType = 0, bool IsRated = false, uint32 MinRating = 0, uint32 MaxRating = 0, uint32 DisregardTime = 0, uint32 excludeTeam = 0);
89 void RemoveGroup(GroupQueueInfo * ginfo);
92 EligibleGroups m_EligibleGroups;
94 // class to select and invite groups to bg
95 class SelectionPool
97 public:
98 void Init();
99 void AddGroup(GroupQueueInfo * group);
100 GroupQueueInfo * GetMaximalGroup();
101 void RemoveGroup(GroupQueueInfo * group);
102 uint32 GetPlayerCount() const {return PlayerCount;}
103 public:
104 std::list<GroupQueueInfo *> SelectedGroups;
105 private:
106 uint32 PlayerCount;
107 GroupQueueInfo * MaxGroup;
110 enum SelectionPoolBuildMode
112 NORMAL_ALLIANCE,
113 NORMAL_HORDE,
114 ONESIDE_ALLIANCE_TEAM1,
115 ONESIDE_ALLIANCE_TEAM2,
116 ONESIDE_HORDE_TEAM1,
117 ONESIDE_HORDE_TEAM2,
119 NUM_SELECTION_POOL_TYPES
122 SelectionPool m_SelectionPools[NUM_SELECTION_POOL_TYPES];
124 bool BuildSelectionPool(BattleGroundTypeId 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);
126 private:
128 bool InviteGroupToBG(GroupQueueInfo * ginfo, BattleGround * bg, uint32 side);
132 This class is used to invite player to BG again, when minute lasts from his first invitation
133 it is capable to solve all possibilities
135 class BGQueueInviteEvent : public BasicEvent
137 public:
138 BGQueueInviteEvent(const uint64& pl_guid, uint32 BgInstanceGUID) : m_PlayerGuid(pl_guid), m_BgInstanceGUID(BgInstanceGUID) {};
139 virtual ~BGQueueInviteEvent() {};
141 virtual bool Execute(uint64 e_time, uint32 p_time);
142 virtual void Abort(uint64 e_time);
143 private:
144 uint64 m_PlayerGuid;
145 uint32 m_BgInstanceGUID;
149 This class is used to remove player from BG queue after 2 minutes from first invitation
151 class BGQueueRemoveEvent : public BasicEvent
153 public:
154 BGQueueRemoveEvent(const uint64& pl_guid, uint32 bgInstanceGUID, uint32 playersTeam) :
155 m_PlayerGuid(pl_guid), m_BgInstanceGUID(bgInstanceGUID), m_PlayersTeam(playersTeam)
158 virtual ~BGQueueRemoveEvent() {};
160 virtual bool Execute(uint64 e_time, uint32 p_time);
161 virtual void Abort(uint64 e_time);
162 private:
163 uint64 m_PlayerGuid;
164 uint32 m_BgInstanceGUID;
165 uint32 m_PlayersTeam;
168 class BattleGroundMgr
170 public:
171 /* Construction */
172 BattleGroundMgr();
173 ~BattleGroundMgr();
174 void Update(uint32 diff);
176 /* Packet Building */
177 void BuildPlayerJoinedBattleGroundPacket(WorldPacket *data, Player *plr);
178 void BuildPlayerLeftBattleGroundPacket(WorldPacket *data, Player *plr);
179 void BuildBattleGroundListPacket(WorldPacket *data, const uint64& guid, Player *plr, BattleGroundTypeId bgTypeId);
180 void BuildGroupJoinedBattlegroundPacket(WorldPacket *data, BattleGroundTypeId bgTypeId);
181 void BuildUpdateWorldStatePacket(WorldPacket *data, uint32 field, uint32 value);
182 void BuildPvpLogDataPacket(WorldPacket *data, BattleGround *bg);
183 void BuildBattleGroundStatusPacket(WorldPacket *data, BattleGround *bg, uint32 team, uint8 QueueSlot, uint8 StatusID, uint32 Time1, uint32 Time2, uint32 arenatype = 0, uint8 israted = 0);
184 void BuildPlaySoundPacket(WorldPacket *data, uint32 soundid);
186 void SendAreaSpiritHealerQueryOpcode(Player *pl, BattleGround *bg, const uint64& guid);
187 /* Player invitation */
188 // called from Queue update, or from Addplayer to queue
189 void InvitePlayer(Player* plr, uint32 bgInstanceGUID, uint32 team);
191 /* Battlegrounds */
192 BattleGroundSet::iterator GetBattleGroundsBegin() { return m_BattleGrounds.begin(); };
193 BattleGroundSet::iterator GetBattleGroundsEnd() { return m_BattleGrounds.end(); };
195 BattleGround* GetBattleGround(uint32 InstanceID)
197 BattleGroundSet::iterator i = m_BattleGrounds.find(InstanceID);
198 return ( (i != m_BattleGrounds.end()) ? i->second : NULL );
201 BattleGround * GetBattleGroundTemplate(BattleGroundTypeId bgTypeId);
202 BattleGround * CreateNewBattleGround(BattleGroundTypeId bgTypeId);
204 uint32 CreateBattleGround(BattleGroundTypeId bgTypeId, bool IsArena, 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);
206 void AddBattleGround(uint32 InstanceID, BattleGround* BG) { m_BattleGrounds[InstanceID] = BG; };
207 void RemoveBattleGround(uint32 instanceID) { m_BattleGrounds.erase(instanceID); }
209 void CreateInitialBattleGrounds();
210 void DeleteAlllBattleGrounds();
212 void SendToBattleGround(Player *pl, uint32 InstanceID);
214 /* Battleground queues */
215 //these queues are instantiated when creating BattlegroundMrg
216 BattleGroundQueue m_BattleGroundQueues[MAX_BATTLEGROUND_QUEUE_TYPES]; // public, because we need to access them in BG handler code
218 BGFreeSlotQueueType BGFreeSlotQueue[MAX_BATTLEGROUND_TYPE_ID];
220 uint32 GetMaxRatingDifference() const;
221 uint32 GetRatingDiscardTimer() const;
222 uint32 GetPrematureFinishTime() const;
224 void InitAutomaticArenaPointDistribution();
225 void DistributeArenaPoints();
226 void ToggleArenaTesting();
227 void ToggleTesting();
229 void LoadBattleMastersEntry();
230 BattleGroundTypeId GetBattleMasterBG(uint32 entry) const
232 BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry);
233 if(itr != mBattleMastersMap.end())
234 return itr->second;
235 return BATTLEGROUND_WS;
238 bool isArenaTesting() const { return m_ArenaTesting; }
239 bool isTesting() const { return m_Testing; }
241 static bool IsArenaType(BattleGroundTypeId bgTypeId);
242 static bool IsBattleGroundType(BattleGroundTypeId bgTypeId) { return !BattleGroundMgr::IsArenaType(bgTypeId); }
243 static BattleGroundQueueTypeId BGQueueTypeId(BattleGroundTypeId bgTypeId, uint8 arenaType);
244 static BattleGroundTypeId BGTemplateId(BattleGroundQueueTypeId bgQueueTypeId);
245 static uint8 BGArenaType(BattleGroundQueueTypeId bgQueueTypeId);
246 private:
247 BattleMastersMap mBattleMastersMap;
249 /* Battlegrounds */
250 BattleGroundSet m_BattleGrounds;
251 uint32 m_NextRatingDiscardUpdate;
252 uint64 m_NextAutoDistributionTime;
253 uint32 m_AutoDistributionTimeChecker;
254 bool m_ArenaTesting;
255 bool m_Testing;
258 #define sBattleGroundMgr MaNGOS::Singleton<BattleGroundMgr>::Instance()
259 #endif