aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Battlegrounds/BattlegroundMgr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/game/Battlegrounds/BattlegroundMgr.cpp')
-rw-r--r--src/server/game/Battlegrounds/BattlegroundMgr.cpp82
1 files changed, 37 insertions, 45 deletions
diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.cpp b/src/server/game/Battlegrounds/BattlegroundMgr.cpp
index 0416a021d16..1b8fb8ee907 100644
--- a/src/server/game/Battlegrounds/BattlegroundMgr.cpp
+++ b/src/server/game/Battlegrounds/BattlegroundMgr.cpp
@@ -16,12 +16,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "Common.h"
-#include "ObjectMgr.h"
#include "ArenaTeamMgr.h"
-#include "World.h"
-#include "WorldPacket.h"
-
#include "BattlegroundMgr.h"
#include "BattlegroundAV.h"
#include "BattlegroundAB.h"
@@ -34,15 +29,26 @@
#include "BattlegroundDS.h"
#include "BattlegroundRV.h"
#include "BattlegroundIC.h"
+#include "Common.h"
+#include "Containers.h"
#include "Chat.h"
+#include "DatabaseEnv.h"
+#include "DisableMgr.h"
+#include "Formulas.h"
+#include "GameEventMgr.h"
#include "Map.h"
#include "MapManager.h"
-#include "Player.h"
-#include "GameEventMgr.h"
#include "SharedDefines.h"
-#include "Formulas.h"
-#include "DisableMgr.h"
+#include "ObjectMgr.h"
#include "Opcodes.h"
+#include "Player.h"
+#include "World.h"
+#include "WorldPacket.h"
+
+bool BattlegroundTemplate::IsArena() const
+{
+ return BattlemasterEntry->type == MAP_ARENA;
+}
/*********************************************************/
/*** BATTLEGROUND MANAGER ***/
@@ -160,7 +166,7 @@ void BattlegroundMgr::Update(uint32 diff)
{
if (m_AutoDistributionTimeChecker < diff)
{
- if (time(NULL) > m_NextAutoDistributionTime)
+ if (time(nullptr) > m_NextAutoDistributionTime)
{
sArenaTeamMgr->DistributeArenaPoints();
m_NextAutoDistributionTime = m_NextAutoDistributionTime + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld->getIntConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS);
@@ -265,14 +271,14 @@ Battleground* BattlegroundMgr::GetBattlegroundThroughClientInstance(uint32 insta
//SMSG_BATTLEFIELD_LIST we need to find the battleground with this clientinstance-id
Battleground* bg = GetBattlegroundTemplate(bgTypeId);
if (!bg)
- return NULL;
+ return nullptr;
if (bg->isArena())
return GetBattleground(instanceId, bgTypeId);
BattlegroundDataContainer::const_iterator it = bgDataStore.find(bgTypeId);
if (it == bgDataStore.end())
- return NULL;
+ return nullptr;
for (BattlegroundContainer::const_iterator itr = it->second.m_Battlegrounds.begin(); itr != it->second.m_Battlegrounds.end(); ++itr)
{
@@ -280,13 +286,13 @@ Battleground* BattlegroundMgr::GetBattlegroundThroughClientInstance(uint32 insta
return itr->second;
}
- return NULL;
+ return nullptr;
}
Battleground* BattlegroundMgr::GetBattleground(uint32 instanceId, BattlegroundTypeId bgTypeId)
{
if (!instanceId)
- return NULL;
+ return nullptr;
BattlegroundDataContainer::const_iterator begin, end;
@@ -299,7 +305,7 @@ Battleground* BattlegroundMgr::GetBattleground(uint32 instanceId, BattlegroundTy
{
end = bgDataStore.find(bgTypeId);
if (end == bgDataStore.end())
- return NULL;
+ return nullptr;
begin = end++;
}
@@ -311,18 +317,18 @@ Battleground* BattlegroundMgr::GetBattleground(uint32 instanceId, BattlegroundTy
return itr->second;
}
- return NULL;
+ return nullptr;
}
Battleground* BattlegroundMgr::GetBattlegroundTemplate(BattlegroundTypeId bgTypeId)
{
BattlegroundDataContainer::const_iterator itr = bgDataStore.find(bgTypeId);
if (itr == bgDataStore.end())
- return NULL;
+ return nullptr;
BattlegroundContainer const& bgs = itr->second.m_Battlegrounds;
//map is sorted and we can be sure that lowest instance id has only BG template
- return bgs.empty() ? NULL : bgs.begin()->second;
+ return bgs.empty() ? nullptr : bgs.begin()->second;
}
uint32 BattlegroundMgr::CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id)
@@ -361,10 +367,10 @@ Battleground* BattlegroundMgr::CreateNewBattleground(BattlegroundTypeId original
if (!bg_template)
{
TC_LOG_ERROR("bg.battleground", "Battleground: CreateNewBattleground - bg template not found for %u", bgTypeId);
- return NULL;
+ return nullptr;
}
- Battleground* bg = NULL;
+ Battleground* bg = nullptr;
// create a copy of the BG template
switch (bgTypeId)
{
@@ -404,7 +410,7 @@ Battleground* BattlegroundMgr::CreateNewBattleground(BattlegroundTypeId original
case BATTLEGROUND_RB:
case BATTLEGROUND_AA:
default:
- return NULL;
+ return nullptr;
}
bool isRandom = bgTypeId != originalBgTypeId && !bg->isArena();
@@ -541,7 +547,7 @@ void BattlegroundMgr::LoadBattlegroundTemplates()
BattlegroundTypeId bgTypeId = BattlegroundTypeId(fields[0].GetUInt32());
- if (DisableMgr::IsDisabledFor(DISABLE_TYPE_BATTLEGROUND, bgTypeId, NULL))
+ if (DisableMgr::IsDisabledFor(DISABLE_TYPE_BATTLEGROUND, bgTypeId, nullptr))
continue;
// can be overwrite by values from DB
@@ -624,7 +630,7 @@ void BattlegroundMgr::InitAutomaticArenaPointDistribution()
return;
time_t wstime = time_t(sWorld->getWorldState(WS_ARENA_DISTRIBUTION_TIME));
- time_t curtime = time(NULL);
+ time_t curtime = time(nullptr);
TC_LOG_DEBUG("bg.battleground", "Initializing Automatic Arena Point Distribution");
if (wstime < curtime)
{
@@ -724,7 +730,7 @@ void BattlegroundMgr::SendAreaSpiritHealerQueryOpcode(Player* player, Battlegrou
if (time_ == uint32(-1))
time_ = 0;
data << guid << time_;
- player->GetSession()->SendPacket(&data);
+ player->SendDirectMessage(&data);
}
bool BattlegroundMgr::IsArenaType(BattlegroundTypeId bgTypeId)
@@ -967,9 +973,11 @@ BattlegroundTypeId BattlegroundMgr::GetRandomBG(BattlegroundTypeId bgTypeId)
{
if (BattlegroundTemplate const* bgTemplate = GetBattlegroundTemplateByTypeId(bgTypeId))
{
- uint32 weight = 0;
BattlegroundSelectionWeightMap selectionWeights;
-
+ std::vector<BattlegroundTypeId> ids;
+ ids.reserve(16);
+ std::vector<double> weights;
+ weights.reserve(16);
for (int32 mapId : bgTemplate->BattlemasterEntry->mapid)
{
if (mapId == -1)
@@ -977,28 +985,12 @@ BattlegroundTypeId BattlegroundMgr::GetRandomBG(BattlegroundTypeId bgTypeId)
if (BattlegroundTemplate const* bg = GetBattlegroundTemplateByMapId(mapId))
{
- weight += bg->Weight;
- selectionWeights[bg->Id] = bg->Weight;
+ ids.push_back(bg->Id);
+ weights.push_back(bg->Weight);
}
}
- // there is only one bg to select
- if (selectionWeights.size() == 1)
- return selectionWeights.begin()->first;
-
- if (weight)
- {
- // Select a random value
- uint32 selectedWeight = urand(0, weight - 1);
- // Select the correct bg (if we have in DB A(10), B(20), C(10), D(15) --> [0---A---9|10---B---29|30---C---39|40---D---54])
- weight = 0;
- for (auto it : selectionWeights)
- {
- weight += it.second;
- if (selectedWeight < weight)
- return it.first;
- }
- }
+ return *Trinity::Containers::SelectRandomWeightedContainerElement(ids, weights);
}
return BATTLEGROUND_TYPE_NONE;