Skip to content

Commit

Permalink
Core/Misc: Reduce code differences between branches
Browse files Browse the repository at this point in the history
  • Loading branch information
Shauren committed Feb 9, 2025
1 parent 2fd120d commit afbde88
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
26 changes: 6 additions & 20 deletions src/server/game/Battlegrounds/BattlegroundMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,8 @@ void BattlegroundMgr::Update(uint32 diff)
std::vector<ScheduledQueueUpdate> scheduled;
std::swap(scheduled, m_QueueUpdateScheduler);

for (uint8 i = 0; i < scheduled.size(); i++)
{
uint32 arenaMMRating = scheduled[i].ArenaMatchmakerRating;
BattlegroundQueueTypeId bgQueueTypeId = scheduled[i].QueueId;
BattlegroundBracketId bracket_id = scheduled[i].BracketId;
for (auto& [arenaMMRating, bgQueueTypeId, bracket_id] : scheduled)
GetBattlegroundQueue(bgQueueTypeId).BattlegroundQueueUpdate(diff, bracket_id, arenaMMRating);
}
}

// if rating difference counts, maybe force-update queues
Expand Down Expand Up @@ -499,7 +494,7 @@ bool BattlegroundMgr::IsRandomBattleground(uint32 battlemasterListId)

BattlegroundQueueTypeId BattlegroundMgr::BGQueueTypeId(uint16 battlemasterListId, BattlegroundQueueIdType type, bool rated, uint8 teamSize)
{
return { battlemasterListId, AsUnderlyingType(type), rated, teamSize };
return { .BattlemasterListId = battlemasterListId, .Type = AsUnderlyingType(type), .Rated = rated, .TeamSize = teamSize };
}

void BattlegroundMgr::ToggleTesting()
Expand Down Expand Up @@ -687,23 +682,14 @@ BattlegroundTypeId BattlegroundMgr::GetRandomBG(BattlegroundTypeId bgTypeId)
{
if (BattlegroundTemplate const* bgTemplate = GetBattlegroundTemplateByTypeId(bgTypeId))
{
std::vector<BattlegroundTypeId> ids;
std::vector<BattlegroundTemplate const*> ids;
ids.reserve(bgTemplate->MapIDs.size());
std::vector<double> weights;
weights.reserve(bgTemplate->MapIDs.size());
double totalWeight = 0.0;
for (int32 mapId : bgTemplate->MapIDs)
{
if (BattlegroundTemplate const* bg = GetBattlegroundTemplateByMapId(mapId))
{
ids.push_back(bg->Id);
weights.push_back(bg->Weight);
totalWeight += bg->Weight;
}
}
ids.push_back(bg);

if (totalWeight > 0.0)
return *Trinity::Containers::SelectRandomWeightedContainerElement(ids, std::span(weights));
if (!ids.empty())
return (*Trinity::Containers::SelectRandomWeightedContainerElement(ids, [](BattlegroundTemplate const* bg) { return bg->Weight; }))->Id;
}

return BATTLEGROUND_TYPE_NONE;
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Battlegrounds/BattlegroundQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class TC_GAME_API BattlegroundQueue
SelectionPool m_SelectionPools[PVP_TEAMS_COUNT];
uint32 GetPlayersInQueue(TeamId id);

BattlegroundQueueTypeId const GetQueueId() const { return m_queueId; }
BattlegroundQueueTypeId GetQueueId() const { return m_queueId; }
private:

BattlegroundQueueTypeId m_queueId;
Expand Down
8 changes: 5 additions & 3 deletions src/server/game/Groups/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,8 @@ void Group::UpdateLooterGuid(WorldObject* pLootedObject, bool ifneed)

GroupJoinBattlegroundResult Group::CanJoinBattlegroundQueue(BattlegroundTemplate const* bgOrTemplate, BattlegroundQueueTypeId bgQueueTypeId, uint32 MinPlayerCount, uint32 /*MaxPlayerCount*/, bool isRated, uint32 arenaSlot, ObjectGuid& errorGuid) const
{
errorGuid = ObjectGuid::Empty;

// check if this group is LFG group
if (isLFGGroup())
return ERR_LFG_CANT_USE_BATTLEGROUND;
Expand Down Expand Up @@ -1230,15 +1232,13 @@ GroupJoinBattlegroundResult Group::CanJoinBattlegroundQueue(BattlegroundTemplate
// offline member? don't let join
if (!member)
return ERR_BATTLEGROUND_JOIN_FAILED;
errorGuid = member->GetGUID();
// rbac permissions
if (!member->CanJoinToBattleground(bgOrTemplate))
return ERR_BATTLEGROUND_JOIN_TIMED_OUT;
// don't allow cross-faction join as group
if (member->GetTeam() != team)
{
errorGuid = member->GetGUID();
return ERR_BATTLEGROUND_JOIN_TIMED_OUT;
}
// not in the same battleground level braket, don't let join
PVPDifficultyEntry const* memberBracketEntry = DB2Manager::GetBattlegroundBracketByLevel(bracketEntry->MapID, member->GetLevel());
if (memberBracketEntry != bracketEntry)
Expand Down Expand Up @@ -1273,6 +1273,8 @@ GroupJoinBattlegroundResult Group::CanJoinBattlegroundQueue(BattlegroundTemplate
return ERR_BATTLEGROUND_JOIN_MERCENARY;
}

errorGuid = ObjectGuid::Empty;

// only check for MinPlayerCount since MinPlayerCount == MaxPlayerCount for arenas...
if (bgOrTemplate->IsArena() && memberscount != MinPlayerCount)
return ERR_ARENA_TEAM_PARTY_SIZE;
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/Handlers/BattleGroundHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "Creature.h"
#include "DB2Stores.h"
#include "DisableMgr.h"
#include "GameTime.h"
#include "Group.h"
#include "Language.h"
#include "Log.h"
Expand Down Expand Up @@ -491,7 +492,7 @@ void WorldSession::HandleRequestBattlefieldStatusOpcode(WorldPackets::Battlegrou
continue;

WorldPackets::Battleground::BattlefieldStatusNeedConfirmation battlefieldStatus;
BattlegroundMgr::BuildBattlegroundStatusNeedConfirmation(&battlefieldStatus, bg, _player, i, _player->GetBattlegroundQueueJoinTime(bgQueueTypeId), getMSTimeDiff(getMSTime(), ginfo.RemoveInviteTime), bgQueueTypeId);
BattlegroundMgr::BuildBattlegroundStatusNeedConfirmation(&battlefieldStatus, bg, _player, i, _player->GetBattlegroundQueueJoinTime(bgQueueTypeId), getMSTimeDiff(GameTime::GetGameTimeMS(), ginfo.RemoveInviteTime), bgQueueTypeId);
SendPacket(battlefieldStatus.Write());
}
else
Expand Down

0 comments on commit afbde88

Please sign in to comment.