diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index 1729978b0..800ed9f83 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -1917,6 +1917,52 @@ XS(XS__repopzone) XSRETURN_EMPTY; } +XS(XS__ConnectNodeToNode); +XS(XS__ConnectNodeToNode) +{ + dXSARGS; + if (items != 4) + Perl_croak(aTHX_ "Usage: ConnectNodeToNode(node1, node2, teleport, doorid)"); + + int node1 = (int)SvIV(ST(0)); + int node2 = (int)SvIV(ST(1)); + int teleport = (int)SvIV(ST(2)); + int doorid = (int)SvIV(ST(3)); + + quest_manager.ConnectNodeToNode(node1, node2, teleport, doorid); + + XSRETURN_EMPTY; +} + +XS(XS__AddNode); +XS(XS__AddNode) +{ + dXSARGS; + //void QuestManager::AddNode(float x, float y, float z, float best_z, int32 requested_id); + if (items < 3 || items > 5) + Perl_croak(aTHX_ "Usage: AddNode(x, y, z, [best_z], [requested_id])"); + + int x = (int)SvIV(ST(0)); + int y = (int)SvIV(ST(1)); + int z = (int)SvIV(ST(2)); + int best_z = 0; + int requested_id = 0; + + if (items == 4) + { + best_z = (int)SvIV(ST(3)); + } + else if (items == 5) + { + best_z = (int)SvIV(ST(3)); + requested_id = (int)SvIV(ST(4)); + } + + quest_manager.AddNode(x, y, z, best_z, requested_id); + + XSRETURN_EMPTY; +} + XS(XS__npcrace); XS(XS__npcrace) { @@ -3699,6 +3745,8 @@ EXTERN_C XS(boot_quest) newXS(strcpy(buf, "reloadzonestaticdata"), XS__reloadzonestaticdata, file); newXS(strcpy(buf, "removetitle"), XS__removetitle, file); newXS(strcpy(buf, "repopzone"), XS__repopzone, file); + newXS(strcpy(buf, "ConnectNodeToNode"), XS__ConnectNodeToNode, file); + newXS(strcpy(buf, "AddNode"), XS__AddNode, file); newXS(strcpy(buf, "resettaskactivity"), XS__resettaskactivity, file); newXS(strcpy(buf, "respawn"), XS__respawn, file); newXS(strcpy(buf, "resume"), XS__resume, file); diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index 47d92b68e..b9025956e 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -668,6 +668,79 @@ void QuestManager::repopzone() { } } +void QuestManager::ConnectNodeToNode(int node1, int node2, int teleport, int doorid) { + if (!node1 || !node2) + { + Log.Out(Logs::General, Logs::Quests, "QuestManager::ConnectNodeToNode called without node1 or node2. Probably syntax error in quest file."); + } + else + { + if (!teleport) + { + teleport = 0; + } + else if (teleport == 1 || teleport == -1) + { + teleport = -1; + } + + if (!doorid) + { + doorid = 0; + } + + if (!zone->pathing) + { + // if no pathing bits available, make them available. + zone->pathing = new PathManager(); + } + + if (zone->pathing) + { + zone->pathing->ConnectNodeToNode(node1, node2, teleport, doorid); + Log.Out(Logs::Moderate, Logs::Quests, "QuestManager::ConnectNodeToNode connecting node %i to node %i.", node1, node2); + } + } +} + +void QuestManager::AddNode(float x, float y, float z, float best_z, int32 requested_id) +{ + if (!x || !y || !z) + { + Log.Out(Logs::General, Logs::Quests, "QuestManager::AddNode called without x, y, z. Probably syntax error in quest file."); + } + + if (!best_z || best_z == 0) + { + if (zone->zonemap) + { + glm::vec3 loc(x, y, z); + best_z = zone->zonemap->FindBestZ(loc, nullptr); + } + else + { + best_z = z; + } + } + + if (!requested_id) + { + requested_id = 0; + } + + if (!zone->pathing) + { + // if no pathing bits available, make them available. + zone->pathing = new PathManager(); + } + + if (zone->pathing) + { + zone->pathing->AddNode(x, y, z, best_z, requested_id); + Log.Out(Logs::Moderate, Logs::Quests, "QuestManager::AddNode adding node at (%i, %i, %i).", x, y, z); + } +} + void QuestManager::settarget(const char *type, int target_id) { QuestManagerCurrentQuestVars(); if (!owner || !owner->IsNPC()) diff --git a/zone/questmgr.h b/zone/questmgr.h index d2f018b8c..b278e2c2a 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -87,6 +87,8 @@ public: void depopall(int npc_type = 0); void depopzone(bool StartSpawnTimer = true); void repopzone(); + void ConnectNodeToNode(int node1, int node2, int teleport, int doorid); + void AddNode(float x, float y, float z, float best_z, int32 requested_id); void settarget(const char *type, int target_id); void follow(int entity_id, int distance); void sfollow();