From c5a4d04bf5f315802130c2d0ba8d27127e133b9f Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 7 Feb 2026 20:05:14 -0800 Subject: [PATCH] Add taxi path BFS for activation --- src/game/game_handler.cpp | 56 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/game/game_handler.cpp b/src/game/game_handler.cpp index ca4f7382..06e0a517 100644 --- a/src/game/game_handler.cpp +++ b/src/game/game_handler.cpp @@ -4201,8 +4201,62 @@ void GameHandler::activateTaxi(uint32_t destNodeId) { uint32_t startNode = currentTaxiData_.nearestNode; if (startNode == 0 || destNodeId == 0 || startNode == destNodeId) return; - auto pkt = ActivateTaxiPacket::build(taxiNpcGuid_, startNode, destNodeId); + // BFS to find path from startNode to destNodeId + std::unordered_map> adj; + for (const auto& edge : taxiPathEdges_) { + adj[edge.fromNode].push_back(edge.toNode); + } + + std::unordered_map parent; + std::deque queue; + queue.push_back(startNode); + parent[startNode] = startNode; + + bool found = false; + while (!queue.empty()) { + uint32_t cur = queue.front(); + queue.pop_front(); + if (cur == destNodeId) { found = true; break; } + for (uint32_t next : adj[cur]) { + if (parent.find(next) == parent.end()) { + parent[next] = cur; + queue.push_back(next); + } + } + } + + if (!found) { + LOG_WARNING("No taxi path found from node ", startNode, " to ", destNodeId); + addSystemChatMessage("No flight path available to that destination."); + return; + } + + std::vector path; + for (uint32_t n = destNodeId; n != startNode; n = parent[n]) { + path.push_back(n); + } + path.push_back(startNode); + std::reverse(path.begin(), path.end()); + + LOG_INFO("Taxi path: ", path.size(), " nodes, from ", startNode, " to ", destNodeId); + + LOG_INFO("Taxi activate: npc=0x", std::hex, taxiNpcGuid_, std::dec, + " start=", startNode, " dest=", destNodeId, " pathLen=", path.size()); + if (!path.empty()) { + std::string pathStr; + for (size_t i = 0; i < path.size(); i++) { + pathStr += std::to_string(path[i]); + if (i + 1 < path.size()) pathStr += "->"; + } + LOG_INFO("Taxi path nodes: ", pathStr); + } + + auto pkt = ActivateTaxiExpressPacket::build(taxiNpcGuid_, path); socket->send(pkt); + + // Fallback: some servers expect basic CMSG_ACTIVATETAXI. + auto basicPkt = ActivateTaxiPacket::build(taxiNpcGuid_, startNode, destNodeId); + socket->send(basicPkt); } // ============================================================