Skip to content

feat(Core/Battlegrounds): Match Random BG maps to recent demand - #28610

Merged
Nyeriah merged 1 commit into
azerothcore:masterfrom
Nyeriah:claude/rbg-demand-map-filter-fe45ac
Nov 29, 2026
Merged

Nyeriah merged 1 commit into
azerothcore:masterfrom
Nyeriah:claude/rbg-demand-map-filter-fe45ac

Conversation

@Nyeriah

@Nyeriah Nyeriah commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Changes Proposed:

This PR proposes changes to:

  • Core (units, players, creatures, game systems).
  • Scripts (bosses, spell scripts, creature scripts).
  • Database (SAI, creatures, etc).

Follow-up to #28595. Random BG queues fill gradually and pop as soon as the Random BG MinPlayersPerTeam is reached, so almost every match starts at exactly that size. With Battleground.Random.CheckMapMinPlayers on, maps needing more players (EotS, SotA, ...) then practically never get picked, even on realms where matches regularly fill up to 9v9 or 10v10 once started.

Battleground.Random.CheckMapMinPlayers becomes a mode. No new config keys.

  • 0: off (default, unchanged).

  • 1: the existing check on the smaller team of the starting match. Same values as the old bool, so existing configs keep their behavior.

  • 2: checks the larger of the starting match size and the recent demand of its level bracket. The recent demand is the smaller of the two teams' peak player counts in the most recently finished Random BG of that bracket, used only if it finished within the last 30 minutes. Matches still running are never counted, since those players won't join the new one.

    A match picked this way can start below the map's own minimum. If the queue doesn't fill it, Battleground.PrematureFinishTimer ends it early as usual, and its lower peak then becomes the bracket's recent demand.

How it works:

  • Battleground tracks each team's peak player count as players join.
  • EndBattleground records the demand per bracket in BattlegroundMgr for BGs started from the Random BG queue (they keep BATTLEGROUND_RB as their type), only when mode 2 is set. Each finished match replaces the previous record of its bracket. It's kept in memory only, so after a restart mode 2 behaves like mode 1 until a Random BG of that bracket finishes.
  • The queue feeds the resulting team size into the existing filter. The full-match bypass, the zero-weight fallback and the low-level override handling are unchanged, so a recent full match (peak at the Random BG MaxPlayersPerTeam) lets the next one start in any map.

Values above 2 are rejected and fall back to 0. The expiry logic is in BattlegroundUtils and covered by unit tests.

AI-assisted Pull Requests

Important

Using AI tools to prepare pull requests is allowed, but it must be disclosed and it must follow our AC guidelines for AI Agentic Engineering (link below).

You are expected to fully understand the changes you submit and to be able to explain and justify them when maintainers ask.

  • AI tools (e.g. Claude, ChatGPT, or similar) were used entirely or partially to prepare this pull request. If checked, specify which tools and models below.
    • Tools/models used: Claude Code, Claude Opus 5.5
  • I have read and understood the AC guidelines for AI Agentic Engineering

Issues Addressed:

  • Closes

SOURCE:

The changes have been validated through:

  • Live research (checked on live servers, e.g Classic WotLK, Retail, etc.)
  • Sniffs (remember to share them with the open source community!)
  • Video evidence, knowledge databases or other public sources (e.g forums, Wowhead, etc.)
  • The changes promoted by this pull request come partially or entirely from another project (cherry-pick). Cherry-picks must be committed using the proper --author tag in order to be accepted, thus crediting the original authors, unless otherwise unable to be found

Tests Performed:

This PR has been:

  • Tested in-game by the author.
  • Tested in-game by other community members/someone else other than the author/has been live on production servers.
  • This pull request requires further testing and may have edge cases to be tested.

