From be3a253dcc64d1f1e229132cb8c1305a602f13f7 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 10 May 2026 04:01:42 -0700 Subject: [PATCH] feat(pipeline): WPRT mage portal destinations catalog (129th open format) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Novel replacement for the implicit portal-spell -> destination- coordinate binding vanilla WoW carried in scattered pieces: SpellEffects.dbc effect-71 (TELEPORT_UNITS) + per-spell hard- coded destination tables in the server's SpellMgr + AreaTrigger.dbc destination rows. Each WPRT entry binds one Teleport/Portal spellId to its destination world coords, faction-access gate, level requirement, and reagent requirement. PortalKind enum captures the canonical Teleport (self-only, Rune of Teleportation, level 20) vs Portal (group, Rune of Portals, level 40) distinction. Three presets: --gen-prt-alliance 4 Alliance city portals (Stormwind / Ironforge / Darnassus / Theramore) with canonical spellIds 10059/11416/11419/ 49361 and Rune of Portals reagent --gen-prt-horde 3 Horde city portals (Orgrimmar / Undercity / Thunder Bluff) --gen-prt-teleports 3 self-teleports paired across factions (Teleport: Stormwind/Ironforge Alliance + Teleport: Orgrimmar Horde) — illustrates the Teleport-vs-Portal kind distinction with proper reagent (Rune of Teleportation 17031 NOT Rune of Portals 17032) Validator catches: id+spellId+destination required, factionAccess/portalKind range, no duplicate portalIds, no duplicate spellIds (cast-handler conflict). Warns on levelRequirement < 20 (vanilla mage cannot unlock), Portal kind without Rune of Portals (17032), Teleport kind without Rune of Teleportation (17031), and duplicate destination names (could be legitimate Teleport+Portal pair OR copy-paste bug — the editor flags both). Format count 128 -> 129. CLI flag count 1355 -> 1362. --- CMakeLists.txt | 3 + include/pipeline/wowee_mage_portals.hpp | 142 +++++++++ src/pipeline/wowee_mage_portals.cpp | 266 +++++++++++++++++ tools/editor/cli_arg_required.cpp | 2 + tools/editor/cli_dispatch.cpp | 2 + tools/editor/cli_format_table.cpp | 1 + tools/editor/cli_help.cpp | 10 + tools/editor/cli_list_formats.cpp | 1 + tools/editor/cli_mage_portals_catalog.cpp | 333 ++++++++++++++++++++++ tools/editor/cli_mage_portals_catalog.hpp | 12 + 10 files changed, 772 insertions(+) create mode 100644 include/pipeline/wowee_mage_portals.hpp create mode 100644 src/pipeline/wowee_mage_portals.cpp create mode 100644 tools/editor/cli_mage_portals_catalog.cpp create mode 100644 tools/editor/cli_mage_portals_catalog.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bf51bc1..6ac2cd7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -717,6 +717,7 @@ set(WOWEE_SOURCES src/pipeline/wowee_spell_pack.cpp src/pipeline/wowee_player_movement_anim.cpp src/pipeline/wowee_transit_schedule.cpp + src/pipeline/wowee_mage_portals.cpp src/pipeline/custom_zone_discovery.cpp src/pipeline/dbc_layout.cpp @@ -1597,6 +1598,7 @@ add_executable(wowee_editor tools/editor/cli_spell_pack_catalog.cpp tools/editor/cli_player_movement_anim_catalog.cpp tools/editor/cli_transit_schedule_catalog.cpp + tools/editor/cli_mage_portals_catalog.cpp tools/editor/cli_catalog_pluck.cpp tools/editor/cli_catalog_find.cpp tools/editor/cli_catalog_by_name.cpp @@ -1796,6 +1798,7 @@ add_executable(wowee_editor src/pipeline/wowee_spell_pack.cpp src/pipeline/wowee_player_movement_anim.cpp src/pipeline/wowee_transit_schedule.cpp + src/pipeline/wowee_mage_portals.cpp src/pipeline/custom_zone_discovery.cpp src/pipeline/terrain_mesh.cpp diff --git a/include/pipeline/wowee_mage_portals.hpp b/include/pipeline/wowee_mage_portals.hpp new file mode 100644 index 00000000..236a6dd0 --- /dev/null +++ b/include/pipeline/wowee_mage_portals.hpp @@ -0,0 +1,142 @@ +#pragma once + +#include +#include +#include + +namespace wowee { +namespace pipeline { + +// Wowee Open Mage Portal Destinations catalog +// (.wprt) — novel replacement for the implicit +// portal-spell -> destination-coordinate binding +// vanilla WoW carried in scattered pieces: +// SpellEffects.dbc effect-71 (TELEPORT_UNITS) + +// per-spell hard-coded destination tables in the +// server's SpellMgr + AreaTrigger.dbc destination +// rows. Each WPRT entry binds one Teleport/Portal +// spellId to its destination world coords, faction +// access gate, level requirement, and reagent +// requirement. +// +// Cross-references with previously-added formats: +// WSPL: spellId references the WSPL spell catalog +// (the actual spell-to-cast — Portal: Stormwind +// is spellId 10059, Teleport: Stormwind is +// 3561, etc.). +// WMS: destinationMapId references the WMS map +// catalog. +// WIT: reagentItemId references the WIT item +// catalog (Rune of Teleportation = 17031, +// Rune of Portals = 17032). +// +// Binary layout (little-endian): +// magic[4] = "WPRT" +// version (uint32) = current 1 +// nameLen + name (catalog label) +// entryCount (uint32) +// entries (each): +// portalId (uint32) +// spellId (uint32) — WSPL spell to +// cast +// nameLen + destinationName — display label +// destX (float) +// destY (float) +// destZ (float) +// destOrientation (float) — facing direction +// in radians +// destMapId (uint32) +// factionAccess (uint8) — 0=Both / +// 1=Alliance / +// 2=Horde / +// 3=Neutral +// portalKind (uint8) — 0=Teleport (self +// only) / +// 1=Portal (group) +// levelRequirement (uint8) — minimum mage +// level to learn +// reagentCount (uint8) +// reagentItemId (uint32) — 0 if no reagent +struct WoweeMagePortals { + enum FactionAccess : uint8_t { + Both = 0, + Alliance = 1, + Horde = 2, + Neutral = 3, + }; + + enum PortalKind : uint8_t { + Teleport = 0, // self-only, lower mana cost + // + reagent + Portal = 1, // group portal, costs Rune + // of Portals + }; + + struct Entry { + uint32_t portalId = 0; + uint32_t spellId = 0; + std::string destinationName; + float destX = 0.f; + float destY = 0.f; + float destZ = 0.f; + float destOrientation = 0.f; + uint32_t destMapId = 0; + uint8_t factionAccess = Both; + uint8_t portalKind = Teleport; + uint8_t levelRequirement = 0; + uint8_t reagentCount = 0; + uint32_t reagentItemId = 0; + }; + + std::string name; + std::vector entries; + + bool isValid() const { return !entries.empty(); } + + const Entry* findById(uint32_t portalId) const; + + // Returns the binding for a given cast spellId — + // the lookup the portal-cast handler uses to + // decide where to teleport the target. + const Entry* findBySpellId(uint32_t spellId) const; + + // Returns all portals accessible to a faction. + // Used by the spellbook UI to filter the mage + // portal tab (Alliance mages don't see Horde + // city portals). + std::vector findByFaction(uint8_t faction) const; +}; + +class WoweeMagePortalsLoader { +public: + static bool save(const WoweeMagePortals& cat, + const std::string& basePath); + static WoweeMagePortals load(const std::string& basePath); + static bool exists(const std::string& basePath); + + // Preset emitters used by --gen-prt* variants. + // + // makeAllianceCities — 4 Alliance city portals + // (Stormwind / Ironforge / + // Darnassus / Theramore). + // All Alliance-only, + // require Rune of Portals. + // makeHordeCities — 3 Horde city portals + // (Orgrimmar / Undercity / + // Thunder Bluff). Horde- + // only. + // makeTeleports — 3 self-teleport spells + // (Teleport: Stormwind / + // Teleport: Ironforge / + // Teleport: Orgrimmar) — + // paired Alliance/Horde + // set illustrating the + // self-vs-group portal + // distinction. + static WoweeMagePortals makeAllianceCities(const std::string& catalogName); + static WoweeMagePortals makeHordeCities(const std::string& catalogName); + static WoweeMagePortals makeTeleports(const std::string& catalogName); +}; + +} // namespace pipeline +} // namespace wowee diff --git a/src/pipeline/wowee_mage_portals.cpp b/src/pipeline/wowee_mage_portals.cpp new file mode 100644 index 00000000..581de0f7 --- /dev/null +++ b/src/pipeline/wowee_mage_portals.cpp @@ -0,0 +1,266 @@ +#include "pipeline/wowee_mage_portals.hpp" + +#include +#include +#include + +namespace wowee { +namespace pipeline { + +namespace { + +constexpr char kMagic[4] = {'W', 'P', 'R', 'T'}; +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) != ".wprt") { + base += ".wprt"; + } + return base; +} + +} // namespace + +const WoweeMagePortals::Entry* +WoweeMagePortals::findById(uint32_t portalId) const { + for (const auto& e : entries) + if (e.portalId == portalId) return &e; + return nullptr; +} + +const WoweeMagePortals::Entry* +WoweeMagePortals::findBySpellId(uint32_t spellId) const { + for (const auto& e : entries) + if (e.spellId == spellId) return &e; + return nullptr; +} + +std::vector +WoweeMagePortals::findByFaction(uint8_t faction) const { + std::vector out; + for (const auto& e : entries) { + if (e.factionAccess == Both || + e.factionAccess == Neutral || + (faction != Both && e.factionAccess == faction)) { + out.push_back(&e); + } + } + return out; +} + +bool WoweeMagePortalsLoader::save(const WoweeMagePortals& 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.portalId); + writePOD(os, e.spellId); + writeStr(os, e.destinationName); + writePOD(os, e.destX); + writePOD(os, e.destY); + writePOD(os, e.destZ); + writePOD(os, e.destOrientation); + writePOD(os, e.destMapId); + writePOD(os, e.factionAccess); + writePOD(os, e.portalKind); + writePOD(os, e.levelRequirement); + writePOD(os, e.reagentCount); + writePOD(os, e.reagentItemId); + } + return os.good(); +} + +WoweeMagePortals WoweeMagePortalsLoader::load( + const std::string& basePath) { + WoweeMagePortals 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.portalId) || + !readPOD(is, e.spellId)) { + out.entries.clear(); return out; + } + if (!readStr(is, e.destinationName)) { + out.entries.clear(); return out; + } + if (!readPOD(is, e.destX) || + !readPOD(is, e.destY) || + !readPOD(is, e.destZ) || + !readPOD(is, e.destOrientation) || + !readPOD(is, e.destMapId) || + !readPOD(is, e.factionAccess) || + !readPOD(is, e.portalKind) || + !readPOD(is, e.levelRequirement) || + !readPOD(is, e.reagentCount) || + !readPOD(is, e.reagentItemId)) { + out.entries.clear(); return out; + } + } + return out; +} + +bool WoweeMagePortalsLoader::exists( + const std::string& basePath) { + std::ifstream is(normalizePath(basePath), std::ios::binary); + return is.good(); +} + +WoweeMagePortals WoweeMagePortalsLoader::makeAllianceCities( + const std::string& catalogName) { + using P = WoweeMagePortals; + WoweeMagePortals c; + c.name = catalogName; + auto add = [&](uint32_t pid, uint32_t spellId, + const char* destName, + float x, float y, float z, float o, + uint32_t mapId, uint8_t levelReq) { + P::Entry e; + e.portalId = pid; e.spellId = spellId; + e.destinationName = destName; + e.destX = x; e.destY = y; e.destZ = z; + e.destOrientation = o; + e.destMapId = mapId; + e.factionAccess = P::Alliance; + e.portalKind = P::Portal; + e.levelRequirement = levelReq; + e.reagentCount = 1; + e.reagentItemId = 17032; // Rune of + // Portals + c.entries.push_back(e); + }; + // Vanilla mage portal coords (capital city + // portal-room or central plaza). Coords sourced + // from the canonical Stormwind, Ironforge, + // Darnassus and Theramore portal landing zones. + add(1, 10059, "Stormwind", + -9009.f, 873.f, 148.f, 0.f, 0, 40); + add(2, 11416, "Ironforge", + -4623.f, -915.f, 502.f, 0.f, 0, 40); + add(3, 11419, "Darnassus", + 9982.f, 2300.f, 1330.f, 0.f, 1, 40); + add(4, 49361, "Theramore", + -3753.f, -4527.f, 9.f, 0.f, 1, 40); + return c; +} + +WoweeMagePortals WoweeMagePortalsLoader::makeHordeCities( + const std::string& catalogName) { + using P = WoweeMagePortals; + WoweeMagePortals c; + c.name = catalogName; + auto add = [&](uint32_t pid, uint32_t spellId, + const char* destName, + float x, float y, float z, float o, + uint32_t mapId) { + P::Entry e; + e.portalId = pid; e.spellId = spellId; + e.destinationName = destName; + e.destX = x; e.destY = y; e.destZ = z; + e.destOrientation = o; + e.destMapId = mapId; + e.factionAccess = P::Horde; + e.portalKind = P::Portal; + e.levelRequirement = 40; + e.reagentCount = 1; + e.reagentItemId = 17032; // Rune of + // Portals + c.entries.push_back(e); + }; + add(10, 11417, "Orgrimmar", + 1576.f, -4453.f, 16.f, 0.f, 1); + add(11, 11418, "Undercity", + 1830.f, 239.f, 60.f, 0.f, 0); + add(12, 11420, "Thunder Bluff", + -1277.f, 122.f, 132.f, 0.f, 1); + return c; +} + +WoweeMagePortals WoweeMagePortalsLoader::makeTeleports( + const std::string& catalogName) { + using P = WoweeMagePortals; + WoweeMagePortals c; + c.name = catalogName; + auto addT = [&](uint32_t pid, uint32_t spellId, + const char* destName, + float x, float y, float z, float o, + uint32_t mapId, uint8_t faction, + uint8_t levelReq) { + P::Entry e; + e.portalId = pid; e.spellId = spellId; + e.destinationName = destName; + e.destX = x; e.destY = y; e.destZ = z; + e.destOrientation = o; + e.destMapId = mapId; + e.factionAccess = faction; + e.portalKind = P::Teleport; // self-only, + // costs Rune of + // Teleportation + e.levelRequirement = levelReq; + e.reagentCount = 1; + e.reagentItemId = 17031; // Rune of + // Teleportation + // (NOT Rune of + // Portals) + c.entries.push_back(e); + }; + addT(20, 3561, "Stormwind", + -9009.f, 873.f, 148.f, 0.f, 0, + P::Alliance, 20); + addT(21, 3562, "Ironforge", + -4623.f, -915.f, 502.f, 0.f, 0, + P::Alliance, 20); + addT(22, 3567, "Orgrimmar", + 1576.f, -4453.f, 16.f, 0.f, 1, + P::Horde, 20); + return c; +} + +} // namespace pipeline +} // namespace wowee diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 59879666..5f9e154c 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -395,6 +395,8 @@ const char* const kArgRequired[] = { "--gen-trn-zeppelins", "--gen-trn-boats", "--gen-trn-taxis", "--info-wtsc", "--validate-wtsc", "--export-wtsc-json", "--import-wtsc-json", + "--gen-prt-alliance", "--gen-prt-horde", "--gen-prt-teleports", + "--info-wprt", "--validate-wprt", "--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 20bf83ab..6826c5b7 100644 --- a/tools/editor/cli_dispatch.cpp +++ b/tools/editor/cli_dispatch.cpp @@ -173,6 +173,7 @@ #include "cli_spell_pack_catalog.hpp" #include "cli_player_movement_anim_catalog.hpp" #include "cli_transit_schedule_catalog.hpp" +#include "cli_mage_portals_catalog.hpp" #include "cli_catalog_pluck.hpp" #include "cli_catalog_find.hpp" #include "cli_catalog_by_name.hpp" @@ -391,6 +392,7 @@ constexpr DispatchFn kDispatchTable[] = { handleSpellPackCatalog, handlePlayerMovementAnimCatalog, handleTransitScheduleCatalog, + handleMagePortalsCatalog, handleCatalogPluck, handleCatalogFind, handleCatalogByName, diff --git a/tools/editor/cli_format_table.cpp b/tools/editor/cli_format_table.cpp index ca7def8f..e0f60697 100644 --- a/tools/editor/cli_format_table.cpp +++ b/tools/editor/cli_format_table.cpp @@ -131,6 +131,7 @@ constexpr FormatMagicEntry kFormats[] = { {{'W','S','P','K'}, ".wspk", "spells", "--info-wspk", "Spell pack catalog"}, {{'W','P','H','M'}, ".wphm", "anim", "--info-wphm", "Player movement-to-animation map"}, {{'W','T','S','C'}, ".wtsc", "transit", "--info-wtsc", "Transit schedule catalog"}, + {{'W','P','R','T'}, ".wprt", "portals", "--info-wprt", "Mage portal destinations 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 d24841f1..f77a6f2e 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2559,6 +2559,16 @@ void printUsage(const char* argv0) { std::printf(" Export binary .wtsc to a human-editable JSON sidecar (defaults to .wtsc.json; emits both vehicleType and factionAccess as int + name string; floats preserved bit-for-bit)\n"); std::printf(" --import-wtsc-json [out-base]\n"); std::printf(" Import a .wtsc.json sidecar back into binary .wtsc (vehicleType int OR \"taxi\"/\"zeppelin\"/\"boat\"/\"mount\"; factionAccess int OR \"both\"/\"alliance\"/\"horde\"/\"neutral\")\n"); + std::printf(" --gen-prt-alliance [name]\n"); + std::printf(" Emit .wprt 4 Alliance city portals (Stormwind/Ironforge/Darnassus/Theramore) with Rune of Portals reagent (itemId 17032), level 40\n"); + std::printf(" --gen-prt-horde [name]\n"); + std::printf(" Emit .wprt 3 Horde city portals (Orgrimmar/Undercity/Thunder Bluff) with Rune of Portals, level 40\n"); + std::printf(" --gen-prt-teleports [name]\n"); + std::printf(" Emit .wprt 3 self-teleport spells (Teleport: Stormwind/Ironforge/Orgrimmar) — Teleport kind, costs Rune of Teleportation (itemId 17031), level 20\n"); + std::printf(" --info-wprt [--json]\n"); + std::printf(" Print WPRT entries (id / spellId / portalKind / factionAccess / levelRequirement / reagentItemId / destination)\n"); + std::printf(" --validate-wprt [--json]\n"); + std::printf(" Static checks: id+spellId+destination required, factionAccess 0..3, portalKind 0..1, no duplicate portalIds, no duplicate spellIds (would conflict on cast); warns on levelRequirement < 20 (vanilla mage cannot unlock), Portal kind without Rune of Portals (17032), Teleport kind without Rune of Teleportation (17031), and duplicate destination names (likely Teleport+Portal pair OR copy-paste bug)\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 b010043d..332dfa7e 100644 --- a/tools/editor/cli_list_formats.cpp +++ b/tools/editor/cli_list_formats.cpp @@ -153,6 +153,7 @@ constexpr FormatRow kFormats[] = { {"WSPK", ".wspk", "spells", "SkillLineAbility + per-spec tab order","Spell pack catalog (per-class spellbook tab layout)"}, {"WPHM", ".wphm", "anim", "implicit M2 movementState->anim map","Player movement-to-animation map (per race/gender/state)"}, {"WTSC", ".wtsc", "transit", "TaxiNodes + zeppelin GO scripts", "Transit schedule catalog (taxi/zeppelin/boat scheduled departures)"}, + {"WPRT", ".wprt", "portals", "SpellEffect TELEPORT_UNITS + AreaTrigger","Mage portal destinations catalog (spellId -> coords binding)"}, // Additional pipeline catalogs without the alternating // gen/info/validate CLI surface (loaded by the engine diff --git a/tools/editor/cli_mage_portals_catalog.cpp b/tools/editor/cli_mage_portals_catalog.cpp new file mode 100644 index 00000000..a32c2837 --- /dev/null +++ b/tools/editor/cli_mage_portals_catalog.cpp @@ -0,0 +1,333 @@ +#include "cli_mage_portals_catalog.hpp" +#include "cli_arg_parse.hpp" +#include "cli_box_emitter.hpp" + +#include "pipeline/wowee_mage_portals.hpp" +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace wowee { +namespace editor { +namespace cli { + +namespace { + +std::string stripWprtExt(std::string base) { + stripExt(base, ".wprt"); + return base; +} + +const char* factionAccessName(uint8_t f) { + using P = wowee::pipeline::WoweeMagePortals; + switch (f) { + case P::Both: return "both"; + case P::Alliance: return "alliance"; + case P::Horde: return "horde"; + case P::Neutral: return "neutral"; + default: return "?"; + } +} + +const char* portalKindName(uint8_t k) { + using P = wowee::pipeline::WoweeMagePortals; + switch (k) { + case P::Teleport: return "teleport"; + case P::Portal: return "portal"; + default: return "?"; + } +} + +bool saveOrError(const wowee::pipeline::WoweeMagePortals& c, + const std::string& base, const char* cmd) { + if (!wowee::pipeline::WoweeMagePortalsLoader::save(c, base)) { + std::fprintf(stderr, "%s: failed to save %s.wprt\n", + cmd, base.c_str()); + return false; + } + return true; +} + +void printGenSummary(const wowee::pipeline::WoweeMagePortals& c, + const std::string& base) { + std::printf("Wrote %s.wprt\n", base.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" portals : %zu\n", c.entries.size()); +} + +int handleGenAlliance(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "AllianceCityPortals"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWprtExt(base); + auto c = wowee::pipeline::WoweeMagePortalsLoader:: + makeAllianceCities(name); + if (!saveOrError(c, base, "gen-prt-alliance")) return 1; + printGenSummary(c, base); + return 0; +} + +int handleGenHorde(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "HordeCityPortals"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWprtExt(base); + auto c = wowee::pipeline::WoweeMagePortalsLoader:: + makeHordeCities(name); + if (!saveOrError(c, base, "gen-prt-horde")) return 1; + printGenSummary(c, base); + return 0; +} + +int handleGenTeleports(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string name = "TeleportSpells"; + if (parseOptArg(i, argc, argv)) name = argv[++i]; + base = stripWprtExt(base); + auto c = wowee::pipeline::WoweeMagePortalsLoader:: + makeTeleports(name); + if (!saveOrError(c, base, "gen-prt-teleports")) 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 = stripWprtExt(base); + if (!wowee::pipeline::WoweeMagePortalsLoader::exists(base)) { + std::fprintf(stderr, "WPRT not found: %s.wprt\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeMagePortalsLoader::load(base); + if (jsonOut) { + nlohmann::json j; + j["wprt"] = base + ".wprt"; + j["name"] = c.name; + j["count"] = c.entries.size(); + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"portalId", e.portalId}, + {"spellId", e.spellId}, + {"destinationName", e.destinationName}, + {"destX", e.destX}, + {"destY", e.destY}, + {"destZ", e.destZ}, + {"destOrientation", e.destOrientation}, + {"destMapId", e.destMapId}, + {"factionAccess", e.factionAccess}, + {"factionAccessName", + factionAccessName(e.factionAccess)}, + {"portalKind", e.portalKind}, + {"portalKindName", + portalKindName(e.portalKind)}, + {"levelRequirement", e.levelRequirement}, + {"reagentCount", e.reagentCount}, + {"reagentItemId", e.reagentItemId}, + }); + } + j["entries"] = arr; + std::printf("%s\n", j.dump(2).c_str()); + return 0; + } + std::printf("WPRT: %s.wprt\n", base.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" portals : %zu\n", c.entries.size()); + if (c.entries.empty()) return 0; + std::printf(" id spell kind fact lvl reagent destination\n"); + for (const auto& e : c.entries) { + std::printf(" %4u %7u %-8s %-8s %3u %7u %s\n", + e.portalId, e.spellId, + portalKindName(e.portalKind), + factionAccessName(e.factionAccess), + e.levelRequirement, e.reagentItemId, + e.destinationName.c_str()); + } + return 0; +} + +int handleValidate(int& i, int argc, char** argv) { + std::string base = argv[++i]; + bool jsonOut = consumeJsonFlag(i, argc, argv); + base = stripWprtExt(base); + if (!wowee::pipeline::WoweeMagePortalsLoader::exists(base)) { + std::fprintf(stderr, + "validate-wprt: WPRT not found: %s.wprt\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeMagePortalsLoader::load(base); + std::vector errors; + std::vector warnings; + if (c.entries.empty()) { + warnings.push_back("catalog has zero entries"); + } + std::set idsSeen; + std::set spellIdsSeen; + std::set destNamesSeen; + 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.portalId); + if (!e.destinationName.empty()) + ctx += " " + e.destinationName; + ctx += ")"; + if (e.portalId == 0) + errors.push_back(ctx + ": portalId is 0"); + if (e.spellId == 0) + errors.push_back(ctx + + ": spellId is 0 (no spell to cast)"); + if (e.destinationName.empty()) + errors.push_back(ctx + + ": destinationName is empty"); + if (e.factionAccess > 3) { + errors.push_back(ctx + ": factionAccess " + + std::to_string(e.factionAccess) + + " out of range (0..3)"); + } + if (e.portalKind > 1) { + errors.push_back(ctx + ": portalKind " + + std::to_string(e.portalKind) + + " out of range (0=Teleport, 1=Portal)"); + } + // Mage portal/teleport spells unlock at + // level 20 (Teleport) or 40 (Portal) in + // vanilla. A levelRequirement below 20 would + // be impossible to satisfy with a vanilla + // mage. Warn (not error) since custom + // servers may rebalance. + if (e.levelRequirement > 0 && + e.levelRequirement < 20) { + warnings.push_back(ctx + + ": levelRequirement=" + + std::to_string(e.levelRequirement) + + " is below 20 — vanilla mage cannot " + "unlock until 20 (Teleport) or 40 " + "(Portal). Possible typo?"); + } + // Cross-faction sanity: an Alliance-only + // portal pointing to a Horde city, or vice + // versa, would let a mage flag PvP + // permanently. Validator can't know which + // map is which faction without WMS lookup, + // so just warn on Both/Neutral with a city + // name suggesting one-faction. + using P = wowee::pipeline::WoweeMagePortals; + if (e.portalKind == P::Portal && + e.reagentItemId != 17032 && + e.reagentItemId != 0) { + warnings.push_back(ctx + + ": Portal kind with reagentItemId=" + + std::to_string(e.reagentItemId) + + " — vanilla group portals require " + "Rune of Portals (itemId 17032). " + "Verify intentional"); + } + if (e.portalKind == P::Teleport && + e.reagentItemId != 17031 && + e.reagentItemId != 0) { + warnings.push_back(ctx + + ": Teleport kind with reagentItemId=" + + std::to_string(e.reagentItemId) + + " — vanilla self-teleports require " + "Rune of Teleportation (itemId 17031). " + "Verify intentional"); + } + // Duplicate spellId across portals would mean + // two portal-cast handlers fight over the same + // spell — error. + if (e.spellId != 0 && + !spellIdsSeen.insert(e.spellId).second) { + errors.push_back(ctx + + ": duplicate spellId " + + std::to_string(e.spellId) + + " — two portals would respond to the " + "same cast"); + } + if (!e.destinationName.empty() && + !destNamesSeen.insert(e.destinationName).second) { + // Duplicate destination NAME is allowed + // (e.g., Teleport: SW + Portal: SW are + // both "Stormwind") — only warn so the + // editor can flag potential dupes. + warnings.push_back(ctx + + ": duplicate destinationName '" + + e.destinationName + + "' — could be a Teleport/Portal pair " + "(legitimate) or a copy-paste bug"); + // Re-allow in the seen set so subsequent + // duplicates also warn + } + if (!idsSeen.insert(e.portalId).second) { + errors.push_back(ctx + ": duplicate portalId"); + } + } + bool ok = errors.empty(); + if (jsonOut) { + nlohmann::json j; + j["wprt"] = base + ".wprt"; + 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-wprt: %s.wprt\n", base.c_str()); + if (ok && warnings.empty()) { + std::printf(" OK — %zu portals, all portalIds + " + "spellIds unique, factionAccess 0..3, " + "portalKind 0..1, levelRequirement >= 20, " + "reagent matches kind\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 handleMagePortalsCatalog(int& i, int argc, char** argv, + int& outRc) { + if (std::strcmp(argv[i], "--gen-prt-alliance") == 0 && + i + 1 < argc) { + outRc = handleGenAlliance(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--gen-prt-horde") == 0 && + i + 1 < argc) { + outRc = handleGenHorde(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--gen-prt-teleports") == 0 && + i + 1 < argc) { + outRc = handleGenTeleports(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--info-wprt") == 0 && i + 1 < argc) { + outRc = handleInfo(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--validate-wprt") == 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_mage_portals_catalog.hpp b/tools/editor/cli_mage_portals_catalog.hpp new file mode 100644 index 00000000..70d50d14 --- /dev/null +++ b/tools/editor/cli_mage_portals_catalog.hpp @@ -0,0 +1,12 @@ +#pragma once + +namespace wowee { +namespace editor { +namespace cli { + +bool handleMagePortalsCatalog(int& i, int argc, char** argv, + int& outRc); + +} // namespace cli +} // namespace editor +} // namespace wowee