1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
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. |
---|
8 | * |
---|
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. |
---|
13 | * |
---|
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 |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef __BATTLEGROUNDMGR_H |
---|
20 | #define __BATTLEGROUNDMGR_H |
---|
21 | |
---|
22 | #include "BattleGround.h" |
---|
23 | #include "Policies/Singleton.h" |
---|
24 | |
---|
25 | class BattleGround; |
---|
26 | |
---|
27 | //TODO it is not possible to have this structure, because we should have BattlegroundSet for each queue |
---|
28 | //so i propose to change this type to array 1..MAX_BATTLEGROUND_TYPES of sets or maps.. |
---|
29 | typedef std::map<uint32, BattleGround*> BattleGroundSet; |
---|
30 | //typedef std::map<uint32, BattleGroundQueue*> BattleGroundQueueSet; |
---|
31 | typedef std::deque<BattleGround*> BGFreeSlotQueueType; |
---|
32 | |
---|
33 | #define MAX_BATTLEGROUND_QUEUES 7 // for level ranges 10-19, 20-29, 30-39, 40-49, 50-59, 60-69, 70+ |
---|
34 | |
---|
35 | #define MAX_BATTLEGROUND_TYPES 9 // each BG type will be in array |
---|
36 | |
---|
37 | struct PlayerQueueInfo |
---|
38 | { |
---|
39 | uint32 InviteTime; // first invite time |
---|
40 | uint32 LastInviteTime; // last invite time |
---|
41 | uint32 IsInvitedToBGInstanceGUID; // was invited to certain BG |
---|
42 | uint32 LastOnlineTime; // for tracking and removing offline players from queue after 5 minutes |
---|
43 | uint32 Team; // Player team (ALLIANCE/HORDE) |
---|
44 | bool IsRated; |
---|
45 | bool AsGroup; // uint32 GroupId; |
---|
46 | uint8 ArenaType; |
---|
47 | }; |
---|
48 | |
---|
49 | struct PlayersCount |
---|
50 | { |
---|
51 | uint32 Alliance; |
---|
52 | uint32 Horde; |
---|
53 | }; |
---|
54 | |
---|
55 | template<class _Kty, class _Ty> class bgqueue: public std::map<_Kty, _Ty> |
---|
56 | { |
---|
57 | public: |
---|
58 | uint32 Alliance; |
---|
59 | uint32 Horde; |
---|
60 | //bool Ready; // not used now |
---|
61 | //uint32 AverageTime; //not already implemented (it should be average time in queue for last 10 players) |
---|
62 | }; |
---|
63 | |
---|
64 | class BattleGroundQueue |
---|
65 | { |
---|
66 | public: |
---|
67 | BattleGroundQueue(); |
---|
68 | ~BattleGroundQueue(); |
---|
69 | /* |
---|
70 | uint32 GetType(); |
---|
71 | void SetType(uint32 type);*/ |
---|
72 | |
---|
73 | void Update(uint32 bgTypeId, uint32 queue_id); |
---|
74 | |
---|
75 | void AddPlayer(Player *plr, uint32 bgTypeId); |
---|
76 | void RemovePlayer(uint64 guid, bool decreaseInvitedCount); |
---|
77 | |
---|
78 | typedef bgqueue<uint64, PlayerQueueInfo> QueuedPlayersMap; |
---|
79 | QueuedPlayersMap m_QueuedPlayers[MAX_BATTLEGROUND_QUEUES]; |
---|
80 | typedef std::list<uint64> PlayerGuidsSortedByTimeQueue; |
---|
81 | PlayerGuidsSortedByTimeQueue m_PlayersSortedByWaitTime[MAX_BATTLEGROUND_QUEUES]; |
---|
82 | }; |
---|
83 | |
---|
84 | /* |
---|
85 | This class is used to invite player to BG again, when minute lasts from his first invitation |
---|
86 | it is capable to solve all possibilities |
---|
87 | */ |
---|
88 | class BGQueueInviteEvent : public BasicEvent |
---|
89 | { |
---|
90 | public: |
---|
91 | BGQueueInviteEvent(uint64 pl_guid, uint32 BgInstanceGUID) : m_PlayerGuid(pl_guid), m_BgInstanceGUID(BgInstanceGUID) {}; |
---|
92 | virtual ~BGQueueInviteEvent() {}; |
---|
93 | |
---|
94 | virtual bool Execute(uint64 e_time, uint32 p_time); |
---|
95 | virtual void Abort(uint64 e_time); |
---|
96 | private: |
---|
97 | uint64 m_PlayerGuid; |
---|
98 | uint32 m_BgInstanceGUID; |
---|
99 | |
---|
100 | }; |
---|
101 | |
---|
102 | /* |
---|
103 | This class is used to remove player from BG queue after 2 minutes from first invitation |
---|
104 | */ |
---|
105 | class BGQueueRemoveEvent : public BasicEvent |
---|
106 | { |
---|
107 | public: |
---|
108 | BGQueueRemoveEvent(uint64 pl_guid, uint32 bgInstanceGUID, uint32 playersTeam) : m_PlayerGuid(pl_guid), m_BgInstanceGUID(bgInstanceGUID), m_PlayersTeam(playersTeam) {}; |
---|
109 | virtual ~BGQueueRemoveEvent() {}; |
---|
110 | |
---|
111 | virtual bool Execute(uint64 e_time, uint32 p_time); |
---|
112 | virtual void Abort(uint64 e_time); |
---|
113 | private: |
---|
114 | uint64 m_PlayerGuid; |
---|
115 | uint32 m_BgInstanceGUID; |
---|
116 | uint32 m_PlayersTeam; |
---|
117 | }; |
---|
118 | |
---|
119 | |
---|
120 | class BattleGroundMgr |
---|
121 | { |
---|
122 | public: |
---|
123 | /* Construction */ |
---|
124 | BattleGroundMgr(); |
---|
125 | ~BattleGroundMgr(); |
---|
126 | void Update(time_t diff); |
---|
127 | |
---|
128 | /* Packet Building */ |
---|
129 | void BuildPlayerJoinedBattleGroundPacket(WorldPacket *data, Player *plr); |
---|
130 | void BuildPlayerLeftBattleGroundPacket(WorldPacket *data, Player *plr); |
---|
131 | void BuildBattleGroundListPacket(WorldPacket *data, uint64 guid, Player *plr, uint32 bgTypeId); |
---|
132 | void BuildGroupJoinedBattlegroundPacket(WorldPacket *data, uint32 bgTypeId); |
---|
133 | void BuildUpdateWorldStatePacket(WorldPacket *data, uint32 field, uint32 value); |
---|
134 | void BuildPvpLogDataPacket(WorldPacket *data, BattleGround *bg); |
---|
135 | void BuildBattleGroundStatusPacket(WorldPacket *data, BattleGround *bg, uint32 team, uint8 QueueSlot, uint8 StatusID, uint32 Time1, uint32 Time2); |
---|
136 | void BuildPlaySoundPacket(WorldPacket *data, uint32 soundid); |
---|
137 | |
---|
138 | /* Player invitation */ |
---|
139 | // called from Queue update, or from Addplayer to queue |
---|
140 | void InvitePlayer(Player* plr, uint32 bgInstanceGUID); |
---|
141 | |
---|
142 | /* Battlegrounds */ |
---|
143 | BattleGroundSet::iterator GetBattleGroundsBegin() { return m_BattleGrounds.begin(); }; |
---|
144 | BattleGroundSet::iterator GetBattleGroundsEnd() { return m_BattleGrounds.end(); }; |
---|
145 | |
---|
146 | BattleGround* GetBattleGround(uint8 ID) |
---|
147 | { |
---|
148 | BattleGroundSet::iterator i = m_BattleGrounds.find(ID); |
---|
149 | if(i != m_BattleGrounds.end()) |
---|
150 | return i->second; |
---|
151 | else |
---|
152 | return NULL; |
---|
153 | }; |
---|
154 | |
---|
155 | 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); |
---|
156 | |
---|
157 | inline void AddBattleGround(uint32 ID, BattleGround* BG) { m_BattleGrounds[ID] = BG; }; |
---|
158 | |
---|
159 | void CreateInitialBattleGrounds(); |
---|
160 | |
---|
161 | void SendToBattleGround(Player *pl, uint32 bgTypeId); |
---|
162 | |
---|
163 | /* Battleground queues */ |
---|
164 | //these queues are instantiated when creating BattlegroundMrg |
---|
165 | BattleGroundQueue m_BattleGroundQueues[MAX_BATTLEGROUND_TYPES]; // public, because we need to access them in BG handler code |
---|
166 | |
---|
167 | BGFreeSlotQueueType BGFreeSlotQueue[MAX_BATTLEGROUND_TYPES]; |
---|
168 | |
---|
169 | void SendAreaSpiritHealerQueryOpcode(Player *pl, BattleGround *bg, uint64 guid); |
---|
170 | |
---|
171 | private: |
---|
172 | |
---|
173 | /* Battlegrounds */ |
---|
174 | BattleGroundSet m_BattleGrounds; |
---|
175 | }; |
---|
176 | |
---|
177 | #define sBattleGroundMgr MaNGOS::Singleton<BattleGroundMgr>::Instance() |
---|
178 | #endif |
---|