/* * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version. * Copyright (C) 2008-2016 TrinityCore * Copyright (C) 2005-2009 MaNGOS */ #ifndef ACORE_WAYPOINTMOVEMENTGENERATOR_H #define ACORE_WAYPOINTMOVEMENTGENERATOR_H /** @page PathMovementGenerator is used to generate movements * of waypoints and flight paths. Each serves the purpose * of generate activities so that it generates updated * packets for the players. */ #include "MovementGenerator.h" #include "Player.h" #include "WaypointManager.h" #define FLIGHT_TRAVEL_UPDATE 100 #define TIMEDIFF_NEXT_WP 250 template class PathMovementBase { public: PathMovementBase() : i_path(), i_currentNode(0) {} PathMovementBase(P path) : i_path(path), i_currentNode(0) {} virtual ~PathMovementBase() {}; uint32 GetCurrentNode() const { return i_currentNode; } protected: P i_path; uint32 i_currentNode; }; template class WaypointMovementGenerator; template<> class WaypointMovementGenerator : public MovementGeneratorMedium< Creature, WaypointMovementGenerator >, public PathMovementBase { public: WaypointMovementGenerator(uint32 _path_id = 0, bool _repeating = true) : PathMovementBase((WaypointPath const*)nullptr), i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating) {} ~WaypointMovementGenerator() { i_path = nullptr; } void DoInitialize(Creature*); void DoFinalize(Creature*); void DoReset(Creature*); bool DoUpdate(Creature*, uint32 diff); void MovementInform(Creature*); MovementGeneratorType GetMovementGeneratorType() { return WAYPOINT_MOTION_TYPE; } // now path movement implmementation void LoadPath(Creature*); private: void Stop(int32 time) { i_nextMoveTime.Reset(time);} bool Stopped() { return !i_nextMoveTime.Passed();} bool CanMove(int32 diff) { i_nextMoveTime.Update(diff); return i_nextMoveTime.Passed(); } void OnArrived(Creature*); bool StartMove(Creature*); void StartMoveNow(Creature* creature) { i_nextMoveTime.Reset(0); StartMove(creature); } TimeTrackerSmall i_nextMoveTime; bool m_isArrivalDone; uint32 path_id; bool repeating; }; /** FlightPathMovementGenerator generates movement of the player for the paths * and hence generates ground and activities for the player. */ class FlightPathMovementGenerator : public MovementGeneratorMedium< Player, FlightPathMovementGenerator >, public PathMovementBase { public: explicit FlightPathMovementGenerator(uint32 startNode = 0) { i_currentNode = startNode; _endGridX = 0.0f; _endGridY = 0.0f; _endMapId = 0; _preloadTargetNode = 0; _mapSwitch = false; } void LoadPath(Player* player); void DoInitialize(Player*); void DoReset(Player*); void DoFinalize(Player*); bool DoUpdate(Player*, uint32); MovementGeneratorType GetMovementGeneratorType() { return FLIGHT_MOTION_TYPE; } TaxiPathNodeList const& GetPath() { return i_path; } uint32 GetPathAtMapEnd() const; bool HasArrived() const { return (i_currentNode >= i_path.size()); } void SetCurrentNodeAfterTeleport(); void SkipCurrentNode() { ++i_currentNode; } void DoEventIfAny(Player* player, TaxiPathNodeEntry const* node, bool departure); void InitEndGridInfo(); void PreloadEndGrid(); private: float _endGridX; //! X coord of last node location float _endGridY; //! Y coord of last node location uint32 _endMapId; //! map Id of last node location uint32 _preloadTargetNode; //! node index where preloading starts bool _mapSwitch; std::deque _pointsForPathSwitch; //! node indexes and costs where TaxiPath changes }; #endif