diff --git a/CMakeLists.txt b/CMakeLists.txt index 847b9343..3397fe5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -616,6 +616,7 @@ set(WOWEE_SOURCES src/pipeline/wowee_maps.cpp src/pipeline/wowee_chars.cpp src/pipeline/wowee_tokens.cpp + src/pipeline/wowee_triggers.cpp src/pipeline/custom_zone_discovery.cpp src/pipeline/dbc_layout.cpp @@ -1378,6 +1379,7 @@ add_executable(wowee_editor tools/editor/cli_maps_catalog.cpp tools/editor/cli_chars_catalog.cpp tools/editor/cli_tokens_catalog.cpp + tools/editor/cli_triggers_catalog.cpp tools/editor/cli_quest_objective.cpp tools/editor/cli_quest_reward.cpp tools/editor/cli_clone.cpp @@ -1472,6 +1474,7 @@ add_executable(wowee_editor src/pipeline/wowee_maps.cpp src/pipeline/wowee_chars.cpp src/pipeline/wowee_tokens.cpp + src/pipeline/wowee_triggers.cpp src/pipeline/custom_zone_discovery.cpp src/pipeline/terrain_mesh.cpp diff --git a/include/pipeline/wowee_triggers.hpp b/include/pipeline/wowee_triggers.hpp new file mode 100644 index 00000000..ace5c5eb --- /dev/null +++ b/include/pipeline/wowee_triggers.hpp @@ -0,0 +1,121 @@ +#pragma once + +#include +#include +#include +#include + +namespace wowee { +namespace pipeline { + +// Wowee Open Area Trigger catalog (.wtrg) — novel +// replacement for Blizzard's AreaTrigger.dbc + +// AreaTriggerTeleport.dbc + the AzerothCore-style +// areatrigger_template / areatrigger_teleport SQL tables. +// The 29th open format added to the editor. +// +// Defines proximity-based event zones — when a player +// enters a defined region (box or sphere), the runtime +// fires the trigger's action: teleport to another map, +// award exploration XP for a quest, run a server script, +// gate an instance entrance behind a key item, etc. +// +// Cross-references with previously-added formats: +// WTRG.entry.mapId / areaId → WMS.map.mapId / WMS.area.areaId +// WTRG.entry.actionTarget (kind=Teleport) → WMS.mapId +// WTRG.entry.actionTarget (kind=QuestExploration) → WQT.questId +// WTRG.entry.requiredQuestId → WQT.entry.questId +// WTRG.entry.requiredItemId → WIT.entry.itemId (key) +// +// Binary layout (little-endian): +// magic[4] = "WTRG" +// version (uint32) = current 1 +// nameLen + name (catalog label) +// entryCount (uint32) +// entries (each): +// triggerId (uint32) +// mapId (uint32) +// areaId (uint32) +// nameLen + name +// center (3 × float) +// shape (uint8) + kind (uint8) + pad[2] +// boxDims (3 × float) +// radius (float) +// actionTarget (uint32) +// dest (3 × float) +// destOrientation (float) +// requiredQuestId (uint32) +// requiredItemId (uint32) +// minLevel (uint16) + pad[2] +struct WoweeTrigger { + enum Shape : uint8_t { + ShapeBox = 0, + ShapeSphere = 1, + }; + + enum Kind : uint8_t { + KindTeleport = 0, // moves player to dest + KindQuestExploration = 1, // awards XP toward a quest + KindScript = 2, // runs a server script + KindInstanceEntrance = 3, // dungeon / raid portal + KindAreaName = 4, // shows "Discovered: ..." text + KindCombatStartZone = 5, // marks PvP-flag boundary + KindWaypoint = 6, // waypoint marker (NPCs / quests) + }; + + struct Entry { + uint32_t triggerId = 0; + uint32_t mapId = 0; + uint32_t areaId = 0; // 0 = anywhere on the map + std::string name; + glm::vec3 center{0}; + uint8_t shape = ShapeBox; + uint8_t kind = KindAreaName; + glm::vec3 boxDims{0}; // half-extents; ignored if sphere + float radius = 0.0f; // ignored if box + uint32_t actionTarget = 0; + glm::vec3 dest{0}; // teleport destination + float destOrientation = 0.0f; // teleport facing (radians) + uint32_t requiredQuestId = 0; // 0 = no quest gate + uint32_t requiredItemId = 0; // 0 = no key item required + uint16_t minLevel = 0; + }; + + std::string name; + std::vector entries; + + bool isValid() const { return !entries.empty(); } + + const Entry* findById(uint32_t triggerId) const; + + static const char* shapeName(uint8_t s); + static const char* kindName(uint8_t k); +}; + +class WoweeTriggerLoader { +public: + static bool save(const WoweeTrigger& cat, + const std::string& basePath); + static WoweeTrigger load(const std::string& basePath); + static bool exists(const std::string& basePath); + + // Preset emitters used by --gen-triggers* variants. + // + // makeStarter — 2 triggers: 1 area-name (player enters + // Goldshire) + 1 quest exploration + // (matches WQT 100 "Investigate the Camp"). + // makeDungeon — 3 triggers around an instance: outdoor + // approach area-name + portal-style + // teleport into the instance + instance + // exit teleport back outdoors. + // makeFlightPath — 2 triggers marking flight-master + // proximity (Stormwind / Goldshire) so + // the runtime knows when to open the + // flight UI without explicit interact. + static WoweeTrigger makeStarter(const std::string& catalogName); + static WoweeTrigger makeDungeon(const std::string& catalogName); + static WoweeTrigger makeFlightPath(const std::string& catalogName); +}; + +} // namespace pipeline +} // namespace wowee diff --git a/src/pipeline/wowee_triggers.cpp b/src/pipeline/wowee_triggers.cpp new file mode 100644 index 00000000..c9603337 --- /dev/null +++ b/src/pipeline/wowee_triggers.cpp @@ -0,0 +1,272 @@ +#include "pipeline/wowee_triggers.hpp" + +#include +#include +#include + +namespace wowee { +namespace pipeline { + +namespace { + +constexpr char kMagic[4] = {'W', 'T', 'R', 'G'}; +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) != ".wtrg") { + base += ".wtrg"; + } + return base; +} + +} // namespace + +const WoweeTrigger::Entry* WoweeTrigger::findById(uint32_t triggerId) const { + for (const auto& e : entries) if (e.triggerId == triggerId) return &e; + return nullptr; +} + +const char* WoweeTrigger::shapeName(uint8_t s) { + switch (s) { + case ShapeBox: return "box"; + case ShapeSphere: return "sphere"; + default: return "unknown"; + } +} + +const char* WoweeTrigger::kindName(uint8_t k) { + switch (k) { + case KindTeleport: return "teleport"; + case KindQuestExploration: return "quest-explore"; + case KindScript: return "script"; + case KindInstanceEntrance: return "instance"; + case KindAreaName: return "area-name"; + case KindCombatStartZone: return "pvp-zone"; + case KindWaypoint: return "waypoint"; + default: return "unknown"; + } +} + +bool WoweeTriggerLoader::save(const WoweeTrigger& 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.triggerId); + writePOD(os, e.mapId); + writePOD(os, e.areaId); + writeStr(os, e.name); + writePOD(os, e.center.x); + writePOD(os, e.center.y); + writePOD(os, e.center.z); + writePOD(os, e.shape); + writePOD(os, e.kind); + uint8_t pad2[2] = {0, 0}; + os.write(reinterpret_cast(pad2), 2); + writePOD(os, e.boxDims.x); + writePOD(os, e.boxDims.y); + writePOD(os, e.boxDims.z); + writePOD(os, e.radius); + writePOD(os, e.actionTarget); + writePOD(os, e.dest.x); + writePOD(os, e.dest.y); + writePOD(os, e.dest.z); + writePOD(os, e.destOrientation); + writePOD(os, e.requiredQuestId); + writePOD(os, e.requiredItemId); + writePOD(os, e.minLevel); + os.write(reinterpret_cast(pad2), 2); + } + return os.good(); +} + +WoweeTrigger WoweeTriggerLoader::load(const std::string& basePath) { + WoweeTrigger 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.triggerId) || + !readPOD(is, e.mapId) || + !readPOD(is, e.areaId)) { + out.entries.clear(); return out; + } + if (!readStr(is, e.name)) { + out.entries.clear(); return out; + } + if (!readPOD(is, e.center.x) || + !readPOD(is, e.center.y) || + !readPOD(is, e.center.z) || + !readPOD(is, e.shape) || + !readPOD(is, e.kind)) { + out.entries.clear(); return out; + } + uint8_t pad2[2]; + is.read(reinterpret_cast(pad2), 2); + if (is.gcount() != 2) { out.entries.clear(); return out; } + if (!readPOD(is, e.boxDims.x) || + !readPOD(is, e.boxDims.y) || + !readPOD(is, e.boxDims.z) || + !readPOD(is, e.radius) || + !readPOD(is, e.actionTarget) || + !readPOD(is, e.dest.x) || + !readPOD(is, e.dest.y) || + !readPOD(is, e.dest.z) || + !readPOD(is, e.destOrientation) || + !readPOD(is, e.requiredQuestId) || + !readPOD(is, e.requiredItemId) || + !readPOD(is, e.minLevel)) { + out.entries.clear(); return out; + } + is.read(reinterpret_cast(pad2), 2); + if (is.gcount() != 2) { out.entries.clear(); return out; } + } + return out; +} + +bool WoweeTriggerLoader::exists(const std::string& basePath) { + std::ifstream is(normalizePath(basePath), std::ios::binary); + return is.good(); +} + +WoweeTrigger WoweeTriggerLoader::makeStarter(const std::string& catalogName) { + WoweeTrigger c; + c.name = catalogName; + { + WoweeTrigger::Entry e; + e.triggerId = 1; e.mapId = 0; e.areaId = 87; // WMS Goldshire + e.name = "Goldshire entrance"; + e.center = {-9460.0f, 60.0f, 56.0f}; + e.shape = WoweeTrigger::ShapeSphere; + e.radius = 60.0f; + e.kind = WoweeTrigger::KindAreaName; + c.entries.push_back(e); + } + { + WoweeTrigger::Entry e; + e.triggerId = 2; e.mapId = 0; e.areaId = 12; // Elwynn Forest + e.name = "Bandit Camp clearing"; + e.center = {-9700.0f, 50.0f, 200.0f}; + e.shape = WoweeTrigger::ShapeSphere; + e.radius = 30.0f; + e.kind = WoweeTrigger::KindQuestExploration; + e.actionTarget = 100; // matches WQT.makeChain quest id + c.entries.push_back(e); + } + return c; +} + +WoweeTrigger WoweeTriggerLoader::makeDungeon(const std::string& catalogName) { + WoweeTrigger c; + c.name = catalogName; + // Outdoor approach area-name marker. + { + WoweeTrigger::Entry e; + e.triggerId = 100; e.mapId = 0; e.areaId = 40; // Westfall + e.name = "Approaching Deadmines"; + e.center = {-11000.0f, 50.0f, 1500.0f}; + e.shape = WoweeTrigger::ShapeSphere; + e.radius = 25.0f; + e.kind = WoweeTrigger::KindAreaName; + c.entries.push_back(e); + } + // Portal-style instance entrance with key requirement. + { + WoweeTrigger::Entry e; + e.triggerId = 101; e.mapId = 0; e.areaId = 40; + e.name = "Deadmines Portal"; + e.center = {-11200.0f, 60.0f, 1600.0f}; + e.shape = WoweeTrigger::ShapeBox; + e.boxDims = {3.0f, 5.0f, 3.0f}; + e.kind = WoweeTrigger::KindInstanceEntrance; + e.actionTarget = 36; // WMS Deadmines mapId + e.dest = {-15.0f, 20.0f, 0.0f}; + e.destOrientation = 0.0f; + e.requiredItemId = 5200; // matches WLCK.makeDungeon "Boss Vault Seal" key + e.minLevel = 17; + c.entries.push_back(e); + } + // Inside-instance exit teleport back to the outdoor portal. + { + WoweeTrigger::Entry e; + e.triggerId = 102; e.mapId = 36; e.areaId = 0; + e.name = "Deadmines Exit"; + e.center = {-15.0f, 20.0f, 5.0f}; + e.shape = WoweeTrigger::ShapeBox; + e.boxDims = {3.0f, 5.0f, 3.0f}; + e.kind = WoweeTrigger::KindTeleport; + e.actionTarget = 0; // back to Eastern Kingdoms + e.dest = {-11200.0f, 60.0f, 1605.0f}; + e.destOrientation = 3.14159265f; // facing south on exit + c.entries.push_back(e); + } + return c; +} + +WoweeTrigger WoweeTriggerLoader::makeFlightPath(const std::string& catalogName) { + WoweeTrigger c; + c.name = catalogName; + auto add = [&](uint32_t id, uint32_t mapId, uint32_t areaId, + const char* name, glm::vec3 center) { + WoweeTrigger::Entry e; + e.triggerId = id; e.mapId = mapId; e.areaId = areaId; + e.name = name; e.center = center; + e.shape = WoweeTrigger::ShapeSphere; e.radius = 8.0f; + e.kind = WoweeTrigger::KindWaypoint; + c.entries.push_back(e); + }; + add(200, 0, 1, "Stormwind Gryphon Master proximity", + {-9000.0f, 100.0f, 50.0f}); + add(201, 0, 87, "Goldshire Gryphon Master proximity", + {-9460.0f, 60.0f, 56.0f}); + return c; +} + +} // namespace pipeline +} // namespace wowee diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 326d4051..0741a621 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -83,6 +83,8 @@ const char* const kArgRequired[] = { "--gen-tokens", "--gen-tokens-pvp", "--gen-tokens-seasonal", "--info-wtkn", "--validate-wtkn", "--export-wtkn-json", "--import-wtkn-json", + "--gen-triggers", "--gen-triggers-dungeon", "--gen-triggers-flightpath", + "--info-wtrg", "--validate-wtrg", "--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 8c3979c5..f683e7d2 100644 --- a/tools/editor/cli_dispatch.cpp +++ b/tools/editor/cli_dispatch.cpp @@ -56,6 +56,7 @@ #include "cli_maps_catalog.hpp" #include "cli_chars_catalog.hpp" #include "cli_tokens_catalog.hpp" +#include "cli_triggers_catalog.hpp" #include "cli_quest_objective.hpp" #include "cli_quest_reward.hpp" #include "cli_clone.hpp" @@ -153,6 +154,7 @@ constexpr DispatchFn kDispatchTable[] = { handleMapsCatalog, handleCharsCatalog, handleTokensCatalog, + handleTriggersCatalog, handleQuestObjective, handleQuestReward, handleClone, diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index f8266bf5..77f8b5bf 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1107,6 +1107,16 @@ void printUsage(const char* argv0) { std::printf(" Export binary .wtkn to a human-editable JSON sidecar (defaults to .wtkn.json)\n"); std::printf(" --import-wtkn-json [out-base]\n"); std::printf(" Import a .wtkn.json sidecar back into binary .wtkn (accepts category/flag int OR name forms)\n"); + std::printf(" --gen-triggers [name]\n"); + std::printf(" Emit .wtrg starter: 2 triggers (Goldshire area-name + bandit-camp quest exploration ref WQT 100)\n"); + std::printf(" --gen-triggers-dungeon [name]\n"); + std::printf(" Emit .wtrg dungeon set: outdoor area-name + Deadmines portal (key-gated) + interior exit teleport\n"); + std::printf(" --gen-triggers-flightpath [name]\n"); + std::printf(" Emit .wtrg flight-master proximity waypoints (Stormwind / Goldshire) for auto-open flight UI\n"); + std::printf(" --info-wtrg [--json]\n"); + std::printf(" Print WTRG triggers (id / map / area / kind / shape + dims / dest + facing / quest+key gates)\n"); + std::printf(" --validate-wtrg [--json]\n"); + std::printf(" Static checks: id>0+unique, finite center, sphere needs radius>0, box needs >=1 nonzero half-extent, quest-explore needs target\n"); std::printf(" --gen-weather-temperate [zoneName]\n"); std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n"); std::printf(" --gen-weather-arctic [zoneName]\n"); diff --git a/tools/editor/cli_triggers_catalog.cpp b/tools/editor/cli_triggers_catalog.cpp new file mode 100644 index 00000000..030a860d --- /dev/null +++ b/tools/editor/cli_triggers_catalog.cpp @@ -0,0 +1,277 @@ +#include "cli_triggers_catalog.hpp" +#include "cli_arg_parse.hpp" +#include "cli_box_emitter.hpp" + +#include "pipeline/wowee_triggers.hpp" +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace wowee { +namespace editor { +namespace cli { + +namespace { + +std::string stripWtrgExt(std::string base) { + stripExt(base, ".wtrg"); + return base; +} + +bool saveOrError(const wowee::pipeline::WoweeTrigger& c, + const std::string& base, const char* cmd) { + if (!wowee::pipeline::WoweeTriggerLoader::save(c, base)) { + std::fprintf(stderr, "%s: failed to save %s.wtrg\n", + cmd, base.c_str()); + return false; + } + return true; +} + +void printGenSummary(const wowee::pipeline::WoweeTrigger& c, + const std::string& base) { + std::printf("Wrote %s.wtrg\n", base.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" triggers : %zu\n", c.entries.size()); +} + +int handleGenStarter(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "StarterTriggers"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWtrgExt(base); + auto c = wowee::pipeline::WoweeTriggerLoader::makeStarter(name); + if (!saveOrError(c, base, "gen-triggers")) return 1; + printGenSummary(c, base); + return 0; +} + +int handleGenDungeon(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "DungeonTriggers"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWtrgExt(base); + auto c = wowee::pipeline::WoweeTriggerLoader::makeDungeon(name); + if (!saveOrError(c, base, "gen-triggers-dungeon")) return 1; + printGenSummary(c, base); + return 0; +} + +int handleGenFlightPath(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "FlightPathTriggers"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWtrgExt(base); + auto c = wowee::pipeline::WoweeTriggerLoader::makeFlightPath(name); + if (!saveOrError(c, base, "gen-triggers-flightpath")) 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 = stripWtrgExt(base); + if (!wowee::pipeline::WoweeTriggerLoader::exists(base)) { + std::fprintf(stderr, "WTRG not found: %s.wtrg\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeTriggerLoader::load(base); + if (jsonOut) { + nlohmann::json j; + j["wtrg"] = base + ".wtrg"; + j["name"] = c.name; + j["count"] = c.entries.size(); + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"triggerId", e.triggerId}, + {"mapId", e.mapId}, + {"areaId", e.areaId}, + {"name", e.name}, + {"center", {e.center.x, e.center.y, e.center.z}}, + {"shape", e.shape}, + {"shapeName", wowee::pipeline::WoweeTrigger::shapeName(e.shape)}, + {"kind", e.kind}, + {"kindName", wowee::pipeline::WoweeTrigger::kindName(e.kind)}, + {"boxDims", {e.boxDims.x, e.boxDims.y, e.boxDims.z}}, + {"radius", e.radius}, + {"actionTarget", e.actionTarget}, + {"dest", {e.dest.x, e.dest.y, e.dest.z}}, + {"destOrientation", e.destOrientation}, + {"requiredQuestId", e.requiredQuestId}, + {"requiredItemId", e.requiredItemId}, + {"minLevel", e.minLevel}, + }); + } + j["entries"] = arr; + std::printf("%s\n", j.dump(2).c_str()); + return 0; + } + std::printf("WTRG: %s.wtrg\n", base.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" triggers : %zu\n", c.entries.size()); + if (c.entries.empty()) return 0; + for (const auto& e : c.entries) { + std::printf("\n triggerId=%u map=%u area=%u kind=%s shape=%s\n", + e.triggerId, e.mapId, e.areaId, + wowee::pipeline::WoweeTrigger::kindName(e.kind), + wowee::pipeline::WoweeTrigger::shapeName(e.shape)); + std::printf(" name : %s\n", e.name.c_str()); + std::printf(" center : (%.1f, %.1f, %.1f)\n", + e.center.x, e.center.y, e.center.z); + if (e.shape == wowee::pipeline::WoweeTrigger::ShapeBox) { + std::printf(" dims (h) : (%.1f, %.1f, %.1f)\n", + e.boxDims.x, e.boxDims.y, e.boxDims.z); + } else { + std::printf(" radius : %.1f\n", e.radius); + } + if (e.actionTarget != 0) { + std::printf(" target : %u\n", e.actionTarget); + } + if (e.kind == wowee::pipeline::WoweeTrigger::KindTeleport || + e.kind == wowee::pipeline::WoweeTrigger::KindInstanceEntrance) { + std::printf(" dest : (%.1f, %.1f, %.1f) facing=%.2f rad\n", + e.dest.x, e.dest.y, e.dest.z, e.destOrientation); + } + if (e.requiredQuestId || e.requiredItemId || e.minLevel) { + std::printf(" gates :"); + if (e.requiredQuestId) std::printf(" quest=%u", e.requiredQuestId); + if (e.requiredItemId) std::printf(" key=%u", e.requiredItemId); + if (e.minLevel) std::printf(" lvl>=%u", e.minLevel); + std::printf("\n"); + } + } + return 0; +} + +int handleValidate(int& i, int argc, char** argv) { + std::string base = argv[++i]; + bool jsonOut = consumeJsonFlag(i, argc, argv); + base = stripWtrgExt(base); + if (!wowee::pipeline::WoweeTriggerLoader::exists(base)) { + std::fprintf(stderr, + "validate-wtrg: WTRG not found: %s.wtrg\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeTriggerLoader::load(base); + std::vector errors; + std::vector warnings; + if (c.entries.empty()) { + warnings.push_back("catalog has zero entries"); + } + std::vector 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.triggerId); + if (!e.name.empty()) ctx += " " + e.name; + ctx += ")"; + if (e.triggerId == 0) errors.push_back(ctx + ": triggerId is 0"); + if (e.shape > wowee::pipeline::WoweeTrigger::ShapeSphere) { + errors.push_back(ctx + ": shape " + + std::to_string(e.shape) + " not in 0..1"); + } + if (e.kind > wowee::pipeline::WoweeTrigger::KindWaypoint) { + errors.push_back(ctx + ": kind " + + std::to_string(e.kind) + " not in 0..6"); + } + if (!std::isfinite(e.center.x) || + !std::isfinite(e.center.y) || + !std::isfinite(e.center.z)) { + errors.push_back(ctx + ": center not finite"); + } + // Sphere needs positive radius; box needs at least one + // positive half-extent. + if (e.shape == wowee::pipeline::WoweeTrigger::ShapeSphere) { + if (!std::isfinite(e.radius) || e.radius <= 0) { + errors.push_back(ctx + + ": sphere shape requires positive radius"); + } + } else { + if (e.boxDims.x <= 0 && e.boxDims.y <= 0 && e.boxDims.z <= 0) { + errors.push_back(ctx + + ": box shape has all-zero half-extents"); + } + } + // Teleport / InstanceEntrance must have a destination. + if (e.kind == wowee::pipeline::WoweeTrigger::KindTeleport || + e.kind == wowee::pipeline::WoweeTrigger::KindInstanceEntrance) { + if (e.dest.x == 0 && e.dest.y == 0 && e.dest.z == 0) { + warnings.push_back(ctx + + ": teleport / instance trigger has dest=(0,0,0)"); + } + } + // Quest exploration must reference a quest id. + if (e.kind == wowee::pipeline::WoweeTrigger::KindQuestExploration && + e.actionTarget == 0) { + errors.push_back(ctx + + ": KindQuestExploration requires actionTarget=questId"); + } + for (uint32_t prev : idsSeen) { + if (prev == e.triggerId) { + errors.push_back(ctx + ": duplicate triggerId"); + break; + } + } + idsSeen.push_back(e.triggerId); + } + bool ok = errors.empty(); + if (jsonOut) { + nlohmann::json j; + j["wtrg"] = base + ".wtrg"; + 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-wtrg: %s.wtrg\n", base.c_str()); + if (ok && warnings.empty()) { + std::printf(" OK — %zu triggers, all triggerIds unique\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 handleTriggersCatalog(int& i, int argc, char** argv, int& outRc) { + if (std::strcmp(argv[i], "--gen-triggers") == 0 && i + 1 < argc) { + outRc = handleGenStarter(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--gen-triggers-dungeon") == 0 && i + 1 < argc) { + outRc = handleGenDungeon(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--gen-triggers-flightpath") == 0 && i + 1 < argc) { + outRc = handleGenFlightPath(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--info-wtrg") == 0 && i + 1 < argc) { + outRc = handleInfo(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--validate-wtrg") == 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_triggers_catalog.hpp b/tools/editor/cli_triggers_catalog.hpp new file mode 100644 index 00000000..672134ca --- /dev/null +++ b/tools/editor/cli_triggers_catalog.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace wowee { +namespace editor { +namespace cli { + +bool handleTriggersCatalog(int& i, int argc, char** argv, int& outRc); + +} // namespace cli +} // namespace editor +} // namespace wowee