Core/Battleground: Make Battleground queues and Free slot queue structures private.
This commit is contained in:
@@ -219,7 +219,7 @@ Battleground::~Battleground()
|
||||
for (uint32 i = 0; i < size; ++i)
|
||||
DelObject(i);
|
||||
|
||||
sBattlegroundMgr->RemoveBattleground(GetInstanceID(), GetTypeID());
|
||||
sBattlegroundMgr->RemoveBattleground(GetTypeID(), GetInstanceID());
|
||||
// unload map
|
||||
if (m_Map)
|
||||
{
|
||||
@@ -1101,7 +1101,8 @@ void Battleground::StartBattleground()
|
||||
// add bg to update list
|
||||
// This must be done here, because we need to have already invited some players when first BG::Update() method is executed
|
||||
// and it doesn't matter if we call StartBattleground() more times, because m_Battlegrounds is a map and instance id never changes
|
||||
sBattlegroundMgr->AddBattleground(GetInstanceID(), GetTypeID(), this);
|
||||
sBattlegroundMgr->AddBattleground(this);
|
||||
|
||||
if (m_IsRated)
|
||||
sLog->outDebug(LOG_FILTER_ARENAS, "Arena match type: %u for Team1Id: %u - Team2Id: %u started.", m_ArenaType, m_ArenaTeamIds[BG_TEAM_ALLIANCE], m_ArenaTeamIds[BG_TEAM_HORDE]);
|
||||
}
|
||||
@@ -1269,27 +1270,20 @@ void Battleground::EventPlayerLoggedOut(Player* player)
|
||||
// This method should be called only once ... it adds pointer to queue
|
||||
void Battleground::AddToBGFreeSlotQueue()
|
||||
{
|
||||
// make sure to add only once
|
||||
if (!m_InBGFreeSlotQueue && isBattleground())
|
||||
{
|
||||
sBattlegroundMgr->BGFreeSlotQueue[m_TypeID].push_front(this);
|
||||
sBattlegroundMgr->AddToBGFreeSlotQueue(m_TypeID, this);
|
||||
m_InBGFreeSlotQueue = true;
|
||||
}
|
||||
}
|
||||
|
||||
// This method removes this battleground from free queue - it must be called when deleting battleground - not used now
|
||||
// This method removes this battleground from free queue - it must be called when deleting battleground
|
||||
void Battleground::RemoveFromBGFreeSlotQueue()
|
||||
{
|
||||
// set to be able to re-add if needed
|
||||
m_InBGFreeSlotQueue = false;
|
||||
// uncomment this code when battlegrounds will work like instances
|
||||
for (BGFreeSlotQueueType::iterator itr = sBattlegroundMgr->BGFreeSlotQueue[m_TypeID].begin(); itr != sBattlegroundMgr->BGFreeSlotQueue[m_TypeID].end(); ++itr)
|
||||
if (m_InBGFreeSlotQueue)
|
||||
{
|
||||
if ((*itr)->GetInstanceID() == m_InstanceID)
|
||||
{
|
||||
sBattlegroundMgr->BGFreeSlotQueue[m_TypeID].erase(itr);
|
||||
return;
|
||||
}
|
||||
sBattlegroundMgr->RemoveFromBGFreeSlotQueue(m_TypeID, m_InstanceID);
|
||||
m_InBGFreeSlotQueue = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@
|
||||
#include "BattlegroundWS.h"
|
||||
#include "BattlegroundNA.h"
|
||||
#include "BattlegroundBE.h"
|
||||
#include "BattlegroundAA.h"
|
||||
#include "BattlegroundRL.h"
|
||||
#include "BattlegroundSA.h"
|
||||
#include "BattlegroundDS.h"
|
||||
#include "BattlegroundRV.h"
|
||||
#include "BattlegroundIC.h"
|
||||
#include "BattlegroundRB.h"
|
||||
#include "BattlegroundAA.h"
|
||||
#include "Chat.h"
|
||||
#include "Map.h"
|
||||
#include "MapInstanced.h"
|
||||
@@ -51,13 +51,10 @@
|
||||
/*** BATTLEGROUND MANAGER ***/
|
||||
/*********************************************************/
|
||||
|
||||
BattlegroundMgr::BattlegroundMgr() : m_AutoDistributionTimeChecker(0), m_ArenaTesting(false)
|
||||
{
|
||||
for (uint32 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; i++)
|
||||
m_Battlegrounds[i].clear();
|
||||
m_NextRatedArenaUpdate = sWorld->getIntConfig(CONFIG_ARENA_RATED_UPDATE_TIMER);
|
||||
m_Testing=false;
|
||||
}
|
||||
BattlegroundMgr::BattlegroundMgr() :
|
||||
m_NextRatedArenaUpdate(sWorld->getIntConfig(CONFIG_ARENA_RATED_UPDATE_TIMER)),
|
||||
m_AutoDistributionTimeChecker(0), m_ArenaTesting(false), m_Testing(false)
|
||||
{ }
|
||||
|
||||
BattlegroundMgr::~BattlegroundMgr()
|
||||
{
|
||||
@@ -68,7 +65,7 @@ void BattlegroundMgr::DeleteAllBattlegrounds()
|
||||
{
|
||||
for (uint32 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; ++i)
|
||||
{
|
||||
for (BattlegroundSet::iterator itr = m_Battlegrounds[i].begin(); itr != m_Battlegrounds[i].end();)
|
||||
for (BattlegroundContainer::iterator itr = m_Battlegrounds[i].begin(); itr != m_Battlegrounds[i].end();)
|
||||
{
|
||||
Battleground* bg = itr->second;
|
||||
m_Battlegrounds[i].erase(itr++);
|
||||
@@ -90,7 +87,7 @@ void BattlegroundMgr::DeleteAllBattlegrounds()
|
||||
// used to update running battlegrounds, and delete finished ones
|
||||
void BattlegroundMgr::Update(uint32 diff)
|
||||
{
|
||||
BattlegroundSet::iterator itr, next;
|
||||
BattlegroundContainer::iterator itr, next;
|
||||
for (uint32 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; ++i)
|
||||
{
|
||||
itr = m_Battlegrounds[i].begin();
|
||||
@@ -303,7 +300,7 @@ void BattlegroundMgr::BuildPvpLogDataPacket(WorldPacket* data, Battleground* bg)
|
||||
}
|
||||
*data << uint32(itr2->second->DamageDone); // damage done
|
||||
*data << uint32(itr2->second->HealingDone); // healing done
|
||||
switch (bg->GetTypeID(true)) // battleground specific things
|
||||
switch (bg->GetTypeID(true)) // battleground specific things
|
||||
{
|
||||
case BATTLEGROUND_RB:
|
||||
switch (bg->GetMapId())
|
||||
@@ -443,7 +440,7 @@ Battleground* BattlegroundMgr::GetBattlegroundThroughClientInstance(uint32 insta
|
||||
if (bg->isArena())
|
||||
return GetBattleground(instanceId, bgTypeId);
|
||||
|
||||
for (BattlegroundSet::iterator itr = m_Battlegrounds[bgTypeId].begin(); itr != m_Battlegrounds[bgTypeId].end(); ++itr)
|
||||
for (BattlegroundContainer::iterator itr = m_Battlegrounds[bgTypeId].begin(); itr != m_Battlegrounds[bgTypeId].end(); ++itr)
|
||||
{
|
||||
if (itr->second->GetClientInstanceID() == instanceId)
|
||||
return itr->second;
|
||||
@@ -451,23 +448,23 @@ Battleground* BattlegroundMgr::GetBattlegroundThroughClientInstance(uint32 insta
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Battleground* BattlegroundMgr::GetBattleground(uint32 InstanceID, BattlegroundTypeId bgTypeId)
|
||||
Battleground* BattlegroundMgr::GetBattleground(uint32 instanceId, BattlegroundTypeId bgTypeId)
|
||||
{
|
||||
if (!InstanceID)
|
||||
if (!instanceId)
|
||||
return NULL;
|
||||
//search if needed
|
||||
BattlegroundSet::iterator itr;
|
||||
|
||||
BattlegroundContainer::iterator itr;
|
||||
if (bgTypeId == BATTLEGROUND_TYPE_NONE)
|
||||
{
|
||||
for (uint32 i = BATTLEGROUND_AV; i < MAX_BATTLEGROUND_TYPE_ID; i++)
|
||||
{
|
||||
itr = m_Battlegrounds[i].find(InstanceID);
|
||||
itr = m_Battlegrounds[i].find(instanceId);
|
||||
if (itr != m_Battlegrounds[i].end())
|
||||
return itr->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
itr = m_Battlegrounds[bgTypeId].find(InstanceID);
|
||||
itr = m_Battlegrounds[bgTypeId].find(instanceId);
|
||||
return ((itr != m_Battlegrounds[bgTypeId].end()) ? itr->second : NULL);
|
||||
}
|
||||
|
||||
@@ -495,6 +492,7 @@ uint32 BattlegroundMgr::CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeI
|
||||
break;
|
||||
lastId = *itr;
|
||||
}
|
||||
|
||||
m_ClientBattlegroundIds[bgTypeId][bracket_id].insert(lastId + 1);
|
||||
return lastId + 1;
|
||||
}
|
||||
@@ -574,9 +572,6 @@ Battleground* BattlegroundMgr::CreateNewBattleground(BattlegroundTypeId bgTypeId
|
||||
case BATTLEGROUND_BE:
|
||||
bg = new BattlegroundBE(*(BattlegroundBE*)bg_template);
|
||||
break;
|
||||
case BATTLEGROUND_AA:
|
||||
bg = new BattlegroundAA(*(BattlegroundAA*)bg_template);
|
||||
break;
|
||||
case BATTLEGROUND_EY:
|
||||
bg = new BattlegroundEY(*(BattlegroundEY*)bg_template);
|
||||
break;
|
||||
@@ -598,52 +593,73 @@ Battleground* BattlegroundMgr::CreateNewBattleground(BattlegroundTypeId bgTypeId
|
||||
case BATTLEGROUND_RB:
|
||||
bg = new BattlegroundRB(*(BattlegroundRB*)bg_template);
|
||||
break;
|
||||
case BATTLEGROUND_AA:
|
||||
bg = new BattlegroundAA(*(BattlegroundAA*)bg_template);
|
||||
break;
|
||||
default:
|
||||
//error, but it is handled few lines above
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// set battelground difficulty before initialization
|
||||
bg->SetBracket(bracketEntry);
|
||||
|
||||
// generate a new instance id
|
||||
bg->SetInstanceID(sMapMgr->GenerateInstanceId()); // set instance id
|
||||
bg->SetInstanceID(sMapMgr->GenerateInstanceId());
|
||||
bg->SetClientInstanceID(CreateClientVisibleInstanceId(isRandom ? BATTLEGROUND_RB : bgTypeId, bracketEntry->GetBracketId()));
|
||||
|
||||
// reset the new bg (set status to status_wait_queue from status_none)
|
||||
bg->Reset();
|
||||
|
||||
// start the joining of the bg
|
||||
bg->SetStatus(STATUS_WAIT_JOIN);
|
||||
bg->Reset(); // reset the new bg (set status to status_wait_queue from status_none)
|
||||
bg->SetStatus(STATUS_WAIT_JOIN); // start the joining of the bg
|
||||
bg->SetArenaType(arenaType);
|
||||
bg->SetRated(isRated);
|
||||
bg->SetRandom(isRandom);
|
||||
bg->SetTypeID(isRandom ? BATTLEGROUND_RB : bgTypeId);
|
||||
bg->SetRandomTypeID(bgTypeId);
|
||||
bg->SetRated(isRated);
|
||||
bg->SetRandom(isRandom);
|
||||
|
||||
return bg;
|
||||
}
|
||||
|
||||
// used to create the BG templates
|
||||
uint32 BattlegroundMgr::CreateBattleground(CreateBattlegroundData& data)
|
||||
bool BattlegroundMgr::CreateBattleground(CreateBattlegroundData& data)
|
||||
{
|
||||
// Create the BG
|
||||
Battleground* bg = NULL;
|
||||
switch (data.bgTypeId)
|
||||
{
|
||||
case BATTLEGROUND_AV: bg = new BattlegroundAV; break;
|
||||
case BATTLEGROUND_WS: bg = new BattlegroundWS; break;
|
||||
case BATTLEGROUND_AB: bg = new BattlegroundAB; break;
|
||||
case BATTLEGROUND_NA: bg = new BattlegroundNA; break;
|
||||
case BATTLEGROUND_BE: bg = new BattlegroundBE; break;
|
||||
case BATTLEGROUND_AA: bg = new BattlegroundAA; break;
|
||||
case BATTLEGROUND_EY: bg = new BattlegroundEY; break;
|
||||
case BATTLEGROUND_RL: bg = new BattlegroundRL; break;
|
||||
case BATTLEGROUND_SA: bg = new BattlegroundSA; break;
|
||||
case BATTLEGROUND_DS: bg = new BattlegroundDS; break;
|
||||
case BATTLEGROUND_RV: bg = new BattlegroundRV; break;
|
||||
case BATTLEGROUND_IC: bg = new BattlegroundIC; break;
|
||||
case BATTLEGROUND_RB: bg = new BattlegroundRB; break;
|
||||
case BATTLEGROUND_AV:
|
||||
bg = new BattlegroundAV;
|
||||
break;
|
||||
case BATTLEGROUND_WS:
|
||||
bg = new BattlegroundWS;
|
||||
break;
|
||||
case BATTLEGROUND_AB:
|
||||
bg = new BattlegroundAB;
|
||||
break;
|
||||
case BATTLEGROUND_NA:
|
||||
bg = new BattlegroundNA;
|
||||
break;
|
||||
case BATTLEGROUND_BE:
|
||||
bg = new BattlegroundBE;
|
||||
break;
|
||||
case BATTLEGROUND_EY:
|
||||
bg = new BattlegroundEY;
|
||||
break;
|
||||
case BATTLEGROUND_RL:
|
||||
bg = new BattlegroundRL;
|
||||
break;
|
||||
case BATTLEGROUND_SA:
|
||||
bg = new BattlegroundSA;
|
||||
break;
|
||||
case BATTLEGROUND_DS:
|
||||
bg = new BattlegroundDS;
|
||||
break;
|
||||
case BATTLEGROUND_RV:
|
||||
bg = new BattlegroundRV;
|
||||
break;
|
||||
case BATTLEGROUND_IC:
|
||||
bg = new BattlegroundIC;
|
||||
break;
|
||||
case BATTLEGROUND_RB:
|
||||
bg = new BattlegroundRB;
|
||||
break;
|
||||
case BATTLEGROUND_AA:
|
||||
bg = new BattlegroundAA;
|
||||
break;
|
||||
default:
|
||||
bg = new Battleground;
|
||||
break;
|
||||
@@ -664,20 +680,14 @@ uint32 BattlegroundMgr::CreateBattleground(CreateBattlegroundData& data)
|
||||
bg->SetLevelRange(data.LevelMin, data.LevelMax);
|
||||
bg->SetScriptId(data.scriptId);
|
||||
|
||||
// add bg to update list
|
||||
AddBattleground(bg->GetInstanceID(), bg->GetTypeID(), bg);
|
||||
AddBattleground(bg);
|
||||
|
||||
// return some not-null value, bgTypeId is good enough for me
|
||||
return data.bgTypeId;
|
||||
return true;
|
||||
}
|
||||
|
||||
void BattlegroundMgr::CreateInitialBattlegrounds()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
uint8 selectionWeight;
|
||||
BattlemasterListEntry const* bl;
|
||||
|
||||
// 0 1 2 3 4 5 6 7 8 9 10 11
|
||||
QueryResult result = WorldDatabase.Query("SELECT id, MinPlayersPerTeam, MaxPlayersPerTeam, MinLvl, MaxLvl, AllianceStartLoc, AllianceStartO, HordeStartLoc, HordeStartO, StartMaxDist, Weight, ScriptName FROM battleground_template");
|
||||
|
||||
@@ -687,33 +697,38 @@ void BattlegroundMgr::CreateInitialBattlegrounds()
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 count = 0, startId;
|
||||
uint32 count = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 bgTypeID_ = fields[0].GetUInt32();
|
||||
if (DisableMgr::IsDisabledFor(DISABLE_TYPE_BATTLEGROUND, bgTypeID_, NULL))
|
||||
uint32 bgTypeId = fields[0].GetUInt32();
|
||||
if (DisableMgr::IsDisabledFor(DISABLE_TYPE_BATTLEGROUND, bgTypeId, NULL))
|
||||
continue;
|
||||
|
||||
// can be overwrite by values from DB
|
||||
bl = sBattlemasterListStore.LookupEntry(bgTypeID_);
|
||||
BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(bgTypeId);
|
||||
if (!bl)
|
||||
{
|
||||
sLog->outError(LOG_FILTER_BATTLEGROUND, "Battleground ID %u not found in BattlemasterList.dbc. Battleground not created.", bgTypeID_);
|
||||
sLog->outError(LOG_FILTER_BATTLEGROUND, "Battleground ID %u not found in BattlemasterList.dbc. Battleground not created.", bgTypeId);
|
||||
continue;
|
||||
}
|
||||
|
||||
CreateBattlegroundData data;
|
||||
data.bgTypeId = BattlegroundTypeId(bgTypeID_);
|
||||
data.bgTypeId = BattlegroundTypeId(bgTypeId);
|
||||
data.IsArena = (bl->type == TYPE_ARENA);
|
||||
data.MinPlayersPerTeam = fields[1].GetUInt16();
|
||||
data.MaxPlayersPerTeam = fields[2].GetUInt16();
|
||||
data.LevelMin = fields[3].GetUInt8();
|
||||
data.LevelMax = fields[4].GetUInt8();
|
||||
|
||||
// check values from DB
|
||||
data.StartMaxDist = fields[9].GetFloat();
|
||||
|
||||
data.scriptId = sObjectMgr->GetScriptId(fields[11].GetCString());
|
||||
data.BattlegroundName = bl->name[sWorld->GetDefaultDbcLocale()];
|
||||
data.MapID = bl->mapid[0];
|
||||
|
||||
if (data.MaxPlayersPerTeam == 0 || data.MinPlayersPerTeam > data.MaxPlayersPerTeam)
|
||||
{
|
||||
sLog->outError(LOG_FILTER_SQL, "Table `battleground_template` for id %u has bad values for MinPlayersPerTeam (%u) and MaxPlayersPerTeam(%u)",
|
||||
@@ -728,37 +743,12 @@ void BattlegroundMgr::CreateInitialBattlegrounds()
|
||||
continue;
|
||||
}
|
||||
|
||||
startId = fields[5].GetUInt32();
|
||||
if (WorldSafeLocsEntry const* start = sWorldSafeLocsStore.LookupEntry(startId))
|
||||
{
|
||||
data.Team1StartLocX = start->x;
|
||||
data.Team1StartLocY = start->y;
|
||||
data.Team1StartLocZ = start->z;
|
||||
data.Team1StartLocO = fields[6].GetFloat();
|
||||
}
|
||||
else if (data.bgTypeId == BATTLEGROUND_AA || data.bgTypeId == BATTLEGROUND_RB)
|
||||
if (data.bgTypeId == BATTLEGROUND_AA || data.bgTypeId == BATTLEGROUND_RB)
|
||||
{
|
||||
data.Team1StartLocX = 0;
|
||||
data.Team1StartLocY = 0;
|
||||
data.Team1StartLocZ = 0;
|
||||
data.Team1StartLocO = fields[6].GetFloat();
|
||||
}
|
||||
else
|
||||
{
|
||||
sLog->outError(LOG_FILTER_SQL, "Table `battleground_template` for id %u have non-existed WorldSafeLocs.dbc id %u in field `AllianceStartLoc`. BG not created.", data.bgTypeId, startId);
|
||||
continue;
|
||||
}
|
||||
|
||||
startId = fields[7].GetUInt32();
|
||||
if (WorldSafeLocsEntry const* start = sWorldSafeLocsStore.LookupEntry(startId))
|
||||
{
|
||||
data.Team2StartLocX = start->x;
|
||||
data.Team2StartLocY = start->y;
|
||||
data.Team2StartLocZ = start->z;
|
||||
data.Team2StartLocO = fields[8].GetFloat();
|
||||
}
|
||||
else if (data.bgTypeId == BATTLEGROUND_AA || data.bgTypeId == BATTLEGROUND_RB)
|
||||
{
|
||||
data.Team2StartLocX = 0;
|
||||
data.Team2StartLocY = 0;
|
||||
data.Team2StartLocZ = 0;
|
||||
@@ -766,27 +756,46 @@ void BattlegroundMgr::CreateInitialBattlegrounds()
|
||||
}
|
||||
else
|
||||
{
|
||||
sLog->outError(LOG_FILTER_SQL, "Table `battleground_template` for id %u have non-existed WorldSafeLocs.dbc id %u in field `HordeStartLoc`. BG not created.", data.bgTypeId, startId);
|
||||
continue;
|
||||
uint32 startId = fields[5].GetUInt32();
|
||||
if (WorldSafeLocsEntry const* start = sWorldSafeLocsStore.LookupEntry(startId))
|
||||
{
|
||||
data.Team1StartLocX = start->x;
|
||||
data.Team1StartLocY = start->y;
|
||||
data.Team1StartLocZ = start->z;
|
||||
data.Team1StartLocO = fields[6].GetFloat();
|
||||
}
|
||||
else
|
||||
{
|
||||
sLog->outError(LOG_FILTER_SQL, "Table `battleground_template` for id %u have non-existed WorldSafeLocs.dbc id %u in field `AllianceStartLoc`. BG not created.", data.bgTypeId, startId);
|
||||
continue;
|
||||
}
|
||||
|
||||
startId = fields[7].GetUInt32();
|
||||
if (WorldSafeLocsEntry const* start = sWorldSafeLocsStore.LookupEntry(startId))
|
||||
{
|
||||
data.Team2StartLocX = start->x;
|
||||
data.Team2StartLocY = start->y;
|
||||
data.Team2StartLocZ = start->z;
|
||||
data.Team2StartLocO = fields[8].GetFloat();
|
||||
}
|
||||
else
|
||||
{
|
||||
sLog->outError(LOG_FILTER_SQL, "Table `battleground_template` for id %u have non-existed WorldSafeLocs.dbc id %u in field `HordeStartLoc`. BG not created.", data.bgTypeId, startId);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
data.StartMaxDist = fields[9].GetFloat();
|
||||
|
||||
selectionWeight = fields[10].GetUInt8();
|
||||
data.scriptId = sObjectMgr->GetScriptId(fields[11].GetCString());
|
||||
data.BattlegroundName = bl->name[sWorld->GetDefaultDbcLocale()];
|
||||
data.MapID = bl->mapid[0];
|
||||
|
||||
if (!CreateBattleground(data))
|
||||
continue;
|
||||
|
||||
if (data.IsArena)
|
||||
{
|
||||
if (data.bgTypeId != BATTLEGROUND_AA)
|
||||
m_ArenaSelectionWeights[data.bgTypeId] = selectionWeight;
|
||||
m_ArenaSelectionWeights[data.bgTypeId] = fields[10].GetUInt8();
|
||||
}
|
||||
else if (data.bgTypeId != BATTLEGROUND_RB)
|
||||
m_BGSelectionWeights[data.bgTypeId] = selectionWeight;
|
||||
m_BGSelectionWeights[data.bgTypeId] = fields[10].GetUInt8();
|
||||
|
||||
++count;
|
||||
}
|
||||
while (result->NextRow());
|
||||
@@ -1134,3 +1143,36 @@ bool BattlegroundMgr::IsBGWeekend(BattlegroundTypeId bgTypeId)
|
||||
{
|
||||
return IsHolidayActive(BGTypeToWeekendHolidayId(bgTypeId));
|
||||
}
|
||||
|
||||
BGFreeSlotQueueContainer& BattlegroundMgr::GetBGFreeSlotQueueStore(BattlegroundTypeId bgTypeId)
|
||||
{
|
||||
return BGFreeSlotQueue[bgTypeId];
|
||||
}
|
||||
|
||||
void BattlegroundMgr::AddToBGFreeSlotQueue(BattlegroundTypeId bgTypeId, Battleground* bg)
|
||||
{
|
||||
BGFreeSlotQueue[bgTypeId].push_front(bg);
|
||||
}
|
||||
|
||||
void BattlegroundMgr::RemoveFromBGFreeSlotQueue(BattlegroundTypeId bgTypeId, uint32 instanceId)
|
||||
{
|
||||
BGFreeSlotQueueContainer& queues = BGFreeSlotQueue[bgTypeId];
|
||||
for (BGFreeSlotQueueContainer::iterator itr = queues.begin(); itr != queues.end(); ++itr)
|
||||
if ((*itr)->GetInstanceID() == instanceId)
|
||||
{
|
||||
queues.erase(itr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void BattlegroundMgr::AddBattleground(Battleground* bg)
|
||||
{
|
||||
if (bg)
|
||||
m_Battlegrounds[bg->GetTypeID()][bg->GetInstanceID()] = bg;
|
||||
}
|
||||
|
||||
void BattlegroundMgr::RemoveBattleground(BattlegroundTypeId bgTypeId, uint32 instanceId)
|
||||
{
|
||||
m_Battlegrounds[bgTypeId].erase(instanceId);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "BattlegroundQueue.h"
|
||||
#include <ace/Singleton.h>
|
||||
|
||||
typedef std::map<uint32, Battleground*> BattlegroundSet;
|
||||
typedef std::map<uint32, Battleground*> BattlegroundContainer;
|
||||
|
||||
typedef UNORDERED_MAP<uint32, BattlegroundTypeId> BattleMastersMap;
|
||||
|
||||
@@ -78,16 +78,15 @@ class BattlegroundMgr
|
||||
|
||||
/* Battlegrounds */
|
||||
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 InstanceID, BattlegroundTypeId bgTypeId);
|
||||
Battleground* GetBattlegroundTemplate(BattlegroundTypeId bgTypeId);
|
||||
Battleground* CreateNewBattleground(BattlegroundTypeId bgTypeId, PvPDifficultyEntry const* bracketEntry, uint8 arenaType, bool isRated);
|
||||
|
||||
uint32 CreateBattleground(CreateBattlegroundData& data);
|
||||
|
||||
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, BattlegroundBracketId bracket_id);
|
||||
void AddBattleground(Battleground* bg);
|
||||
void RemoveBattleground(BattlegroundTypeId bgTypeId, uint32 instanceId);
|
||||
void AddToBGFreeSlotQueue(BattlegroundTypeId bgTypeId, Battleground* bg);
|
||||
void RemoveFromBGFreeSlotQueue(BattlegroundTypeId bgTypeId, uint32 instanceId);
|
||||
BGFreeSlotQueueContainer& GetBGFreeSlotQueueStore(BattlegroundTypeId bgTypeId);
|
||||
|
||||
void CreateInitialBattlegrounds();
|
||||
void DeleteAllBattlegrounds();
|
||||
@@ -95,21 +94,29 @@ class BattlegroundMgr
|
||||
void SendToBattleground(Player* player, 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_TYPE_ID];
|
||||
|
||||
BattlegroundQueue& GetBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId) { return m_BattlegroundQueues[bgQueueTypeId]; }
|
||||
void ScheduleQueueUpdate(uint32 arenaMatchmakerRating, uint8 arenaType, BattlegroundQueueTypeId bgQueueTypeId, BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id);
|
||||
uint32 GetMaxRatingDifference() const;
|
||||
uint32 GetRatingDiscardTimer() const;
|
||||
uint32 GetPrematureFinishTime() const;
|
||||
|
||||
void InitAutomaticArenaPointDistribution();
|
||||
void ToggleArenaTesting();
|
||||
void ToggleTesting();
|
||||
|
||||
void SetHolidayWeekends(uint32 mask);
|
||||
|
||||
bool isArenaTesting() const { return m_ArenaTesting; }
|
||||
bool isTesting() const { return m_Testing; }
|
||||
|
||||
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType);
|
||||
static BattlegroundTypeId BGTemplateId(BattlegroundQueueTypeId bgQueueTypeId);
|
||||
static uint8 BGArenaType(BattlegroundQueueTypeId bgQueueTypeId);
|
||||
|
||||
static HolidayIds BGTypeToWeekendHolidayId(BattlegroundTypeId bgTypeId);
|
||||
static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday);
|
||||
static bool IsBGWeekend(BattlegroundTypeId bgTypeId);
|
||||
|
||||
uint32 GetMaxRatingDifference() const;
|
||||
uint32 GetRatingDiscardTimer() const;
|
||||
void InitAutomaticArenaPointDistribution();
|
||||
void LoadBattleMastersEntry();
|
||||
BattlegroundTypeId GetBattleMasterBG(uint32 entry) const
|
||||
{
|
||||
@@ -119,28 +126,24 @@ class BattlegroundMgr
|
||||
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 !IsArenaType(bgTypeId); }
|
||||
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType);
|
||||
static BattlegroundTypeId BGTemplateId(BattlegroundQueueTypeId bgQueueTypeId);
|
||||
static uint8 BGArenaType(BattlegroundQueueTypeId bgQueueTypeId);
|
||||
|
||||
static HolidayIds BGTypeToWeekendHolidayId(BattlegroundTypeId bgTypeId);
|
||||
static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday);
|
||||
static bool IsBGWeekend(BattlegroundTypeId bgTypeId);
|
||||
private:
|
||||
bool CreateBattleground(CreateBattlegroundData& data);
|
||||
uint32 CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id);
|
||||
static bool IsArenaType(BattlegroundTypeId bgTypeId);
|
||||
BattlegroundTypeId GetRandomBG(BattlegroundTypeId id);
|
||||
|
||||
BattleMastersMap mBattleMastersMap;
|
||||
|
||||
typedef std::map<BattlegroundTypeId, uint8> BattlegroundSelectionWeightMap; // TypeId and its selectionWeight
|
||||
/* Battlegrounds */
|
||||
BattlegroundSet m_Battlegrounds[MAX_BATTLEGROUND_TYPE_ID];
|
||||
|
||||
BattlegroundQueue m_BattlegroundQueues[MAX_BATTLEGROUND_QUEUE_TYPES];
|
||||
BGFreeSlotQueueContainer BGFreeSlotQueue[MAX_BATTLEGROUND_TYPE_ID];
|
||||
BattlegroundContainer m_Battlegrounds[MAX_BATTLEGROUND_TYPE_ID];
|
||||
std::set<uint32> m_ClientBattlegroundIds[MAX_BATTLEGROUND_TYPE_ID][MAX_BATTLEGROUND_BRACKETS]; //the instanceids just visible for the client
|
||||
|
||||
BattlegroundSelectionWeightMap m_ArenaSelectionWeights;
|
||||
BattlegroundSelectionWeightMap m_BGSelectionWeights;
|
||||
std::vector<uint64> m_QueueUpdateScheduler;
|
||||
std::set<uint32> m_ClientBattlegroundIds[MAX_BATTLEGROUND_TYPE_ID][MAX_BATTLEGROUND_BRACKETS]; //the instanceids just visible for the client
|
||||
uint32 m_NextRatedArenaUpdate;
|
||||
time_t m_NextAutoDistributionTime;
|
||||
uint32 m_AutoDistributionTimeChecker;
|
||||
@@ -150,4 +153,3 @@ class BattlegroundMgr
|
||||
|
||||
#define sBattlegroundMgr ACE_Singleton<BattlegroundMgr, ACE_Null_Mutex>::instance()
|
||||
#endif
|
||||
|
||||
|
||||
@@ -740,20 +740,16 @@ void BattlegroundQueue::BattlegroundQueueUpdate(uint32 /*diff*/, BattlegroundTyp
|
||||
m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].empty())
|
||||
return;
|
||||
|
||||
//battleground with free slot for player should be always in the beggining of the queue
|
||||
// battleground with free slot for player should be always in the beggining of the queue
|
||||
// maybe it would be better to create bgfreeslotqueue for each bracket_id
|
||||
BGFreeSlotQueueType::iterator itr, next;
|
||||
for (itr = sBattlegroundMgr->BGFreeSlotQueue[bgTypeId].begin(); itr != sBattlegroundMgr->BGFreeSlotQueue[bgTypeId].end(); itr = next)
|
||||
BGFreeSlotQueueContainer& bgQueues = sBattlegroundMgr->GetBGFreeSlotQueueStore(bgTypeId);
|
||||
for (BGFreeSlotQueueContainer::iterator itr = bgQueues.begin(); itr != bgQueues.end();)
|
||||
{
|
||||
next = itr;
|
||||
++next;
|
||||
// DO NOT allow queue manager to invite new player to arena
|
||||
if ((*itr)->isBattleground() && (*itr)->GetTypeID() == bgTypeId && (*itr)->GetBracketId() == bracket_id &&
|
||||
(*itr)->GetStatus() > STATUS_WAIT_QUEUE && (*itr)->GetStatus() < STATUS_WAIT_LEAVE)
|
||||
Battleground* bg = *itr; ++itr;
|
||||
// DO NOT allow queue manager to invite new player to rated games
|
||||
if (!bg->isRated() && bg->GetTypeID() == bgTypeId && bg->GetBracketId() == bracket_id &&
|
||||
bg->GetStatus() > STATUS_WAIT_QUEUE && bg->GetStatus() < STATUS_WAIT_LEAVE)
|
||||
{
|
||||
Battleground* bg = *itr; //we have to store battleground pointer here, because when battleground is full, it is removed from free queue (not yet implemented!!)
|
||||
// and iterator is invalid
|
||||
|
||||
// clear selection pools
|
||||
m_SelectionPools[BG_TEAM_ALLIANCE].Init();
|
||||
m_SelectionPools[BG_TEAM_HORDE].Init();
|
||||
@@ -768,10 +764,7 @@ void BattlegroundQueue::BattlegroundQueueUpdate(uint32 /*diff*/, BattlegroundTyp
|
||||
InviteGroupToBG((*citr), bg, (*citr)->Team);
|
||||
|
||||
if (!bg->HasFreeSlots())
|
||||
{
|
||||
// remove BG from BGFreeSlotQueue
|
||||
bg->RemoveFromBGFreeSlotQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1017,7 +1010,7 @@ bool BGQueueInviteEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
|
||||
if (queueSlot < PLAYER_MAX_BATTLEGROUND_QUEUES) // player is in queue or in battleground
|
||||
{
|
||||
// check if player is invited to this bg
|
||||
BattlegroundQueue &bgQueue = sBattlegroundMgr->m_BattlegroundQueues[bgQueueTypeId];
|
||||
BattlegroundQueue &bgQueue = sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId);
|
||||
if (bgQueue.IsPlayerInvited(m_PlayerGuid, m_BgInstanceGUID, m_RemoveTime))
|
||||
{
|
||||
WorldPacket data;
|
||||
@@ -1058,7 +1051,7 @@ bool BGQueueRemoveEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
|
||||
if (queueSlot < PLAYER_MAX_BATTLEGROUND_QUEUES) // player is in queue, or in Battleground
|
||||
{
|
||||
// check if player is in queue for this BG and if we are removing his invite event
|
||||
BattlegroundQueue &bgQueue = sBattlegroundMgr->m_BattlegroundQueues[m_BgQueueTypeId];
|
||||
BattlegroundQueue &bgQueue = sBattlegroundMgr->GetBattlegroundQueue(m_BgQueueTypeId);
|
||||
if (bgQueue.IsPlayerInvited(m_PlayerGuid, m_BgInstanceGUID, m_RemoveTime))
|
||||
{
|
||||
sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Battleground: removing player %u from bg queue for instance %u because of not pressing enter battle in time.", player->GetGUIDLow(), m_BgInstanceGUID);
|
||||
|
||||
@@ -24,8 +24,10 @@
|
||||
#include "Battleground.h"
|
||||
#include "EventProcessor.h"
|
||||
|
||||
#include <deque>
|
||||
|
||||
//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;
|
||||
typedef std::list<Battleground*> BGFreeSlotQueueContainer;
|
||||
|
||||
#define COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME 10
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ void WorldSession::HandleBattlemasterJoinOpcode(WorldPacket & recv_data)
|
||||
|
||||
if (_player->GetBattlegroundQueueIndex(bgQueueTypeIdRandom) < PLAYER_MAX_BATTLEGROUND_QUEUES)
|
||||
{
|
||||
//player is already in random queue
|
||||
// player is already in random queue
|
||||
WorldPacket data;
|
||||
sBattlegroundMgr->BuildGroupJoinedBattlegroundPacket(&data, ERR_IN_RANDOM_BG);
|
||||
_player->GetSession()->SendPacket(&data);
|
||||
@@ -157,7 +157,7 @@ void WorldSession::HandleBattlemasterJoinOpcode(WorldPacket & recv_data)
|
||||
|
||||
if (_player->InBattlegroundQueue() && bgTypeId == BATTLEGROUND_RB)
|
||||
{
|
||||
//player is already in queue, can't start random queue
|
||||
// player is already in queue, can't start random queue
|
||||
WorldPacket data;
|
||||
sBattlegroundMgr->BuildGroupJoinedBattlegroundPacket(&data, ERR_IN_NON_RANDOM_BG);
|
||||
_player->GetSession()->SendPacket(&data);
|
||||
@@ -166,7 +166,7 @@ void WorldSession::HandleBattlemasterJoinOpcode(WorldPacket & recv_data)
|
||||
|
||||
// check if already in queue
|
||||
if (_player->GetBattlegroundQueueIndex(bgQueueTypeId) < PLAYER_MAX_BATTLEGROUND_QUEUES)
|
||||
//player is already in this queue
|
||||
// player is already in this queue
|
||||
return;
|
||||
|
||||
// check if has free queue slots
|
||||
@@ -178,7 +178,7 @@ void WorldSession::HandleBattlemasterJoinOpcode(WorldPacket & recv_data)
|
||||
return;
|
||||
}
|
||||
|
||||
BattlegroundQueue& bgQueue = sBattlegroundMgr->m_BattlegroundQueues[bgQueueTypeId];
|
||||
BattlegroundQueue& bgQueue = sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId);
|
||||
|
||||
GroupQueueInfo* ginfo = bgQueue.AddGroup(_player, NULL, bgTypeId, bracketEntry, 0, false, isPremade, 0, 0);
|
||||
uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, bracketEntry->GetBracketId());
|
||||
@@ -189,7 +189,8 @@ void WorldSession::HandleBattlemasterJoinOpcode(WorldPacket & recv_data)
|
||||
// send status packet (in queue)
|
||||
sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, queueSlot, STATUS_WAIT_QUEUE, avgTime, 0, ginfo->ArenaType);
|
||||
SendPacket(&data);
|
||||
sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s", bgQueueTypeId, bgTypeId, _player->GetGUIDLow(), _player->GetName());
|
||||
sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s",
|
||||
bgQueueTypeId, bgTypeId, _player->GetGUIDLow(), _player->GetName());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -202,7 +203,7 @@ void WorldSession::HandleBattlemasterJoinOpcode(WorldPacket & recv_data)
|
||||
err = grp->CanJoinBattlegroundQueue(bg, bgQueueTypeId, 0, bg->GetMaxPlayersPerTeam(), false, 0);
|
||||
isPremade = (grp->GetMembersCount() >= bg->GetMinPlayersPerTeam());
|
||||
|
||||
BattlegroundQueue& bgQueue = sBattlegroundMgr->m_BattlegroundQueues[bgQueueTypeId];
|
||||
BattlegroundQueue& bgQueue = sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId);
|
||||
GroupQueueInfo* ginfo = NULL;
|
||||
uint32 avgTime = 0;
|
||||
|
||||
@@ -366,7 +367,7 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPacket &recv_data)
|
||||
//get GroupQueueInfo from BattlegroundQueue
|
||||
BattlegroundTypeId bgTypeId = BattlegroundTypeId(bgTypeId_);
|
||||
BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr::BGQueueTypeId(bgTypeId, type);
|
||||
BattlegroundQueue& bgQueue = sBattlegroundMgr->m_BattlegroundQueues[bgQueueTypeId];
|
||||
BattlegroundQueue& bgQueue = sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId);
|
||||
//we must use temporary variable, because GroupQueueInfo pointer can be deleted in BattlegroundQueue::RemovePlayer() function
|
||||
GroupQueueInfo ginfo;
|
||||
if (!bgQueue.GetPlayerGroupInfoData(_player->GetGUID(), &ginfo))
|
||||
@@ -540,7 +541,7 @@ void WorldSession::HandleBattlefieldStatusOpcode(WorldPacket & /*recv_data*/)
|
||||
}
|
||||
//we are sending update to player about queue - he can be invited there!
|
||||
//get GroupQueueInfo for queue status
|
||||
BattlegroundQueue& bgQueue = sBattlegroundMgr->m_BattlegroundQueues[bgQueueTypeId];
|
||||
BattlegroundQueue& bgQueue = sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId);
|
||||
GroupQueueInfo ginfo;
|
||||
if (!bgQueue.GetPlayerGroupInfoData(_player->GetGUID(), &ginfo))
|
||||
continue;
|
||||
@@ -680,7 +681,7 @@ void WorldSession::HandleBattlemasterJoinArena(WorldPacket & recv_data)
|
||||
arenaRating = 1;
|
||||
}
|
||||
|
||||
BattlegroundQueue &bgQueue = sBattlegroundMgr->m_BattlegroundQueues[bgQueueTypeId];
|
||||
BattlegroundQueue &bgQueue = sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId);
|
||||
if (asGroup)
|
||||
{
|
||||
uint32 avgTime = 0;
|
||||
|
||||
@@ -483,7 +483,8 @@ void WorldSession::LogoutPlayer(bool Save)
|
||||
if (BattlegroundQueueTypeId bgQueueTypeId = _player->GetBattlegroundQueueTypeId(i))
|
||||
{
|
||||
_player->RemoveBattlegroundQueueId(bgQueueTypeId);
|
||||
sBattlegroundMgr->m_BattlegroundQueues[ bgQueueTypeId ].RemovePlayer(_player->GetGUID(), true);
|
||||
BattlegroundQueue& queue = sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId);
|
||||
queue.RemovePlayer(_player->GetGUID(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user