AzeorthCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
WaypointMovementGenerator< Creature > Class Reference

#include "WaypointMovementGenerator.h"

Inheritance diagram for WaypointMovementGenerator< Creature >:
MovementGeneratorMedium< Creature, WaypointMovementGenerator< Creature > > PathMovementBase< T, P > MovementGenerator

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 ()
 
void LoadPath (Creature *)
 
- 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 Initialize (Unit *)=0
 
virtual void Finalize (Unit *)=0
 
virtual void Reset (Unit *)=0
 
virtual bool Update (Unit *, uint32 time_diff)=0
 
virtual MovementGeneratorType GetMovementGeneratorType ()=0
 
virtual uint32 GetSplineId () const
 
virtual void unitSpeedChanged ()
 
virtual void Pause (uint32)
 
virtual void Resume (uint32)
 
virtual bool GetResetPosition (float &, float &, float &)
 
- Public Member Functions inherited from PathMovementBase< T, P >
 PathMovementBase ()
 
 PathMovementBase (P path)
 
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< T, P >
i_path
 
uint32 i_currentNode
 

Detailed Description

Constructor & Destructor Documentation

◆ WaypointMovementGenerator()

WaypointMovementGenerator< Creature >::WaypointMovementGenerator ( uint32  _path_id = 0,
bool  _repeating = true 
)
inline
58 : PathMovementBase((WaypointPath const*)nullptr), i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating) {}
std::vector< WaypointData * > WaypointPath
Definition: WaypointMgr.h:46
PathMovementBase()
Definition: WaypointMovementGenerator.h:38
bool m_isArrivalDone
Definition: WaypointMovementGenerator.h:93
bool repeating
Definition: WaypointMovementGenerator.h:95
TimeTrackerSmall i_nextMoveTime
Definition: WaypointMovementGenerator.h:92
uint32 path_id
Definition: WaypointMovementGenerator.h:94

◆ ~WaypointMovementGenerator()

59{ i_path = nullptr; }
P i_path
Definition: WaypointMovementGenerator.h:45

Member Function Documentation

◆ CanMove()

bool WaypointMovementGenerator< Creature >::CanMove ( int32  diff)
inlineprivate
78 {
80 return i_nextMoveTime.Passed();
81 }
void Update(int32 diff)
Definition: Timer.h:239
bool Passed() const
Definition: Timer.h:244

◆ DoFinalize()

void WaypointMovementGenerator< Creature >::DoFinalize ( Creature creature)
57{
59 creature->SetWalk(false);
60}
@ UNIT_STATE_ROAMING_MOVE
Definition: Unit.h:347
@ UNIT_STATE_ROAMING
Definition: Unit.h:329
bool SetWalk(bool enable) override
Definition: Creature.cpp:3053
void ClearUnitState(uint32 f)
Definition: Unit.h:1399

References Unit::ClearUnitState(), Creature::SetWalk(), UNIT_STATE_ROAMING, and UNIT_STATE_ROAMING_MOVE.

◆ DoInitialize()

void WaypointMovementGenerator< Creature >::DoInitialize ( Creature creature)
51{
52 LoadPath(creature);
54}
void AddUnitState(uint32 f)
Definition: Unit.h:1397
void LoadPath(Creature *)
Definition: WaypointMovementGenerator.cpp:32

References Unit::AddUnitState(), UNIT_STATE_ROAMING, and UNIT_STATE_ROAMING_MOVE.

◆ DoReset()

void WaypointMovementGenerator< Creature >::DoReset ( Creature creature)
63{
65 StartMoveNow(creature);
66}
void StartMoveNow(Creature *creature)
Definition: WaypointMovementGenerator.h:86

References Unit::AddUnitState(), UNIT_STATE_ROAMING, and UNIT_STATE_ROAMING_MOVE.

◆ DoUpdate()

bool WaypointMovementGenerator< Creature >::DoUpdate ( Creature creature,
uint32  diff 
)
209{
210 // Waypoint movement can be switched on/off
211 // This is quite handy for escort quests and other stuff
213 {
214 creature->StopMoving();
215 Stop(1000);
216 return true;
217 }
218
219 // prevent a crash at empty waypoint path.
220 if (!i_path || i_path->empty())
221 return false;
222
223 // Xinef: Dont allow dead creatures to move
224 if (!creature->IsAlive())
225 return false;
226
227 if (Stopped())
228 {
229 if (CanMove(diff))
230 return StartMove(creature);
231 }
232 else
233 {
234 if (creature->IsStopped())
236 else
237 {
238 bool finished = creature->movespline->Finalized();
239 // xinef: code to detect pre-empetively if we should start movement to next waypoint
240 // xinef: do not start pre-empetive movement if current node has delay or we are ending waypoint movement
241 //if (!finished && !i_path->at(i_currentNode)->delay && ((i_currentNode != i_path->size() - 1) || repeating))
242 // finished = (creature->movespline->_Spline().length(creature->movespline->_currentSplineIdx() + 1) - creature->movespline->timePassed()) < 200;
243
244 if (finished)
245 {
246 OnArrived(creature);
247 return StartMove(creature);
248 }
249 }
250 }
251 return true;
252}
constexpr auto IN_MILLISECONDS
Definition: Common.h:62
@ UNIT_STATE_NOT_MOVE
Definition: Unit.h:371
@ CONFIG_WAYPOINT_MOVEMENT_STOP_TIME_FOR_PLAYER
Definition: IWorld.h:391
#define sWorld
Definition: World.h:458
bool IsMovementPreventedByCasting() const override
Definition: Creature.cpp:3484
bool IsStopped() const
Definition: Unit.h:2264
Movement::MoveSpline * movespline
Definition: Unit.h:2438
bool IsAlive() const
Definition: Unit.h:1808
void StopMoving()
Definition: Unit.cpp:16754
bool HasUnitState(const uint32 f) const
Definition: Unit.h:1398
bool Stopped()
Definition: WaypointMovementGenerator.h:75
void OnArrived(Creature *)
Definition: WaypointMovementGenerator.cpp:68
void Stop(int32 time)
Definition: WaypointMovementGenerator.h:73
bool CanMove(int32 diff)
Definition: WaypointMovementGenerator.h:77
bool StartMove(Creature *)
Definition: WaypointMovementGenerator.cpp:97
bool Finalized() const
Definition: MoveSpline.h:116

References CONFIG_WAYPOINT_MOVEMENT_STOP_TIME_FOR_PLAYER, Movement::MoveSpline::Finalized(), Unit::HasUnitState(), IN_MILLISECONDS, Unit::IsAlive(), Creature::IsMovementPreventedByCasting(), Unit::IsStopped(), Unit::movespline, Unit::StopMoving(), sWorld, and UNIT_STATE_NOT_MOVE.

◆ GetMovementGeneratorType()

MovementGeneratorType WaypointMovementGenerator< Creature >::GetMovementGeneratorType ( )
inlinevirtual

Implements MovementGenerator.

67{ return WAYPOINT_MOTION_TYPE; }
@ WAYPOINT_MOTION_TYPE
Definition: MotionMaster.h:39

References WAYPOINT_MOTION_TYPE.

◆ LoadPath()

void WaypointMovementGenerator< Creature >::LoadPath ( Creature creature)
33{
34 if (!path_id)
35 path_id = creature->GetWaypointPath();
36
37 i_path = sWaypointMgr->GetPath(path_id);
38
39 if (!i_path)
40 {
41 // No movement found for entry
42 LOG_ERROR("sql.sql", "WaypointMovementGenerator::LoadPath: creature {} ({}) doesn't have waypoint path id: {}",
43 creature->GetName(), creature->GetGUID().ToString(), path_id);
44 return;
45 }
46
47 StartMoveNow(creature);
48}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
#define sWaypointMgr
Definition: WaypointMgr.h:77
uint32 GetWaypointPath() const
Definition: Creature.h:330
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
std::string const & GetName() const
Definition: Object.h:446
std::string ToString() const
Definition: ObjectGuid.cpp:47

References Object::GetGUID(), WorldObject::GetName(), Creature::GetWaypointPath(), LOG_ERROR, sWaypointMgr, and ObjectGuid::ToString().

◆ MovementInform()

void WaypointMovementGenerator< Creature >::MovementInform ( Creature creature)
255{
256 if (creature->AI())
258
259 if (Unit* owner = creature->GetCharmerOrOwner())
260 {
261 if (UnitAI* AI = owner->GetAI())
262 {
263 AI->SummonMovementInform(creature, WAYPOINT_MOTION_TYPE, i_currentNode);
264 }
265 }
266}
Definition: UnitAI.h:182
virtual void MovementInform(uint32, uint32)
Definition: CreatureAI.h:149
CreatureAI * AI() const
Definition: Creature.h:134
Definition: Unit.h:1290
Unit * GetCharmerOrOwner() const
Definition: Unit.h:1847
uint32 i_currentNode
Definition: WaypointMovementGenerator.h:46

References Creature::AI(), Unit::GetCharmerOrOwner(), CreatureAI::MovementInform(), and WAYPOINT_MOTION_TYPE.

◆ OnArrived()

void WaypointMovementGenerator< Creature >::OnArrived ( Creature creature)
private
69{
70 if (!i_path || i_path->empty())
71 return;
73 return;
74
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 LOG_DEBUG("maps.script", "Creature movement start script {} at point {} for {}.",
81 i_path->at(i_currentNode)->event_id, i_currentNode, creature->GetGUID().ToString());
83 creature->GetMap()->ScriptsStart(sWaypointScripts, i_path->at(i_currentNode)->event_id, creature, nullptr);
84 }
85
86 // Inform script
87 MovementInform(creature);
89
90 if (i_path->at(i_currentNode)->delay)
91 {
93 Stop(i_path->at(i_currentNode)->delay);
94 }
95}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:44
ScriptMapMap sWaypointScripts
Definition: ObjectMgr.cpp:59
void UpdateWaypointID(uint32 wpID)
Definition: Creature.h:334
Map * GetMap() const
Definition: Object.h:517
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:34
void MovementInform(Creature *)
Definition: WaypointMovementGenerator.cpp:254

References Unit::ClearUnitState(), Object::GetGUID(), WorldObject::GetMap(), LOG_DEBUG, Map::ScriptsStart(), sWaypointScripts, ObjectGuid::ToString(), UNIT_STATE_ROAMING_MOVE, Creature::UpdateWaypointID(), and urand().

◆ StartMove()

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

98{
99 if (!i_path || i_path->empty())
100 return false;
101
102 // Xinef: Dont allow dead creatures to move
103 if (!creature->IsAlive())
104 return false;
105
106 if (Stopped())
107 return true;
108
109 bool transportPath = creature->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && creature->GetTransGUID();
110
111 if (m_isArrivalDone)
112 {
113 // Xinef: not true... update this at every waypoint!
114 //if ((i_currentNode == i_path->size() - 1) && !repeating) // If that's our last waypoint
115 {
116 float x = i_path->at(i_currentNode)->x;
117 float y = i_path->at(i_currentNode)->y;
118 float z = i_path->at(i_currentNode)->z;
119 float o = creature->GetOrientation();
120
121 if (!transportPath)
122 creature->SetHomePosition(x, y, z, o);
123 else
124 {
125 if (Transport* trans = (creature->GetTransport() ? creature->GetTransport()->ToMotionTransport() : nullptr))
126 {
127 o -= trans->GetOrientation();
128 creature->SetTransportHomePosition(x, y, z, o);
129 trans->CalculatePassengerPosition(x, y, z, &o);
130 creature->SetHomePosition(x, y, z, o);
131 }
132 else
133 transportPath = false;
134 // else if (vehicle) - this should never happen, vehicle offsets are const
135 }
136 }
137
138 // Xinef: moved the upper IF here
139 if ((i_currentNode == i_path->size() - 1) && !repeating) // If that's our last waypoint
140 {
141 creature->AI()->PathEndReached(path_id);
142 creature->GetMotionMaster()->Initialize();
143 return false;
144 }
145
146 i_currentNode = (i_currentNode + 1) % i_path->size();
147 }
148
149 // xinef: do not initialize motion if we got stunned in movementinform
151 {
152 return true;
153 }
154
155 WaypointData const* node = i_path->at(i_currentNode);
156
157 m_isArrivalDone = false;
158
160
161 Movement::Location formationDest(node->x, node->y, node->z, 0.0f);
162 Movement::MoveSplineInit init(creature);
163
165 if (transportPath)
166 {
167 init.DisableTransportPathTransformations();
168 if (TransportBase* trans = creature->GetDirectTransport())
169 trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation);
170 }
171
172 float z = node->z;
173 creature->UpdateAllowedPositionZ(node->x, node->y, z);
176 init.MoveTo(node->x, node->y, z, true, true);
177
178 if (node->orientation.has_value() && node->delay > 0)
179 init.SetFacing(*node->orientation);
180
181 switch (node->move_type)
182 {
184 init.SetAnimation(Movement::ToGround);
185 break;
187 init.SetAnimation(Movement::ToFly);
188 break;
190 init.SetWalk(false);
191 break;
193 init.SetWalk(true);
194 break;
195 default:
196 break;
197 }
198
199 init.Launch();
200
201 //Call for creature group update
202 if (creature->GetFormation() && creature->GetFormation()->GetLeader() == creature)
203 creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z, node->move_type == WAYPOINT_MOVE_TYPE_RUN);
204
205 return true;
206}
@ MOVEMENTFLAG_ONTRANSPORT
Definition: Unit.h:561
@ WAYPOINT_MOVE_TYPE_RUN
Definition: WaypointMgr.h:28
@ WAYPOINT_MOVE_TYPE_LAND
Definition: WaypointMgr.h:29
@ WAYPOINT_MOVE_TYPE_TAKEOFF
Definition: WaypointMgr.h:30
@ WAYPOINT_MOVE_TYPE_WALK
Definition: WaypointMgr.h:27
@ ToFly
Definition: MoveSplineInit.h:36
@ ToGround
Definition: MoveSplineInit.h:34
virtual void PathEndReached(uint32)
Definition: CreatureAI.h:152
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:320
CreatureGroup const * GetFormation() const
Definition: Creature.h:337
void SetTransportHomePosition(float x, float y, float z, float o)
Definition: Creature.h:325
Creature * GetLeader() const
Definition: CreatureGroups.h:97
void LeaderMoveTo(float x, float y, float z, bool run)
Definition: CreatureGroups.cpp:312
MotionTransport * ToMotionTransport()
Definition: GameObject.h:1022
void UpdateAllowedPositionZ(float x, float y, float &z, float *groundZ=nullptr) const
Definition: Object.cpp:1554
Transport * GetTransport() const
Definition: Object.h:585
float GetOrientation() const
Definition: Position.h:120
Definition: Transport.h:29
MotionMaster * GetMotionMaster()
Definition: Unit.h:2260
bool HasUnitMovementFlag(uint32 f) const
Definition: Unit.h:2272
TransportBase * GetDirectTransport() const
Returns the transport this unit is on directly (if on vehicle and transport, return vehicle)
Definition: Unit.cpp:18822
ObjectGuid GetTransGUID() const override
Definition: Unit.cpp:18811
Definition: VehicleDefines.h:107
void Initialize()
Definition: MotionMaster.cpp:72
Definition: MoveSpline.h:27
Definition: MoveSplineInit.h:71
Definition: WaypointMgr.h:36
float z
Definition: WaypointMgr.h:38
float x
Definition: WaypointMgr.h:38
float y
Definition: WaypointMgr.h:38
std::optional< float > orientation
Definition: WaypointMgr.h:39
uint32 delay
Definition: WaypointMgr.h:40
uint32 move_type
Definition: WaypointMgr.h:42

References Unit::AddUnitState(), Creature::AI(), WaypointData::delay, Movement::MoveSplineInit::DisableTransportPathTransformations(), Unit::GetDirectTransport(), Creature::GetFormation(), CreatureGroup::GetLeader(), Unit::GetMotionMaster(), Position::GetOrientation(), Unit::GetTransGUID(), WorldObject::GetTransport(), Unit::HasUnitMovementFlag(), Unit::HasUnitState(), MotionMaster::Initialize(), Unit::IsAlive(), Creature::IsMovementPreventedByCasting(), Movement::MoveSplineInit::Launch(), CreatureGroup::LeaderMoveTo(), WaypointData::move_type, MOVEMENTFLAG_ONTRANSPORT, Movement::MoveSplineInit::MoveTo(), Movement::Location::orientation, WaypointData::orientation, CreatureAI::PathEndReached(), Movement::MoveSplineInit::SetAnimation(), Movement::MoveSplineInit::SetFacing(), Creature::SetHomePosition(), Creature::SetTransportHomePosition(), Movement::MoveSplineInit::SetWalk(), Movement::ToFly, Movement::ToGround, GameObject::ToMotionTransport(), UNIT_STATE_NOT_MOVE, UNIT_STATE_ROAMING_MOVE, WorldObject::UpdateAllowedPositionZ(), WAYPOINT_MOVE_TYPE_LAND, WAYPOINT_MOVE_TYPE_RUN, WAYPOINT_MOVE_TYPE_TAKEOFF, WAYPOINT_MOVE_TYPE_WALK, WaypointData::x, WaypointData::y, and WaypointData::z.

◆ StartMoveNow()

void WaypointMovementGenerator< Creature >::StartMoveNow ( Creature creature)
inlineprivate
87 {
89 StartMove(creature);
90 }
void Reset(int32 interval)
Definition: Timer.h:249

◆ Stop()

void WaypointMovementGenerator< Creature >::Stop ( int32  time)
inlineprivate
73{ i_nextMoveTime.Reset(time);}

◆ Stopped()

bool WaypointMovementGenerator< Creature >::Stopped ( )
inlineprivate
75{ return !i_nextMoveTime.Passed();}

Member Data Documentation

◆ i_nextMoveTime

◆ m_isArrivalDone

bool WaypointMovementGenerator< Creature >::m_isArrivalDone
private

◆ path_id

◆ repeating

bool WaypointMovementGenerator< Creature >::repeating
private