Advertisement
EmuDevs

BattlegroundQueue.h GvG

Feb 26th, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.14 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
  3.  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify it
  6.  * under the terms of the GNU General Public License as published by the
  7.  * Free Software Foundation; either version 2 of the License, or (at your
  8.  * option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful, but WITHOUT
  11.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12.  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13.  * more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License along
  16.  * with this program. If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. #ifndef __BATTLEGROUNDQUEUE_H
  20. #define __BATTLEGROUNDQUEUE_H
  21.  
  22. #include "Common.h"
  23. #include "DBCEnums.h"
  24. #include "Battleground.h"
  25. #include "EventProcessor.h"
  26.  
  27. #include <deque>
  28.  
  29. //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
  30. typedef std::list<Battleground*> BGFreeSlotQueueContainer;
  31.  
  32. #define COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME 10
  33.  
  34. struct GroupQueueInfo;                                      // type predefinition
  35. struct PlayerQueueInfo                                      // stores information for players in queue
  36. {
  37.     uint32  LastOnlineTime;                                 // for tracking and removing offline players from queue after 5 minutes
  38.     GroupQueueInfo* GroupInfo;                             // pointer to the associated groupqueueinfo
  39. };
  40.  
  41. struct GroupQueueInfo                                       // stores information about the group in queue (also used when joined as solo!)
  42. {
  43.     std::map<uint64, PlayerQueueInfo*> Players;             // player queue info map
  44.     uint32  Team;                                           // Player team (ALLIANCE/HORDE)
  45.     BattlegroundTypeId BgTypeId;                            // battleground type id
  46.     bool    IsRated;                                        // rated
  47.     uint8   ArenaType;                                      // 2v2, 3v3, 5v5 or 0 when BG
  48.     uint32  ArenaTeamId;                                    // team id if rated match
  49.     uint32  JoinTime;                                       // time when group was added
  50.     uint32  RemoveInviteTime;                               // time when we will remove invite for players in group
  51.     uint32  IsInvitedToBGInstanceGUID;                      // was invited to certain BG
  52.     uint32  ArenaTeamRating;                                // if rated match, inited to the rating of the team
  53.     uint32  ArenaMatchmakerRating;                          // if rated match, inited to the rating of the team
  54.     uint32  OpponentsTeamRating;                            // for rated arena matches
  55.     uint32  OpponentsMatchmakerRating;                      // for rated arena matches
  56.     uint32 guildId;                                         // Guild vs Guild
  57. };
  58.  
  59. enum BattlegroundQueueGroupTypes
  60. {
  61.     BG_QUEUE_PREMADE_ALLIANCE   = 0,
  62.     BG_QUEUE_PREMADE_HORDE      = 1,
  63.     BG_QUEUE_NORMAL_ALLIANCE    = 2,
  64.     BG_QUEUE_NORMAL_HORDE       = 3,
  65.     BG_CROSS_FACTION            = 4
  66. };
  67. #define BG_QUEUE_GROUP_TYPES_COUNT 5
  68.  
  69. enum BattlegroundQueueGuildTypes
  70. {
  71.     BG_QUEUE_GUILD              = 0,
  72.     BG_QUEUE_NOT_GUILD          = 1
  73. };
  74. #define BG_QUEUE_GROUP_TYPES_GUILD 2
  75.  
  76. class Battleground;
  77. class BattlegroundQueue
  78. {
  79.     public:
  80.         BattlegroundQueue();
  81.         ~BattlegroundQueue();
  82.  
  83.         void BattlegroundQueueUpdate(uint32 diff, BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id, uint8 arenaType = 0, bool isRated = false, uint32 minRating = 0);
  84.         void UpdateEvents(uint32 diff);
  85.  
  86.         void FillPlayersToBG(Battleground* bg, BattlegroundBracketId bracket_id, bool GuildvsGuild);
  87.         bool CheckCrossFactionMatch(BattlegroundBracketId bracket_id, Battleground* bg);
  88.         bool CanFillPlayersToBGForCrossFaction(Battleground* bg, BattlegroundBracketId bracket_id, bool check);
  89.         bool CheckPremadeMatch(BattlegroundBracketId bracket_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam, bool GuildvsGuild = false);
  90.         bool CheckNormalMatch(Battleground* bg_template, BattlegroundBracketId bracket_id, uint32 minPlayers, uint32 maxPlayers, bool GuildvsGuild = false);
  91.         bool CheckSkirmishForSameFaction(BattlegroundBracketId bracket_id, uint32 minPlayersPerTeam);
  92.         GroupQueueInfo* AddGroup(Player* leader, Group* group, BattlegroundTypeId bgTypeId, PvPDifficultyEntry const*  bracketEntry, uint8 ArenaType, bool isRated, bool isPremade, uint32 ArenaRating, uint32 MatchmakerRating, uint32 ArenaTeamId = 0, uint32 guildId = 0);
  93.         void RemovePlayer(uint64 guid, bool decreaseInvitedCount);
  94.         bool IsPlayerInvited(uint64 pl_guid, const uint32 bgInstanceGuid, const uint32 removeTime);
  95.         bool GetPlayerGroupInfoData(uint64 guid, GroupQueueInfo* ginfo);
  96.         void PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, BattlegroundBracketId bracket_id);
  97.         uint32 GetAverageQueueWaitTime(GroupQueueInfo* ginfo, BattlegroundBracketId bracket_id) const;
  98.  
  99.         typedef std::map<uint64, PlayerQueueInfo> QueuedPlayersMap;
  100.         QueuedPlayersMap m_QueuedPlayers;
  101.  
  102.         //we need constant add to begin and constant remove / add from the end, therefore deque suits our problem well
  103.         typedef std::deque<GroupQueueInfo*> GroupsQueueType;
  104.  
  105.         /*
  106.         This two dimensional array is used to store All queued groups
  107.         First dimension specifies the bgTypeId
  108.         Second dimension specifies the player's group types -
  109.              BG_QUEUE_PREMADE_ALLIANCE  is used for premade alliance groups and alliance rated arena teams
  110.              BG_QUEUE_PREMADE_HORDE     is used for premade horde groups and horde rated arena teams
  111.              BG_QUEUE_NORMAL_ALLIANCE   is used for normal (or small) alliance groups or non-rated arena matches
  112.              BG_QUEUE_NORMAL_HORDE      is used for normal (or small) horde groups or non-rated arena matches
  113.         */
  114.         GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_GROUP_TYPES_COUNT][BG_QUEUE_GROUP_TYPES_GUILD];
  115.  
  116.         // class to select and invite groups to bg
  117.         class SelectionPool
  118.         {
  119.         public:
  120.             SelectionPool(): PlayerCount(0) {};
  121.             void Init();
  122.             bool AddGroup(GroupQueueInfo* ginfo, uint32 desiredCount);
  123.             bool KickGroup(uint32 size);
  124.             uint32 GetPlayerCount() const {return PlayerCount;}
  125.         public:
  126.             GroupsQueueType SelectedGroups;
  127.         private:
  128.             uint32 PlayerCount;
  129.         };
  130.  
  131.         //one selection pool for horde, other one for alliance
  132.         SelectionPool m_SelectionPools[BG_TEAMS_COUNT];
  133.         uint32 GetPlayersInQueue(TeamId id);
  134.     private:
  135.  
  136.         bool InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, uint32 side);
  137.         uint32 m_WaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS][COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME];
  138.         uint32 m_WaitTimeLastPlayer[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS];
  139.         uint32 m_SumOfWaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS];
  140.  
  141.         // Event handler
  142.         EventProcessor m_events;
  143. };
  144.  
  145. /*
  146.     This class is used to invite player to BG again, when minute lasts from his first invitation
  147.     it is capable to solve all possibilities
  148. */
  149. class BGQueueInviteEvent : public BasicEvent
  150. {
  151.     public:
  152.         BGQueueInviteEvent(uint64 pl_guid, uint32 BgInstanceGUID, BattlegroundTypeId BgTypeId, uint8 arenaType, uint32 removeTime) :
  153.           m_PlayerGuid(pl_guid), m_BgInstanceGUID(BgInstanceGUID), m_BgTypeId(BgTypeId), m_ArenaType(arenaType), m_RemoveTime(removeTime)
  154.           { }
  155.         virtual ~BGQueueInviteEvent() { }
  156.  
  157.         virtual bool Execute(uint64 e_time, uint32 p_time);
  158.         virtual void Abort(uint64 e_time);
  159.     private:
  160.         uint64 m_PlayerGuid;
  161.         uint32 m_BgInstanceGUID;
  162.         BattlegroundTypeId m_BgTypeId;
  163.         uint8  m_ArenaType;
  164.         uint32 m_RemoveTime;
  165. };
  166.  
  167. /*
  168.     This class is used to remove player from BG queue after 1 minute 20 seconds from first invitation
  169.     We must store removeInvite time in case player left queue and joined and is invited again
  170.     We must store bgQueueTypeId, because battleground can be deleted already, when player entered it
  171. */
  172. class BGQueueRemoveEvent : public BasicEvent
  173. {
  174.     public:
  175.         BGQueueRemoveEvent(uint64 pl_guid, uint32 bgInstanceGUID, BattlegroundTypeId BgTypeId, BattlegroundQueueTypeId bgQueueTypeId, uint32 removeTime)
  176.             : m_PlayerGuid(pl_guid), m_BgInstanceGUID(bgInstanceGUID), m_RemoveTime(removeTime), m_BgTypeId(BgTypeId), m_BgQueueTypeId(bgQueueTypeId)
  177.         {}
  178.  
  179.         virtual ~BGQueueRemoveEvent() {}
  180.  
  181.         virtual bool Execute(uint64 e_time, uint32 p_time);
  182.         virtual void Abort(uint64 e_time);
  183.     private:
  184.         uint64 m_PlayerGuid;
  185.         uint32 m_BgInstanceGUID;
  186.         uint32 m_RemoveTime;
  187.         BattlegroundTypeId m_BgTypeId;
  188.         BattlegroundQueueTypeId m_BgQueueTypeId;
  189. };
  190.  
  191. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement