[6844] Daily quest fixes.
[getmangos.git] / src / game / BattleGroundMgr.h
blob193e5f430b59e542fe6f5f68b2b240ba64cecb9c
1 /*
2 * Copyright (C) 2005-2008 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 "BattleGround.h"
23 #include "Policies/Singleton.h"
25 class BattleGround;
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;
33 #define MAX_BATTLEGROUND_QUEUES 7 // for level ranges 10-19, 20-29, 30-39, 40-49, 50-59, 60-69, 70+
35 #define MAX_BATTLEGROUND_TYPES 9 // each BG type will be in array
37 struct PlayerQueueInfo
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;
49 struct PlayersCount
51 uint32 Alliance;
52 uint32 Horde;
55 template<class _Kty, class _Ty> class bgqueue: public std::map<_Kty, _Ty>
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)
64 class BattleGroundQueue
66 public:
67 BattleGroundQueue();
68 ~BattleGroundQueue();
70 uint32 GetType();
71 void SetType(uint32 type);*/
73 void Update(uint32 bgTypeId, uint32 queue_id);
75 void AddPlayer(Player *plr, uint32 bgTypeId);
76 void RemovePlayer(uint64 guid, bool decreaseInvitedCount);
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];
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
88 class BGQueueInviteEvent : public BasicEvent
90 public:
91 BGQueueInviteEvent(uint64 pl_guid, uint32 BgInstanceGUID) : m_PlayerGuid(pl_guid), m_BgInstanceGUID(BgInstanceGUID) {};
92 virtual ~BGQueueInviteEvent() {};
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;
103 This class is used to remove player from BG queue after 2 minutes from first invitation
105 class BGQueueRemoveEvent : public BasicEvent
107 public:
108 BGQueueRemoveEvent(uint64 pl_guid, uint32 bgInstanceGUID, uint32 playersTeam) : m_PlayerGuid(pl_guid), m_BgInstanceGUID(bgInstanceGUID), m_PlayersTeam(playersTeam) {};
109 virtual ~BGQueueRemoveEvent() {};
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;
120 class BattleGroundMgr
122 public:
123 /* Construction */
124 BattleGroundMgr();
125 ~BattleGroundMgr();
126 void Update(time_t diff);
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);
138 /* Player invitation */
139 // called from Queue update, or from Addplayer to queue
140 void InvitePlayer(Player* plr, uint32 bgInstanceGUID);
142 /* Battlegrounds */
143 BattleGroundSet::iterator GetBattleGroundsBegin() { return m_BattleGrounds.begin(); };
144 BattleGroundSet::iterator GetBattleGroundsEnd() { return m_BattleGrounds.end(); };
146 BattleGround* GetBattleGround(uint8 ID)
148 BattleGroundSet::iterator i = m_BattleGrounds.find(ID);
149 if(i != m_BattleGrounds.end())
150 return i->second;
151 else
152 return NULL;
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);
157 inline void AddBattleGround(uint32 ID, BattleGround* BG) { m_BattleGrounds[ID] = BG; };
159 void CreateInitialBattleGrounds();
161 void SendToBattleGround(Player *pl, uint32 bgTypeId);
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
167 BGFreeSlotQueueType BGFreeSlotQueue[MAX_BATTLEGROUND_TYPES];
169 void SendAreaSpiritHealerQueryOpcode(Player *pl, BattleGround *bg, uint64 guid);
171 private:
173 /* Battlegrounds */
174 BattleGroundSet m_BattleGrounds;
177 #define sBattleGroundMgr MaNGOS::Singleton<BattleGroundMgr>::Instance()
178 #endif