mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 05:20:05 +00:00
Move constructPathNPC to Transport
This commit is contained in:
parent
6ae4ab2cbf
commit
974b67d4b6
@ -57,39 +57,6 @@ static void constructPathSkyway(json& pathData) {
|
|||||||
Transport::SkywayPaths[pathData["iRouteID"]] = points;
|
Transport::SkywayPaths[pathData["iRouteID"]] = points;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void constructPathNPC(int32_t id, NPCPath* path) {
|
|
||||||
BaseNPC* npc = NPCManager::NPCs[id];
|
|
||||||
if(npc->type == EntityType::MOB)
|
|
||||||
((Mob*)(npc))->staticPath = true;
|
|
||||||
|
|
||||||
// Interpolate
|
|
||||||
std::vector<Vec3> pathPoints = path->points;
|
|
||||||
std::queue<Vec3> points;
|
|
||||||
|
|
||||||
auto _point = pathPoints.begin();
|
|
||||||
Vec3 from = *_point; // point A coords
|
|
||||||
for (_point++; _point != pathPoints.end(); _point++) { // loop through all point Bs
|
|
||||||
Vec3 to = *_point; // point B coords
|
|
||||||
// add point A to the queue
|
|
||||||
if (path->isRelative) {
|
|
||||||
// relative; the NPCs current position is assumed to be its spawn point
|
|
||||||
Vec3 fromReal = { from.x + npc->x, from.y + npc->y, from.z + npc->z };
|
|
||||||
Vec3 toReal = { to.x + npc->x, to.y + npc->y, to.z + npc->z };
|
|
||||||
points.push(fromReal);
|
|
||||||
Transport::lerp(&points, fromReal, toReal, path->speed); // lerp from A to B
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// absolute
|
|
||||||
points.push(from);
|
|
||||||
Transport::lerp(&points, from, to, path->speed); // lerp from A to B
|
|
||||||
}
|
|
||||||
|
|
||||||
from = to; // update point A
|
|
||||||
}
|
|
||||||
|
|
||||||
Transport::NPCQueues[id] = points;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load all relevant data from the XDT into memory
|
* Load all relevant data from the XDT into memory
|
||||||
* This should be called first, before any of the other load functions
|
* This should be called first, before any of the other load functions
|
||||||
@ -908,7 +875,7 @@ static void loadNPCs(json& npcData) {
|
|||||||
NPCPath* npcPath = Transport::findApplicablePath(npcID, type);
|
NPCPath* npcPath = Transport::findApplicablePath(npcID, type);
|
||||||
if (npcPath != nullptr) {
|
if (npcPath != nullptr) {
|
||||||
//std::cout << "[INFO] Found path for NPC " << npcID << std::endl;
|
//std::cout << "[INFO] Found path for NPC " << npcID << std::endl;
|
||||||
constructPathNPC(npcID, npcPath);
|
Transport::constructPathNPC(npcID, npcPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -954,7 +921,7 @@ static void loadMobs(json& npcData, int32_t* nextId) {
|
|||||||
NPCPath* npcPath = Transport::findApplicablePath(npcID, npc["iNPCType"]);
|
NPCPath* npcPath = Transport::findApplicablePath(npcID, npc["iNPCType"]);
|
||||||
if (npcPath != nullptr) {
|
if (npcPath != nullptr) {
|
||||||
//std::cout << "[INFO] Found path for mob " << npcID << std::endl;
|
//std::cout << "[INFO] Found path for mob " << npcID << std::endl;
|
||||||
constructPathNPC(npcID, npcPath);
|
Transport::constructPathNPC(npcID, npcPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -983,7 +950,7 @@ static void loadMobs(json& npcData, int32_t* nextId) {
|
|||||||
NPCPath* npcPath = Transport::findApplicablePath(leadID, leader["iNPCType"]);
|
NPCPath* npcPath = Transport::findApplicablePath(leadID, leader["iNPCType"]);
|
||||||
if (npcPath != nullptr) {
|
if (npcPath != nullptr) {
|
||||||
//std::cout << "[INFO] Found path for mob " << leadID << std::endl;
|
//std::cout << "[INFO] Found path for mob " << leadID << std::endl;
|
||||||
constructPathNPC(leadID, npcPath);
|
Transport::constructPathNPC(leadID, npcPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp->groupLeader = leadID;
|
tmp->groupLeader = leadID;
|
||||||
|
@ -384,6 +384,39 @@ NPCPath* Transport::findApplicablePath(int32_t id, int32_t type, int taskID) {
|
|||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Transport::constructPathNPC(int32_t id, NPCPath* path) {
|
||||||
|
BaseNPC* npc = NPCManager::NPCs[id];
|
||||||
|
if (npc->type == EntityType::MOB)
|
||||||
|
((Mob*)(npc))->staticPath = true;
|
||||||
|
|
||||||
|
// Interpolate
|
||||||
|
std::vector<Vec3> pathPoints = path->points;
|
||||||
|
std::queue<Vec3> points;
|
||||||
|
|
||||||
|
auto _point = pathPoints.begin();
|
||||||
|
Vec3 from = *_point; // point A coords
|
||||||
|
for (_point++; _point != pathPoints.end(); _point++) { // loop through all point Bs
|
||||||
|
Vec3 to = *_point; // point B coords
|
||||||
|
// add point A to the queue
|
||||||
|
if (path->isRelative) {
|
||||||
|
// relative; the NPCs current position is assumed to be its spawn point
|
||||||
|
Vec3 fromReal = { from.x + npc->x, from.y + npc->y, from.z + npc->z };
|
||||||
|
Vec3 toReal = { to.x + npc->x, to.y + npc->y, to.z + npc->z };
|
||||||
|
points.push(fromReal);
|
||||||
|
Transport::lerp(&points, fromReal, toReal, path->speed); // lerp from A to B
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// absolute
|
||||||
|
points.push(from);
|
||||||
|
Transport::lerp(&points, from, to, path->speed); // lerp from A to B
|
||||||
|
}
|
||||||
|
|
||||||
|
from = to; // update point A
|
||||||
|
}
|
||||||
|
|
||||||
|
Transport::NPCQueues[id] = points;
|
||||||
|
}
|
||||||
|
|
||||||
void Transport::init() {
|
void Transport::init() {
|
||||||
REGISTER_SHARD_TIMER(tickTransportationSystem, 1000);
|
REGISTER_SHARD_TIMER(tickTransportationSystem, 1000);
|
||||||
|
|
||||||
|
@ -51,4 +51,5 @@ namespace Transport {
|
|||||||
void lerp(std::queue<Vec3>*, Vec3, Vec3, int);
|
void lerp(std::queue<Vec3>*, Vec3, Vec3, int);
|
||||||
|
|
||||||
NPCPath* findApplicablePath(int32_t, int32_t, int = -1);
|
NPCPath* findApplicablePath(int32_t, int32_t, int = -1);
|
||||||
|
void constructPathNPC(int32_t, NPCPath*);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user