diff --git a/src/TableData.cpp b/src/TableData.cpp index fc19562..49e8082 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -234,10 +234,16 @@ void TableData::loadPaths() { // skyway paths nlohmann::json pathDataSkyway = pathData["skyway"]; for (nlohmann::json::iterator skywayPath = pathDataSkyway.begin(); skywayPath != pathDataSkyway.end(); skywayPath++) { - constructPath(skywayPath); + constructPathSkyway(skywayPath); } - std::cout << "[INFO] Loaded " << TransportManager::SkywayPaths.size() << " skyway paths" << std::endl; + + // npc paths + nlohmann::json pathDataNPC = pathData["npc"]; + for (nlohmann::json::iterator npcPath = pathDataNPC.begin(); npcPath != pathDataNPC.end(); npcPath++) { + constructPathNPC(npcPath); + } + std::cout << "[INFO] Loaded " << TransportManager::NPCQueues.size() << " NPC paths" << std::endl; } catch (const std::exception& err) { std::cerr << "[WARN] Malformed paths.json file! Reason:" << err.what() << std::endl; @@ -245,9 +251,9 @@ void TableData::loadPaths() { } /* - * Create a full and properly-paced Skyway System path by interpolating between keyframes. + * Create a full and properly-paced path by interpolating between keyframes. */ -void TableData::constructPath(nlohmann::json::iterator _pathData) { +void TableData::constructPathSkyway(nlohmann::json::iterator _pathData) { auto pathData = _pathData.value(); // Interpolate nlohmann::json pathPoints = pathData["points"]; @@ -265,3 +271,24 @@ void TableData::constructPath(nlohmann::json::iterator _pathData) { } TransportManager::SkywayPaths[pathData["iRouteID"]] = points; } + +void TableData::constructPathNPC(nlohmann::json::iterator _pathData) { + auto pathData = _pathData.value(); + // Interpolate + nlohmann::json pathPoints = pathData["points"]; + std::queue points; + nlohmann::json::iterator _point = pathPoints.begin(); + auto point = _point.value(); + WarpLocation from = { point["iX"] , point["iY"] , point["iZ"] }; // point A coords + int stopTime = point["stop"]; + for (_point++; _point != pathPoints.end(); _point++) { // loop through all point Bs + point = _point.value(); + for(int i = 0; i < stopTime + 1; i++) // repeat point if it's a stop + points.push(from); // add point A to the queue + WarpLocation to = { point["iX"] , point["iY"] , point["iZ"] }; // point B coords + TransportManager::lerp(&points, from, to, pathData["iBaseSpeed"]); // lerp from A to B + from = to; // update point A + stopTime = point["stop"]; + } + TransportManager::NPCQueues[pathData["iNPCID"]] = points; +} diff --git a/src/TableData.hpp b/src/TableData.hpp index 640e275..a2c3b64 100644 --- a/src/TableData.hpp +++ b/src/TableData.hpp @@ -9,5 +9,6 @@ namespace TableData { int getItemType(int); void loadPaths(); - void constructPath(nlohmann::json::iterator); + void constructPathSkyway(nlohmann::json::iterator); + void constructPathNPC(nlohmann::json::iterator); } diff --git a/src/TransportManager.cpp b/src/TransportManager.cpp index 9479793..ea5d3e9 100644 --- a/src/TransportManager.cpp +++ b/src/TransportManager.cpp @@ -304,7 +304,7 @@ void TransportManager::stepNPCPathing() { move.iToX = point.x; move.iToY = point.y; move.iToZ = point.z; - move.iSpeed = 600; // TODO: figure out a way to make this variable + move.iSpeed = distanceBetween; // send packet to players in view for (Chunk* chunk : chunks) { diff --git a/tdata b/tdata index dc47c07..2d16da5 160000 --- a/tdata +++ b/tdata @@ -1 +1 @@ -Subproject commit dc47c07f115ac279a1301670783cc27b08246fb3 +Subproject commit 2d16da519452c934b6fc2fa61adbcb25f855e95f