From 66f47dc848fe2b2f115b7f70ac3f9a9cfd371091 Mon Sep 17 00:00:00 2001 From: Shauren Date: Mon, 14 Sep 2015 21:55:03 +0200 Subject: Core/Taxi: Fixed selecting paths that cross map boundaries (Light's Hope to Silvermoon for example) --- src/server/game/DataStores/DBCStores.cpp | 2 + src/server/game/DataStores/DBCStores.h | 1 + src/server/game/DataStores/DBCStructure.h | 14 +++++ src/server/game/DataStores/DBCfmt.h | 1 + src/server/game/Entities/Taxi/TaxiPathGraph.cpp | 75 +++++++++++++++++++------ src/server/game/Entities/Taxi/TaxiPathGraph.h | 15 ++--- 6 files changed, 83 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/server/game/DataStores/DBCStores.cpp b/src/server/game/DataStores/DBCStores.cpp index 8402c3989b3..61d97043523 100644 --- a/src/server/game/DataStores/DBCStores.cpp +++ b/src/server/game/DataStores/DBCStores.cpp @@ -156,6 +156,7 @@ DBCStorage sVehicleSeatStore(VehicleSeatfmt); DBCStorage sWMOAreaTableStore(WMOAreaTablefmt); static WMOAreaInfoByTripple sWMOAreaInfoByTripple; DBCStorage sWorldMapAreaStore(WorldMapAreafmt); +DBCStorage sWorldMapTransformsStore(WorldMapTransformsfmt); DBCStorage sWorldSafeLocsStore(WorldSafeLocsfmt); GameTable sGtBarberShopCostBaseStore(GtBarberShopCostBasefmt); @@ -376,6 +377,7 @@ void LoadDBCStores(const std::string& dataPath, uint32 defaultLocale) LOAD_DBC(sVehicleStore, "Vehicle.dbc");//20444 LOAD_DBC(sWMOAreaTableStore, "WMOAreaTable.dbc");//20444 LOAD_DBC(sWorldMapAreaStore, "WorldMapArea.dbc");//20444 + LOAD_DBC(sWorldMapTransformsStore, "WorldMapTransforms.dbc");//20444 LOAD_DBC(sWorldSafeLocsStore, "WorldSafeLocs.dbc"); // 20444 #undef LOAD_DBC diff --git a/src/server/game/DataStores/DBCStores.h b/src/server/game/DataStores/DBCStores.h index c8e03ee95e7..2d59afa7c5a 100644 --- a/src/server/game/DataStores/DBCStores.h +++ b/src/server/game/DataStores/DBCStores.h @@ -206,6 +206,7 @@ extern TalentsByPosition sTalentByPos; extern DBCStorage sVehicleStore; extern DBCStorage sVehicleSeatStore; extern DBCStorage sWMOAreaTableStore; +extern DBCStorage sWorldMapTransformsStore; extern DBCStorage sWorldSafeLocsStore; extern GameTable sGtBarberShopCostBaseStore; diff --git a/src/server/game/DataStores/DBCStructure.h b/src/server/game/DataStores/DBCStructure.h index b2a2704307e..94e577e9a26 100644 --- a/src/server/game/DataStores/DBCStructure.h +++ b/src/server/game/DataStores/DBCStructure.h @@ -1411,6 +1411,20 @@ struct WorldMapAreaEntry //uint32 LevelRangeMax; // 13 Maximum recommended level displayed on world map }; +struct WorldMapTransformsEntry +{ + //uint32 ID; // + uint32 MapID; // + DBCPosition3D RegionMin; // + DBCPosition3D RegionMax; // + //uint32 NewMapID; // + DBCPosition2D RegionOffset; // + //uint32 NewDungeonMapID; // + //uint32 Flags; // + //uint32 NewAreaID; // + float RegionScale; // +}; + struct WorldSafeLocsEntry { uint32 ID; // 0 diff --git a/src/server/game/DataStores/DBCfmt.h b/src/server/game/DataStores/DBCfmt.h index 6b2163cabca..8a01eac733e 100644 --- a/src/server/game/DataStores/DBCfmt.h +++ b/src/server/game/DataStores/DBCfmt.h @@ -120,6 +120,7 @@ char const Vehiclefmt[] = "niiffffiiiiiiiifffffffffffffffxxxxfifiiii"; char const VehicleSeatfmt[] = "niiffffffffffiiiiiifffffffiiifffiiiiiiiffiiiiffffffffffffiiiiiiiii"; char const WMOAreaTablefmt[] = "niiixxxxxiixxxx"; char const WorldMapAreafmt[] = "xinxffffixxxxx"; +char const WorldMapTransformsfmt[] = "diffffffxffxxxf"; char const WorldSafeLocsfmt[] = "niffffx"; #endif diff --git a/src/server/game/Entities/Taxi/TaxiPathGraph.cpp b/src/server/game/Entities/Taxi/TaxiPathGraph.cpp index 62d249cc5c0..589cbe04047 100644 --- a/src/server/game/Entities/Taxi/TaxiPathGraph.cpp +++ b/src/server/game/Entities/Taxi/TaxiPathGraph.cpp @@ -1,6 +1,7 @@ #include "TaxiPathGraph.h" #include #include "Util.h" +#include "DBCStores.h" #include "DB2Stores.h" #include "Config.h" #include @@ -16,41 +17,79 @@ TaxiPathGraph::TaxiPathGraph() { } TaxiPathGraph::~TaxiPathGraph() { } +void DeterminaAlternateMapPosition(TaxiPathGraph::TaxiNodeInfo& info) +{ + WorldMapTransformsEntry const* transformation = nullptr; + for (WorldMapTransformsEntry const* transform : sWorldMapTransformsStore) + { + if (transform->MapID != info.mapId) + continue; + + if (transform->RegionMin.X > info.pos.x || transform->RegionMax.X < info.pos.x) + continue; + if (transform->RegionMin.Y > info.pos.y || transform->RegionMax.Y < info.pos.y) + continue; + if (transform->RegionMin.Z > info.pos.z || transform->RegionMax.Z < info.pos.z) + continue; + + transformation = transform; + } + + if (!transformation) + return; + + if (transformation->RegionScale > 0.0f && transformation->RegionScale < 1.0f) + { + info.pos.x = (info.pos.x - transformation->RegionMin.X) * transformation->RegionScale + transformation->RegionMin.X; + info.pos.y = (info.pos.y - transformation->RegionMin.Y) * transformation->RegionScale + transformation->RegionMin.Y; + } + + info.pos.x += transformation->RegionOffset.X; + info.pos.y += transformation->RegionOffset.Y; +} + void TaxiPathGraph::Initialize() { if (_getVertexCount() > 0) return; - + m_edgeDuplicateControl.clear(); std::vector> edges; - + std::set returnableNodeIDs; // Used to omit special nodes which you can't return from - + for (TaxiPathEntry const* nodeInfo : sTaxiPathStore) if (nodeInfo->From != nodeInfo->To) returnableNodeIDs.insert(nodeInfo->From); - + // Initialize here for (TaxiPathEntry const* nodeInfo : sTaxiPathStore) { TaxiNodesEntry const* from = sTaxiNodesStore.LookupEntry(nodeInfo->From); TaxiNodesEntry const* to = sTaxiNodesStore.LookupEntry(nodeInfo->To); - if (from && to && + if (from && to && returnableNodeIDs.find(nodeInfo->From) != returnableNodeIDs.end() && returnableNodeIDs.find(nodeInfo->To) != returnableNodeIDs.end()) { - _addVerticeAndEdgeFromNodeInfo(TaxiNodeInfo(from->ID, from->Name->Str[sConfigMgr->GetIntDefault("DBC.Locale", LOCALE_enUS)], from->Pos.X, from->Pos.Y, from->Pos.Z), - TaxiNodeInfo(to->ID, to->Name->Str[sConfigMgr->GetIntDefault("DBC.Locale", LOCALE_enUS)], to->Pos.X, to->Pos.Y, to->Pos.Z), nodeInfo->Cost, edges); + TaxiNodeInfo fromInfo(from->ID, from->Name->Str[sConfigMgr->GetIntDefault("DBC.Locale", LOCALE_enUS)], from->MapID, from->Pos.X, from->Pos.Y, from->Pos.Z); + TaxiNodeInfo toInfo(to->ID, to->Name->Str[sConfigMgr->GetIntDefault("DBC.Locale", LOCALE_enUS)], to->MapID, to->Pos.X, to->Pos.Y, to->Pos.Z); + + DeterminaAlternateMapPosition(fromInfo); + DeterminaAlternateMapPosition(toInfo); + + _addVerticeAndEdgeFromNodeInfo(fromInfo, toInfo, nodeInfo->Cost, edges); } } returnableNodeIDs.clear(); // create graph m_graph = Graph(_getVertexCount()); - WeightMap weightmap = boost::get(boost::edge_weight, m_graph); + WeightMap& weightmap = boost::get(boost::edge_weight, m_graph); /*IndexMap indexmap = boost::get(boost::vertex_index, m_graph);*/ - - for(std::size_t j = 0; j < edges.size(); ++j) { - edge_descriptor e; bool inserted; + + for(std::size_t j = 0; j < edges.size(); ++j) + { + edge_descriptor e; + bool inserted; boost::tie(e, inserted) = boost::add_edge(edges[j].first.first, edges[j].first.second, m_graph); @@ -63,7 +102,7 @@ uint32 TaxiPathGraph::_getNodeIDFromVertexID(vertex vertexID) { if (vertexID < m_vertices.size()) return m_vertices[vertexID].nodeID; - + return std::numeric_limits::max(); } @@ -71,7 +110,7 @@ TaxiPathGraph::vertex TaxiPathGraph::_getVertexIDFromNodeID(uint32_t nodeID) { if (m_nodeIDToVertexID.find(nodeID) != m_nodeIDToVertexID.end()) return m_nodeIDToVertexID[nodeID]; - + return std::numeric_limits::max(); } @@ -79,7 +118,7 @@ TaxiPathGraph::vertex TaxiPathGraph::_getVertexIDFromNodeID(TaxiNodeInfo const& { if (m_nodeIDToVertexID.find(nodeInfo.nodeID) != m_nodeIDToVertexID.end()) return m_nodeIDToVertexID[nodeInfo.nodeID]; - + return std::numeric_limits::max(); } @@ -95,7 +134,7 @@ void TaxiPathGraph::_addVerticeAndEdgeFromNodeInfo(const TaxiNodeInfo& from, con { vertex fromVertexID = _createVertexFromFromNodeInfoIfNeeded(from); vertex toVertexID = _createVertexFromFromNodeInfoIfNeeded(to); - + edges.push_back(std::make_pair(edge(fromVertexID, toVertexID), from.pos.Distance(to.pos))); m_edgeDuplicateControl.insert(edge(from.nodeID, to.nodeID)); } @@ -116,13 +155,13 @@ size_t TaxiPathGraph::GetCompleteNodeRoute(uint32_t sourceNodeID, uint32_t desti */ bool hasDirectPath = false; shortestPath.clear(); - + // Find if we have a direct path from sourceNodeID to destinationNodeID in graph - typename boost::graph_traits::out_edge_iterator ei, ei_end; + boost::graph_traits::out_edge_iterator ei, ei_end; for (boost::tie(ei, ei_end) = boost::out_edges(_getVertexIDFromNodeID(sourceNodeID), m_graph); ei != ei_end && !hasDirectPath; ++ei) if (boost::target(*ei, m_graph) == _getVertexIDFromNodeID(destinationNodeID)) hasDirectPath = true; - + if (hasDirectPath) shortestPath = { sourceNodeID, destinationNodeID }; else diff --git a/src/server/game/Entities/Taxi/TaxiPathGraph.h b/src/server/game/Entities/Taxi/TaxiPathGraph.h index 5ef031d697d..a6b8797793a 100644 --- a/src/server/game/Entities/Taxi/TaxiPathGraph.h +++ b/src/server/game/Entities/Taxi/TaxiPathGraph.h @@ -19,12 +19,13 @@ public: }; struct TaxiNodeInfo { - TaxiNodeInfo(uint32 id, std::string const& flightName, float posX, float posY, float posZ): nodeID(id), name(flightName), pos(posX, posY, posZ) + TaxiNodeInfo(uint32 id, std::string const& flightName, uint32 mapid, float posX, float posY, float posZ): nodeID(id), name(flightName), mapId(mapid), pos(posX, posY, posZ) { name.erase(std::remove(name.begin(), name.end(), '\"' ), name.end()); } uint32 nodeID; std::string name; + uint32 mapId; Location pos; }; static TaxiPathGraph* instance() @@ -33,7 +34,7 @@ public: return &instance; } ~TaxiPathGraph(); - + static void Initialize(); static size_t GetCompleteNodeRoute(uint32 /* sourceNodeID */, uint32 /* destinationNodeID */, std::vector& /* shortestPath */); static TaxiNodeInfo const* GetTaxiNodeInfoByID(uint32 nodeID); @@ -57,7 +58,7 @@ private: private: Vertex m_goal; }; - + // specify some types typedef boost::adjacency_list, boost::property > Graph; typedef boost::property_map::type WeightMap; @@ -67,18 +68,18 @@ private: typedef Graph::vertex_descriptor vertex_descriptor; typedef Graph::vertex_iterator vertex_iterator; typedef std::pair edge; - + static Graph m_graph; static std::vector m_vertices; static std::map m_nodeIDToVertexID; static std::set m_edgeDuplicateControl; static const int MaxFlightDistanceThreshold; - + static void _addVerticeAndEdgeFromNodeInfo(TaxiNodeInfo const& /* from */, TaxiNodeInfo const& /* to */, uint32 /* money */, std::vector>& /* edgeList */); TaxiPathGraph(); TaxiPathGraph(TaxiPathGraph const&) = delete; TaxiPathGraph& operator=(TaxiPathGraph const&) = delete; - + static vertex _getVertexIDFromNodeID(uint32 nodeID); static vertex _getVertexIDFromNodeID(TaxiNodeInfo const& nodeInfo); static uint32 _getNodeIDFromVertexID(vertex vertexID); @@ -88,4 +89,4 @@ private: #define sTaxiPathGraph TaxiPathGraph::instance() -#endif /* TAXIPATHGRAPH_HPP */ +#endif /* TAXIPATHGRAPH_HPP */ -- cgit v1.2.3