mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 05:20:05 +00:00
Load NPC paths from JSON
This commit is contained in:
parent
c33f218e56
commit
72c16587e0
@ -238,10 +238,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;
|
||||
@ -249,9 +255,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"];
|
||||
@ -269,3 +275,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<WarpLocation> 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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
2
tdata
2
tdata
@ -1 +1 @@
|
||||
Subproject commit dc47c07f115ac279a1301670783cc27b08246fb3
|
||||
Subproject commit 2d16da519452c934b6fc2fa61adbcb25f855e95f
|
Loading…
Reference in New Issue
Block a user