mirror of
				https://github.com/OpenFusionProject/OpenFusion.git
				synced 2025-11-03 18:30:15 +00:00 
			
		
		
		
	Move findApplicablePaths to Transport, add taskID argument
This commit is contained in:
		@@ -36,38 +36,6 @@ public:
 | 
				
			|||||||
    const char *what() const throw() { return msg.c_str(); }
 | 
					    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.
 | 
					 * 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 });
 | 
					                NPCManager::RespawnPoints.push_back({ npc["iX"], npc["iY"], ((int)npc["iZ"]) + RESURRECT_HEIGHT, instanceID });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // see if any paths target this NPC
 | 
					            // see if any paths target this NPC
 | 
				
			||||||
            NPCPath* npcPath = 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);
 | 
					                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"]);
 | 
					            NPCManager::updateNPCPosition(npcID, npc["iX"], npc["iY"], npc["iZ"], instanceID, npc["iAngle"]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // see if any paths target this mob
 | 
					            // see if any paths target this mob
 | 
				
			||||||
            NPCPath* npcPath = 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);
 | 
					                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"]);
 | 
					            NPCManager::updateNPCPosition(leadID, leader["iX"], leader["iY"], leader["iZ"], instanceID, leader["iAngle"]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // see if any paths target this group leader
 | 
					            // see if any paths target this group leader
 | 
				
			||||||
            NPCPath* npcPath = 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);
 | 
					                constructPathNPC(leadID, npcPath);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -347,6 +347,43 @@ void Transport::lerp(std::queue<Vec3>* queue, Vec3 start, Vec3 end, int gapSize)
 | 
				
			|||||||
    lerp(queue, start, end, gapSize, 1);
 | 
					    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() {
 | 
					void Transport::init() {
 | 
				
			||||||
    REGISTER_SHARD_TIMER(tickTransportationSystem, 1000);
 | 
					    REGISTER_SHARD_TIMER(tickTransportationSystem, 1000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,4 +49,6 @@ namespace Transport {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    void lerp(std::queue<Vec3>*, Vec3, Vec3, int, float);
 | 
					    void lerp(std::queue<Vec3>*, Vec3, Vec3, int, float);
 | 
				
			||||||
    void lerp(std::queue<Vec3>*, Vec3, Vec3, int);
 | 
					    void lerp(std::queue<Vec3>*, Vec3, Vec3, int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    NPCPath* findApplicablePath(int32_t, int32_t, int = -1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user