diff options
| author | Machiavelli <none@none> | 2010-06-23 00:57:16 +0200 |
|---|---|---|
| committer | Machiavelli <none@none> | 2010-06-23 00:57:16 +0200 |
| commit | d50cb473cbb1ad0e276b6fc31b477a54d37b2255 (patch) | |
| tree | 6ae8d2fd311f861b7c40cfd618d52ba652509a15 /src/server/game/Movement | |
| parent | 1daa1c09f9c03fdc99bafb14886160f13870e277 (diff) | |
Use original taxipath data in taxi flight movement generator. Author: Vladimir
+ Cleanup
--HG--
branch : trunk
Diffstat (limited to 'src/server/game/Movement')
4 files changed, 93 insertions, 85 deletions
diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index 5c20494bfcc..46a4c806067 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -440,9 +440,17 @@ MotionMaster::MoveTaxiFlight(uint32 path, uint32 pathnode) { if (i_owner->GetTypeId() == TYPEID_PLAYER) { - DEBUG_LOG("Player (GUID: %u) taxi to (Path %u node %u)", i_owner->GetGUIDLow(), path, pathnode); - FlightPathMovementGenerator* mgen = new FlightPathMovementGenerator(path,pathnode); - Mutate(mgen, MOTION_SLOT_CONTROLLED); + if (path < sTaxiPathNodesByPath.size()) + { + DEBUG_LOG("%s taxi to (Path %u node %u)", i_owner->GetName(), path, pathnode); + FlightPathMovementGenerator* mgen = new FlightPathMovementGenerator(sTaxiPathNodesByPath[path],pathnode); + Mutate(mgen, MOTION_SLOT_CONTROLLED); + } + else + { + sLog.outError("%s attempt taxi to (not existed Path %u node %u)", + i_owner->GetName(), path, pathnode); + } } else { diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp index 2a0c7c0253d..2f9e4ce602e 100644 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp @@ -229,24 +229,20 @@ template bool WaypointMovementGenerator<Player>::Update(Player &, const uint32 & template void WaypointMovementGenerator<Player>::MovementInform(Player &); //----------------------------------------------------// -void FlightPathMovementGenerator::LoadPath(Player &) -{ - objmgr.GetTaxiPathNodes(i_pathId, i_path,i_mapIds); -} uint32 FlightPathMovementGenerator::GetPathAtMapEnd() const { - if (i_currentNode >= i_mapIds.size()) - return i_mapIds.size(); + if (i_currentNode >= i_path->size()) + return i_path->size(); - uint32 curMapId = i_mapIds[i_currentNode]; - for (uint32 i = i_currentNode; i < i_mapIds.size(); ++i) + uint32 curMapId = (*i_path)[i_currentNode].mapid; + for (uint32 i = i_currentNode; i < i_path->size(); ++i) { - if (i_mapIds[i] != curMapId) + if ((*i_path)[i].mapid != curMapId) return i; } - return i_mapIds.size(); + return i_path->size(); } void FlightPathMovementGenerator::Initialize(Player &player) @@ -254,23 +250,12 @@ void FlightPathMovementGenerator::Initialize(Player &player) player.getHostileRefManager().setOnlineOfflineState(false); player.addUnitState(UNIT_STAT_IN_FLIGHT); player.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_TAXI_FLIGHT); - LoadPath(player); Traveller<Player> traveller(player); // 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); - + i_destinationHolder.SetDestination(traveller, (*i_path)[i_currentNode].x, (*i_path)[i_currentNode].y, (*i_path)[i_currentNode].z, false); + // For preloading end grid + InitEndGridInfo(); 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) @@ -280,6 +265,7 @@ void FlightPathMovementGenerator::Finalize(Player & player) float x, y, z; i_destinationHolder.GetLocationNow(player.GetBaseMap(), x, y, z); player.SetPosition(x, y, z, player.GetOrientation()); + } bool FlightPathMovementGenerator::Update(Player &player, const uint32 &diff) @@ -292,18 +278,18 @@ bool FlightPathMovementGenerator::Update(Player &player, const uint32 &diff) i_destinationHolder.ResetUpdate(FLIGHT_TRAVEL_UPDATE); if (i_destinationHolder.HasArrived()) { - uint32 curMap = i_mapIds[i_currentNode]; + uint32 curMap = (*i_path)[i_currentNode].mapid; ++i_currentNode; if (MovementInProgress()) { DEBUG_LOG("loading node %u for player %s", i_currentNode, player.GetName()); - if (i_mapIds[i_currentNode] == curMap) + if ((*i_path)[i_currentNode].mapid == curMap) { // 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); + 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 + + // check if it's time to preload the flightmaster grid at path end if (i_currentNode == m_preloadTargetNode) PreloadEndGrid(); @@ -324,13 +310,13 @@ bool FlightPathMovementGenerator::Update(Player &player, const uint32 &diff) void FlightPathMovementGenerator::SetCurrentNodeAfterTeleport() { - if (i_mapIds.empty()) + if (i_path->empty()) return; - uint32 map0 = i_mapIds[0]; - for (size_t i = 1; i < i_mapIds.size(); ++i) + uint32 map0 = (*i_path)[0].mapid; + for (size_t i = 1; i < i_path->size(); ++i) { - if (i_mapIds[i] != map0) + if ((*i_path)[i].mapid != map0) { i_currentNode = i; return; @@ -338,6 +324,18 @@ void FlightPathMovementGenerator::SetCurrentNodeAfterTeleport() } } +void FlightPathMovementGenerator::InitEndGridInfo() +{ + // 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_path).size(); // Get the number of nodes in the path. + m_endMapId = (*i_path)[nodeCount -1].mapid; // 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 the Y position from the last node +} + void FlightPathMovementGenerator::PreloadEndGrid() { // used to preload the final grid where the flightmaster is diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h index 4b74e80e168..a03ff223b8e 100644 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h @@ -42,18 +42,21 @@ #define STOP_TIME_FOR_PLAYER 3 * MINUTE * IN_MILISECONDS // 3 Minutes #define TIMEDIFF_NEXT_WP 250 -template<class T, class P = Path> +template<class T, class P> class PathMovementBase { public: PathMovementBase() : i_currentNode(0) {} virtual ~PathMovementBase() {}; - bool MovementInProgress(void) const { return i_currentNode < i_path.Size(); } + bool MovementInProgress(void) const { return i_currentNode < i_path->size(); } void LoadPath(T &); void ReloadPath(T &); uint32 GetCurrentNode() const { return i_currentNode; } + + bool GetDestination(float& x, float& y, float& z) const { i_destinationHolder.GetDestination(x,y,z); return true; } + bool GetPosition(float& x, float& y, float& z) const { i_destinationHolder.GetLocationNowNoMicroMovement(x,y,z); return true; } protected: uint32 i_currentNode; @@ -64,7 +67,7 @@ class PathMovementBase template<class T> class WaypointMovementGenerator - : public MovementGeneratorMedium< T, WaypointMovementGenerator<T> >, public PathMovementBase<T> + : public MovementGeneratorMedium< T, WaypointMovementGenerator<T> >, public PathMovementBase<T, WaypointPath const*> { public: WaypointMovementGenerator(uint32 _path_id = 0, bool _repeating = true) : @@ -93,28 +96,29 @@ class WaypointMovementGenerator */ class FlightPathMovementGenerator : public MovementGeneratorMedium< Player, FlightPathMovementGenerator >, -public PathMovementBase<Player> +public PathMovementBase<Player,TaxiPathNodeList const*> { - uint32 i_pathId; - std::vector<uint32> i_mapIds; public: - explicit FlightPathMovementGenerator(uint32 id, uint32 startNode = 0) : i_pathId(id) { i_currentNode = startNode; } + explicit FlightPathMovementGenerator(TaxiPathNodeList const& pathnodes, uint32 startNode = 0) + { + i_path = &pathnodes; + i_currentNode = startNode; + } void Initialize(Player &); + void Reset(Player &u){}; void Finalize(Player &); - void Reset(Player &) {} bool Update(Player &, const uint32 &); MovementGeneratorType GetMovementGeneratorType() { return FLIGHT_MOTION_TYPE; } - void LoadPath(Player &); - void ReloadPath(Player &) { /* don't reload flight path */ } - - Path& GetPath() { return i_path; } + TaxiPathNodeList const& GetPath() { return *i_path; } uint32 GetPathAtMapEnd() const; - bool HasArrived() const { return (i_currentNode >= i_path.Size()); } + bool HasArrived() const { return (i_currentNode >= i_path->size()); } void SetCurrentNodeAfterTeleport(); void SkipCurrentNode() { ++i_currentNode; } - bool GetDestination(float& x, float& y, float& z) const { i_destinationHolder.GetDestination(x,y,z); return true; } + bool GetDestination(float& x, float& y, float& z) const { return PathMovementBase<Player,TaxiPathNodeList const*>::GetDestination(x,y,z); } + void PreloadEndGrid(); + void InitEndGridInfo(); private: // storage for preloading the flightmaster grid at end // before reaching final waypoint @@ -122,7 +126,6 @@ public PathMovementBase<Player> uint32 m_preloadTargetNode; float m_endGridX; float m_endGridY; - void PreloadEndGrid(); }; #endif diff --git a/src/server/game/Movement/Waypoints/Path.h b/src/server/game/Movement/Waypoints/Path.h index 9ec079f3c9c..de73d9270af 100644 --- a/src/server/game/Movement/Waypoints/Path.h +++ b/src/server/game/Movement/Waypoints/Path.h @@ -24,65 +24,64 @@ #include "Common.h" #include <vector> +struct SimplePathNode +{ + float x, y, z; +}; +template<typename PathElem, typename PathNode = PathElem> + class Path { public: - struct PathNode - { - float x,y,z; - }; - - void SetLength(const unsigned int sz) - { - i_nodes.resize(sz); - } + size_t size() const { return i_nodes.size(); } + bool empty() const { return i_nodes.empty(); } + void resize(unsigned int sz) { i_nodes.resize(sz); } + void clear() { i_nodes.clear(); } + void erase(uint32 idx) { i_nodes.erase(i_nodes.begin()+idx); } - unsigned int Size() const { return i_nodes.size(); } - bool Empty() const { return i_nodes.empty(); } - void Resize(unsigned int sz) { i_nodes.resize(sz); } - void Clear(void) { i_nodes.clear(); } - PathNode const* GetNodes(uint32 start = 0) const { return &i_nodes[start]; } - float GetTotalLength() const { return GetTotalLength(0,Size()); } float GetTotalLength(uint32 start, uint32 end) const { - float len = 0, xd, yd, zd; - for (unsigned int idx=start+1; idx < end; ++idx) + float len = 0.0f; + for (uint32 idx=start+1; idx < end; ++idx) { - xd = i_nodes[ idx ].x - i_nodes[ idx-1 ].x; - yd = i_nodes[ idx ].y - i_nodes[ idx-1 ].y; - zd = i_nodes[ idx ].z - i_nodes[ idx-1 ].z; + PathNode const& node = i_nodes[idx]; + PathNode const& prev = i_nodes[idx-1]; + float xd = node.x - prev.x; + float yd = node.y - prev.y; + float zd = node.z - prev.z; len += sqrtf(xd*xd + yd*yd + zd*zd); } return len; } + + float GetTotalLength() const { return GetTotalLength(0,size()); } float GetPassedLength(uint32 curnode, float x, float y, float z) { - float len = 0, xd, yd, zd; - for (unsigned int idx=1; idx < curnode; ++idx) - { - xd = i_nodes[ idx ].x - i_nodes[ idx-1 ].x; - yd = i_nodes[ idx ].y - i_nodes[ idx-1 ].y; - zd = i_nodes[ idx ].z - i_nodes[ idx-1 ].z; - len += sqrtf(xd*xd + yd*yd + zd*zd); - } + float len = GetTotalLength(0,curnode); if (curnode > 0) { - xd = x - i_nodes[curnode-1].x; - yd = y - i_nodes[curnode-1].y; - zd = z - i_nodes[curnode-1].z; + PathNode const& node = i_nodes[curnode-1]; + float xd = x - node.x; + float yd = y - node.y; + float zd = z - node.z; len += sqrtf(xd*xd + yd*yd + zd*zd); } return len; } - PathNode& operator[](const unsigned int idx) { return i_nodes[idx]; } - const PathNode& operator()(const unsigned int idx) const { return i_nodes[idx]; } + PathNode& operator[](size_t idx) { return i_nodes[idx]; } + PathNode const& operator[](size_t idx) const { return i_nodes[idx]; } + + void set(size_t idx, PathElem elem) { i_nodes[idx] = elem; } protected: - std::vector<PathNode> i_nodes; + std::vector<PathElem> i_nodes; }; + +typedef Path<SimplePathNode> SimplePath; + #endif |
