#include "cli_creature_difficulties_catalog.hpp" #include "cli_arg_parse.hpp" #include "cli_box_emitter.hpp" #include "pipeline/wowee_creature_difficulties.hpp" #include #include #include #include #include #include #include #include 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 errors; std::vector warnings; if (c.entries.empty()) { warnings.push_back("catalog has zero entries"); } std::vector idsSeen; std::vector 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