diff options
-rw-r--r-- | src/game/WaypointMovementGenerator.cpp | 38 | ||||
-rw-r--r-- | src/game/WaypointMovementGenerator.h | 8 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/game/WaypointMovementGenerator.cpp b/src/game/WaypointMovementGenerator.cpp index 0bfd007011b..1e00c766e5e 100644 --- a/src/game/WaypointMovementGenerator.cpp +++ b/src/game/WaypointMovementGenerator.cpp @@ -21,6 +21,7 @@ //Extended headers #include "ObjectMgr.h" #include "World.h" +#include "MapManager.h" // for flightmaster grid preloading //Creature-specific headers #include "Creature.h" #include "CreatureAI.h" @@ -254,6 +255,18 @@ void FlightPathMovementGenerator::Initialize(Player &player) i_destinationHolder.SetDestination(traveller, i_path[i_currentNode].x, i_path[i_currentNode].y, i_path[i_currentNode].z, false); player.SendMonsterMoveByPath(GetPath(),GetCurrentNode(),GetPathAtMapEnd()); + + // Storage to preload flightmaster grid at end of flight. For multi-stop flights, this will + // be reinitialized for each flightmaster at the end of each spline (or stop) in the flight. + + uint32 nodeCount = i_mapIds.size(); // Get the number of nodes in the path. i_path and i_mapIds are the + // same size when loaded in ObjectMgr::GetTaxiPathNodes, called from LoadPath() + + m_endMapId = i_mapIds[nodeCount -1]; // Get the map ID from the last node + m_preloadTargetNode = nodeCount / 2; // Split the number of nodes in half to preload the flightmaster half-way through the flight + m_endGridX = i_path[nodeCount -1].x; // Get the X position from the last node + m_endGridY = i_path[nodeCount -1].y; // Get tye Y position from the last node + } void FlightPathMovementGenerator::Finalize(Player & player) @@ -285,6 +298,13 @@ bool FlightPathMovementGenerator::Update(Player &player, const uint32 &diff) // do not send movement, it was sent already i_destinationHolder.SetDestination(traveller, i_path[i_currentNode].x, i_path[i_currentNode].y, i_path[i_currentNode].z, false); } + + // check if it's time to preload the flightmaster grid + // at path end + if (i_currentNode == m_preloadTargetNode) + { + PreloadEndGrid(); + } return true; } //else HasArrived() @@ -316,6 +336,24 @@ void FlightPathMovementGenerator::SetCurrentNodeAfterTeleport() } } +void FlightPathMovementGenerator::PreloadEndGrid() +{ + // used to preload the final grid where the flightmaster is + Map *endMap = MapManager::Instance().FindMap(m_endMapId); + + // Load the grid + if (endMap) + { + sLog.outDetail("Preloading flightmaster at grid (%f, %f) for map %u", m_endGridX, m_endGridY, m_endMapId); + endMap->LoadGrid(m_endGridX, m_endGridY); + } + else + { + sLog.outDetail("Unable to determine map to preload flightmaster grid"); + } + +} + // // Unique1's ASTAR Pathfinding Code... For future use & reference... // diff --git a/src/game/WaypointMovementGenerator.h b/src/game/WaypointMovementGenerator.h index 9804c150d63..ad531e7a91f 100644 --- a/src/game/WaypointMovementGenerator.h +++ b/src/game/WaypointMovementGenerator.h @@ -114,6 +114,14 @@ public PathMovementBase<Player> void SkipCurrentNode() { ++i_currentNode; } bool GetDestination(float& x, float& y, float& z) const { i_destinationHolder.GetDestination(x,y,z); return true; } + private: + // storage for preloading the flightmaster grid at end + // before reaching final waypoint + uint32 m_endMapId; + uint32 m_preloadTargetNode; + float m_endGridX; + float m_endGridY; + void PreloadEndGrid(); }; #endif |