diff --git a/CMakeLists.txt b/CMakeLists.txt index b3c8f956..55621fff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -725,6 +725,7 @@ set(WOWEE_SOURCES src/pipeline/wowee_world_locations.cpp src/pipeline/wowee_soulbind_rules.cpp src/pipeline/wowee_creature_behavior.cpp + src/pipeline/wowee_random_property.cpp src/pipeline/custom_zone_discovery.cpp src/pipeline/dbc_layout.cpp @@ -1613,6 +1614,7 @@ add_executable(wowee_editor tools/editor/cli_world_locations_catalog.cpp tools/editor/cli_soulbind_rules_catalog.cpp tools/editor/cli_creature_behavior_catalog.cpp + tools/editor/cli_random_property_catalog.cpp tools/editor/cli_catalog_pluck.cpp tools/editor/cli_catalog_find.cpp tools/editor/cli_catalog_by_name.cpp @@ -1820,6 +1822,7 @@ add_executable(wowee_editor src/pipeline/wowee_world_locations.cpp src/pipeline/wowee_soulbind_rules.cpp src/pipeline/wowee_creature_behavior.cpp + src/pipeline/wowee_random_property.cpp src/pipeline/custom_zone_discovery.cpp src/pipeline/terrain_mesh.cpp diff --git a/include/pipeline/wowee_random_property.hpp b/include/pipeline/wowee_random_property.hpp new file mode 100644 index 00000000..eabb73fe --- /dev/null +++ b/include/pipeline/wowee_random_property.hpp @@ -0,0 +1,131 @@ +#pragma once + +#include +#include +#include + +namespace wowee { +namespace pipeline { + +// Wowee Open Item Random Property Pool catalog +// (.wirc) — novel replacement for the random- +// suffix enchant pool that vanilla WoW carried in +// ItemRandomProperties.dbc + ItemRandomSuffix.dbc +// (TBC+) + the per-item RandomProperty rolls baked +// into the LootMgr. Each WIRC entry binds one +// random-property pool to a name suffix ("of the +// Bear", "of the Eagle"), a weighted enchant table +// (variable-length array of {enchantId, weight}), +// and the equipment slots + class restrictions +// where the suffix can roll. +// +// At loot time, each green+ item rolls one pool +// based on its slot, then picks one enchant from +// that pool weighted by enchant.weight / +// totalWeight. +// +// Cross-references with previously-added formats: +// WIT: pool affinity is determined by the +// item's slot (which lives in WIT). At +// runtime the loot generator picks the +// pool whose allowedSlots bitmask matches +// the item's slot. +// WSPL: enchantId references the WSPL spell +// catalog (enchant spells have spellId +// ranges 7000..30000 in vanilla). +// +// Binary layout (little-endian): +// magic[4] = "WIRC" +// version (uint32) = current 1 +// nameLen + name (catalog label) +// entryCount (uint32) +// entries (each): +// poolId (uint32) +// nameLen + name (suffix display: "of the X") +// scaleLevel (uint8) — itemLevel band +// (1..60 vanilla); +// 0 = any +// allowedSlotsMask (uint8) — 0x01=Helm, +// 0x02=Shoulder, +// 0x04=Chest, +// 0x08=Leg, +// 0x10=Boot, +// 0x20=Glove, +// 0x40=Bracer, +// 0x80=Belt +// allowedClassesMask (uint16) — bitmask 1< enchants; + }; + + std::string name; + std::vector entries; + + bool isValid() const { return !entries.empty(); } + + const Entry* findById(uint32_t poolId) const; + + // Returns pools applicable to a given slot mask + // — used by the loot generator to pick eligible + // suffix pools at roll time. + std::vector findBySlot(uint8_t slotMask) const; +}; + +class WoweeRandomPropertyLoader { +public: + static bool save(const WoweeRandomProperty& cat, + const std::string& basePath); + static WoweeRandomProperty load(const std::string& basePath); + static bool exists(const std::string& basePath); + + // Preset emitters used by --gen-irc* variants. + // + // makeOfTheBear — STA-focused suffix pool for + // plate/mail slots (Helm, + // Chest, Leg, Boot). 4 + // enchants weighted toward + // +Sta variants. + // makeOfTheEagle — INT+STA caster pool for + // cloth slots. 5 enchants + // weighted toward +Int +Sta. + // makeOfTheTiger — STR+AGI hybrid pool for + // leather slots. 5 enchants + // covering AGI/STR/AP + // variants. + static WoweeRandomProperty makeOfTheBear(const std::string& catalogName); + static WoweeRandomProperty makeOfTheEagle(const std::string& catalogName); + static WoweeRandomProperty makeOfTheTiger(const std::string& catalogName); +}; + +} // namespace pipeline +} // namespace wowee diff --git a/src/pipeline/wowee_random_property.cpp b/src/pipeline/wowee_random_property.cpp new file mode 100644 index 00000000..f2a166d9 --- /dev/null +++ b/src/pipeline/wowee_random_property.cpp @@ -0,0 +1,255 @@ +#include "pipeline/wowee_random_property.hpp" + +#include +#include +#include + +namespace wowee { +namespace pipeline { + +namespace { + +constexpr char kMagic[4] = {'W', 'I', 'R', 'C'}; +constexpr uint32_t kVersion = 1; + +template +void writePOD(std::ofstream& os, const T& v) { + os.write(reinterpret_cast(&v), sizeof(T)); +} + +template +bool readPOD(std::ifstream& is, T& v) { + is.read(reinterpret_cast(&v), sizeof(T)); + return is.gcount() == static_cast(sizeof(T)); +} + +void writeStr(std::ofstream& os, const std::string& s) { + uint32_t n = static_cast(s.size()); + writePOD(os, n); + if (n > 0) os.write(s.data(), n); +} + +bool readStr(std::ifstream& is, std::string& s) { + uint32_t n = 0; + if (!readPOD(is, n)) return false; + if (n > (1u << 20)) return false; + s.resize(n); + if (n > 0) { + is.read(s.data(), n); + if (is.gcount() != static_cast(n)) { + s.clear(); + return false; + } + } + return true; +} + +std::string normalizePath(std::string base) { + if (base.size() < 5 || base.substr(base.size() - 5) != ".wirc") { + base += ".wirc"; + } + return base; +} + +} // namespace + +const WoweeRandomProperty::Entry* +WoweeRandomProperty::findById(uint32_t poolId) const { + for (const auto& e : entries) + if (e.poolId == poolId) return &e; + return nullptr; +} + +std::vector +WoweeRandomProperty::findBySlot(uint8_t slotMask) const { + std::vector out; + for (const auto& e : entries) { + if (e.allowedSlotsMask & slotMask) + out.push_back(&e); + } + return out; +} + +bool WoweeRandomPropertyLoader::save( + const WoweeRandomProperty& cat, + const std::string& basePath) { + std::ofstream os(normalizePath(basePath), std::ios::binary); + if (!os) return false; + os.write(kMagic, 4); + writePOD(os, kVersion); + writeStr(os, cat.name); + uint32_t entryCount = static_cast(cat.entries.size()); + writePOD(os, entryCount); + for (const auto& e : cat.entries) { + writePOD(os, e.poolId); + writeStr(os, e.name); + writePOD(os, e.scaleLevel); + writePOD(os, e.allowedSlotsMask); + writePOD(os, e.allowedClassesMask); + writePOD(os, e.totalWeight); + uint32_t enchantCount = + static_cast(e.enchants.size()); + writePOD(os, enchantCount); + for (const auto& en : e.enchants) { + writePOD(os, en.enchantId); + writePOD(os, en.weight); + } + } + return os.good(); +} + +WoweeRandomProperty WoweeRandomPropertyLoader::load( + const std::string& basePath) { + WoweeRandomProperty out; + std::ifstream is(normalizePath(basePath), std::ios::binary); + if (!is) return out; + char magic[4]; + is.read(magic, 4); + if (std::memcmp(magic, kMagic, 4) != 0) return out; + uint32_t version = 0; + if (!readPOD(is, version) || version != kVersion) return out; + if (!readStr(is, out.name)) return out; + uint32_t entryCount = 0; + if (!readPOD(is, entryCount)) return out; + if (entryCount > (1u << 20)) return out; + out.entries.resize(entryCount); + for (auto& e : out.entries) { + if (!readPOD(is, e.poolId)) { + out.entries.clear(); return out; + } + if (!readStr(is, e.name)) { + out.entries.clear(); return out; + } + if (!readPOD(is, e.scaleLevel) || + !readPOD(is, e.allowedSlotsMask) || + !readPOD(is, e.allowedClassesMask) || + !readPOD(is, e.totalWeight)) { + out.entries.clear(); return out; + } + uint32_t enchantCount = 0; + if (!readPOD(is, enchantCount)) { + out.entries.clear(); return out; + } + // Sanity cap — vanilla pools never exceed 12 + // enchants; format cap 64. + if (enchantCount > 64) { + out.entries.clear(); return out; + } + e.enchants.resize(enchantCount); + for (auto& en : e.enchants) { + if (!readPOD(is, en.enchantId) || + !readPOD(is, en.weight)) { + out.entries.clear(); return out; + } + } + } + return out; +} + +bool WoweeRandomPropertyLoader::exists( + const std::string& basePath) { + std::ifstream is(normalizePath(basePath), std::ios::binary); + return is.good(); +} + +namespace { + +// Helper: build entry with auto-summed totalWeight. +WoweeRandomProperty::Entry makePool( + uint32_t poolId, const char* name, + uint8_t scaleLevel, uint8_t slotsMask, + uint16_t classesMask, + std::vector enchants) { + WoweeRandomProperty::Entry e; + e.poolId = poolId; e.name = name; + e.scaleLevel = scaleLevel; + e.allowedSlotsMask = slotsMask; + e.allowedClassesMask = classesMask; + e.enchants = std::move(enchants); + uint32_t sum = 0; + for (const auto& en : e.enchants) sum += en.weight; + e.totalWeight = sum; + return e; +} + +WoweeRandomProperty::EnchantEntry mkEn(uint32_t enchantId, + uint32_t weight) { + WoweeRandomProperty::EnchantEntry en; + en.enchantId = enchantId; + en.weight = weight; + return en; +} + +} // namespace + +WoweeRandomProperty WoweeRandomPropertyLoader::makeOfTheBear( + const std::string& catalogName) { + using R = WoweeRandomProperty; + WoweeRandomProperty c; + c.name = catalogName; + // "of the Bear" = +Sta. Plate slots (Helm/Chest/ + // Leg/Boot). Class mask: Warrior(1)+Paladin(2)+ + // DK(6) = 1<<1 | 1<<2 | 1<<6 = 0x46. + // Enchants 1189..1192 are vanilla +3/+5/+7/+10 + // Stamina enchants. Weights tilt toward middle + // tier (5 stamina being most common). + c.entries.push_back(makePool( + 1, "of the Bear (low)", 20, + R::Helm | R::Chest | R::Leg | R::Boot, + 0x46, + {mkEn(1189, 30), // +3 Sta + mkEn(1190, 50), // +5 Sta — most likely + mkEn(1191, 15), // +7 Sta + mkEn(1192, 5)})); // +10 Sta — rare + return c; +} + +WoweeRandomProperty WoweeRandomPropertyLoader::makeOfTheEagle( + const std::string& catalogName) { + using R = WoweeRandomProperty; + WoweeRandomProperty c; + c.name = catalogName; + // "of the Eagle" = +Int+Sta. Cloth slots. + // Class mask: Mage(8)+Priest(5)+Warlock(9) = + // 1<<8 | 1<<5 | 1<<9 = 0x320. + // Enchant ids approximate (canonical IDs would + // be looked up from Spell.dbc). + c.entries.push_back(makePool( + 2, "of the Eagle", 30, + R::Helm | R::Chest | R::Leg | R::Glove, + 0x320, + {mkEn(1503, 25), // +3 Int +3 Sta + mkEn(1504, 35), // +5 Int +5 Sta — most + // common + mkEn(1505, 25), // +7 Int +7 Sta + mkEn(1506, 10), // +10 Int +10 Sta + mkEn(1507, 5)})); // +12 Int +12 Sta + // — rarest + return c; +} + +WoweeRandomProperty WoweeRandomPropertyLoader::makeOfTheTiger( + const std::string& catalogName) { + using R = WoweeRandomProperty; + WoweeRandomProperty c; + c.name = catalogName; + // "of the Tiger" = +Str+Agi (rogue/druid AP + // suffix). Leather slots. Class mask: Rogue(4)+ + // Druid(11)+Hunter(3) = 1<<4 | 1<<11 | 1<<3 = + // 0x818. + c.entries.push_back(makePool( + 3, "of the Tiger", 35, + R::Helm | R::Chest | R::Leg | R::Glove | R::Boot, + 0x818, + {mkEn(1605, 25), // +3 Str +3 Agi + mkEn(1606, 30), // +5 Str +5 Agi — most + // common + mkEn(1607, 25), // +7 Str +7 Agi + mkEn(1608, 15), // +10 Str +10 Agi + mkEn(1609, 5)})); // +12 Str +12 Agi — + // rarest + return c; +} + +} // namespace pipeline +} // namespace wowee diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index d7742115..f8d3c6d1 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -419,6 +419,8 @@ const char* const kArgRequired[] = { "--gen-bhv-melee", "--gen-bhv-caster", "--gen-bhv-boss", "--info-wbhv", "--validate-wbhv", "--export-wbhv-json", "--import-wbhv-json", + "--gen-irc-bear", "--gen-irc-eagle", "--gen-irc-tiger", + "--info-wirc", "--validate-wirc", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_dispatch.cpp b/tools/editor/cli_dispatch.cpp index bf3a9c88..0fb40205 100644 --- a/tools/editor/cli_dispatch.cpp +++ b/tools/editor/cli_dispatch.cpp @@ -181,6 +181,7 @@ #include "cli_world_locations_catalog.hpp" #include "cli_soulbind_rules_catalog.hpp" #include "cli_creature_behavior_catalog.hpp" +#include "cli_random_property_catalog.hpp" #include "cli_catalog_pluck.hpp" #include "cli_catalog_find.hpp" #include "cli_catalog_by_name.hpp" @@ -407,6 +408,7 @@ constexpr DispatchFn kDispatchTable[] = { handleWorldLocationsCatalog, handleSoulbindRulesCatalog, handleCreatureBehaviorCatalog, + handleRandomPropertyCatalog, handleCatalogPluck, handleCatalogFind, handleCatalogByName, diff --git a/tools/editor/cli_format_table.cpp b/tools/editor/cli_format_table.cpp index d11de8c2..7e04eb8c 100644 --- a/tools/editor/cli_format_table.cpp +++ b/tools/editor/cli_format_table.cpp @@ -139,6 +139,7 @@ constexpr FormatMagicEntry kFormats[] = { {{'W','L','O','C'}, ".wloc", "world", "--info-wloc", "World locations catalog"}, {{'W','B','N','D'}, ".wbnd", "loot", "--info-wbnd", "Soulbind rules catalog"}, {{'W','B','H','V'}, ".wbhv", "ai", "--info-wbhv", "Creature behavior catalog"}, + {{'W','I','R','C'}, ".wirc", "loot", "--info-wirc", "Item random-property pool catalog"}, {{'W','F','A','C'}, ".wfac", "factions", nullptr, "Faction catalog"}, {{'W','L','C','K'}, ".wlck", "locks", nullptr, "Lock catalog"}, {{'W','S','K','L'}, ".wskl", "skills", nullptr, "Skill catalog"}, diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index b18cc772..0aeb5d71 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2671,6 +2671,16 @@ void printUsage(const char* argv0) { std::printf(" Export binary .wbhv to a human-editable JSON sidecar (defaults to .wbhv.json; emits both creatureKind and evadeBehavior as int + name string; specialAbilities as JSON object array of {spellId, cooldownMs, useChancePct})\n"); std::printf(" --import-wbhv-json [out-base]\n"); std::printf(" Import a .wbhv.json sidecar back into binary .wbhv (creatureKind int OR \"melee\"/\"caster\"/\"tank\"/\"healer\"/\"pet\"/\"beast\"; evadeBehavior int OR \"resettospawn\"/\"healatpath\"/\"fleetospawn\"/\"noevade\"; specialAbilities accept JSON object array — round-trips per-behavior variable-length ability lists byte-identical)\n"); + std::printf(" --gen-irc-bear [name]\n"); + std::printf(" Emit .wirc 'of the Bear' STA-suffix pool for plate slots (Helm/Chest/Leg/Boot) with 4 weighted +Sta enchants (3/5/7/10), Warrior+Paladin+DK class mask\n"); + std::printf(" --gen-irc-eagle [name]\n"); + std::printf(" Emit .wirc 'of the Eagle' INT+STA caster pool for cloth slots with 5 weighted +Int+Sta enchants (3/5/7/10/12), Mage+Priest+Warlock class mask\n"); + std::printf(" --gen-irc-tiger [name]\n"); + std::printf(" Emit .wirc 'of the Tiger' STR+AGI hybrid pool for leather slots with 5 weighted enchants (3/5/7/10/12), Rogue+Hunter+Druid class mask\n"); + std::printf(" --info-wirc [--json]\n"); + std::printf(" Print WIRC entries (poolId / scaleLevel / allowedSlots-mask-as-string / classes-bitmask / totalWeight / enchant count / name)\n"); + std::printf(" --validate-wirc [--json]\n"); + std::printf(" Static checks: id+name required, allowedSlotsMask != 0 (else pool is unreachable — no slot would ever roll it), non-empty enchant array (loot generator needs something to pick), no zero-id enchants, no duplicate enchantIds within same pool (should be merged with summed weight), no duplicate poolIds; CRITICAL: totalWeight MUST equal sum of enchant weights (else loot generator's denormalized roll mis-picks the distribution). Warns on enchant weight=0 (never picked, dead entry)\n"); std::printf(" --catalog-pluck [--json]\n"); std::printf(" Extract one entry by id from any registered catalog format. Auto-detects magic, dispatches to the per-format --info-* handler internally, then prints just the matching entry. Primary-key field is auto-detected (first *Id field, or first numeric)\n"); std::printf(" --catalog-find [--magic ] [--json]\n"); diff --git a/tools/editor/cli_list_formats.cpp b/tools/editor/cli_list_formats.cpp index 48a10f17..59b7e926 100644 --- a/tools/editor/cli_list_formats.cpp +++ b/tools/editor/cli_list_formats.cpp @@ -161,6 +161,7 @@ constexpr FormatRow kFormats[] = { {"WLOC", ".wloc", "world", "AreaPOI + GO spawns + AreaTrigger.dbc","World locations catalog (POI/RareSpawn/HerbNode/MineralVein/FishingSpot/Trigger/PortalLand)"}, {"WBND", ".wbnd", "loot", "ItemTemplate.bondingType + LootMgr", "Soulbind rules catalog (BoP/BoE/BoU/BoA + raid-trade window)"}, {"WBHV", ".wbhv", "ai", "creature_template.AIName + ScriptMgr","Creature behavior catalog (combat AI archetypes + special abilities)"}, + {"WIRC", ".wirc", "loot", "ItemRandomProperties.dbc + LootMgr", "Item random-property pool catalog (weighted suffix enchants)"}, // Additional pipeline catalogs without the alternating // gen/info/validate CLI surface (loaded by the engine diff --git a/tools/editor/cli_random_property_catalog.cpp b/tools/editor/cli_random_property_catalog.cpp new file mode 100644 index 00000000..7ca907cd --- /dev/null +++ b/tools/editor/cli_random_property_catalog.cpp @@ -0,0 +1,308 @@ +#include "cli_random_property_catalog.hpp" +#include "cli_arg_parse.hpp" +#include "cli_box_emitter.hpp" + +#include "pipeline/wowee_random_property.hpp" +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace wowee { +namespace editor { +namespace cli { + +namespace { + +std::string stripWircExt(std::string base) { + stripExt(base, ".wirc"); + return base; +} + +bool saveOrError(const wowee::pipeline::WoweeRandomProperty& c, + const std::string& base, const char* cmd) { + if (!wowee::pipeline::WoweeRandomPropertyLoader::save(c, base)) { + std::fprintf(stderr, "%s: failed to save %s.wirc\n", + cmd, base.c_str()); + return false; + } + return true; +} + +void printGenSummary(const wowee::pipeline::WoweeRandomProperty& c, + const std::string& base) { + std::printf("Wrote %s.wirc\n", base.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" pools : %zu\n", c.entries.size()); +} + +int handleGenBear(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "OfTheBearPool"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWircExt(base); + auto c = wowee::pipeline::WoweeRandomPropertyLoader:: + makeOfTheBear(name); + if (!saveOrError(c, base, "gen-irc-bear")) return 1; + printGenSummary(c, base); + return 0; +} + +int handleGenEagle(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "OfTheEaglePool"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWircExt(base); + auto c = wowee::pipeline::WoweeRandomPropertyLoader:: + makeOfTheEagle(name); + if (!saveOrError(c, base, "gen-irc-eagle")) return 1; + printGenSummary(c, base); + return 0; +} + +int handleGenTiger(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "OfTheTigerPool"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWircExt(base); + auto c = wowee::pipeline::WoweeRandomPropertyLoader:: + makeOfTheTiger(name); + if (!saveOrError(c, base, "gen-irc-tiger")) return 1; + printGenSummary(c, base); + return 0; +} + +std::string slotsMaskString(uint8_t mask) { + using R = wowee::pipeline::WoweeRandomProperty; + if (mask == 0) return "(none)"; + std::string s; + auto add = [&](uint8_t bit, const char* label) { + if (mask & bit) { + if (!s.empty()) s += "|"; + s += label; + } + }; + add(R::Helm, "Helm"); add(R::Shoulder, "Shoulder"); + add(R::Chest, "Chest"); add(R::Leg, "Leg"); + add(R::Boot, "Boot"); add(R::Glove, "Glove"); + add(R::Bracer, "Bracer"); add(R::Belt, "Belt"); + return s; +} + +int handleInfo(int& i, int argc, char** argv) { + std::string base = argv[++i]; + bool jsonOut = consumeJsonFlag(i, argc, argv); + base = stripWircExt(base); + if (!wowee::pipeline::WoweeRandomPropertyLoader::exists(base)) { + std::fprintf(stderr, "WIRC not found: %s.wirc\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeRandomPropertyLoader::load(base); + if (jsonOut) { + nlohmann::json j; + j["wirc"] = base + ".wirc"; + j["name"] = c.name; + j["count"] = c.entries.size(); + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json enchants = nlohmann::json::array(); + for (const auto& en : e.enchants) { + enchants.push_back({ + {"enchantId", en.enchantId}, + {"weight", en.weight}, + }); + } + arr.push_back({ + {"poolId", e.poolId}, + {"name", e.name}, + {"scaleLevel", e.scaleLevel}, + {"allowedSlotsMask", e.allowedSlotsMask}, + {"allowedSlotsString", + slotsMaskString(e.allowedSlotsMask)}, + {"allowedClassesMask", e.allowedClassesMask}, + {"totalWeight", e.totalWeight}, + {"enchants", enchants}, + }); + } + j["entries"] = arr; + std::printf("%s\n", j.dump(2).c_str()); + return 0; + } + std::printf("WIRC: %s.wirc\n", base.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" pools : %zu\n", c.entries.size()); + if (c.entries.empty()) return 0; + std::printf(" id scale slots classes total enchants name\n"); + for (const auto& e : c.entries) { + std::printf(" %4u %5u %-30s 0x%04X %5u %8zu %s\n", + e.poolId, e.scaleLevel, + slotsMaskString(e.allowedSlotsMask).c_str(), + e.allowedClassesMask, + e.totalWeight, + e.enchants.size(), + 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 = stripWircExt(base); + if (!wowee::pipeline::WoweeRandomPropertyLoader::exists(base)) { + std::fprintf(stderr, + "validate-wirc: WIRC not found: %s.wirc\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeRandomPropertyLoader::load(base); + std::vector errors; + std::vector warnings; + if (c.entries.empty()) { + warnings.push_back("catalog has zero entries"); + } + std::set idsSeen; + 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.poolId); + if (!e.name.empty()) ctx += " " + e.name; + ctx += ")"; + if (e.poolId == 0) + errors.push_back(ctx + ": poolId is 0"); + if (e.name.empty()) + errors.push_back(ctx + ": name is empty"); + // allowedSlotsMask=0 means no slot can roll + // this pool — pool is unreachable. + if (e.allowedSlotsMask == 0) { + errors.push_back(ctx + + ": allowedSlotsMask is 0 — no slot " + "would ever roll this pool (unreachable)"); + } + // Empty enchant array means the loot generator + // would have nothing to pick from. + if (e.enchants.empty()) { + errors.push_back(ctx + + ": no enchants — loot generator would " + "have nothing to pick"); + } + // Per-enchant checks. + std::set enchantsSeen; + uint64_t weightSum = 0; + for (size_t k2 = 0; k2 < e.enchants.size(); ++k2) { + const auto& en = e.enchants[k2]; + if (en.enchantId == 0) { + errors.push_back(ctx + + ": enchant[" + std::to_string(k2) + + "].enchantId is 0"); + } + // Weight 0 means the enchant is in the + // pool but never picked — wastes catalog + // space. Warn. + if (en.weight == 0 && en.enchantId != 0) { + warnings.push_back(ctx + + ": enchant[" + std::to_string(k2) + + "] enchantId=" + + std::to_string(en.enchantId) + + " has weight=0 — never picked, " + "remove or assign weight"); + } + // Same enchant listed twice — should be + // merged into single entry with summed + // weight. + if (en.enchantId != 0 && + !enchantsSeen.insert(en.enchantId).second) { + errors.push_back(ctx + + ": enchant id " + + std::to_string(en.enchantId) + + " appears twice in same pool — " + "should be merged into single entry " + "with summed weight"); + } + weightSum += en.weight; + } + // totalWeight should match sum of enchant + // weights — if not, the loot generator's + // denormalized rolling won't pick the right + // distribution. + if (e.totalWeight != + static_cast(weightSum)) { + errors.push_back(ctx + + ": totalWeight=" + + std::to_string(e.totalWeight) + + " does not match sum of enchant weights=" + + std::to_string(weightSum) + + " — loot generator would mis-pick"); + } + if (!idsSeen.insert(e.poolId).second) { + errors.push_back(ctx + ": duplicate poolId"); + } + } + bool ok = errors.empty(); + if (jsonOut) { + nlohmann::json j; + j["wirc"] = base + ".wirc"; + 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-wirc: %s.wirc\n", base.c_str()); + if (ok && warnings.empty()) { + std::printf(" OK — %zu pools, all poolIds unique, " + "non-zero allowedSlotsMask, non-empty " + "enchant array, no zero-id enchants, no " + "duplicate enchants in same pool, " + "totalWeight matches enchant-weight sum\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 handleRandomPropertyCatalog(int& i, int argc, char** argv, + int& outRc) { + if (std::strcmp(argv[i], "--gen-irc-bear") == 0 && + i + 1 < argc) { + outRc = handleGenBear(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--gen-irc-eagle") == 0 && + i + 1 < argc) { + outRc = handleGenEagle(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--gen-irc-tiger") == 0 && + i + 1 < argc) { + outRc = handleGenTiger(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--info-wirc") == 0 && i + 1 < argc) { + outRc = handleInfo(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--validate-wirc") == 0 && + i + 1 < argc) { + outRc = handleValidate(i, argc, argv); return true; + } + return false; +} + +} // namespace cli +} // namespace editor +} // namespace wowee diff --git a/tools/editor/cli_random_property_catalog.hpp b/tools/editor/cli_random_property_catalog.hpp new file mode 100644 index 00000000..0583b846 --- /dev/null +++ b/tools/editor/cli_random_property_catalog.hpp @@ -0,0 +1,12 @@ +#pragma once + +namespace wowee { +namespace editor { +namespace cli { + +bool handleRandomPropertyCatalog(int& i, int argc, char** argv, + int& outRc); + +} // namespace cli +} // namespace editor +} // namespace wowee