diff options
Diffstat (limited to 'src/game/BattleGroundMgr.h')
-rw-r--r-- | src/game/BattleGroundMgr.h | 219 |
1 files changed, 115 insertions, 104 deletions
diff --git a/src/game/BattleGroundMgr.h b/src/game/BattleGroundMgr.h index 5edcc1457d3..9c38fea1ad4 100644 --- a/src/game/BattleGroundMgr.h +++ b/src/game/BattleGroundMgr.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,30 +21,24 @@ #ifndef __BATTLEGROUNDMGR_H #define __BATTLEGROUNDMGR_H -#include "BattleGround.h" +#include "Common.h" #include "Policies/Singleton.h" -class BattleGround; +#include "BattleGround.h" -//TODO it is not possible to have this structure, because we should have BattlegroundSet for each queue -//so i propose to change this type to array 1..MAX_BATTLEGROUND_TYPES of sets or maps.. typedef std::map<uint32, BattleGround*> BattleGroundSet; -//typedef std::map<uint32, BattleGroundQueue*> BattleGroundQueueSet; -typedef std::deque<BattleGround*> BGFreeSlotQueueType; - -#define MAX_BATTLEGROUND_QUEUES 7 // for level ranges 10-19, 20-29, 30-39, 40-49, 50-59, 60-69, 70+ -#define MAX_BATTLEGROUND_TYPES 9 // each BG type will be in array +//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 +typedef std::list<BattleGround*> BGFreeSlotQueueType; -#define MAX_BATTLEGROUND_QUEUE_TYPES 8 +typedef UNORDERED_MAP<uint32, BattleGroundTypeId> BattleMastersMap; -#define BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY 86400 // seconds in a day +#define BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY 86400 // seconds in a day +#define COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME 10 struct GroupQueueInfo; // type predefinition struct PlayerQueueInfo // stores information for players in queue { - uint32 InviteTime; // first invite time - uint32 LastInviteTime; // last invite time uint32 LastOnlineTime; // for tracking and removing offline players from queue after 5 minutes GroupQueueInfo * GroupInfo; // pointer to the associated groupqueueinfo }; @@ -53,16 +47,26 @@ struct GroupQueueInfo // stores informatio { std::map<uint64, PlayerQueueInfo*> Players; // player queue info map uint32 Team; // Player team (ALLIANCE/HORDE) - uint32 BgTypeId; // battleground type id + BattleGroundTypeId BgTypeId; // battleground type id bool IsRated; // rated uint8 ArenaType; // 2v2, 3v3, 5v5 or 0 when BG uint32 ArenaTeamId; // team id if rated match uint32 JoinTime; // time when group was added + uint32 RemoveInviteTime; // time when we will remove invite for players in group uint32 IsInvitedToBGInstanceGUID; // was invited to certain BG uint32 ArenaTeamRating; // if rated match, inited to the rating of the team uint32 OpponentsTeamRating; // for rated arena matches }; +enum BattleGroundQueueGroupTypes +{ + BG_QUEUE_PREMADE_ALLIANCE = 0, + BG_QUEUE_PREMADE_HORDE = 1, + BG_QUEUE_NORMAL_ALLIANCE = 2, + BG_QUEUE_NORMAL_HORDE = 3 +}; +#define BG_QUEUE_GROUP_TYPES_COUNT 4 + class BattleGround; class BattleGroundQueue { @@ -70,64 +74,61 @@ class BattleGroundQueue BattleGroundQueue(); ~BattleGroundQueue(); - void Update(uint32 bgTypeId, uint32 queue_id, uint8 arenatype = 0, bool isRated = false, uint32 minRating = 0); + void Update(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id, uint8 arenaType = 0, bool isRated = false, uint32 minRating = 0); - GroupQueueInfo * AddGroup(Player * leader, uint32 BgTypeId, uint8 ArenaType, bool isRated, uint32 ArenaRating, uint32 ArenaTeamId = 0); + void FillPlayersToBG(BattleGround* bg, BGQueueIdBasedOnLevel queue_id); + bool CheckPremadeMatch(BGQueueIdBasedOnLevel queue_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam); + bool CheckNormalMatch(BattleGround* bg_template, BGQueueIdBasedOnLevel queue_id, uint32 minPlayers, uint32 maxPlayers); + bool CheckSkirmishForSameFaction(BGQueueIdBasedOnLevel queue_id, uint32 minPlayersPerTeam); + GroupQueueInfo * AddGroup(Player * leader, BattleGroundTypeId bgTypeId, uint8 ArenaType, bool isRated, bool isPremade, uint32 ArenaRating, uint32 ArenaTeamId = 0); void AddPlayer(Player *plr, GroupQueueInfo *ginfo); - void RemovePlayer(uint64 guid, bool decreaseInvitedCount); + void RemovePlayer(const uint64& guid, bool decreaseInvitedCount); + void PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, BGQueueIdBasedOnLevel queue_id); + uint32 GetAverageQueueWaitTime(GroupQueueInfo* ginfo, BGQueueIdBasedOnLevel queue_id); + void DecreaseGroupLength(uint32 queueId, uint32 AsGroup); - void BGEndedRemoveInvites(BattleGround * bg); + void AnnounceWorld(GroupQueueInfo *ginfo, const uint64& playerGUID, bool isAddedToQueue); typedef std::map<uint64, PlayerQueueInfo> QueuedPlayersMap; - QueuedPlayersMap m_QueuedPlayers[MAX_BATTLEGROUND_QUEUES]; - - typedef std::list<GroupQueueInfo*> QueuedGroupsList; - QueuedGroupsList m_QueuedGroups[MAX_BATTLEGROUND_QUEUES]; - - // class to hold pointers to the groups eligible for a specific selection pool building mode - class EligibleGroups : public std::list<GroupQueueInfo *> - { - public: - 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); - }; - - EligibleGroups m_EligibleGroups; + QueuedPlayersMap m_QueuedPlayers; + + //we need constant add to begin and constant remove / add from the end, therefore deque suits our problem well + typedef std::list<GroupQueueInfo*> GroupsQueueType; + + /* + This two dimensional array is used to store All queued groups + First dimension specifies the bgTypeId + Second dimension specifies the player's group types - + BG_QUEUE_PREMADE_ALLIANCE is used for premade alliance groups and alliance rated arena teams + BG_QUEUE_PREMADE_HORDE is used for premade horde groups and horde rated arena teams + BG_QUEUE_NORMAL_ALLIANCE is used for normal (or small) alliance groups or non-rated arena matches + BG_QUEUE_NORMAL_HORDE is used for normal (or small) horde groups or non-rated arena matches + */ + GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_QUEUES][BG_QUEUE_GROUP_TYPES_COUNT]; // class to select and invite groups to bg class SelectionPool { public: - void Init(EligibleGroups * curr); - void AddGroup(GroupQueueInfo * group); - void RemoveGroup(GroupQueueInfo * group); + void Init(); + bool AddGroup(GroupQueueInfo *ginfo, uint32 desiredCount); + bool KickGroup(uint32 size); uint32 GetPlayerCount() const {return PlayerCount;} - bool Build(uint32 MinPlayers, uint32 MaxPlayers, EligibleGroups::iterator startitr); public: - std::list<GroupQueueInfo *> SelectedGroups; + GroupsQueueType SelectedGroups; private: uint32 PlayerCount; - EligibleGroups * m_CurrEligGroups; - }; - - enum SelectionPoolBuildMode - { - NORMAL_ALLIANCE, - NORMAL_HORDE, - ONESIDE_ALLIANCE_TEAM1, - ONESIDE_ALLIANCE_TEAM2, - ONESIDE_HORDE_TEAM1, - ONESIDE_HORDE_TEAM2, - - NUM_SELECTION_POOL_TYPES }; - SelectionPool m_SelectionPools[NUM_SELECTION_POOL_TYPES]; - - 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); + //one selection pool for horde, other one for alliance + SelectionPool m_SelectionPools[BG_TEAMS_COUNT]; private: bool InviteGroupToBG(GroupQueueInfo * ginfo, BattleGround * bg, uint32 side); + uint32 m_WaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_QUEUES][COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME]; + uint32 m_WaitTimeLastPlayer[BG_TEAMS_COUNT][MAX_BATTLEGROUND_QUEUES]; + uint32 m_SumOfWaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_QUEUES]; }; /* @@ -137,7 +138,10 @@ class BattleGroundQueue class BGQueueInviteEvent : public BasicEvent { public: - BGQueueInviteEvent(uint64 pl_guid, uint32 BgInstanceGUID) : m_PlayerGuid(pl_guid), m_BgInstanceGUID(BgInstanceGUID) {}; + BGQueueInviteEvent(const uint64& pl_guid, uint32 BgInstanceGUID, BattleGroundTypeId BgTypeId, uint32 removeTime) : + m_PlayerGuid(pl_guid), m_BgInstanceGUID(BgInstanceGUID), m_BgTypeId(BgTypeId), m_RemoveTime(removeTime) + { + }; virtual ~BGQueueInviteEvent() {}; virtual bool Execute(uint64 e_time, uint32 p_time); @@ -145,23 +149,32 @@ class BGQueueInviteEvent : public BasicEvent private: uint64 m_PlayerGuid; uint32 m_BgInstanceGUID; + uint32 m_RemoveTime; + BattleGroundTypeId m_BgTypeId; }; /* - This class is used to remove player from BG queue after 2 minutes from first invitation + This class is used to remove player from BG queue after 1 minute 20 seconds from first invitation + We must store removeInvite time in case player left queue and joined and is invited again + We must store bgQueueTypeId, because battleground can be deleted already, when player entered it */ class BGQueueRemoveEvent : public BasicEvent { public: - BGQueueRemoveEvent(uint64 pl_guid, uint32 bgInstanceGUID, uint32 playersTeam) : m_PlayerGuid(pl_guid), m_BgInstanceGUID(bgInstanceGUID), m_PlayersTeam(playersTeam) {}; - virtual ~BGQueueRemoveEvent() {}; + BGQueueRemoveEvent(const uint64& pl_guid, uint32 bgInstanceGUID, BattleGroundTypeId BgTypeId, BattleGroundQueueTypeId bgQueueTypeId, uint32 removeTime) + : m_PlayerGuid(pl_guid), m_BgInstanceGUID(bgInstanceGUID), m_RemoveTime(removeTime), m_BgTypeId(BgTypeId), m_BgQueueTypeId(bgQueueTypeId) + {} + + virtual ~BGQueueRemoveEvent() {} virtual bool Execute(uint64 e_time, uint32 p_time); virtual void Abort(uint64 e_time); private: uint64 m_PlayerGuid; uint32 m_BgInstanceGUID; - uint32 m_PlayersTeam; + uint32 m_RemoveTime; + BattleGroundTypeId m_BgTypeId; + BattleGroundQueueTypeId m_BgQueueTypeId; }; class BattleGroundMgr @@ -170,83 +183,81 @@ class BattleGroundMgr /* Construction */ BattleGroundMgr(); ~BattleGroundMgr(); - void Update(time_t diff); + void Update(uint32 diff); /* Packet Building */ void BuildPlayerJoinedBattleGroundPacket(WorldPacket *data, Player *plr); - void BuildPlayerLeftBattleGroundPacket(WorldPacket *data, Player *plr); - void BuildBattleGroundListPacket(WorldPacket *data, uint64 guid, Player *plr, uint32 bgTypeId); - void BuildGroupJoinedBattlegroundPacket(WorldPacket *data, uint32 bgTypeId); + void BuildPlayerLeftBattleGroundPacket(WorldPacket *data, const uint64& guid); + void BuildBattleGroundListPacket(WorldPacket *data, const uint64& guid, Player *plr, BattleGroundTypeId bgTypeId, uint8 fromWhere); + void BuildGroupJoinedBattlegroundPacket(WorldPacket *data, BattleGroundTypeId bgTypeId); void BuildUpdateWorldStatePacket(WorldPacket *data, uint32 field, uint32 value); void BuildPvpLogDataPacket(WorldPacket *data, BattleGround *bg); - void BuildBattleGroundStatusPacket(WorldPacket *data, BattleGround *bg, uint32 team, uint8 QueueSlot, uint8 StatusID, uint32 Time1, uint32 Time2, uint32 arenatype = 0, uint8 israted = 0); + void BuildBattleGroundStatusPacket(WorldPacket *data, BattleGround *bg, uint8 QueueSlot, uint8 StatusID, uint32 Time1, uint32 Time2, uint8 arenatype); void BuildPlaySoundPacket(WorldPacket *data, uint32 soundid); - - /* Player invitation */ - // called from Queue update, or from Addplayer to queue - void InvitePlayer(Player* plr, uint32 bgInstanceGUID, uint32 team); + void SendAreaSpiritHealerQueryOpcode(Player *pl, BattleGround *bg, const uint64& guid); /* Battlegrounds */ - BattleGroundSet::iterator GetBattleGroundsBegin() { return m_BattleGrounds.begin(); }; - BattleGroundSet::iterator GetBattleGroundsEnd() { return m_BattleGrounds.end(); }; + BattleGround* GetBattleGroundThroughClientInstance(uint32 instanceId, BattleGroundTypeId bgTypeId); + BattleGround* GetBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId); //there must be uint32 because MAX_BATTLEGROUND_TYPE_ID means unknown - BattleGround* GetBattleGround(uint32 ID) - { - BattleGroundSet::iterator i = m_BattleGrounds.find(ID); - if(i != m_BattleGrounds.end()) - return i->second; - else - return NULL; - }; - - BattleGround * GetBattleGroundTemplate(uint32 bgTypeId); - BattleGround * CreateNewBattleGround(uint32 bgTypeId); + BattleGround* GetBattleGroundTemplate(BattleGroundTypeId bgTypeId); + BattleGround* CreateNewBattleGround(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id, uint8 arenaType, bool isRated); - 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); + 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); - inline void AddBattleGround(uint32 ID, BattleGround* BG) { m_BattleGrounds[ID] = BG; }; - void RemoveBattleGround(uint32 instanceID); + void AddBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId, BattleGround* BG) { m_BattleGrounds[bgTypeId][InstanceID] = BG; }; + void RemoveBattleGround(uint32 instanceID, BattleGroundTypeId bgTypeId) { m_BattleGrounds[bgTypeId].erase(instanceID); } + uint32 CreateClientVisibleInstanceId(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id); void CreateInitialBattleGrounds(); + void DeleteAllBattleGrounds(); - void SendToBattleGround(Player *pl, uint32 bgTypeId); + void SendToBattleGround(Player *pl, uint32 InstanceID, BattleGroundTypeId bgTypeId); /* Battleground queues */ //these queues are instantiated when creating BattlegroundMrg BattleGroundQueue m_BattleGroundQueues[MAX_BATTLEGROUND_QUEUE_TYPES]; // public, because we need to access them in BG handler code - BGFreeSlotQueueType BGFreeSlotQueue[MAX_BATTLEGROUND_TYPES]; + BGFreeSlotQueueType BGFreeSlotQueue[MAX_BATTLEGROUND_TYPE_ID]; - void SendAreaSpiritHealerQueryOpcode(Player *pl, BattleGround *bg, uint64 guid); - - bool IsArenaType(uint32 bgTypeId) const; - bool IsBattleGroundType(uint32 bgTypeId) const; - uint32 BGQueueTypeId(uint32 bgTypeId, uint8 arenaType) const; - uint32 BGTemplateId(uint32 bgQueueTypeId) const; - uint8 BGArenaType(uint32 bgQueueTypeId) const; - - uint32 GetMaxRatingDifference() const {return m_MaxRatingDifference;} - uint32 GetRatingDiscardTimer() const {return m_RatingDiscardTimer;} + uint32 GetMaxRatingDifference() const; + uint32 GetRatingDiscardTimer() const; + uint32 GetPrematureFinishTime() const; void InitAutomaticArenaPointDistribution(); void DistributeArenaPoints(); - uint32 GetPrematureFinishTime() const {return m_PrematureFinishTimer;} void ToggleArenaTesting(); - const bool isArenaTesting() const { return m_ArenaTesting; } + void ToggleTesting(); void SetHolidayWeekends(uint32 mask); + void LoadBattleMastersEntry(); + BattleGroundTypeId GetBattleMasterBG(uint32 entry) const + { + BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry); + if (itr != mBattleMastersMap.end()) + return itr->second; + return BATTLEGROUND_WS; + } + + bool isArenaTesting() const { return m_ArenaTesting; } + bool isTesting() const { return m_Testing; } + + static bool IsArenaType(BattleGroundTypeId bgTypeId); + static bool IsBattleGroundType(BattleGroundTypeId bgTypeId) { return !BattleGroundMgr::IsArenaType(bgTypeId); } + static BattleGroundQueueTypeId BGQueueTypeId(BattleGroundTypeId bgTypeId, uint8 arenaType); + static BattleGroundTypeId BGTemplateId(BattleGroundQueueTypeId bgQueueTypeId); + static uint8 BGArenaType(BattleGroundQueueTypeId bgQueueTypeId); private: + BattleMastersMap mBattleMastersMap; /* Battlegrounds */ - BattleGroundSet m_BattleGrounds; - uint32 m_MaxRatingDifference; - uint32 m_RatingDiscardTimer; + BattleGroundSet m_BattleGrounds[MAX_BATTLEGROUND_TYPE_ID]; + std::set<uint32> m_ClientBattleGroundIds[MAX_BATTLEGROUND_TYPE_ID][MAX_BATTLEGROUND_QUEUES]; //the instanceids just visible for the client uint32 m_NextRatingDiscardUpdate; - bool m_AutoDistributePoints; - uint64 m_NextAutoDistributionTime; + time_t m_NextAutoDistributionTime; uint32 m_AutoDistributionTimeChecker; - uint32 m_PrematureFinishTimer; bool m_ArenaTesting; + bool m_Testing; }; #define sBattleGroundMgr Trinity::Singleton<BattleGroundMgr>::Instance() |