How to Test the Changes:

  • This pull request can be tested by following the reproduction steps provided in the linked issue
  • This pull request requires further testing. Provide steps to test your changes. If it requires any specific setup e.g multiple players please specify it as well.
  1. Set Battleground.Random.CheckMapMinPlayers = 2. Lower the minimums so small matches start: Random BG to 2 (UPDATE battleground_template SET MinPlayersPerTeam = 2 WHERE ID IN (2, 32);, which also sets Warsong Gulch to 2) and Strand of the Ancients to 3 (UPDATE battleground_template SET MinPlayersPerTeam = 3 WHERE ID = 9;). Restart.
  2. Queue 2 level 80 players per faction for Random Battleground. The match starts in Warsong Gulch. Finish it with 3 players per faction having joined (a third player per faction joins through the queue while it runs).
  3. Within 30 minutes of that match ending, queue 2 players per faction again. Strand of the Ancients can now come up as well as Warsong Gulch. When this match ends it records its own peak of 2 and the demand drops back, so to roll again, repeat steps 2 and 3 together. A 2v2 Strand of the Ancients ends early through Battleground.PrematureFinishTimer, since it's below its own minimum of 3.
  4. Repeat step 2, then restart (or wait more than 30 minutes without finishing another Random BG) and queue 2 players per faction several times: every match starts in Warsong Gulch.
  5. Set the option to 1 and repeat steps 2 and 3: every 2v2 match starts in Warsong Gulch, as before this PR.
  6. Unit tests: unit_tests --gtest_filter=RandomBGMinPlayersFilterTest.*

Known Issues and TODO List:

  • [ ]
  • [ ]

How to Test AzerothCore PRs

When a PR is ready to be tested, it will be marked as [WAITING TO BE TESTED].

You can help by testing PRs and writing your feedback here on the PR's page on GitHub. Follow the instructions here:

http://www.azerothcore.org/wiki/How-to-test-a-PR

REMEMBER: when testing a PR that changes something generic (i.e. a part of code that handles more than one specific thing), the tester should not only check that the PR does its job (e.g. fixing spell XXX) but especially check that the PR does not cause any regression (i.e. introducing new bugs).

For example: if a PR fixes spell X by changing a part of code that handles spells X, Y, and Z, we should not only test X, but we should test Y and Z as well.

Random BG queues pop as soon as the template minimum is reached, so
nearly every match starts at that size and maps with a higher
MinPlayersPerTeam are never picked by Battleground.Random.CheckMapMinPlayers,
even when matches regularly fill up.

The setting is now a mode. 1 keeps the current check on the starting
match size. 2 checks the larger of that and the smaller team's peak
player count in the most recently finished Random BG of the same
bracket, when it finished within the last 30 minutes. Running matches
are not counted.
Copilot AI balanced review requested due to automatic review settings November 29, 2026 21:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The change replaces the Random Battleground map minimum-player boolean setting with three modes. In demand mode, completed battlegrounds record the smaller peak team size by bracket, and map selection uses recent demand for up to 30 minutes. New tests cover demand adjustment, expiry, and the team-size cap.

Merge Risk: Low · up to 8a204

The change adds a recent-demand mode for Random Battleground map selection and is mostly safe. Operators who set the option to true will find the check silently disabled. Two battlegrounds in the same bracket finishing at the same moment could race on the demand record. Both issues are small and should be addressed or accepted before merge.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 11ae1aa and 8a204a4.

Files selected for processing: 11

  • src/server/apps/worldserver/worldserver.conf.dist
  • src/server/game/Battlegrounds/Battleground.cpp
  • src/server/game/Battlegrounds/Battleground.h
  • src/server/game/Battlegrounds/BattlegroundMgr.cpp
  • src/server/game/Battlegrounds/BattlegroundMgr.h
  • src/server/game/Battlegrounds/BattlegroundQueue.cpp
  • src/server/game/Battlegrounds/BattlegroundUtils.cpp
  • src/server/game/Battlegrounds/BattlegroundUtils.h
  • src/server/game/World/WorldConfig.cpp
  • src/server/game/World/WorldConfig.h
  • src/test/server/game/Battlegrounds/RandomBGMinPlayersFilterTest.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.


void BattlegroundMgr::RecordRandomBGDemand(BattlegroundBracketId bracketId, uint32 peakPlayersPerTeam)
{
_randomBGDemand[bracketId] = { peakPlayersPerTeam, GameTime::GetGameTime() };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Stability & Availability · Quick win

Serialize demand publication across battleground instances.

With multiple map workers, two Random BG Alterac Valley instances in the same bracket can reach this assignment concurrently through boss-kill callbacks, which creates conflicting writes to the same non-atomic record. (raw.githubusercontent.com)
The manager update loop does not serialize these callbacks, so the demand record has undefined behavior rather than a reliable completed-match value. (raw.githubusercontent.com)
Publish through one owning thread, or synchronize publication and return a protected snapshot from GetRandomBGDemand.

SetConfigValue<bool>(CONFIG_BATTLEGROUND_DISABLE_READY_CHECK_IN_BG, "Battleground.DisableReadyCheckInBG", false);
SetConfigValue<bool>(CONFIG_BATTLEGROUND_CAST_DESERTER, "Battleground.CastDeserter", true);
SetConfigValue<bool>(CONFIG_BATTLEGROUND_RANDOM_CHECK_MAP_MIN_PLAYERS, "Battleground.Random.CheckMapMinPlayers", false);
SetConfigValue<uint32>(CONFIG_BATTLEGROUND_RANDOM_CHECK_MAP_MIN_PLAYERS, "Battleground.Random.CheckMapMinPlayers", 0, ConfigValueCache::Reloadable::Yes, [](uint32 const& value) { return value <= 2; }, "<= 2");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Preserve existing enabled boolean values.

An existing Battleground.Random.CheckMapMinPlayers = true previously enabled checking, but the new integer parser rejects true, logs a conversion error, and uses 0, which disables checking. (raw.githubusercontent.com)
Accept the previous boolean spellings as aliases for modes 0 and 1, while retaining numeric mode 2.

@Nyeriah

Nyeriah commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Self-review — claude/rbg-demand-map-filter-fe45ac → master

Outcome 3 findings (PR description) — 3 fixed — code clean since round 1

Fixes not re-reviewed How to Test step 4 rewrite (round 3 finding 1)

Reviewed 8a204a48df (claude/rbg-demand-map-filter-fe45ac vs upstream/master, merge-base diff — 11 files, +103 −6)

By Claude Code, claude-opus-5-5 — self-review v0.10, 2026-11-29

Review details (rounds 2–3)

Intent Battleground.Random.CheckMapMinPlayers becomes a mode: 0 off, 1 the previous check on the starting match's smaller team, 2 also considers the smaller team peak of the most recently finished Random BG in the same bracket when it finished within 30 minutes; running matches are not counted and the existing bypass, fallback and low-level override handling stay.

Project rules .agents/docs/self-review-rules.md found and applied

Diff 7c30d51fe56d4bec88f159773b8d2595816ea9c5

Metadata 5f3b9f443cb74db0bc47e6238295bc824f2d1273

Carries forward round 1 (rbg-demand-map-filter.SELF-REVIEW.md): code clean.

Round 2 — 8a204a48df, PR metadata only (opened PR, diff unchanged), 2 findings

  1. How to Test step 3 — repeating 2v2 "several times" fails after the first roll: each ended match overwrites the recorded demand with 2 → fixed
  2. Description — omitted that mode 2 can start a match below the map's minimum, which ends through the premature finish timer if unfilled and lowers the demand → fixed

Round 3 — 8a204a48df, round 2 description fixes, 1 finding

  1. How to Test step 4 — after the new step 3 the demand is already 2, so "restart and repeat step 3" passes without testing restart or expiry → fixed

@github-actions github-actions Bot added CORE Related to the core UnitTests file-cpp Used to trigger the matrix build labels Nov 29, 2026
@Nyeriah
Nyeriah merged commit 64537d4 into azerothcore:master Nov 29, 2026
13 of 17 checks passed
@Nyeriah
Nyeriah deleted the claude/rbg-demand-map-filter-fe45ac branch November 29, 2026 22:39
dimtoneff pushed a commit to dimtoneff/azerothcore-wotlk that referenced this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CORE Related to the core file-cpp Used to trigger the matrix build UnitTests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants