From 6ae4ab2cbf6085379a89a5d441688f158736273e Mon Sep 17 00:00:00 2001 From: gsemaj Date: Wed, 5 May 2021 21:17:06 -0400 Subject: [PATCH] Move findApplicablePaths to Transport, add taskID argument --- src/TableData.cpp | 38 +++----------------------------------- src/Transport.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/Transport.hpp | 2 ++ 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/TableData.cpp b/src/TableData.cpp index ebcb5b4..eacdc0d 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -36,38 +36,6 @@ public: const char *what() const throw() { return msg.c_str(); } }; -/* - * Find and return the first path that targets either the type or the ID. - * If no matches are found, return nullptr - */ -static NPCPath* findApplicablePath(int32_t id, int32_t type) { - NPCPath* match = nullptr; - for (auto _path = Transport::NPCPaths.begin(); _path != Transport::NPCPaths.end(); _path++) { - // search target IDs - for (int32_t pID : _path->targetIDs) { - if (id == pID) { - match = &(*_path); - break; - } - } - - if (match != nullptr) - break; // early break for ID matches, since ID has higher priority than type - - // search target types - for (int32_t pType : _path->targetTypes) { - if (type == pType) { - match = &(*_path); - break; - } - } - - if (match != nullptr) - break; - } - return match; -} - /* * Create a full and properly-paced path by interpolating between keyframes. */ @@ -937,7 +905,7 @@ static void loadNPCs(json& npcData) { NPCManager::RespawnPoints.push_back({ npc["iX"], npc["iY"], ((int)npc["iZ"]) + RESURRECT_HEIGHT, instanceID }); // see if any paths target this NPC - NPCPath* npcPath = findApplicablePath(npcID, type); + NPCPath* npcPath = Transport::findApplicablePath(npcID, type); if (npcPath != nullptr) { //std::cout << "[INFO] Found path for NPC " << npcID << std::endl; constructPathNPC(npcID, npcPath); @@ -983,7 +951,7 @@ static void loadMobs(json& npcData, int32_t* nextId) { NPCManager::updateNPCPosition(npcID, npc["iX"], npc["iY"], npc["iZ"], instanceID, npc["iAngle"]); // see if any paths target this mob - NPCPath* npcPath = findApplicablePath(npcID, npc["iNPCType"]); + NPCPath* npcPath = Transport::findApplicablePath(npcID, npc["iNPCType"]); if (npcPath != nullptr) { //std::cout << "[INFO] Found path for mob " << npcID << std::endl; constructPathNPC(npcID, npcPath); @@ -1012,7 +980,7 @@ static void loadMobs(json& npcData, int32_t* nextId) { NPCManager::updateNPCPosition(leadID, leader["iX"], leader["iY"], leader["iZ"], instanceID, leader["iAngle"]); // see if any paths target this group leader - NPCPath* npcPath = findApplicablePath(leadID, leader["iNPCType"]); + NPCPath* npcPath = Transport::findApplicablePath(leadID, leader["iNPCType"]); if (npcPath != nullptr) { //std::cout << "[INFO] Found path for mob " << leadID << std::endl; constructPathNPC(leadID, npcPath); diff --git a/src/Transport.cpp b/src/Transport.cpp index b9a7f8c..fdc9dac 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -347,6 +347,43 @@ void Transport::lerp(std::queue* queue, Vec3 start, Vec3 end, int gapSize) lerp(queue, start, end, gapSize, 1); } +/* + * Find and return the first path that targets either the type or the ID. + * If no matches are found, return nullptr + */ +NPCPath* Transport::findApplicablePath(int32_t id, int32_t type, int taskID) { + NPCPath* match = nullptr; + for (auto _path = Transport::NPCPaths.begin(); _path != Transport::NPCPaths.end(); _path++) { + + // task ID for the path must match so escorts don't start early + if (_path->escortTaskID != taskID) + continue; + + // search target IDs + for (int32_t pID : _path->targetIDs) { + if (id == pID) { + match = &(*_path); + break; + } + } + + if (match != nullptr) + break; // early break for ID matches, since ID has higher priority than type + + // search target types + for (int32_t pType : _path->targetTypes) { + if (type == pType) { + match = &(*_path); + break; + } + } + + if (match != nullptr) + break; + } + return match; +} + void Transport::init() { REGISTER_SHARD_TIMER(tickTransportationSystem, 1000); diff --git a/src/Transport.hpp b/src/Transport.hpp index c903303..82056fd 100644 --- a/src/Transport.hpp +++ b/src/Transport.hpp @@ -49,4 +49,6 @@ namespace Transport { void lerp(std::queue*, Vec3, Vec3, int, float); void lerp(std::queue*, Vec3, Vec3, int); + + NPCPath* findApplicablePath(int32_t, int32_t, int = -1); }