Skip to content

Conversation

@kadeshar
Copy link
Owner

@kadeshar kadeshar commented Jan 8, 2026

No description provided.

Signed-off-by: Engardium <regradius@gmail.com>
Copilot AI review requested due to automatic review settings January 8, 2026 16:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a team size calculation issue for Random Battlegrounds (RB). The RB template often reports a smaller team size (10v10) than what some actual battleground maps require (e.g., 15v15 for Arathi Basin or 40v40 for Alterac Valley). This causes bots to stop queueing prematurely, preventing battlegrounds from filling properly.

Key Changes:

  • Introduces a new helper function GetEffectiveMaxPlayersPerTeam that returns the maximum team size across all non-arena battleground types when dealing with BATTLEGROUND_RB
  • Replaces direct calls to bg->GetMaxPlayersPerTeam() with the new helper function at four locations
  • Adds caching to avoid recalculating the maximum team size on every call

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +34 to +55
static uint32 cachedMaxNonArenaBgTeamSize = 0;
if (!cachedMaxNonArenaBgTeamSize)
{
for (uint32 t = 1; t < MAX_BATTLEGROUND_TYPE_ID; ++t)
{
BattlegroundTypeId id = BattlegroundTypeId(t);

if (id == BATTLEGROUND_RB || id == BATTLEGROUND_AA)
continue;

Battleground* tmpl = sBattlegroundMgr->GetBattlegroundTemplate(id);
if (!tmpl || tmpl->isArena())
continue;

uint32 teamSize = tmpl->GetMaxPlayersPerTeam();
if (teamSize > cachedMaxNonArenaBgTeamSize)
cachedMaxNonArenaBgTeamSize = teamSize;
}

if (!cachedMaxNonArenaBgTeamSize)
cachedMaxNonArenaBgTeamSize = bg->GetMaxPlayersPerTeam();
}
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The static local variable cachedMaxNonArenaBgTeamSize may have thread safety issues. If multiple threads call this function simultaneously when the cache is uninitialized (value is 0), they could all enter the initialization block and compute the value multiple times. While the final cached value should be the same across all threads (assuming the battleground templates don't change), this creates a race condition during the first initialization. Consider using thread-safe initialization patterns such as std::call_once or std::atomic if this code can be called from multiple threads.

Copilot uses AI. Check for mistakes.
// Random Battleground (RB) uses a generic template that often reports 10v10.
// When queueing for RB, use a safe upper bound so bots don't stop filling at 10 per team
// on maps that actually require 15/40 per team (AB/AV/IOC, etc).
static uint32 GetEffectiveMaxPlayersPerTeam(BattlegroundTypeId bgTypeId)
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The static keyword on the function declaration is redundant since it's already in an anonymous namespace. Functions in anonymous namespaces have internal linkage by default, so the static keyword doesn't add any additional effect. Consider removing it for cleaner code.

Suggested change
static uint32 GetEffectiveMaxPlayersPerTeam(BattlegroundTypeId bgTypeId)
uint32 GetEffectiveMaxPlayersPerTeam(BattlegroundTypeId bgTypeId)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants