TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WaypointMovementGenerator< Creature > Class Template Reference

#include <WaypointMovementGenerator.h>

Public Member Functions

 WaypointMovementGenerator (uint32 _path_id=0, bool _repeating=true)
 
 ~WaypointMovementGenerator ()
 
void DoInitialize (Creature *)
 
void DoFinalize (Creature *)
 
void DoReset (Creature *)
 
bool DoUpdate (Creature *, uint32 diff)
 
void MovementInform (Creature *)
 
MovementGeneratorType GetMovementGeneratorType () const override
 
void LoadPath (Creature *)
 
bool GetResetPos (Creature *, float &x, float &y, float &z)
 
- Public Member Functions inherited from MovementGeneratorMedium< Creature, WaypointMovementGenerator< Creature > >
void Initialize (Unit *u) override
 
void Finalize (Unit *u) override
 
void Reset (Unit *u) override
 
bool Update (Unit *u, uint32 time_diff) override
 
- Public Member Functions inherited from MovementGenerator
virtual ~MovementGenerator ()
 
virtual void unitSpeedChanged ()
 
virtual bool GetResetPosition (Unit *, float &, float &, float &)
 
- Public Member Functions inherited from PathMovementBase< Creature, WaypointPath const * >
 PathMovementBase ()
 
virtual ~PathMovementBase ()
 
uint32 GetCurrentNode () const
 

Private Member Functions

void Stop (int32 time)
 
bool Stopped ()
 
bool CanMove (int32 diff)
 
void OnArrived (Creature *)
 
bool StartMove (Creature *)
 
void StartMoveNow (Creature *creature)
 

Private Attributes

TimeTrackerSmall i_nextMoveTime
 
bool m_isArrivalDone
 
uint32 path_id
 
bool repeating
 

Additional Inherited Members

- Protected Attributes inherited from PathMovementBase< Creature, WaypointPath const * >
WaypointPath consti_path
 
uint32 i_currentNode
 

Constructor & Destructor Documentation

WaypointMovementGenerator< Creature >::WaypointMovementGenerator ( uint32  _path_id = 0,
bool  _repeating = true 
)
inline
59  : i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating) { }
TimeTrackerSmall i_nextMoveTime
Definition: WaypointMovementGenerator.h:96
bool m_isArrivalDone
Definition: WaypointMovementGenerator.h:97
bool repeating
Definition: WaypointMovementGenerator.h:99
uint32 path_id
Definition: WaypointMovementGenerator.h:98
60 { i_path = NULL; }
arena_t NULL
Definition: jemalloc_internal.h:624
WaypointPath const * i_path
Definition: WaypointMovementGenerator.h:46

Member Function Documentation

bool WaypointMovementGenerator< Creature >::CanMove ( int32  diff)
inlineprivate
82  {
83  i_nextMoveTime.Update(diff);
84  return i_nextMoveTime.Passed();
85  }
TimeTrackerSmall i_nextMoveTime
Definition: WaypointMovementGenerator.h:96
void Update(int32 diff)
Definition: Timer.h:143
bool Passed() const
Definition: Timer.h:148
void WaypointMovementGenerator< Creature >::DoFinalize ( Creature creature)
58 {
60  creature->SetWalk(false);
61 }
void ClearUnitState(uint32 f)
Definition: Unit.h:1396
Definition: Unit.h:554
Definition: Unit.h:572
bool SetWalk(bool enable)
Definition: Unit.cpp:15800

+ Here is the call graph for this function:

void WaypointMovementGenerator< Creature >::DoInitialize ( Creature creature)
52 {
53  LoadPath(creature);
55 }
void AddUnitState(uint32 f)
Definition: Unit.h:1394
void LoadPath(Creature *)
Definition: WaypointMovementGenerator.cpp:34
Definition: Unit.h:554
Definition: Unit.h:572

+ Here is the call graph for this function:

void WaypointMovementGenerator< Creature >::DoReset ( Creature creature)
64 {
66  StartMoveNow(creature);
67 }
void AddUnitState(uint32 f)
Definition: Unit.h:1394
void StartMoveNow(Creature *creature)
Definition: WaypointMovementGenerator.h:90
Definition: Unit.h:554
Definition: Unit.h:572

+ Here is the call graph for this function:

bool WaypointMovementGenerator< Creature >::DoUpdate ( Creature creature,
uint32  diff 
)
192 {
193  // Waypoint movement can be switched on/off
194  // This is quite handy for escort quests and other stuff
195  if (creature->HasUnitState(UNIT_STATE_NOT_MOVE))
196  {
198  return true;
199  }
200  // prevent a crash at empty waypoint path.
201  if (!i_path || i_path->empty())
202  return false;
203 
204  if (Stopped())
205  {
206  if (CanMove(diff))
207  return StartMove(creature);
208  }
209  else
210  {
211  // Set home position at place on waypoint movement.
212  if (!creature->GetTransGUID())
213  creature->SetHomePosition(creature->GetPosition());
214 
215  if (creature->IsStopped())
217  else if (creature->movespline->Finalized())
218  {
219  OnArrived(creature);
220  return StartMove(creature);
221  }
222  }
223  return true;
224  }
ObjectGuid GetTransGUID() const override
Definition: Unit.cpp:14355
Movement::MoveSpline * movespline
Definition: Unit.h:2213
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:670
WaypointPath const * i_path
Definition: WaypointMovementGenerator.h:46
void OnArrived(Creature *)
Definition: WaypointMovementGenerator.cpp:69
void ClearUnitState(uint32 f)
Definition: Unit.h:1396
#define STOP_TIME_FOR_PLAYER
Definition: WaypointMovementGenerator.h:33
bool IsStopped() const
Definition: Unit.h:2104
Definition: Unit.h:593
void GetPosition(float &x, float &y) const
Definition: Position.h:109
bool StartMove(Creature *)
Definition: WaypointMovementGenerator.cpp:96
bool Finalized() const
Definition: MoveSpline.h:129
bool CanMove(int32 diff)
Definition: WaypointMovementGenerator.h:81
bool Stopped()
Definition: WaypointMovementGenerator.h:79
Definition: Unit.h:572
void Stop(int32 time)
Definition: WaypointMovementGenerator.h:77
bool HasUnitState(const uint32 f) const
Definition: Unit.h:1395

+ Here is the call graph for this function:

MovementGeneratorType WaypointMovementGenerator< Creature >::GetMovementGeneratorType ( ) const
inlineoverridevirtual

Implements MovementGenerator.

68 { return WAYPOINT_MOTION_TYPE; }
Definition: MotionMaster.h:39
bool WaypointMovementGenerator< Creature >::GetResetPos ( Creature ,
float &  x,
float &  y,
float &  z 
)
233 {
234  // prevent a crash at empty waypoint path.
235  if (!i_path || i_path->empty())
236  return false;
237 
238  const WaypointData* node = i_path->at(i_currentNode);
239  x = node->x; y = node->y; z = node->z;
240  return true;
241 }
float x
Definition: WaypointManager.h:37
float z
Definition: WaypointManager.h:37
WaypointPath const * i_path
Definition: WaypointMovementGenerator.h:46
float y
Definition: WaypointManager.h:37
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
uint32 i_currentNode
Definition: WaypointMovementGenerator.h:47
G3D::int16 x
Definition: Vector2int16.h:37
Definition: WaypointManager.h:34
void WaypointMovementGenerator< Creature >::LoadPath ( Creature creature)
35 {
36  if (!path_id)
37  path_id = creature->GetWaypointPath();
38 
39  i_path = sWaypointMgr->GetPath(path_id);
40 
41  if (!i_path)
42  {
43  // No path id found for entry
44  TC_LOG_ERROR("sql.sql", "WaypointMovementGenerator::LoadPath: creature %s (%s DB GUID: " UI64FMTD ") doesn't have waypoint path id: %u", creature->GetName().c_str(), creature->GetGUID().ToString().c_str(), creature->GetSpawnId(), path_id);
45  return;
46  }
47 
48  StartMoveNow(creature);
49 }
uint32 GetWaypointPath() const
Definition: Creature.h:680
std::string const & GetName() const
Definition: Object.h:479
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:487
WaypointPath const * i_path
Definition: WaypointMovementGenerator.h:46
#define sWaypointMgr
Definition: WaypointManager.h:75
void StartMoveNow(Creature *creature)
Definition: WaypointMovementGenerator.h:90
#define UI64FMTD
Definition: Define.h:137
uint32 path_id
Definition: WaypointMovementGenerator.h:98
ObjectGuid const & GetGUID() const
Definition: Object.h:105
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
std::string ToString() const
Definition: ObjectGuid.cpp:99

+ Here is the call graph for this function:

void WaypointMovementGenerator< Creature >::MovementInform ( Creature creature)
227 {
228  if (creature->AI())
230 }
CreatureAI * AI() const
Definition: Creature.h:525
uint32 i_currentNode
Definition: WaypointMovementGenerator.h:47
Definition: MotionMaster.h:39
virtual void MovementInform(uint32, uint32)
Definition: CreatureAI.h:143

+ Here is the call graph for this function:

void WaypointMovementGenerator< Creature >::OnArrived ( Creature creature)
private
70 {
71  if (!i_path || i_path->empty())
72  return;
73  if (m_isArrivalDone)
74  return;
75 
76  m_isArrivalDone = true;
77 
78  if (i_path->at(i_currentNode)->event_id && urand(0, 99) < i_path->at(i_currentNode)->event_chance)
79  {
80  TC_LOG_DEBUG("maps.script", "Creature movement start script %u at point %u for %s.", i_path->at(i_currentNode)->event_id, i_currentNode, creature->GetGUID().ToString().c_str());
82  creature->GetMap()->ScriptsStart(sWaypointScripts, i_path->at(i_currentNode)->event_id, creature, NULL);
83  }
84 
85  // Inform script
86  MovementInform(creature);
88 
89  if (i_path->at(i_currentNode)->delay)
90  {
92  Stop(i_path->at(i_currentNode)->delay);
93  }
94 }
bool m_isArrivalDone
Definition: WaypointMovementGenerator.h:97
void ScriptsStart(std::map< uint32, std::multimap< uint32, ScriptInfo > > const &scripts, uint32 id, Object *source, Object *target)
Put scripts in the execution queue.
Definition: MapScripts.cpp:33
Map * GetMap() const
Definition: Object.h:543
void UpdateWaypointID(uint32 wpID)
Definition: Creature.h:684
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
WaypointPath const * i_path
Definition: WaypointMovementGenerator.h:46
void ClearUnitState(uint32 f)
Definition: Unit.h:1396
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
uint32 i_currentNode
Definition: WaypointMovementGenerator.h:47
ObjectGuid const & GetGUID() const
Definition: Object.h:105
void MovementInform(Creature *)
Definition: WaypointMovementGenerator.cpp:226
Definition: Unit.h:572
void Stop(int32 time)
Definition: WaypointMovementGenerator.h:77
std::string ToString() const
Definition: ObjectGuid.cpp:99
ScriptMapMap sWaypointScripts
Definition: ObjectMgr.cpp:53

+ Here is the call graph for this function:

bool WaypointMovementGenerator< Creature >::StartMove ( Creature creature)
private

If creature is on transport, we assume waypoints set in DB are already transport offsets

Do not use formationDest here, MoveTo requires transport offsets due to DisableTransportPathTransformations() call but formationDest contains global coordinates

Accepts angles such as 0.00001 and -0.00001, 0 must be ignored, default value in waypoint table

97 {
98  if (!i_path || i_path->empty())
99  return false;
100 
101  if (Stopped())
102  return true;
103 
104  bool transportPath = creature->GetTransport() != NULL;
105 
106  if (m_isArrivalDone)
107  {
108  if ((i_currentNode == i_path->size() - 1) && !repeating) // If that's our last waypoint
109  {
110  float x = i_path->at(i_currentNode)->x;
111  float y = i_path->at(i_currentNode)->y;
112  float z = i_path->at(i_currentNode)->z;
113  float o = creature->GetOrientation();
114 
115  if (!transportPath)
116  creature->SetHomePosition(x, y, z, o);
117  else
118  {
119  if (Transport* trans = creature->GetTransport())
120  {
121  o -= trans->GetOrientation();
122  creature->SetTransportHomePosition(x, y, z, o);
123  trans->CalculatePassengerPosition(x, y, z, &o);
124  creature->SetHomePosition(x, y, z, o);
125  }
126  else
127  transportPath = false;
128  // else if (vehicle) - this should never happen, vehicle offsets are const
129  }
130 
131  creature->GetMotionMaster()->Initialize();
132  return false;
133  }
134 
135  i_currentNode = (i_currentNode+1) % i_path->size();
136  }
137 
138  WaypointData const* node = i_path->at(i_currentNode);
139 
140  m_isArrivalDone = false;
141 
143 
144  Movement::Location formationDest(node->x, node->y, node->z, 0.0f);
145  Movement::MoveSplineInit init(creature);
146 
148  if (transportPath)
149  {
150  init.DisableTransportPathTransformations();
151  if (TransportBase* trans = creature->GetDirectTransport())
152  trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation);
153  }
154 
157  init.MoveTo(node->x, node->y, node->z);
158 
160  if (node->orientation && node->delay)
161  init.SetFacing(node->orientation);
162 
163  switch (node->move_type)
164  {
166  init.SetAnimation(Movement::ToGround);
167  break;
169  init.SetAnimation(Movement::ToFly);
170  break;
172  init.SetWalk(false);
173  break;
175  init.SetWalk(true);
176  break;
177  }
178 
179  init.Launch();
180 
181  //Call for creature group update
182  if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature)
183  {
184  creature->SetWalk(node->move_type != WAYPOINT_MOVE_TYPE_RUN);
185  creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z);
186  }
187 
188  return true;
189 }
bool m_isArrivalDone
Definition: WaypointMovementGenerator.h:97
Definition: WaypointManager.h:29
float x
Definition: WaypointManager.h:37
void SetTransportHomePosition(float x, float y, float z, float o)
Definition: Creature.h:675
float z
Definition: WaypointManager.h:37
void AddUnitState(uint32 f)
Definition: Unit.h:1394
Definition: MoveSpline.h:36
MotionMaster * GetMotionMaster()
Definition: Unit.h:2101
arena_t NULL
Definition: jemalloc_internal.h:624
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:670
Definition: Transport.h:28
Creature * getLeader() const
Definition: CreatureGroups.h:71
float orientation
Definition: WaypointManager.h:37
Definition: MoveSplineInit.h:33
WaypointPath const * i_path
Definition: WaypointMovementGenerator.h:46
Definition: VehicleDefines.h:119
bool repeating
Definition: WaypointMovementGenerator.h:99
float y
Definition: WaypointManager.h:37
Definition: WaypointManager.h:28
Definition: MoveSplineInit.h:31
float GetOrientation() const
Definition: Position.h:107
G3D::int16 z
Definition: Vector3int16.h:46
TransportBase * GetDirectTransport() const
Returns the transport this unit is on directly (if on vehicle and transport, return vehicle) ...
Definition: Unit.cpp:14365
G3D::int16 y
Definition: Vector2int16.h:38
uint32 i_currentNode
Definition: WaypointMovementGenerator.h:47
CreatureGroup * GetFormation()
Definition: Creature.h:687
bool Stopped()
Definition: WaypointMovementGenerator.h:79
Definition: WaypointManager.h:26
Transport * GetTransport() const
Definition: Object.h:602
uint32 move_type
Definition: WaypointManager.h:40
Definition: Unit.h:572
bool SetWalk(bool enable)
Definition: Unit.cpp:15800
uint32 delay
Definition: WaypointManager.h:38
Definition: WaypointManager.h:27
G3D::int16 x
Definition: Vector2int16.h:37
Definition: MoveSplineInit.h:52
void Initialize()
Definition: MotionMaster.cpp:39
void LeaderMoveTo(float x, float y, float z)
Definition: CreatureGroups.cpp:220
Definition: WaypointManager.h:34

+ Here is the call graph for this function:

void WaypointMovementGenerator< Creature >::StartMoveNow ( Creature creature)
inlineprivate
91  {
93  StartMove(creature);
94  }
TimeTrackerSmall i_nextMoveTime
Definition: WaypointMovementGenerator.h:96
bool StartMove(Creature *)
Definition: WaypointMovementGenerator.cpp:96
void Reset(uint32 interval)
Definition: Timer.h:153
void WaypointMovementGenerator< Creature >::Stop ( int32  time)
inlineprivate
77 { i_nextMoveTime.Reset(time);}
TimeTrackerSmall i_nextMoveTime
Definition: WaypointMovementGenerator.h:96
void Reset(uint32 interval)
Definition: Timer.h:153
bool WaypointMovementGenerator< Creature >::Stopped ( )
inlineprivate
79 { return !i_nextMoveTime.Passed();}
TimeTrackerSmall i_nextMoveTime
Definition: WaypointMovementGenerator.h:96
bool Passed() const
Definition: Timer.h:148

Member Data Documentation

bool WaypointMovementGenerator< Creature >::m_isArrivalDone
private
bool WaypointMovementGenerator< Creature >::repeating
private

The documentation for this class was generated from the following files: