Kelsidavis-WoWee/tools/editor/cli_creature_difficulties_catalog.cpp

272 lines
10 KiB
C++
Raw Normal View History

feat(editor): add WCDF (Creature Difficulty) open catalog format Open replacement for Blizzard's CreatureDifficulty.dbc. Maps a base creature entry to its difficulty variants: Normal-10 / Normal-25 / Heroic-10 / Heroic-25 in WotLK raid format. Each variant is itself a separate WCRT creature entry with its own stats, abilities, and loot. When a 25-man party engages an instance, the engine looks up the encounter base creature's difficultyId, reads the normal25Id field, and spawns that variant instead. This is how Lord Marrowgar in 25-Heroic ICC has 30M HP and hits for 80k while the same encounter in 10-Normal has 5M HP and hits for 25k — same spawn point, different WCRT entries. 5-man dungeons typically use only normal10Id + heroic10Id (the 25-man fields stay 0 — engine falls through to the 10-man variant when 25-man is queried). World bosses don't scale at all (all 4 variant fields stay 0, engine falls back to the base entry). Cross-references back to WCRT — every non-zero variant id field points at a WCRT.creatureId entry; the base creature itself lives in WCRT too. Three preset emitters: --gen-cdf (4 example bosses with full 4-variant routing), --gen-cdf-wotlk-raid (4 ICC-style raid bosses Marrowgar/Deathwhisper/Saurfang/LK with all 4 difficulty variants), --gen-cdf-fiveman (4 5-man dungeon bosses with only Normal+Heroic 10-man set). resolveVariant(id, mode) is the engine helper. Validation enforces id+name+baseCreatureId presence, spawnGroupKind 0..5, no duplicate ids; warns on: - WorldBoss kind with non-zero variant ids (world bosses don't scale) - duplicate baseCreatureId across routes (only first honored) - all-self-reference non-WorldBoss (creature doesn't actually scale) - Boss with n25 but not n10 (raid sequencing typo — n10 always comes with n25) Wired through the cross-format table; WCDF appears automatically in all 11 cross-format utilities. Format count 74 -> 75; CLI flag count 936 -> 941.
2026-05-09 22:10:09 -07:00
#include "cli_creature_difficulties_catalog.hpp"
#include "cli_arg_parse.hpp"
#include "cli_box_emitter.hpp"
#include "pipeline/wowee_creature_difficulties.hpp"
#include <nlohmann/json.hpp>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <set>
#include <string>
#include <vector>
namespace wowee {
namespace editor {
namespace cli {
namespace {
std::string stripWcdfExt(std::string base) {
stripExt(base, ".wcdf");
return base;
}
bool saveOrError(const wowee::pipeline::WoweeCreatureDifficulty& c,
const std::string& base, const char* cmd) {
if (!wowee::pipeline::WoweeCreatureDifficultyLoader::save(c, base)) {
std::fprintf(stderr, "%s: failed to save %s.wcdf\n",
cmd, base.c_str());
return false;
}
return true;
}
void printGenSummary(const wowee::pipeline::WoweeCreatureDifficulty& c,
const std::string& base) {
std::printf("Wrote %s.wcdf\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" routes : %zu\n", c.entries.size());
}
int handleGenStarter(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "StarterDifficulties";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWcdfExt(base);
auto c = wowee::pipeline::WoweeCreatureDifficultyLoader::makeStarter(name);
if (!saveOrError(c, base, "gen-cdf")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenWotlkRaid(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "WotlkICCBosses";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWcdfExt(base);
auto c = wowee::pipeline::WoweeCreatureDifficultyLoader::makeWotlkRaid(name);
if (!saveOrError(c, base, "gen-cdf-wotlk-raid")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenFiveMan(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "FiveManDungeons";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWcdfExt(base);
auto c = wowee::pipeline::WoweeCreatureDifficultyLoader::makeFiveMan(name);
if (!saveOrError(c, base, "gen-cdf-fiveman")) 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 = stripWcdfExt(base);
if (!wowee::pipeline::WoweeCreatureDifficultyLoader::exists(base)) {
std::fprintf(stderr, "WCDF not found: %s.wcdf\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeCreatureDifficultyLoader::load(base);
if (jsonOut) {
nlohmann::json j;
j["wcdf"] = base + ".wcdf";
j["name"] = c.name;
j["count"] = c.entries.size();
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"difficultyId", e.difficultyId},
{"name", e.name},
{"description", e.description},
{"baseCreatureId", e.baseCreatureId},
{"normal10Id", e.normal10Id},
{"normal25Id", e.normal25Id},
{"heroic10Id", e.heroic10Id},
{"heroic25Id", e.heroic25Id},
{"spawnGroupKind", e.spawnGroupKind},
{"spawnGroupKindName", wowee::pipeline::WoweeCreatureDifficulty::spawnGroupKindName(e.spawnGroupKind)},
{"iconColorRGBA", e.iconColorRGBA},
});
}
j["entries"] = arr;
std::printf("%s\n", j.dump(2).c_str());
return 0;
}
std::printf("WCDF: %s.wcdf\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" routes : %zu\n", c.entries.size());
if (c.entries.empty()) return 0;
std::printf(" id kind base n10 n25 h10 h25 name\n");
for (const auto& e : c.entries) {
std::printf(" %4u %-10s %5u %5u %5u %5u %5u %s\n",
e.difficultyId,
wowee::pipeline::WoweeCreatureDifficulty::spawnGroupKindName(e.spawnGroupKind),
e.baseCreatureId,
e.normal10Id, e.normal25Id,
e.heroic10Id, e.heroic25Id,
e.name.c_str());
}
return 0;
}
int handleValidate(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
base = stripWcdfExt(base);
if (!wowee::pipeline::WoweeCreatureDifficultyLoader::exists(base)) {
std::fprintf(stderr,
"validate-wcdf: WCDF not found: %s.wcdf\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeCreatureDifficultyLoader::load(base);
std::vector<std::string> errors;
std::vector<std::string> warnings;
if (c.entries.empty()) {
warnings.push_back("catalog has zero entries");
}
std::vector<uint32_t> idsSeen;
std::vector<uint32_t> baseSeen;
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.difficultyId);
if (!e.name.empty()) ctx += " " + e.name;
ctx += ")";
if (e.difficultyId == 0)
errors.push_back(ctx + ": difficultyId is 0");
if (e.name.empty())
errors.push_back(ctx + ": name is empty");
if (e.spawnGroupKind > wowee::pipeline::WoweeCreatureDifficulty::WorldBoss) {
errors.push_back(ctx + ": spawnGroupKind " +
std::to_string(e.spawnGroupKind) + " not in 0..5");
}
if (e.baseCreatureId == 0)
errors.push_back(ctx +
": baseCreatureId is 0 — missing WCRT cross-ref");
// World bosses don't scale, so all 4 variant fields
// should be 0 (engine falls through to base).
if (e.spawnGroupKind == wowee::pipeline::WoweeCreatureDifficulty::WorldBoss &&
(e.normal10Id || e.normal25Id || e.heroic10Id || e.heroic25Id)) {
warnings.push_back(ctx +
": WorldBoss kind with non-zero variant ids — "
"world bosses don't scale, set variant fields to 0");
}
// The asymmetric case n25 set without n10 is
// suspicious — typically a typo, since raid
// sequencing always introduces n10 alongside n25.
// (5-man bosses legitimately have only n10/h10, so
// we don't warn on missing n25 alone.)
if (e.spawnGroupKind == wowee::pipeline::WoweeCreatureDifficulty::Boss &&
e.normal25Id && !e.normal10Id) {
warnings.push_back(ctx +
": Boss has normal25Id but not normal10Id — "
"raid sequencing introduces n10 alongside n25; "
"this is probably a typo");
}
for (uint32_t prev : idsSeen) {
if (prev == e.difficultyId) {
errors.push_back(ctx + ": duplicate difficultyId");
break;
}
}
idsSeen.push_back(e.difficultyId);
// Two routes for the same base creature collide —
// engine would only honor the first.
if (e.baseCreatureId != 0) {
for (uint32_t prevBase : baseSeen) {
if (prevBase == e.baseCreatureId) {
warnings.push_back(ctx +
": duplicate baseCreatureId " +
std::to_string(e.baseCreatureId) +
" — only the first route entry will be honored");
break;
}
}
baseSeen.push_back(e.baseCreatureId);
}
// Check for self-reference loops (base == any
// variant) which are valid for world bosses but
// nonsensical otherwise.
if (e.spawnGroupKind != wowee::pipeline::WoweeCreatureDifficulty::WorldBoss) {
if ((e.normal10Id == e.baseCreatureId &&
e.normal25Id == e.baseCreatureId &&
e.heroic10Id == e.baseCreatureId &&
e.heroic25Id == e.baseCreatureId) &&
e.normal10Id != 0) {
warnings.push_back(ctx +
": all four variants point at baseCreatureId — "
"creature doesn't scale; consider WorldBoss kind");
}
}
}
bool ok = errors.empty();
if (jsonOut) {
nlohmann::json j;
j["wcdf"] = base + ".wcdf";
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-wcdf: %s.wcdf\n", base.c_str());
if (ok && warnings.empty()) {
std::printf(" OK — %zu routes, all difficultyIds unique, all base ids set\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 handleCreatureDifficultiesCatalog(int& i, int argc,
char** argv, int& outRc) {
if (std::strcmp(argv[i], "--gen-cdf") == 0 && i + 1 < argc) {
outRc = handleGenStarter(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-cdf-wotlk-raid") == 0 && i + 1 < argc) {
outRc = handleGenWotlkRaid(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-cdf-fiveman") == 0 && i + 1 < argc) {
outRc = handleGenFiveMan(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--info-wcdf") == 0 && i + 1 < argc) {
outRc = handleInfo(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--validate-wcdf") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
return false;
}
} // namespace cli
} // namespace editor
} // namespace wowee