Kelsidavis-WoWee/tools/editor/cli_battleground_rewards_catalog.cpp
Kelsi a10497a026 feat(pipeline): WBRD battleground reward stages catalog (140th open format)
Novel replacement for the per-BG per-bracket reward
configuration vanilla WoW carried in BattlemasterList.dbc +
the hard-coded honor table in the server's BattlegroundMgr
(the "Mark of Honor" item granted on win/loss was hard-coded
per-BG type with no formal data-driven scaling). Each WBRD
entry binds one (battlegroundId, levelBracket) pair to its
win/loss honor amounts, win/loss marks, the mark itemId, an
optional weekly-bonus item, and a minimum-players-to-start
gate.

Three presets covering canonical vanilla BGs:
  --gen-brd-av   Alterac Valley reward ladder for brackets
                 5-6 (51-69 only — AV was endgame). 20
                 players/side, Mark of AV item 17502
  --gen-brd-wsg  Warsong Gulch ladder for all 6 brackets
                 (10-69), 10 players/side, Mark of WSG item
                 20558, monotonically scaling honor
                 (50/100/200/350/500/750)
  --gen-brd-ab   Arathi Basin ladder for brackets 2-6
                 (20-69), 15 players/side, Mark of AB item
                 20559, includes weekly bonus quest token
                 (placeholder itemId 20560)

Validator catches: id+battlegroundId required, bracketIndex
1..6 (vanilla), no duplicate rewardIds, no duplicate
(bgId,bracket) pairs (runtime reward-lookup tie),
bonusItemCount > 0 requires non-zero bonusItemId, minPlayers
ToStart > 0 (else BG queue would never start a match).
CRITICAL: lossHonor <= winHonor (else losing rewards more
than winning, no incentive to play to win — would degenerate
into AFK farming). Warns on winMarks=0 with markItemId set
(vanilla wins always granted at least 1 mark).

Format count 139 -> 140. CLI flag count 1454 -> 1461.
2026-05-10 05:24:26 -07:00

297 lines
10 KiB
C++

#include "cli_battleground_rewards_catalog.hpp"
#include "cli_arg_parse.hpp"
#include "cli_box_emitter.hpp"
#include "pipeline/wowee_battleground_rewards.hpp"
#include <nlohmann/json.hpp>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <set>
#include <string>
#include <utility>
#include <vector>
namespace wowee {
namespace editor {
namespace cli {
namespace {
std::string stripWbrdExt(std::string base) {
stripExt(base, ".wbrd");
return base;
}
const char* bgName(uint16_t bgId) {
switch (bgId) {
case 1: return "AV";
case 2: return "WSG";
case 3: return "AB";
default: return "?";
}
}
bool saveOrError(
const wowee::pipeline::WoweeBattlegroundRewards& c,
const std::string& base, const char* cmd) {
if (!wowee::pipeline::WoweeBattlegroundRewardsLoader::save(
c, base)) {
std::fprintf(stderr, "%s: failed to save %s.wbrd\n",
cmd, base.c_str());
return false;
}
return true;
}
void printGenSummary(
const wowee::pipeline::WoweeBattlegroundRewards& c,
const std::string& base) {
std::printf("Wrote %s.wbrd\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" stages : %zu\n", c.entries.size());
}
int handleGenAV(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "AlteracValleyRewards";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWbrdExt(base);
auto c = wowee::pipeline::WoweeBattlegroundRewardsLoader::
makeAlteracValley(name);
if (!saveOrError(c, base, "gen-brd-av")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenWSG(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "WarsongRewards";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWbrdExt(base);
auto c = wowee::pipeline::WoweeBattlegroundRewardsLoader::
makeWarsong(name);
if (!saveOrError(c, base, "gen-brd-wsg")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenAB(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "ArathiBasinRewards";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWbrdExt(base);
auto c = wowee::pipeline::WoweeBattlegroundRewardsLoader::
makeArathiBasin(name);
if (!saveOrError(c, base, "gen-brd-ab")) return 1;
printGenSummary(c, base);
return 0;
}
int handleInfo(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
base = stripWbrdExt(base);
if (!wowee::pipeline::WoweeBattlegroundRewardsLoader::exists(base)) {
std::fprintf(stderr, "WBRD not found: %s.wbrd\n",
base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeBattlegroundRewardsLoader::load(base);
if (jsonOut) {
nlohmann::json j;
j["wbrd"] = base + ".wbrd";
j["name"] = c.name;
j["count"] = c.entries.size();
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"rewardId", e.rewardId},
{"battlegroundId", e.battlegroundId},
{"battlegroundName", bgName(e.battlegroundId)},
{"bracketIndex", e.bracketIndex},
{"minPlayersToStart", e.minPlayersToStart},
{"winHonor", e.winHonor},
{"lossHonor", e.lossHonor},
{"markItemId", e.markItemId},
{"winMarks", e.winMarks},
{"lossMarks", e.lossMarks},
{"bonusItemId", e.bonusItemId},
{"bonusItemCount", e.bonusItemCount},
});
}
j["entries"] = arr;
std::printf("%s\n", j.dump(2).c_str());
return 0;
}
std::printf("WBRD: %s.wbrd\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" stages : %zu\n", c.entries.size());
if (c.entries.empty()) return 0;
std::printf(" id bg bracket minPl winHonor lossHonor markId winM lossM bonusId bonusN\n");
for (const auto& e : c.entries) {
std::printf(" %4u %-3s %5u %3u %5u %5u %5u %2u %3u %5u %3u\n",
e.rewardId, bgName(e.battlegroundId),
e.bracketIndex, e.minPlayersToStart,
e.winHonor, e.lossHonor,
e.markItemId, e.winMarks, e.lossMarks,
e.bonusItemId, e.bonusItemCount);
}
return 0;
}
int handleValidate(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
base = stripWbrdExt(base);
if (!wowee::pipeline::WoweeBattlegroundRewardsLoader::exists(base)) {
std::fprintf(stderr,
"validate-wbrd: WBRD not found: %s.wbrd\n",
base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeBattlegroundRewardsLoader::load(base);
std::vector<std::string> errors;
std::vector<std::string> warnings;
if (c.entries.empty()) {
warnings.push_back("catalog has zero entries");
}
using B = wowee::pipeline::WoweeBattlegroundRewards;
std::set<uint32_t> idsSeen;
using Pair = std::pair<uint16_t, uint8_t>;
std::set<Pair> bgBracketPairs;
for (size_t k = 0; k < c.entries.size(); ++k) {
const auto& e = c.entries[k];
std::string ctx = "entry " + std::to_string(k) +
" (id=" + std::to_string(e.rewardId) +
" " + bgName(e.battlegroundId) +
" bracket=" +
std::to_string(e.bracketIndex) + ")";
if (e.rewardId == 0)
errors.push_back(ctx + ": rewardId is 0");
if (e.battlegroundId == 0)
errors.push_back(ctx +
": battlegroundId is 0");
if (e.bracketIndex == 0 ||
e.bracketIndex > B::kMaxBracketIndex) {
errors.push_back(ctx + ": bracketIndex " +
std::to_string(e.bracketIndex) +
" out of range (1..6 vanilla)");
}
// CRITICAL invariant: minPlayersToStart > 0,
// else BG queue would never start a match.
if (e.minPlayersToStart == 0) {
errors.push_back(ctx +
": minPlayersToStart is 0 — BG queue "
"would never start a match");
}
// Loss honor should be < win honor (winning
// should always be more rewarding than losing,
// else there's no incentive to play to win).
if (e.lossHonor > e.winHonor) {
errors.push_back(ctx +
": lossHonor=" +
std::to_string(e.lossHonor) +
" > winHonor=" +
std::to_string(e.winHonor) +
" — losing rewards more than winning "
"(no win incentive)");
}
// Mark = 0 on win is unusual — every BG win
// grants at least 1 mark in vanilla. Warn.
if (e.winMarks == 0 && e.markItemId != 0) {
warnings.push_back(ctx +
": winMarks=0 but markItemId is set "
"— win grants no marks; verify "
"intentional (vanilla wins always "
"gave at least 1 mark)");
}
// bonusItemCount > 0 with bonusItemId = 0 is
// a contradiction (count of nothing).
if (e.bonusItemCount > 0 && e.bonusItemId == 0) {
errors.push_back(ctx +
": bonusItemCount=" +
std::to_string(e.bonusItemCount) +
" but bonusItemId is 0 — count of "
"nothing");
}
// (battlegroundId, bracketIndex) MUST be
// unique — runtime dispatch by this pair
// would tie.
Pair p{e.battlegroundId, e.bracketIndex};
if (!bgBracketPairs.insert(p).second) {
errors.push_back(ctx +
": duplicate (bgId=" +
std::to_string(e.battlegroundId) +
", bracket=" +
std::to_string(e.bracketIndex) +
") — runtime reward-lookup tie");
}
if (!idsSeen.insert(e.rewardId).second) {
errors.push_back(ctx + ": duplicate rewardId");
}
}
bool ok = errors.empty();
if (jsonOut) {
nlohmann::json j;
j["wbrd"] = base + ".wbrd";
j["ok"] = ok;
j["errors"] = errors;
j["warnings"] = warnings;
std::printf("%s\n", j.dump(2).c_str());
return ok ? 0 : 1;
}
std::printf("validate-wbrd: %s.wbrd\n", base.c_str());
if (ok && warnings.empty()) {
std::printf(" OK — %zu stages, all rewardIds + "
"(bgId,bracket) pairs unique, "
"bracketIndex 1..6, minPlayersToStart "
"> 0, winHonor >= lossHonor, no "
"bonus-count without bonus-itemId\n",
c.entries.size());
return 0;
}
if (!warnings.empty()) {
std::printf(" warnings (%zu):\n", warnings.size());
for (const auto& w : warnings)
std::printf(" - %s\n", w.c_str());
}
if (!errors.empty()) {
std::printf(" ERRORS (%zu):\n", errors.size());
for (const auto& e : errors)
std::printf(" - %s\n", e.c_str());
}
return ok ? 0 : 1;
}
} // namespace
bool handleBattlegroundRewardsCatalog(int& i, int argc, char** argv,
int& outRc) {
if (std::strcmp(argv[i], "--gen-brd-av") == 0 &&
i + 1 < argc) {
outRc = handleGenAV(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-brd-wsg") == 0 &&
i + 1 < argc) {
outRc = handleGenWSG(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-brd-ab") == 0 &&
i + 1 < argc) {
outRc = handleGenAB(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--info-wbrd") == 0 && i + 1 < argc) {
outRc = handleInfo(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--validate-wbrd") == 0 &&
i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
return false;
}
} // namespace cli
} // namespace editor
} // namespace wowee