mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 11:03:51 +00:00
Novel open 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, mark a PvP boundary,
or simply display a "Discovered: {area name}" banner.
Cross-references with previously-added formats — every
trigger field has a real format target:
WTRG.entry.mapId / areaId -> WMS.map.mapId / WMS.area.areaId
WTRG.actionTarget (Teleport) -> WMS.mapId
WTRG.actionTarget (QuestExploration) -> WQT.questId
WTRG.requiredQuestId -> WQT.entry.questId
WTRG.requiredItemId -> WIT.entry.itemId (key)
Format:
• magic "WTRG", version 1, little-endian
• per trigger: triggerId / mapId / areaId / name /
center vec3 / shape / kind / boxDims vec3 / radius /
actionTarget / dest vec3 / destOrientation /
requiredQuestId / requiredItemId / minLevel
Enums:
• Shape (2): Box / Sphere
• Kind (7): Teleport / QuestExploration / Script /
InstanceEntrance / AreaName / CombatStartZone /
Waypoint
API: WoweeTriggerLoader::save / load / exists / findById.
Three preset emitters showcase common trigger shapes:
• makeStarter — area-name + quest-exploration with
cross-ref to WQT 100 ("Investigate the
Camp")
• makeDungeon — outdoor area-name + portal-style
InstanceEntrance with Deadmines key
gate (WIT itemId 5200, matches
WLCK.makeDungeon's Boss Vault Seal) +
interior exit teleport back outdoors
• makeFlightPath — 2 sphere waypoints near flight masters
so the runtime can auto-open the
flight UI on proximity (matches WTAX
starter node positions)
CLI added (5 flags, 601 documented total now):
--gen-triggers / --gen-triggers-dungeon / --gen-triggers-flightpath
--info-wtrg / --validate-wtrg
Validator catches: triggerId=0 + duplicates, unknown shape /
kind, non-finite center, sphere with radius<=0, box with
all-zero half-extents, teleport / instance with dest=(0,0,0)
(silently does nothing — usually a typo), QuestExploration
without an actionTarget questId.
277 lines
10 KiB
C++
277 lines
10 KiB
C++
#include "cli_triggers_catalog.hpp"
|
|
#include "cli_arg_parse.hpp"
|
|
#include "cli_box_emitter.hpp"
|
|
|
|
#include "pipeline/wowee_triggers.hpp"
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
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<std::string> errors;
|
|
std::vector<std::string> warnings;
|
|
if (c.entries.empty()) {
|
|
warnings.push_back("catalog has zero entries");
|
|
}
|
|
std::vector<uint32_t> 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
|