34 : _nextMoveTime(0), _pathId(pathId), _repeating(repeating), _loadedFromDB(true),
35 _speed(speed), _speedSelectionMode(speedSelectionMode), _waitTimeRangeAtPathEnd(
std::move(waitTimeRangeAtPathEnd)),
36 _wanderDistanceAtPathEnds(wanderDistanceAtPathEnds), _followPathBackwardsFromEndToStart(followPathBackwardsFromEndToStart), _isReturningToStart(false),
37 _generatePath(generatePath)
44 _duration.emplace(*duration);
50 : _nextMoveTime(0), _pathId(0), _repeating(repeating), _loadedFromDB(false),
51 _speed(speed), _speedSelectionMode(speedSelectionMode), _waitTimeRangeAtPathEnd(
std::move(waitTimeRangeAtPathEnd)),
52 _wanderDistanceAtPathEnds(wanderDistanceAtPathEnds), _followPathBackwardsFromEndToStart(followPathBackwardsFromEndToStart), _isReturningToStart(false),
53 _generatePath(generatePath)
55 _path = std::make_unique<WaypointPath>(path);
62 _duration.emplace(*duration);
81 _nextMoveTime.Reset(timer);
87 _nextMoveTime.Reset(1);
95 _nextMoveTime.Reset(overrideTimer);
97 if (_nextMoveTime.Passed())
98 _nextMoveTime.Reset(1);
106 if (!GetPath() || GetPath()->
Nodes.empty())
109 ASSERT(_currentNode < GetPath()->
Nodes.size(),
"WaypointMovementGenerator::GetResetPosition: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, GetPath()->Id);
132 TC_LOG_ERROR(
"sql.sql",
"WaypointMovementGenerator::DoInitialize: couldn't load path for creature ({}) (_pathId: {})", owner->
GetGUID().
ToString(), _pathId);
136 if (GetPath()->
Nodes.size() == 1)
141 _nextMoveTime.Reset(1000);
151 _nextMoveTime.Reset(1);
156 if (!owner || !owner->
IsAlive())
164 _duration->Update(diff);
165 if (_duration->Passed())
194 StartMove(owner,
true);
210 StartMove(owner,
true);
212 else if (!_nextMoveTime.Passed())
214 if (UpdateTimer(diff))
223 StartMove(owner,
true);
238 if (_nextMoveTime.Passed())
269 AI->WaypointReached(
waypoint.Id, GetPath()->Id);
275 if (!GetPath() || GetPath()->
Nodes.empty())
278 ASSERT(_currentNode < GetPath()->
Nodes.size(),
"WaypointMovementGenerator::OnArrived: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, GetPath()->Id);
283 _nextMoveTime.Reset(
waypoint.Delay);
286 if (_waitTimeRangeAtPathEnd && IsFollowingPathBackwardsFromEndToStart()
287 && ((_isReturningToStart && _currentNode == 0) || (!_isReturningToStart && _currentNode == GetPath()->
Nodes.size() - 1)))
290 Milliseconds waitTime =
randtime(_waitTimeRangeAtPathEnd->first, _waitTimeRangeAtPathEnd->second);
292 _duration->Update(waitTime);
294 if (_wanderDistanceAtPathEnds)
297 _nextMoveTime.Reset(waitTime);
300 MovementInform(owner);
313 _nextMoveTime.Reset(1000);
321 if (ComputeNextNode())
323 ASSERT(_currentNode < GetPath()->
Nodes.size(),
"WaypointMovementGenerator::StartMove: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, GetPath()->Id);
327 AI->WaypointStarted(GetPath()->
Nodes[_currentNode].Id, GetPath()->Id);
343 o -= trans->GetTransportOrientation();
345 trans->CalculatePassengerPosition(x, y, z, &o);
355 AI->WaypointPathEnded(
waypoint.Id, GetPath()->Id);
365 AI->WaypointStarted(GetPath()->
Nodes[_currentNode].Id, GetPath()->Id);
368 ASSERT(_currentNode < GetPath()->
Nodes.size(),
"WaypointMovementGenerator::StartMove: tried to reference a node id (%u) which is not included in path (%u)", _currentNode, GetPath()->Id);
385 if (
waypoint.Orientation.has_value() && (
waypoint.Delay > 0 || _currentNode == GetPath()->
Nodes.size() - 1))
388 switch (GetPath()->MoveType)
406 switch (_speedSelectionMode)
431 if ((_currentNode == GetPath()->
Nodes.size() - 1) && !_repeating)
435 _currentNode = (_currentNode + 1) % GetPath()->Nodes.size();
438 if (!_isReturningToStart)
440 if (++_currentNode >= GetPath()->Nodes.size())
443 _isReturningToStart =
true;
448 if (_currentNode-- == 0)
451 _isReturningToStart =
false;
461 if (_followPathBackwardsFromEndToStart)
462 return *_followPathBackwardsFromEndToStart;
469 std::stringstream sstr;
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
std::string GetDebugInfo()
#define TC_LOG_ERROR(filterType__,...)
MovementWalkRunSpeedSelectionMode
@ MOVEMENTGENERATOR_FLAG_TIMED_PAUSED
@ MOVEMENTGENERATOR_FLAG_INITIALIZATION_PENDING
@ MOVEMENTGENERATOR_FLAG_PAUSED
@ MOVEMENTGENERATOR_FLAG_DEACTIVATED
@ MOVEMENTGENERATOR_FLAG_FINALIZED
@ MOVEMENTGENERATOR_FLAG_TRANSITORY
@ MOVEMENTGENERATOR_FLAG_INTERRUPTED
@ MOVEMENTGENERATOR_FLAG_INFORM_ENABLED
@ MOVEMENTGENERATOR_FLAG_INITIALIZED
@ MOVEMENTGENERATOR_FLAG_SPEED_UPDATE_PENDING
std::optional< T > Optional
Optional helper class to wrap optional values within.
Milliseconds randtime(Milliseconds min, Milliseconds max)
std::vector< Node const * > Nodes
@ UNIT_STATE_ROAMING_MOVE
@ UNIT_STATE_LOST_CONTROL
#define WAYPOINT_PATH_FLAG_FOLLOW_PATH_BACKWARDS_MINIMUM_NODES
@ FollowPathBackwardsFromEndToStart
static float waypoint[6][3]
void SetHomePosition(float x, float y, float z, float o)
void SignalFormationMovement()
bool IsFormationLeaderMoveAllowed() const
void UpdateCurrentWaypointInfo(uint32 nodeId, uint32 pathId)
uint32 GetWaypointPathId() const
bool IsFormationLeader() const
void SetTransportHomePosition(float x, float y, float z, float o)
bool IsMovementPreventedByCasting() const override
void MoveRandom(float wanderDistance=0.0f, Optional< Milliseconds > duration={}, MovementSlot slot=MOTION_SLOT_DEFAULT)
virtual std::string GetDebugInfo() const
void MoveTo(Vector3 const &destination, bool generatePath=true, bool forceDestination=false)
void DisableTransportPathTransformations()
void SetWalk(bool enable)
void SetVelocity(float velocity)
void SetFacing(float angle)
void SetAnimation(AnimTier anim, uint32 tierTransitionId=0, Milliseconds transitionStartTime=0ms)
std::string ToString() const
static ObjectGuid GetGUID(Object const *o)
virtual std::string GetDebugInfo() const
void ClearUnitState(uint32 f)
MotionMaster * GetMotionMaster()
void AddUnitState(uint32 f)
bool SetWalk(bool enable)
ObjectGuid GetTransGUID() const override
bool HasUnitState(const uint32 f) const
std::unique_ptr< Movement::MoveSpline > movespline
TransportBase * GetTransport() const
constexpr void GetPosition(float &x, float &y) const
constexpr float GetOrientation() const