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 >
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:738

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:145
@ SMART_WAYPOINT_MGR
#define sSmartWaypointMgr
Definition SmartScriptMgr.h:2282
#define sWaypointMgr
Definition WaypointMgr.h:54
Definition CreatureAI.h:69
uint32 GetWaypointPath() const
Definition Creature.h:357
void UpdateCurrentWaypointInfo(uint32 nodeId, uint32 pathId)
Definition Creature.h:365
CreatureData const * GetCreatureData() const
Definition Creature.h:208
CreatureAI * AI() const
Definition Creature.h:144
std::string ToString() const
Definition ObjectGuid.cpp:48
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:120
uint32 i_currentNode
Definition WaypointMovementGenerator.h:46
void AddUnitState(uint32 f)
Definition Unit.h:736
std::string const & GetName() const
Definition Object.h:535
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:1765
void StopMoving()
Definition Unit.cpp:12639

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

◆ DoUpdate()

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

510{
511 // prevent a crash at empty waypoint path.
512 if (!i_path || i_path->Nodes.empty())
513 return false;
514
515 // A finished non-repeating path no longer owns the creature's reset position.
516 if (_done)
517 return false;
518
519 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);
520 WaypointNode const& waypoint = i_path->Nodes.at(i_currentNode);
521
522 x = waypoint.X;
523 y = waypoint.Y;
524 z = waypoint.Z;
525 return true;
526}
#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
529{
530 if (_stalled || _done)
531 return false;
532
533 if (_pauseTime.has_value())
534 return false;
535
537 return false;
538
539 return true;
540}
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:225
bool IsMovementPreventedByCasting() const override
Definition Creature.cpp:3708
bool HasUnitState(const uint32 f) const
Definition Unit.h:737

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

◆ Pause()

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

Reimplemented from MovementGenerator.

495{
496 _stalled = timer ? false : true;
498 _pauseTime = timer;
499}

◆ 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:157
Definition TemporarySummon.h:50
Definition UnitAI.h:198
Definition Unit.h:665
TempSummon * ToTempSummon()
Definition Unit.h:732
Unit * GetCharmerOrOwner() const
Definition Unit.h:1291

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.

502{
504 _stalled = false;
505 if (overrideTimer)
506 _pauseTime = overrideTimer;
507}

◆ 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 float newZ = node.Z;
246 creature->UpdateAllowedPositionZ(node.X, node.Y, newZ);
247 init.Path().push_back(G3D::Vector3(node.X, node.Y, newZ));
248 segmentNodes++;
249
250 // Stop the segment at a waypoint with a delay
251 if (node.Delay > 0)
252 {
253 hasDelayInSegment = true;
254 break;
255 }
256 }
257
258 // If no delays found and repeating, add wrap-around points for seamless loop
259 if (!hasDelayInSegment && _repeating)
260 {
261 for (uint32 i = 0; i < std::min<uint32>(3, i_path->Nodes.size()); ++i)
262 {
263 uint32 idx = (i_currentNode + i) % i_path->Nodes.size();
264 WaypointNode const& node = i_path->Nodes.at(idx);
265 float newZ = node.Z;
266 creature->UpdateAllowedPositionZ(node.X, node.Y, newZ);
267 init.Path().push_back(G3D::Vector3(node.X, node.Y, newZ));
268 }
269 }
270
271 // Need at least 3 waypoints for a meaningful catmullrom spline
272 if (segmentNodes >= 3)
273 {
274 init.SetFirstPointId(i_currentNode);
275 init.SetSmooth();
278 }
279 else
280 {
281 // Too few points for catmullrom, fall back to linear point-to-point
282 init.Path().clear();
283 init.MoveTo(G3D::Vector3(waypoint.X, waypoint.Y, waypoint.Z));
284 }
285 }
286 else if (!waypoint.SplinePoints.empty())
287 {
288 // We have spline points in waypoint_data_addon table
289 int32 splineIndex = 0;
290
291 auto itr = waypoint.SplinePoints.begin();
292 if (splineIndex)
293 std::advance(itr, splineIndex);
294
295 init.Path().reserve(waypoint.SplinePoints.size() - splineIndex);
296 std::copy(itr, waypoint.SplinePoints.end(), std::back_inserter(init.Path()));
297
298 // Add starting vertex and destination
299 init.Path().insert(init.Path().begin(), PositionToVector3(creature->GetPosition()));
300 init.Path().insert(init.Path().end(), G3D::Vector3(waypoint.X, waypoint.Y, waypoint.Z));
301 }
302 else
303 {
304 // Smooth transition for short paths (<=2 nodes): use previous spline endpoint as start
305 if (waypoint.SmoothTransition && !creature->movespline->Finalized() && _lastSplineId == creature->movespline->GetId())
306 {
307 init.MoveTo(creature->movespline->FinalDestination(), G3D::Vector3(waypoint.X, waypoint.Y, waypoint.Z));
308 if (!init.Path().empty())
309 init.Path().insert(init.Path().begin(), PositionToVector3(creature->GetPosition()));
310 }
311 else
312 init.MoveTo(PositionToVector3(creature->GetPosition()), G3D::Vector3(waypoint.X, waypoint.Y, waypoint.Z));
313 }
314
315 if (waypoint.Orientation.has_value() && waypoint.Delay > 0)
316 init.SetFacing(*waypoint.Orientation);
317
318 switch (waypoint.MoveType)
319 {
321 init.SetAnimation(AnimTier::Ground);
322 break;
324 init.SetAnimation(AnimTier::Hover);
325 break;
327 init.SetWalk(false);
328 break;
330 init.SetWalk(true);
331 break;
332 default:
333 break;
334 }
335
336 if (creature->CanFly())
337 init.SetFly();
338
339 if (waypoint.Velocity > 0.f)
340 init.SetVelocity(waypoint.Velocity);
341
342 init.Launch();
343
344 if (!creature->movespline->Finalized())
345 _lastSplineId = creature->movespline->GetId();
346
347 // Inform formation
348 creature->SignalFormationMovement();
349
350 // Inform AI
351 if (!relaunch)
352 if (CreatureAI* AI = creature->AI())
353 AI->WaypointStarted(waypoint.Id, i_path->Id);
354
355 _waypointReached = false;
356 _recalculateSpeed = false;
357 _hasBeenStalled = false;
358}
@ 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:87
void SignalFormationMovement()
Definition Creature.cpp:404
bool IsFormationLeaderMoveAllowed() const
Definition Creature.cpp:415
bool IsFormationLeader() const
Definition Creature.cpp:396
Definition MoveSplineInit.h:63
Vector3 FinalDestination() const
Definition MoveSpline.h:122
void UpdateAllowedPositionZ(float x, float y, float &z, float *groundZ=nullptr) const
Definition Object.cpp:1619
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, WorldObject::UpdateAllowedPositionZ(), 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
543{
544 if (creature->movespline->GetId() != _lastSplineId)
545 return;
546
547 if (creature->movespline->Finalized())
548 ProcessWaypointArrival(creature, waypointNode);
549}
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: