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 pathId=0, bool repeating=true, PathSource pathSource=PathSource::WAYPOINT_MGR)
 
 WaypointMovementGenerator (WaypointPath &path, bool repeating=true)
 
 ~WaypointMovementGenerator ()
 
void DoInitialize (Creature *)
 
void DoFinalize (Creature *)
 
void DoReset (Creature *)
 
bool DoUpdate (Creature *, uint32 diff)
 
void unitSpeedChanged () override
 
void Pause (uint32 timer=0) override
 
void Resume (uint32 overrideTimer=0) override
 
bool GetResetPosition (float &x, float &y, float &z) override
 
MovementGeneratorType GetMovementGeneratorType () override
 
- 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 uint32 GetSplineId () const
 
- Public Member Functions inherited from PathMovementBase< T, P >
 PathMovementBase ()
 
 PathMovementBase (P path)
 
virtual ~PathMovementBase ()
 
uint32 GetCurrentNode () const
 

Private Member Functions

void ProcessWaypointArrival (Creature *, WaypointNode const &)
 
void StartMove (Creature *, bool relaunch=false)
 
bool IsAllowedToMove (Creature *) const
 
void UpdateWaypointState (Creature *, WaypointNode const &)
 

Private Attributes

uint32 _lastSplineId
 
uint32 _pathId
 
int32 _waypointDelay
 
std::optional< int32_pauseTime
 
bool _waypointReached
 
bool _recalculateSpeed
 
bool _repeating
 
bool _loadedFromDB
 
bool _stalled
 
bool _hasBeenStalled
 
bool _done
 
PathSource _pathSource
 
bool _smoothSplineLaunched
 
int32 _lastPassedSplineIdx
 

Additional Inherited Members

- Protected Attributes inherited from PathMovementBase< T, P >
i_path
 
uint32 i_currentNode
 

Detailed Description

Constructor & Destructor Documentation

◆ WaypointMovementGenerator() [1/2]

WaypointMovementGenerator< Creature >::WaypointMovementGenerator ( uint32  pathId = 0,
bool  repeating = true,
PathSource  pathSource = PathSource::WAYPOINT_MGR 
)
explicit
35 : PathMovementBase((WaypointPath const*)nullptr),
36 _lastSplineId(0), _pathId(pathId), _waypointDelay(0),
37 _waypointReached(true), _recalculateSpeed(false), _repeating(repeating), _loadedFromDB(true), _stalled(false), _hasBeenStalled(false), _done(false), _pathSource(pathSource),
39{
40}
PathMovementBase()
Definition WaypointMovementGenerator.h:38
bool _waypointReached
Definition WaypointMovementGenerator.h:83
bool _smoothSplineLaunched
Definition WaypointMovementGenerator.h:92
int32 _waypointDelay
Definition WaypointMovementGenerator.h:81
bool _stalled
Definition WaypointMovementGenerator.h:88
bool _loadedFromDB
Definition WaypointMovementGenerator.h:87
PathSource _pathSource
Definition WaypointMovementGenerator.h:91
uint32 _lastSplineId
Definition WaypointMovementGenerator.h:79
bool _repeating
Definition WaypointMovementGenerator.h:86
int32 _lastPassedSplineIdx
Definition WaypointMovementGenerator.h:93
bool _hasBeenStalled
Definition WaypointMovementGenerator.h:89
bool _recalculateSpeed
Definition WaypointMovementGenerator.h:85
uint32 _pathId
Definition WaypointMovementGenerator.h:80
bool _done
Definition WaypointMovementGenerator.h:90
Definition WaypointDefines.h:60

◆ WaypointMovementGenerator() [2/2]

WaypointMovementGenerator< Creature >::WaypointMovementGenerator ( WaypointPath path,
bool  repeating = true 
)
explicit
42 : PathMovementBase((WaypointPath const*)nullptr),
46{
47 i_path = &path;
48}
P i_path
Definition WaypointMovementGenerator.h:45

◆ ~WaypointMovementGenerator()

Member Function Documentation

◆ DoFinalize()

void WaypointMovementGenerator< Creature >::DoFinalize ( Creature creature)
96{
98}
@ UNIT_STATE_ROAMING_MOVE
Definition UnitDefines.h:195
@ UNIT_STATE_ROAMING
Definition UnitDefines.h:177
void ClearUnitState(uint32 f)
Definition Unit.h:737

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

◆ DoInitialize()

void WaypointMovementGenerator< Creature >::DoInitialize ( Creature creature)
51{
52 _done = false;
53
54 if (_loadedFromDB)
55 {
56 if (!_pathId)
57 _pathId = creature->GetWaypointPath();
58
59 switch (_pathSource)
60 {
61 default:
63 i_path = sWaypointMgr->GetPath(_pathId);
64 break;
67 break;
68 }
69 }
70
71 if (!i_path)
72 {
73 LOG_ERROR("sql.sql", "WaypointMovementGenerator::DoInitialize: creature {} ({}) doesn't have waypoint path id: {}",
74 creature->GetName(), creature->GetGUID().ToString(), _pathId);
75 return;
76 }
77
78 // Determine our first waypoint from the creature's stored waypoint
79 if (CreatureData const* creatureData = creature->GetCreatureData())
80 {
81 if (i_path->Nodes.size() > creatureData->currentwaypoint)
82 {
83 creature->UpdateCurrentWaypointInfo(creatureData->currentwaypoint, i_path->Id);
84 i_currentNode = creatureData->currentwaypoint;
85 }
86 }
87
89
90 // Inform AI
91 if (CreatureAI* AI = creature->AI())
92 AI->WaypointPathStarted(i_path->Id);
93}
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
@ SMART_WAYPOINT_MGR
#define sSmartWaypointMgr
Definition SmartScriptMgr.h:2263
#define sWaypointMgr
Definition WaypointMgr.h:54
Definition CreatureAI.h:69
uint32 GetWaypointPath() const
Definition Creature.h:355
void UpdateCurrentWaypointInfo(uint32 nodeId, uint32 pathId)
Definition Creature.h:363
CreatureData const * GetCreatureData() const
Definition Creature.h:207
CreatureAI * AI() const
Definition Creature.h:143
std::string ToString() const
Definition ObjectGuid.cpp:47
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
uint32 i_currentNode
Definition WaypointMovementGenerator.h:46
void AddUnitState(uint32 f)
Definition Unit.h:735
std::string const & GetName() const
Definition Object.h:528
ObjectData const creatureData[]
Definition instance_blackwing_lair.cpp:45
Definition CreatureData.h:370

References Unit::AddUnitState(), Creature::AI(), creatureData, Creature::GetCreatureData(), Object::GetGUID(), WorldObject::GetName(), Creature::GetWaypointPath(), LOG_ERROR, SMART_WAYPOINT_MGR, sSmartWaypointMgr, sWaypointMgr, ObjectGuid::ToString(), UNIT_STATE_ROAMING, UNIT_STATE_ROAMING_MOVE, Creature::UpdateCurrentWaypointInfo(), and WAYPOINT_MGR.

◆ DoReset()

void WaypointMovementGenerator< Creature >::DoReset ( Creature creature)
101{
102 // We did not reach our last waypoint before reset, treat this scenario as resuming movement.
103 if (!_done && !_waypointReached)
104 _hasBeenStalled = true;
105 else if (_done)
106 {
107 // mimic IdleMovementGenerator
108 if (!creature->IsStopped())
109 creature->StopMoving();
110 }
111}
bool IsStopped() const
Definition Unit.h:1762
void StopMoving()
Definition Unit.cpp:12997

References Unit::IsStopped(), and Unit::StopMoving().

◆ DoUpdate()

bool WaypointMovementGenerator< Creature >::DoUpdate ( Creature creature,
uint32  diff 
)
357{
358 if (!creature || !creature->IsAlive())
359 return true;
360
361 if (_done || !i_path || i_path->Nodes.empty())
362 return true;
363
364 // Stop movement if paused, rooted, or casting
365 if (!IsAllowedToMove(creature) && !creature->movespline->Finalized())
366 {
367 creature->StopMoving();
368 _lastSplineId = 0;
369 _smoothSplineLaunched = false;
370 }
371
372 // Set home position to current position.
373 if (!creature->movespline->Finalized())
374 {
375 bool transportPath = creature->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && creature->GetTransGUID();
376 if (!transportPath)
377 creature->SetHomePosition(creature->GetPosition());
378 }
379
380 // Smooth spline: track waypoint passages without rebuilding
382 {
383 int32 currentIdx = creature->movespline->currentPathIdx();
384
385 // Process passed waypoints
386 while (_lastPassedSplineIdx < currentIdx)
387 {
389 WaypointNode const& passedWp = i_path->Nodes.at(i_currentNode);
390
391 UpdateHomePosition(creature, passedWp);
392
393 // Save data before AI callbacks — they can invalidate the reference
394 uint32 const wpId = passedWp.Id;
395 uint32 const wpPathId = i_path->Id;
396 uint32 const wpDelay = passedWp.Delay;
397 std::optional<float> const wpOrientation = passedWp.Orientation;
398
399 creature->UpdateWaypointID(wpId);
400 creature->UpdateCurrentWaypointInfo(wpId, wpPathId);
401
402 if (passedWp.EventId && urand(0, 99) < passedWp.EventChance)
403 {
405 creature->GetMap()->ScriptsStart(sWaypointScripts, passedWp.EventId, creature, nullptr);
406 }
407
408 if (CreatureAI* AI = creature->AI())
409 {
410 AI->MovementInform(WAYPOINT_MOTION_TYPE, wpId);
411 AI->WaypointReached(wpId, wpPathId);
412 }
413
414 // Advance node
415 if (i_path && !i_path->Nodes.empty())
416 i_currentNode = (i_currentNode + 1) % i_path->Nodes.size();
417
418 // If this waypoint has a delay, stop the spline and pause
419 if (wpDelay > 0)
420 {
421 creature->StopMoving();
423 _waypointDelay = wpDelay;
424 _waypointReached = true;
425 _smoothSplineLaunched = false;
426 if (wpOrientation.has_value())
427 creature->SetFacingTo(*wpOrientation);
428
429 return true;
430 }
431 }
432
433 if (creature->movespline->Finalized())
434 {
435 if (!_repeating)
436 {
437 // Path ended
438 uint32 const endWpId = i_path->Nodes.at(i_currentNode).Id;
439 uint32 const endPathId = i_path->Id;
440 _done = true;
441 _smoothSplineLaunched = false;
442 creature->UpdateCurrentWaypointInfo(0, 0);
443 if (CreatureAI* AI = creature->AI())
444 AI->PathEndReached(endPathId);
445
446 // Re-fetch AI — PathEndReached may have despawned the creature or swapped its AI
447 if (CreatureAI* AI = creature->AI())
448 AI->WaypointPathEnded(endWpId, endPathId);
449 }
450 else
451 {
452 // Repeating: rebuild spline
453 _smoothSplineLaunched = false;
454 StartMove(creature);
455 }
456 }
457
458 return true;
459 }
460
461 // Non-smooth: per-waypoint logic
462 WaypointNode const& waypoint = i_path->Nodes.at(i_currentNode);
463 UpdateWaypointState(creature, waypoint);
464
465 // Process movement preventing timers
466 if (_waypointDelay > 0)
467 {
468 _waypointDelay -= diff;
469 if (_waypointDelay > 0)
470 return true;
471 }
472
473 if (_pauseTime.has_value())
474 {
475 *_pauseTime -= diff;
476 if (*_pauseTime > 0)
477 return true;
478 else
479 _pauseTime.reset();
480 }
481
482 // Timers are ready, let's try to move
485
486 return true;
487}
std::int32_t int32
Definition Define.h:103
std::uint32_t uint32
Definition Define.h:107
@ WAYPOINT_MOTION_TYPE
Definition MotionMaster.h:41
ScriptMapMap sWaypointScripts
Definition ObjectMgr.cpp:62
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:44
@ MOVEMENTFLAG_ONTRANSPORT
Definition UnitDefines.h:381
void UpdateHomePosition(Creature *creature, WaypointNode const &waypointNode)
Definition WaypointMovementGenerator.cpp:113
void SetHomePosition(float x, float y, float z, float o)
Definition Creature.h:345
void UpdateWaypointID(uint32 wpID)
Definition Creature.h:359
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
uint32 GetId() const
Definition MoveSpline.h:117
bool Finalized() const
Definition MoveSpline.h:118
int32 currentPathIdx() const
Definition MoveSpline.cpp:318
void SetFacingTo(float ori)
Definition Unit.cpp:16411
Movement::MoveSpline * movespline
Definition Unit.h:2114
bool IsAlive() const
Definition Unit.h:1793
bool HasUnitMovementFlag(uint32 f) const
Definition Unit.h:774
ObjectGuid GetTransGUID() const override
Definition Unit.cpp:14981
std::optional< int32 > _pauseTime
Definition WaypointMovementGenerator.h:82
void UpdateWaypointState(Creature *, WaypointNode const &)
Definition WaypointMovementGenerator.cpp:533
bool IsAllowedToMove(Creature *) const
Definition WaypointMovementGenerator.cpp:519
void StartMove(Creature *, bool relaunch=false)
Definition WaypointMovementGenerator.cpp:208
Map * GetMap() const
Definition Object.h:625
void GetPosition(float &x, float &y) const
Definition Position.h:126
Definition WaypointDefines.h:37
uint32 Delay
Definition WaypointDefines.h:51
uint32 EventId
Definition WaypointDefines.h:52
uint8 EventChance
Definition WaypointDefines.h:54
std::optional< float > Orientation
Definition WaypointDefines.h:49
uint32 Id
Definition WaypointDefines.h:47

References Creature::AI(), Unit::ClearUnitState(), Movement::MoveSpline::currentPathIdx(), WaypointNode::Delay, WaypointNode::EventChance, WaypointNode::EventId, Movement::MoveSpline::Finalized(), Movement::MoveSpline::GetId(), WorldObject::GetMap(), Position::GetPosition(), Unit::GetTransGUID(), Unit::HasUnitMovementFlag(), WaypointNode::Id, Unit::IsAlive(), MOVEMENTFLAG_ONTRANSPORT, Unit::movespline, WaypointNode::Orientation, Map::ScriptsStart(), Unit::SetFacingTo(), Creature::SetHomePosition(), Unit::StopMoving(), sWaypointScripts, UNIT_STATE_ROAMING_MOVE, Creature::UpdateCurrentWaypointInfo(), UpdateHomePosition(), Creature::UpdateWaypointID(), urand(), and WAYPOINT_MOTION_TYPE.

◆ GetMovementGeneratorType()

MovementGeneratorType WaypointMovementGenerator< Creature >::GetMovementGeneratorType ( )
inlineoverridevirtual

Implements MovementGenerator.

71{ return WAYPOINT_MOTION_TYPE; }

References WAYPOINT_MOTION_TYPE.

◆ GetResetPosition()

bool WaypointMovementGenerator< Creature >::GetResetPosition ( float &  x,
float &  y,
float &  z 
)
overridevirtual

Reimplemented from MovementGenerator.

505{
506 // prevent a crash at empty waypoint path.
507 if (!i_path || i_path->Nodes.empty())
508 return false;
509
510 ASSERT(i_currentNode < i_path->Nodes.size(), "WaypointMovementGenerator::GetResetPos: tried to reference a node id ({}) which is not included in path ({})", i_currentNode, i_path->Id);
511 WaypointNode const& waypoint = i_path->Nodes.at(i_currentNode);
512
513 x = waypoint.X;
514 y = waypoint.Y;
515 z = waypoint.Z;
516 return true;
517}
#define ASSERT
Definition Errors.h:68
float X
Definition WaypointDefines.h:48
float Z
Definition WaypointDefines.h:48
float Y
Definition WaypointDefines.h:48

References ASSERT, WaypointNode::X, WaypointNode::Y, and WaypointNode::Z.

◆ IsAllowedToMove()

bool WaypointMovementGenerator< Creature >::IsAllowedToMove ( Creature creature) const
private
520{
521 if (_stalled || _done)
522 return false;
523
524 if (_pauseTime.has_value())
525 return false;
526
528 return false;
529
530 return true;
531}
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:225
bool IsMovementPreventedByCasting() const override
Definition Creature.cpp:3558
bool HasUnitState(const uint32 f) const
Definition Unit.h:736

References Unit::HasUnitState(), Creature::IsMovementPreventedByCasting(), and UNIT_STATE_NOT_MOVE.

◆ Pause()

void WaypointMovementGenerator< Creature >::Pause ( uint32  timer = 0)
overridevirtual

Reimplemented from MovementGenerator.

490{
491 _stalled = timer ? false : true;
493 _pauseTime = timer;
494}

◆ ProcessWaypointArrival()

void WaypointMovementGenerator< Creature >::ProcessWaypointArrival ( Creature creature,
WaypointNode const &  waypoint 
)
private
136{
138 return;
139
140 if (waypoint.Delay > 0)
141 {
143 _waypointDelay = waypoint.Delay;
144 }
145
146 bool pathEnded = (i_currentNode == i_path->Nodes.size() - 1) && !_repeating && !_done;
147 if (pathEnded)
148 _done = true;
149
150 UpdateHomePosition(creature, waypoint);
151
152 if (waypoint.EventId && urand(0, 99) < waypoint.EventChance)
153 {
154 LOG_DEBUG("maps.script", "Creature movement start script {} at point {} for {}.",
155 waypoint.EventId, i_currentNode, creature->GetGUID().ToString());
157 creature->GetMap()->ScriptsStart(sWaypointScripts, waypoint.EventId, creature, nullptr);
158 }
159
160 // scripts can invalidate current path, store what we need
161 uint32 const waypointId = waypoint.Id;
162 uint32 const pathId = i_path->Id;
163
164 creature->UpdateWaypointID(waypointId);
165 creature->UpdateCurrentWaypointInfo(waypointId, pathId);
166
167 // Inform AI
168 if (CreatureAI* AI = creature->AI())
169 {
170 AI->MovementInform(WAYPOINT_MOTION_TYPE, waypointId);
171 AI->WaypointReached(waypointId, pathId);
172 }
173
174 if (Unit* owner = creature->GetCharmerOrOwner())
175 {
176 if (UnitAI* AI = owner->GetAI())
177 AI->SummonMovementInform(creature, WAYPOINT_MOTION_TYPE, waypointId);
178 }
179 else
180 {
181 if (TempSummon* tempSummon = creature->ToTempSummon())
182 if (Unit* owner2 = tempSummon->GetSummonerUnit())
183 if (UnitAI* AI = owner2->GetAI())
184 AI->SummonMovementInform(creature, WAYPOINT_MOTION_TYPE, waypointId);
185 }
186
187 // Path end notifications fire after WaypointReached so that m_path_id
188 // is still valid when SmartAI checks it for SMART_EVENT_WAYPOINT_REACHED.
189 if (pathEnded)
190 {
191 creature->UpdateCurrentWaypointInfo(0, 0);
192
193 if (CreatureAI* AI = creature->AI())
194 AI->PathEndReached(pathId);
195
196 // Re-fetch AI — PathEndReached may have despawned the creature or swapped its AI
197 if (CreatureAI* AI = creature->AI())
198 AI->WaypointPathEnded(waypointId, pathId);
199 }
200
201 // All hooks called and infos updated. Time to increment the waypoint node id
202 if (i_path && !i_path->Nodes.empty()) // ensure that the path has not been changed in one of the hooks.
203 i_currentNode = (i_currentNode + 1) % i_path->Nodes.size();
204
205 _waypointReached = true;
206}
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170
Definition TemporarySummon.h:50
Definition UnitAI.h:198
Definition Unit.h:664
TempSummon * ToTempSummon()
Definition Unit.h:731
Unit * GetCharmerOrOwner() const
Definition Unit.h:1286

References Creature::AI(), Unit::ClearUnitState(), WaypointNode::Delay, WaypointNode::EventChance, WaypointNode::EventId, Unit::GetCharmerOrOwner(), Object::GetGUID(), WorldObject::GetMap(), WaypointNode::Id, LOG_DEBUG, Map::ScriptsStart(), sWaypointScripts, ObjectGuid::ToString(), Unit::ToTempSummon(), UNIT_STATE_ROAMING_MOVE, Creature::UpdateCurrentWaypointInfo(), UpdateHomePosition(), Creature::UpdateWaypointID(), urand(), and WAYPOINT_MOTION_TYPE.

◆ Resume()

void WaypointMovementGenerator< Creature >::Resume ( uint32  overrideTimer = 0)
overridevirtual

Reimplemented from MovementGenerator.

497{
499 _stalled = false;
500 if (overrideTimer)
501 _pauseTime = overrideTimer;
502}

◆ StartMove()

void WaypointMovementGenerator< Creature >::StartMove ( Creature creature,
bool  relaunch = false 
)
private

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

209{
210 // Formation checks. Do not launch a new spline when one of our formation members is currently in combat.
211 if (!relaunch)
212 {
213 if (!IsAllowedToMove(creature) || (creature->IsFormationLeader() && !creature->IsFormationLeaderMoveAllowed()))
214 {
215 _waypointDelay = 1000;
216 return;
217 }
218 }
219
220 // Dont allow dead creatures to move
221 if (!creature->IsAlive())
222 return;
223
224 // Step two: node selection is done, build spline data
226 WaypointNode const& waypoint = i_path->Nodes.at(i_currentNode);
227 bool const useTransportPath = creature->HasUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT) && creature->GetTransGUID();
228
229 Movement::MoveSplineInit init(creature);
231 if (useTransportPath)
232 init.DisableTransportPathTransformations();
233
234 if (waypoint.SmoothTransition && i_path->Nodes.size() > 2)
235 {
236 // Build a catmullrom spline segment, stopping at delay waypoints
237 init.Path().push_back(PositionToVector3(creature->GetPosition()));
238
239 bool hasDelayInSegment = false;
240 uint32 segmentNodes = 0;
241 for (uint32 i = 0; i < i_path->Nodes.size(); ++i)
242 {
243 uint32 idx = (i_currentNode + i) % i_path->Nodes.size();
244 WaypointNode const& node = i_path->Nodes.at(idx);
245 init.Path().push_back(G3D::Vector3(node.X, node.Y, node.Z));
246 segmentNodes++;
247
248 // Stop the segment at a waypoint with a delay
249 if (node.Delay > 0)
250 {
251 hasDelayInSegment = true;
252 break;
253 }
254 }
255
256 // If no delays found and repeating, add wrap-around points for seamless loop
257 if (!hasDelayInSegment && _repeating)
258 {
259 for (uint32 i = 0; i < std::min<uint32>(3, i_path->Nodes.size()); ++i)
260 {
261 uint32 idx = (i_currentNode + i) % i_path->Nodes.size();
262 WaypointNode const& node = i_path->Nodes.at(idx);
263 init.Path().push_back(G3D::Vector3(node.X, node.Y, node.Z));
264 }
265 }
266
267 // Need at least 3 waypoints for a meaningful catmullrom spline
268 if (segmentNodes >= 3)
269 {
270 init.SetFirstPointId(i_currentNode);
271 init.SetSmooth();
274 }
275 else
276 {
277 // Too few points for catmullrom, fall back to linear point-to-point
278 init.Path().clear();
279 init.MoveTo(G3D::Vector3(waypoint.X, waypoint.Y, waypoint.Z));
280 }
281 }
282 else if (!waypoint.SplinePoints.empty())
283 {
284 // We have spline points in waypoint_data_addon table
285 int32 splineIndex = 0;
286
287 auto itr = waypoint.SplinePoints.begin();
288 if (splineIndex)
289 std::advance(itr, splineIndex);
290
291 init.Path().reserve(waypoint.SplinePoints.size() - splineIndex);
292 std::copy(itr, waypoint.SplinePoints.end(), std::back_inserter(init.Path()));
293
294 // Add starting vertex and destination
295 init.Path().insert(init.Path().begin(), PositionToVector3(creature->GetPosition()));
296 init.Path().insert(init.Path().end(), G3D::Vector3(waypoint.X, waypoint.Y, waypoint.Z));
297 }
298 else
299 {
300 // Smooth transition for short paths (<=2 nodes): use previous spline endpoint as start
301 if (waypoint.SmoothTransition && !creature->movespline->Finalized() && _lastSplineId == creature->movespline->GetId())
302 {
303 init.MoveTo(creature->movespline->FinalDestination(), G3D::Vector3(waypoint.X, waypoint.Y, waypoint.Z));
304 if (!init.Path().empty())
305 init.Path().insert(init.Path().begin(), PositionToVector3(creature->GetPosition()));
306 }
307 else
308 init.MoveTo(PositionToVector3(creature->GetPosition()), G3D::Vector3(waypoint.X, waypoint.Y, waypoint.Z));
309 }
310
311 if (waypoint.Orientation.has_value() && waypoint.Delay > 0)
312 init.SetFacing(*waypoint.Orientation);
313
314 switch (waypoint.MoveType)
315 {
317 init.SetAnimation(AnimTier::Ground);
318 break;
320 init.SetAnimation(AnimTier::Hover);
321 break;
323 init.SetWalk(false);
324 break;
326 init.SetWalk(true);
327 break;
328 default:
329 break;
330 }
331
332 if (creature->CanFly())
333 init.SetFly();
334
335 if (waypoint.Velocity > 0.f)
336 init.SetVelocity(waypoint.Velocity);
337
338 init.Launch();
339
340 if (!creature->movespline->Finalized())
341 _lastSplineId = creature->movespline->GetId();
342
343 // Inform formation
344 creature->SignalFormationMovement();
345
346 // Inform AI
347 if (!relaunch)
348 if (CreatureAI* AI = creature->AI())
349 AI->WaypointStarted(waypoint.Id, i_path->Id);
350
351 _waypointReached = false;
352 _recalculateSpeed = false;
353 _hasBeenStalled = false;
354}
@ WAYPOINT_MOVE_TYPE_RUN
Definition WaypointDefines.h:29
@ WAYPOINT_MOVE_TYPE_LAND
Definition WaypointDefines.h:30
@ WAYPOINT_MOVE_TYPE_TAKEOFF
Definition WaypointDefines.h:31
@ WAYPOINT_MOVE_TYPE_WALK
Definition WaypointDefines.h:28
G3D::Vector3 PositionToVector3(Position const &p)
Definition WaypointMovementGenerator.cpp:33
bool CanFly() const override
Definition Creature.h:86
void SignalFormationMovement()
Definition Creature.cpp:399
bool IsFormationLeaderMoveAllowed() const
Definition Creature.cpp:410
bool IsFormationLeader() const
Definition Creature.cpp:391
Definition MoveSplineInit.h:63
Vector3 FinalDestination() const
Definition MoveSpline.h:122
std::vector< G3D::Vector3 > SplinePoints
Definition WaypointDefines.h:56
bool SmoothTransition
Definition WaypointDefines.h:55
float Velocity
Definition WaypointDefines.h:50
uint32 MoveType
Definition WaypointDefines.h:53

References Unit::AddUnitState(), Creature::AI(), Creature::CanFly(), WaypointNode::Delay, Movement::MoveSplineInit::DisableTransportPathTransformations(), Movement::MoveSpline::FinalDestination(), Movement::MoveSpline::Finalized(), Movement::MoveSpline::GetId(), Position::GetPosition(), Unit::GetTransGUID(), Ground, Unit::HasUnitMovementFlag(), Hover, WaypointNode::Id, Unit::IsAlive(), Creature::IsFormationLeader(), Creature::IsFormationLeaderMoveAllowed(), Movement::MoveSplineInit::Launch(), MOVEMENTFLAG_ONTRANSPORT, Unit::movespline, Movement::MoveSplineInit::MoveTo(), WaypointNode::MoveType, WaypointNode::Orientation, Movement::MoveSplineInit::Path(), PositionToVector3(), Movement::MoveSplineInit::SetAnimation(), Movement::MoveSplineInit::SetFacing(), Movement::MoveSplineInit::SetFirstPointId(), Movement::MoveSplineInit::SetFly(), Movement::MoveSplineInit::SetSmooth(), Movement::MoveSplineInit::SetVelocity(), Movement::MoveSplineInit::SetWalk(), Creature::SignalFormationMovement(), WaypointNode::SmoothTransition, WaypointNode::SplinePoints, UNIT_STATE_ROAMING_MOVE, WaypointNode::Velocity, WAYPOINT_MOVE_TYPE_LAND, WAYPOINT_MOVE_TYPE_RUN, WAYPOINT_MOVE_TYPE_TAKEOFF, WAYPOINT_MOVE_TYPE_WALK, WaypointNode::X, WaypointNode::Y, and WaypointNode::Z.

◆ unitSpeedChanged()

void WaypointMovementGenerator< Creature >::unitSpeedChanged ( )
inlineoverridevirtual

Reimplemented from MovementGenerator.

66{ _recalculateSpeed = true; }

◆ UpdateWaypointState()

void WaypointMovementGenerator< Creature >::UpdateWaypointState ( Creature creature,
WaypointNode const &  waypointNode 
)
private
534{
535 if (creature->movespline->GetId() != _lastSplineId)
536 return;
537
538 if (creature->movespline->Finalized())
539 ProcessWaypointArrival(creature, waypointNode);
540}
void ProcessWaypointArrival(Creature *, WaypointNode const &)
Definition WaypointMovementGenerator.cpp:135

References Movement::MoveSpline::Finalized(), Movement::MoveSpline::GetId(), and Unit::movespline.

Member Data Documentation

◆ _done

bool WaypointMovementGenerator< Creature >::_done
private

◆ _hasBeenStalled

bool WaypointMovementGenerator< Creature >::_hasBeenStalled
private

◆ _lastPassedSplineIdx

int32 WaypointMovementGenerator< Creature >::_lastPassedSplineIdx
private

◆ _lastSplineId

uint32 WaypointMovementGenerator< Creature >::_lastSplineId
private

◆ _loadedFromDB

bool WaypointMovementGenerator< Creature >::_loadedFromDB
private

◆ _pathId

◆ _pathSource

◆ _pauseTime

std::optional<int32> WaypointMovementGenerator< Creature >::_pauseTime
private

◆ _recalculateSpeed

bool WaypointMovementGenerator< Creature >::_recalculateSpeed
private

◆ _repeating

bool WaypointMovementGenerator< Creature >::_repeating
private

◆ _smoothSplineLaunched

bool WaypointMovementGenerator< Creature >::_smoothSplineLaunched
private

◆ _stalled

bool WaypointMovementGenerator< Creature >::_stalled
private

◆ _waypointDelay

int32 WaypointMovementGenerator< Creature >::_waypointDelay
private

◆ _waypointReached

bool WaypointMovementGenerator< Creature >::_waypointReached
private

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