AzerothCore 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, bool _stalled=false)
 
 ~WaypointMovementGenerator ()
 
void DoInitialize (Creature *)
 
void DoFinalize (Creature *)
 
void DoReset (Creature *)
 
bool DoUpdate (Creature *, uint32 diff)
 
void Pause (uint32 timer)
 
void Resume (uint32 overrideTimer)
 
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
 
bool stalled
 

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,
bool  _stalled = false 
)
inline
58 : PathMovementBase((WaypointPath const*)nullptr), i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating), stalled(_stalled) {}
std::vector< WaypointData * > WaypointPath
Definition: WaypointMgr.h:47
PathMovementBase()
Definition: WaypointMovementGenerator.h:38
bool m_isArrivalDone
Definition: WaypointMovementGenerator.h:95
bool repeating
Definition: WaypointMovementGenerator.h:97
TimeTrackerSmall i_nextMoveTime
Definition: WaypointMovementGenerator.h:94
uint32 path_id
Definition: WaypointMovementGenerator.h:96
bool stalled
Definition: WaypointMovementGenerator.h:98

◆ ~WaypointMovementGenerator()

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

Member Function Documentation

◆ CanMove()

bool WaypointMovementGenerator< Creature >::CanMove ( int32  diff)
inlineprivate
80 {
82 return i_nextMoveTime.Passed();
83 }
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: UnitDefines.h:171
@ UNIT_STATE_ROAMING
Definition: UnitDefines.h:153
bool SetWalk(bool enable) override
Enable or disable the creature's walk mode by removing: MOVEMENTFLAG_WALKING. Infom also the client.
Definition: Creature.cpp:3191
void ClearUnitState(uint32 f)
Definition: Unit.h:702

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:700
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{
64 if (stalled)
65 {
66 return;
67 }
69 StartMoveNow(creature);
70}
void StartMoveNow(Creature *creature)
Definition: WaypointMovementGenerator.h:88

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

◆ DoUpdate()

bool WaypointMovementGenerator< Creature >::DoUpdate ( Creature creature,
uint32  diff 
)
213{
214 // Waypoint movement can be switched on/off
215 // This is quite handy for escort quests and other stuff
216 if (stalled)
217 {
218 Stop(1000);
219 return true;
220 }
222 {
223 creature->StopMoving();
224 Stop(1000);
225 return true;
226 }
227
228 // prevent a crash at empty waypoint path.
229 if (!i_path || i_path->empty())
230 return false;
231
232 // Xinef: Dont allow dead creatures to move
233 if (!creature->IsAlive())
234 return false;
235
236 if (Stopped())
237 {
238 if (CanMove(diff))
239 return StartMove(creature);
240 }
241 else
242 {
243 if (creature->IsStopped())
245 else
246 {
247 bool finished = creature->movespline->Finalized();
248 // xinef: code to detect pre-empetively if we should start movement to next waypoint
249 // xinef: do not start pre-empetive movement if current node has delay or we are ending waypoint movement
250 //if (!finished && !i_path->at(i_currentNode)->delay && ((i_currentNode != i_path->size() - 1) || repeating))
251 // finished = (creature->movespline->_Spline().length(creature->movespline->_currentSplineIdx() + 1) - creature->movespline->timePassed()) < 200;
252
253 if (finished)
254 {
255 OnArrived(creature);
256 return StartMove(creature);
257 }
258 }
259 }
260 return true;
261}
constexpr auto IN_MILLISECONDS
Definition: Common.h:53
@ CONFIG_WAYPOINT_MOVEMENT_STOP_TIME_FOR_PLAYER
Definition: IWorld.h:401
@ UNIT_STATE_NOT_MOVE
Definition: UnitDefines.h:197
#define sWorld
Definition: World.h:443
bool IsMovementPreventedByCasting() const override
Definition: Creature.cpp:3638
bool IsStopped() const
Definition: Unit.h:1624
Movement::MoveSpline * movespline
Definition: Unit.h:1979
bool IsAlive() const
Definition: Unit.h:1654
void StopMoving()
Definition: Unit.cpp:16650
bool HasUnitState(const uint32 f) const
Definition: Unit.h:701
bool Stopped()
Definition: WaypointMovementGenerator.h:77
void OnArrived(Creature *)
Definition: WaypointMovementGenerator.cpp:72
void Stop(int32 time)
Definition: WaypointMovementGenerator.h:75
bool CanMove(int32 diff)
Definition: WaypointMovementGenerator.h:79
bool StartMove(Creature *)
Definition: WaypointMovementGenerator.cpp:101
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.

69{ return WAYPOINT_MOTION_TYPE; }
@ WAYPOINT_MOTION_TYPE
Definition: MotionMaster.h:41

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:157
#define sWaypointMgr
Definition: WaypointMgr.h:78
uint32 GetWaypointPath() const
Definition: Creature.h:346
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
std::string const & GetName() const
Definition: Object.h:463
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)
264{
265 if (creature->AI())
267
268 if (Unit* owner = creature->GetCharmerOrOwner())
269 {
270 if (UnitAI* AI = owner->GetAI())
271 {
272 AI->SummonMovementInform(creature, WAYPOINT_MOTION_TYPE, i_currentNode);
273 }
274 }
275 else
276 {
277 if (TempSummon* tempSummon = creature->ToTempSummon())
278 {
279 if (Unit* owner = tempSummon->GetSummonerUnit())
280 {
281 if (UnitAI* AI = owner->GetAI())
282 {
283 AI->SummonMovementInform(creature, WAYPOINT_MOTION_TYPE, i_currentNode);
284 }
285 }
286 }
287 }
288}
Definition: UnitAI.h:193
virtual void MovementInform(uint32, uint32)
Definition: CreatureAI.h:157
CreatureAI * AI() const
Definition: Creature.h:140
Definition: TemporarySummon.h:40
Definition: Unit.h:630
TempSummon * ToTempSummon()
Definition: Unit.h:696
Unit * GetCharmerOrOwner() const
Definition: Unit.h:1211
uint32 i_currentNode
Definition: WaypointMovementGenerator.h:46

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

◆ OnArrived()

void WaypointMovementGenerator< Creature >::OnArrived ( Creature creature)
private
73{
74 if (!i_path || i_path->empty())
75 return;
77 return;
78
80 m_isArrivalDone = true;
81
82 if (i_path->at(i_currentNode)->event_id && urand(0, 99) < i_path->at(i_currentNode)->event_chance)
83 {
84 LOG_DEBUG("maps.script", "Creature movement start script {} at point {} for {}.",
85 i_path->at(i_currentNode)->event_id, i_currentNode, creature->GetGUID().ToString());
87 creature->GetMap()->ScriptsStart(sWaypointScripts, i_path->at(i_currentNode)->event_id, creature, nullptr);
88 }
89
90 // Inform script
91 MovementInform(creature);
93
94 if (i_path->at(i_currentNode)->delay)
95 {
97 Stop(i_path->at(i_currentNode)->delay);
98 }
99}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:44
ScriptMapMap sWaypointScripts
Definition: ObjectMgr.cpp:61
void UpdateWaypointID(uint32 wpID)
Definition: Creature.h:350
Map * GetMap() const
Definition: Object.h:536
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:31
void MovementInform(Creature *)
Definition: WaypointMovementGenerator.cpp:263

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

◆ Pause()

void WaypointMovementGenerator< Creature >::Pause ( uint32  timer)
virtual

Reimplemented from MovementGenerator.

291{
292 stalled = true;
294}
void Reset(int32 interval)
Definition: Timer.h:249

◆ Resume()

void WaypointMovementGenerator< Creature >::Resume ( uint32  overrideTimer)
virtual

Reimplemented from MovementGenerator.

297{
298 stalled = false;
299}

◆ 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

102{
103 if (!i_path || i_path->empty())
104 return false;
105
106 // Xinef: Dont allow dead creatures to move
107 if (!creature->IsAlive())
108 return false;
109
110 if (Stopped())
111 return true;
112
113 bool transportPath = creature->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && creature->GetTransGUID();
114
115 if (m_isArrivalDone)
116 {
117 // Xinef: not true... update this at every waypoint!
118 //if ((i_currentNode == i_path->size() - 1) && !repeating) // If that's our last waypoint
119 {
120 float x = i_path->at(i_currentNode)->x;
121 float y = i_path->at(i_currentNode)->y;
122 float z = i_path->at(i_currentNode)->z;
123 float o = creature->GetOrientation();
124
125 if (!transportPath)
126 creature->SetHomePosition(x, y, z, o);
127 else
128 {
129 if (Transport* trans = (creature->GetTransport() ? creature->GetTransport()->ToMotionTransport() : nullptr))
130 {
131 o -= trans->GetOrientation();
132 creature->SetTransportHomePosition(x, y, z, o);
133 trans->CalculatePassengerPosition(x, y, z, &o);
134 creature->SetHomePosition(x, y, z, o);
135 }
136 else
137 transportPath = false;
138 // else if (vehicle) - this should never happen, vehicle offsets are const
139 }
140 }
141
142 // Xinef: moved the upper IF here
143 if ((i_currentNode == i_path->size() - 1) && !repeating) // If that's our last waypoint
144 {
145 creature->AI()->PathEndReached(path_id);
146 creature->GetMotionMaster()->Initialize();
147 return false;
148 }
149
150 i_currentNode = (i_currentNode + 1) % i_path->size();
151 }
152
153 // xinef: do not initialize motion if we got stunned in movementinform
155 {
156 return true;
157 }
158
159 WaypointData const* node = i_path->at(i_currentNode);
160
161 m_isArrivalDone = false;
162
164
165 Movement::Location formationDest(node->x, node->y, node->z, 0.0f);
166 Movement::MoveSplineInit init(creature);
167
169 if (transportPath)
170 {
171 init.DisableTransportPathTransformations();
172 if (TransportBase* trans = creature->GetDirectTransport())
173 trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation);
174 }
175
176 float z = node->z;
177 creature->UpdateAllowedPositionZ(node->x, node->y, z);
180 init.MoveTo(node->x, node->y, z, true, true);
181
182 if (node->orientation.has_value() && node->delay > 0)
183 init.SetFacing(*node->orientation);
184
185 switch (node->move_type)
186 {
188 init.SetAnimation(Movement::ToGround);
189 break;
191 init.SetAnimation(Movement::ToFly);
192 break;
194 init.SetWalk(false);
195 break;
197 init.SetWalk(true);
198 break;
199 default:
200 break;
201 }
202
203 init.Launch();
204
205 //Call for creature group update
206 if (creature->GetFormation() && creature->GetFormation()->GetLeader() == creature)
207 creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z, node->move_type);
208
209 return true;
210}
@ MOVEMENTFLAG_ONTRANSPORT
Definition: UnitDefines.h:353
@ WAYPOINT_MOVE_TYPE_RUN
Definition: WaypointMgr.h:29
@ WAYPOINT_MOVE_TYPE_LAND
Definition: WaypointMgr.h:30
@ WAYPOINT_MOVE_TYPE_TAKEOFF
Definition: WaypointMgr.h:31
@ WAYPOINT_MOVE_TYPE_WALK
Definition: WaypointMgr.h:28
@ ToFly
Definition: MoveSplineInit.h:36
@ ToGround
Definition: MoveSplineInit.h:34
virtual void PathEndReached(uint32)
Definition: CreatureAI.h:160
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:336
CreatureGroup const * GetFormation() const
Definition: Creature.h:353
void SetTransportHomePosition(float x, float y, float z, float o)
Definition: Creature.h:341
Creature * GetLeader() const
Definition: CreatureGroups.h:99
void LeaderMoveTo(float x, float y, float z, uint32 move_type)
Definition: CreatureGroups.cpp:346
MotionTransport * ToMotionTransport()
Definition: GameObject.h:327
void UpdateAllowedPositionZ(float x, float y, float &z, float *groundZ=nullptr) const
Definition: Object.cpp:1565
Transport * GetTransport() const
Definition: Object.h:604
float GetOrientation() const
Definition: Position.h:119
Definition: Transport.h:29
MotionMaster * GetMotionMaster()
Definition: Unit.h:1620
bool HasUnitMovementFlag(uint32 f) const
Definition: Unit.h:736
TransportBase * GetDirectTransport() const
Definition: Unit.cpp:18767
ObjectGuid GetTransGUID() const override
Definition: Unit.cpp:18756
Definition: VehicleDefines.h:130
void Initialize()
Definition: MotionMaster.cpp:73
Definition: MoveSpline.h:27
Definition: MoveSplineInit.h:71
Definition: WaypointMgr.h:37
float z
Definition: WaypointMgr.h:39
float x
Definition: WaypointMgr.h:39
float y
Definition: WaypointMgr.h:39
std::optional< float > orientation
Definition: WaypointMgr.h:40
uint32 delay
Definition: WaypointMgr.h:41
uint32 move_type
Definition: WaypointMgr.h:43

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
89 {
91 StartMove(creature);
92 }

◆ Stop()

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

◆ Stopped()

bool WaypointMovementGenerator< Creature >::Stopped ( )
inlineprivate
77{ 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

◆ stalled

bool WaypointMovementGenerator< Creature >::stalled
private