AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ChaseMovementGenerator< T > Class Template Reference

#include "TargetedMovementGenerator.h"

Inheritance diagram for ChaseMovementGenerator< T >:
MovementGeneratorMedium< T, ChaseMovementGenerator< T > > AbstractFollower MovementGenerator

Public Member Functions

 ChaseMovementGenerator (Unit *target, Optional< ChaseRange > range={}, Optional< ChaseAngle > angle={})
 
 ~ChaseMovementGenerator ()
 
MovementGeneratorType GetMovementGeneratorType ()
 
bool DoUpdate (T *, uint32)
 
void DoInitialize (T *)
 
void DoFinalize (T *)
 
void DoReset (T *)
 
void MovementInform (T *)
 
bool PositionOkay (T *owner, Unit *target, Optional< float > maxDistance, Optional< ChaseAngle > angle)
 
void unitSpeedChanged ()
 
Unit * GetTarget () const
 
bool EnableWalking () const
 
bool HasLostTarget (Unit *unit) const
 
void SetOffsetAndAngle (std::optional< ChaseRange > dist, std::optional< ChaseAngle > angle)
 
void SetNewTarget (Unit *target)
 
void DistanceYourself (T *owner, float distance)
 
bool DispatchSplineToPosition (T *owner, float x, float y, float z, bool walk, bool cutPath, float maxTarget, bool forceDest, bool target=false)
 
void DoInitialize (Player *owner)
 
void DoInitialize (Creature *owner)
 
- Public Member Functions inherited from MovementGeneratorMedium< T, ChaseMovementGenerator< T > >
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
 
virtual void Pause (uint32)
 
virtual void Resume (uint32)
 
virtual bool GetResetPosition (float &, float &, float &)
 
- Public Member Functions inherited from AbstractFollower
 AbstractFollower (Unit *target=nullptr)
 
virtual ~AbstractFollower ()
 
void SetTarget (Unit *unit)
 
Unit * GetTarget () const
 

Private Attributes

TimeTrackerSmall i_leashExtensionTimer
 
std::unique_ptr< PathGenerator > i_path
 
TimeTrackerSmall i_recheckDistance
 
bool i_recalculateTravel
 
Optional< Position > _lastTargetPosition
 
Optional< ChaseRange > _range
 
Optional< ChaseAngle > _angle
 
bool _movingTowards = true
 
bool _mutualChase = true
 
bool _fallbackPositioning = false
 
ChaseMovementMode m_currentMode
 

Detailed Description

template<class T>
class ChaseMovementGenerator< T >

Constructor & Destructor Documentation

◆ ChaseMovementGenerator()

template<class T >
ChaseMovementGenerator< T >::ChaseMovementGenerator ( Unit *  target,
Optional< ChaseRange >  range = {},
Optional< ChaseAngle >  angle = {} 
)
inline
40 {}, Optional<ChaseAngle> angle = {})
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
@ CHASE_MODE_NORMAL
Definition TargetedMovementGenerator.h:30
Definition AbstractFollower.h:24
ChaseMovementMode m_currentMode
Definition TargetedMovementGenerator.h:78
Optional< ChaseAngle > _angle
Definition TargetedMovementGenerator.h:73
std::unique_ptr< PathGenerator > i_path
Definition TargetedMovementGenerator.h:67
Optional< ChaseRange > _range
Definition TargetedMovementGenerator.h:72
bool _fallbackPositioning
Definition TargetedMovementGenerator.h:76
bool i_recalculateTravel
Definition TargetedMovementGenerator.h:69
TimeTrackerSmall i_recheckDistance
Definition TargetedMovementGenerator.h:68
TimeTrackerSmall i_leashExtensionTimer
Definition TargetedMovementGenerator.h:66

◆ ~ChaseMovementGenerator()

template<class T >
ChaseMovementGenerator< T >::~ChaseMovementGenerator ( )
inline
42{ }

Member Function Documentation

◆ DispatchSplineToPosition()

template<class T >
bool ChaseMovementGenerator< T >::DispatchSplineToPosition ( T *  owner,
float  x,
float  y,
float  z,
bool  walk,
bool  cutPath,
float  maxTarget,
bool  forceDest,
bool  target = false 
)
103{
104 Creature* cOwner = owner->ToCreature();
105 G3D::Vector3 const targetPos = GetTarget()->GetPosition();
106
107 if (owner->IsHovering())
108 owner->UpdateAllowedPositionZ(x, y, z);
109
110 auto isPathUsable = [&]()
111 {
112 uint32 pathType = i_path->GetPathType();
113 if (pathType & PATHFIND_NOPATH)
114 return false;
115
116 // For pets, treat incomplete paths as failures to avoid clipping through geometry
117 // Players and Player-controlled units have more erratic movement, skip failure
118 if (cOwner && (cOwner->IsPet() || cOwner->IsControlledByPlayer())
120 if (pathType & PATHFIND_INCOMPLETE)
121 return false;
122
123 return true;
124 };
125
126 bool pathFailed = !i_path->CalculatePath(x, y, z, forceDest) || !isPathUsable();
127 bool usedFallback = false;
128
129 // Targets with an oversized combat reach can stand entirely over unwalkable space
130 // (e.g. Kologarn) so pathing to their center or to an angled near point (pets chase
131 // to behind the target, which may hang over the void) fails even though the melee
132 // ring covers the navmesh. Retry against the nearest point on the ring, ignoring the
133 // chase angle, via GetNearPoint2D: GetNearPoint's LoS repositioning must be avoided
134 // here, it can rotate the point to the far side of the target.
135 if (pathFailed && (!_range || _range->MaxRange <= CONTACT_DISTANCE)
136 && !GetTarget()->IsCharmedOwnedByPlayerOrPlayer() && GetTarget()->GetCombatReach() > NOMINAL_MELEE_RANGE)
137 {
138 GetTarget()->GetNearPoint2D(owner, x, y, 0.0f, GetTarget()->GetAngle(owner));
139 z = targetPos.z;
140 owner->UpdateAllowedPositionZ(x, y, z);
141 if (std::abs(z - targetPos.z) < maxTarget)
142 {
143 pathFailed = !i_path->CalculatePath(x, y, z, forceDest) || !isPathUsable();
144 // the destination already lies on the melee ring, nothing to cut
145 cutPath = false;
146
147 if (!pathFailed)
148 usedFallback = true;
149 }
150
151 if (pathFailed)
152 {
153 // If the nearest point on the melee ring is also unpathable (e.g. Brain of Yogg-Saron
154 // where the 30yd combat reach extends beyond the room's walls into geometry, but the
155 // floor directly underneath the target is walkable), fall back to pathing directly
156 // toward the target's ground position and cut the path once within combat range.
157 float groundZ = targetPos.z;
158 owner->UpdateAllowedPositionZ(targetPos.x, targetPos.y, groundZ);
159 if (std::abs(groundZ - targetPos.z) < maxTarget)
160 {
161 x = targetPos.x;
162 y = targetPos.y;
163 z = groundZ;
164 pathFailed = !i_path->CalculatePath(x, y, z, forceDest) || !isPathUsable();
165 cutPath = true;
166 if (!pathFailed)
167 usedFallback = true;
168 }
169 }
170 }
171
172 if (pathFailed)
173 {
174 _fallbackPositioning = false;
175 if (cOwner)
176 {
177 cOwner->SetCannotReachTarget(GetTarget()->GetGUID());
178
179 if (cOwner->IsPet() || cOwner->IsControlledByPlayer())
180 cOwner->AttackStop();
181 }
182
183 owner->StopMoving();
184 return false;
185 }
186
187 _fallbackPositioning = usedFallback;
188
189 if (cutPath)
190 i_path->ShortenPathUntilDist(targetPos, maxTarget);
191
192 if (cOwner)
193 {
194 cOwner->SetCannotReachTarget();
195 }
196
197 owner->AddUnitState(UNIT_STATE_CHASE_MOVE);
198 i_recalculateTravel = true;
199
200 Movement::MoveSplineInit init(owner);
201 init.MovebyPath(i_path->GetPath());
202 if (target)
203 init.SetFacing(GetTarget());
204 init.SetWalk(walk);
205 init.Launch();
206
207 return true;
208}
std::uint32_t uint32
Definition Define.h:107
#define CONTACT_DISTANCE
Definition ObjectDefines.h:23
#define NOMINAL_MELEE_RANGE
Definition ObjectDefines.h:47
@ PATHFIND_NOPATH
Definition PathGenerator.h:50
@ PATHFIND_INCOMPLETE
Definition PathGenerator.h:49
@ UNIT_STATE_CHASE_MOVE
Definition UnitDefines.h:198
Unit * GetTarget() const
Definition TargetedMovementGenerator.h:55
Definition Creature.h:47
void SetCannotReachTarget(ObjectGuid const &target=ObjectGuid::Empty)
Definition Creature.cpp:3730
Definition MoveSplineInit.h:63
Creature * ToCreature()
Definition Object.h:212
bool IsPet() const
Definition Unit.h:798
bool IsCharmedOwnedByPlayerOrPlayer() const
Definition Unit.h:1314
bool IsControlledByPlayer() const
Definition Unit.h:1312
bool AttackStop()
Force the unit to stop attacking. This will clear UNIT_STATE_MELEE_ATTACKING, Interrupt current spell...
Definition Unit.cpp:7240
void GetNearPoint2D(WorldObject const *searcher, float &x, float &y, float distance, float absAngle, Position const *startPos=nullptr) const
Definition Object.cpp:2715
void GetPosition(float &x, float &y) const
Definition Position.h:126

References Unit::AttackStop(), CONTACT_DISTANCE, Position::GetPosition(), Unit::IsCharmedOwnedByPlayerOrPlayer(), Unit::IsControlledByPlayer(), Unit::IsPet(), Movement::MoveSplineInit::Launch(), Movement::MoveSplineInit::MovebyPath(), NOMINAL_MELEE_RANGE, PATHFIND_INCOMPLETE, PATHFIND_NOPATH, Creature::SetCannotReachTarget(), Movement::MoveSplineInit::SetFacing(), Movement::MoveSplineInit::SetWalk(), Object::ToCreature(), and UNIT_STATE_CHASE_MOVE.

◆ DistanceYourself()

template<class T >
template void ChaseMovementGenerator< T >::DistanceYourself ( T *  owner,
float  distance 
)
84{
85 // make a new path if we have to...
86 if (!i_path)
87 i_path = std::make_unique<PathGenerator>(owner);
88
89 float x, y, z;
90 GetTarget()->GetNearPoint(owner, x, y, z, owner->GetBoundaryRadius(), distance, GetTarget()->GetAngle(owner));
91 if (DispatchSplineToPosition(owner, x, y, z, false, false, 0.f, false, false))
92 {
94 if constexpr (!std::is_same_v<T, Player>)
95 {
96 owner->AI()->DistancingStarted();
97 }
98 }
99}
@ CHASE_MODE_DISTANCING
Definition TargetedMovementGenerator.h:32
bool DispatchSplineToPosition(T *owner, float x, float y, float z, bool walk, bool cutPath, float maxTarget, bool forceDest, bool target=false)
Definition TargetedMovementGenerator.cpp:102
void GetNearPoint(WorldObject const *searcher, float &x, float &y, float &z, float searcher_size, float distance2d, float absAngle, float controlZ=0, Position const *startPos=nullptr) const
Definition Object.cpp:2752

References CHASE_MODE_DISTANCING.

Referenced by MotionMaster::DistanceYourself().

◆ DoFinalize()

template<class T >
template void ChaseMovementGenerator< T >::DoFinalize ( T *  )
435{
436 owner->ClearUnitState(UNIT_STATE_CHASE | UNIT_STATE_CHASE_MOVE);
437 if (Creature* cOwner = owner->ToCreature())
438 {
439 cOwner->SetCannotReachTarget();
440 }
441}
@ UNIT_STATE_CHASE
Definition UnitDefines.h:178

References Object::ToCreature(), UNIT_STATE_CHASE, and UNIT_STATE_CHASE_MOVE.

◆ DoInitialize() [1/3]

void ChaseMovementGenerator< Creature >::DoInitialize ( Creature *  owner)
424{
425 i_path = nullptr;
426 _lastTargetPosition.reset();
427 _fallbackPositioning = false;
431}
@ BASE_ATTACK
Definition Unit.h:216
Optional< Position > _lastTargetPosition
Definition TargetedMovementGenerator.h:71
void AddUnitState(uint32 f)
Definition Unit.h:736
uint32 GetAttackTime(WeaponAttackType att) const
Definition Unit.h:915
void Reset(int32 interval)
Definition Timer.h:249

References Unit::AddUnitState(), BASE_ATTACK, Unit::GetAttackTime(), and UNIT_STATE_CHASE.

◆ DoInitialize() [2/3]

void ChaseMovementGenerator< Player >::DoInitialize ( Player *  owner)
414{
415 i_path = nullptr;
416 _lastTargetPosition.reset();
417 _fallbackPositioning = false;
418 owner->StopMoving();
420}
void StopMoving()
Definition Unit.cpp:12639

References Unit::AddUnitState(), Unit::StopMoving(), and UNIT_STATE_CHASE.

◆ DoInitialize() [3/3]

template<class T >
void ChaseMovementGenerator< T >::DoInitialize ( T *  )

◆ DoReset()

template<class T >
template void ChaseMovementGenerator< T >::DoReset ( T *  )
445{
446 DoInitialize(owner);
447}

◆ DoUpdate()

template<class T >
template bool ChaseMovementGenerator< T >::DoUpdate ( T *  ,
uint32   
)
212{
213 if (!GetTarget() || !GetTarget()->IsInWorld() || !owner->IsInMap(GetTarget()))
214 return false;
215
216 if (!owner || !owner->IsAlive())
217 return false;
218
219 if (owner->HasUnitState(UNIT_STATE_NO_COMBAT_MOVEMENT)) // script paused combat movement
220 {
221 owner->StopMoving();
222 _lastTargetPosition.reset();
223 return true;
224 }
225
226 Creature* cOwner = owner->ToCreature();
227 bool isStoppedBecauseOfCasting = cOwner && cOwner->IsMovementPreventedByCasting();
228
229 // the owner might be unable to move (rooted or casting), or we have lost the target, pause movement
230 if (owner->HasUnitState(UNIT_STATE_NOT_MOVE) || HasLostTarget(owner) || isStoppedBecauseOfCasting)
231 {
232 // Every time a caster mob stops to cast a spell, the leash timer ticks down. Once the timer expires, the mob evades and walks home.
233 owner->StopMoving();
234 _lastTargetPosition.reset();
235
236 if (cOwner)
237 cOwner->SetCannotReachTarget();
238
239 return true;
240 }
241
242 bool forceDest =
243 //(cOwner && (cOwner->isWorldBoss() || cOwner->IsDungeonBoss())) || // force for all bosses, even not in instances
244 (GetTarget()->IsPlayer() && GetTarget()->ToPlayer()->IsGameMaster()) || // for .npc follow
245 (owner->CanFly())
246 ; // closes "bool forceDest", that way it is more appropriate, so we can comment out crap whenever we need to
247
248 Unit* target = GetTarget();
249
250 bool mutualChase = IsMutualChase(owner, target);
251 bool const mutualTarget = target->GetVictim() == owner;
252 float const chaseRange = GetChaseRange(owner, target);
253 float const meleeRange = owner->GetMeleeRange(target);
254 float const minTarget = (_range ? _range->MinTolerance : 0.0f) + chaseRange;
255 float const maxRange = _range ? _range->MaxRange + chaseRange : meleeRange; // melee range already includes hitboxes
256 float const maxTarget = _range ? _range->MaxTolerance + chaseRange : CONTACT_DISTANCE + chaseRange;
257
259
260 // Prevent almost infinite spinning of mutual targets.
261 if (angle && !mutualChase && _mutualChase && mutualTarget && chaseRange < meleeRange)
262 {
263 angle = Optional<ChaseAngle>();
264 mutualChase = true;
265 }
266
267 // Prevent almost infinite spinning for pets with mutualTarget
268 // _mutualChase is false for previous check
269 if (angle && !mutualChase && !_mutualChase && mutualTarget && chaseRange < meleeRange && cOwner && cOwner->IsPet())
270 {
271 angle = Optional<ChaseAngle>();
272 mutualChase = true;
273 }
274
275 // periodically check if we're already in the expected range...
276 i_recheckDistance.Update(time_diff);
278 {
279 i_recheckDistance.Reset(400); // Sniffed value
280
282 {
283 if (i_recalculateTravel && PositionOkay(owner, target, _movingTowards ? maxTarget : Optional<float>(), angle))
284 {
285 if ((owner->HasUnitState(UNIT_STATE_CHASE_MOVE) && !target->isMoving() && !mutualChase) || _range)
286 {
287 i_recalculateTravel = false;
288 i_path = nullptr;
289 if (cOwner)
290 cOwner->SetCannotReachTarget();
291 owner->StopMoving();
292 owner->SetInFront(target);
293 MovementInform(owner);
294 return true;
295 }
296 }
297 }
298 }
299
300 // if we're done moving, we want to clean up
301 if (owner->HasUnitState(UNIT_STATE_CHASE_MOVE) && owner->movespline->Finalized())
302 {
303 i_recalculateTravel = false;
304 i_path = nullptr;
305 owner->ClearUnitState(UNIT_STATE_CHASE_MOVE);
306 owner->SetInFront(target);
307
308 if (cOwner)
309 cOwner->SetCannotReachTarget();
310
311 MovementInform(owner);
312 }
313
314 if (cOwner)
315 {
318 }
319
321 return true;
322
323 // if the target moved, we have to consider whether to adjust
324 if (!_lastTargetPosition || target->GetPosition() != _lastTargetPosition.value() || mutualChase != _mutualChase || !owner->IsWithinLOSInMap(target))
325 {
327 _mutualChase = mutualChase;
328 _fallbackPositioning = false;
329 angle = mutualChase ? Optional<ChaseAngle>() : _angle;
330 if (owner->HasUnitState(UNIT_STATE_CHASE_MOVE) || !PositionOkay(owner, target, maxTarget, angle))
331 {
332 // can we get to the target?
333 if (cOwner && !target->isInAccessiblePlaceFor(cOwner))
334 {
335 cOwner->SetCannotReachTarget(target->GetGUID());
336 cOwner->StopMoving();
337 i_path = nullptr;
338 return true;
339 }
340
341 // figure out which way we want to move
342 float x, y, z;
343 target->GetPosition(x, y, z);
344 bool withinRange = owner->IsInDist(target, maxRange);
345 bool withinLOS = owner->IsWithinLOS(x, y, z);
346 bool moveToward = !(withinRange && withinLOS);
347
348 // make a new path if we have to...
349 if (!i_path || moveToward != _movingTowards)
350 i_path = std::make_unique<PathGenerator>(owner);
351 else
352 i_path->Clear();
353
354 // Predict chase destination to keep up with chase target
355 float additionalRange = 0;
356 bool predictDestination = !mutualChase && target->isMoving();
357 if (predictDestination)
358 {
359 UnitMoveType moveType = MOVE_RUN;
360 if (target->CanFly())
362 else
363 {
364 if (target->IsWalking())
365 moveType = MOVE_WALK;
366 else
368 }
369 float speed = target->GetSpeed(moveType) * 0.5f;
370 additionalRange = owner->GetExactDistSq(target) < G3D::square(speed) ? 0 : speed;
371 }
372
373 bool shortenPath;
374
375 // if we want to move toward the target and there's no fixed angle...
376 if (moveToward && !angle)
377 {
378 // ...we'll pathfind to the center, then shorten the path
379 shortenPath = true;
380 }
381 else
382 {
383 // otherwise, we fall back to nearpoint finding
384 target->GetNearPoint(owner, x, y, z, (moveToward ? maxTarget : minTarget) - chaseRange - additionalRange, 0, angle ? target->ToAbsoluteAngle(angle->RelativeAngle) : target->GetAngle(owner));
385 shortenPath = false;
386 }
387
388 bool walk = false;
389 if (cOwner && !cOwner->IsPet())
390 {
391 switch (cOwner->GetMovementTemplate().GetChase())
392 {
394 walk = owner->IsWalking();
395 break;
397 walk = true;
398 break;
399 default:
400 break;
401 }
402 }
403
404 DispatchSplineToPosition(owner, x, y, z, walk, shortenPath, maxTarget, forceDest, true);
405 }
406 }
407
408 return true;
409}
float GetChaseRange(Unit const *owner, Unit const *target)
Definition TargetedMovementGenerator.cpp:35
static bool IsMutualChase(Unit *owner, Unit *target)
Definition TargetedMovementGenerator.cpp:27
@ MOVEMENTFLAG_BACKWARD
Definition UnitDefines.h:373
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:225
@ UNIT_STATE_NO_COMBAT_MOVEMENT
Definition UnitDefines.h:204
UnitMoveType
Definition UnitDefines.h:355
@ MOVE_FLIGHT
Definition UnitDefines.h:362
@ MOVE_FLIGHT_BACK
Definition UnitDefines.h:363
@ MOVE_RUN
Definition UnitDefines.h:357
@ MOVE_RUN_BACK
Definition UnitDefines.h:358
@ MOVE_WALK
Definition UnitDefines.h:356
bool _mutualChase
Definition TargetedMovementGenerator.h:75
bool PositionOkay(T *owner, Unit *target, Optional< float > maxDistance, Optional< ChaseAngle > angle)
Definition TargetedMovementGenerator.cpp:47
void MovementInform(T *)
Definition TargetedMovementGenerator.cpp:450
bool HasLostTarget(Unit *unit) const
Definition TargetedMovementGenerator.h:58
bool _movingTowards
Definition TargetedMovementGenerator.h:74
CreatureMovementData const & GetMovementTemplate() const
Definition Creature.cpp:3148
bool IsMovementPreventedByCasting() const override
Definition Creature.cpp:3708
bool IsPlayer() const
Definition Object.h:207
Player * ToPlayer()
Definition Object.h:208
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:120
bool IsGameMaster() const
Definition Player.h:1178
Definition Unit.h:665
float GetSpeed(UnitMoveType mtype) const
Definition Unit.cpp:11047
virtual bool CanFly() const =0
bool isInAccessiblePlaceFor(Creature const *c) const
Definition Unit.cpp:4140
bool HasUnitMovementFlag(uint32 f) const
Definition Unit.h:775
bool isMoving() const
Definition Unit.h:1715
Unit * GetVictim() const
Definition Unit.h:904
bool IsWalking() const
Definition Unit.h:1714
bool IsInMap(WorldObject const *obj) const
Definition Object.cpp:1344
CreatureChaseMovementType GetChase() const
Definition CreatureData.h:151
void Update(int32 diff)
Definition Timer.h:239
bool Passed() const
Definition Timer.h:244

References AlwaysWalk, BASE_ATTACK, Unit::CanFly(), CanWalk, CHASE_MODE_DISTANCING, CONTACT_DISTANCE, Position::GetAngle(), Unit::GetAttackTime(), CreatureMovementData::GetChase(), GetChaseRange(), Object::GetGUID(), Creature::GetMovementTemplate(), WorldObject::GetNearPoint(), Position::GetPosition(), Unit::GetSpeed(), Unit::GetVictim(), Unit::HasUnitMovementFlag(), Unit::isInAccessiblePlaceFor(), Creature::IsMovementPreventedByCasting(), Unit::isMoving(), IsMutualChase(), Unit::IsPet(), Unit::IsWalking(), MOVE_FLIGHT, MOVE_FLIGHT_BACK, MOVE_RUN, MOVE_RUN_BACK, MOVE_WALK, MOVEMENTFLAG_BACKWARD, Creature::SetCannotReachTarget(), Unit::StopMoving(), Position::ToAbsoluteAngle(), Object::ToCreature(), UNIT_STATE_CHASE_MOVE, UNIT_STATE_NO_COMBAT_MOVEMENT, and UNIT_STATE_NOT_MOVE.

◆ EnableWalking()

template<class T >
bool ChaseMovementGenerator< T >::EnableWalking ( ) const
inline
57{ return false; }

◆ GetMovementGeneratorType()

template<class T >
MovementGeneratorType ChaseMovementGenerator< T >::GetMovementGeneratorType ( )
inlinevirtual

Implements MovementGenerator.

44{ return CHASE_MOTION_TYPE; }
@ CHASE_MOTION_TYPE
Definition MotionMaster.h:45

References CHASE_MOTION_TYPE.

◆ GetTarget()

template<class T >
Unit * ChaseMovementGenerator< T >::GetTarget ( ) const
inline
Unit * GetTarget() const
Definition AbstractFollower.h:30

References AbstractFollower::GetTarget().

Referenced by ChaseMovementGenerator< T >::HasLostTarget().

◆ HasLostTarget()

template<class T >
bool ChaseMovementGenerator< T >::HasLostTarget ( Unit *  unit) const
inline
58{ return unit->GetVictim() != this->GetTarget(); }

References ChaseMovementGenerator< T >::GetTarget(), and Unit::GetVictim().

◆ MovementInform()

template<class T >
template void ChaseMovementGenerator< T >::MovementInform ( T *  )
451{
452 if (!owner->IsCreature())
453 return;
454
455 switch (m_currentMode)
456 {
457 default:
458 {
459 // Pass back the GUIDLow of the target. If it is pet's owner then PetAI will handle
460 if (CreatureAI* AI = owner->ToCreature()->AI())
461 AI->MovementInform(CHASE_MOTION_TYPE, GetTarget()->GetGUID().GetCounter());
462 break;
463 }
465 {
466 if (CreatureAI* AI = owner->ToCreature()->AI())
467 AI->DistancingEnded();
468 break;
469 }
470 }
471
473}
Definition CreatureAI.h:69

References CHASE_MODE_DISTANCING, CHASE_MODE_NORMAL, and CHASE_MOTION_TYPE.

◆ PositionOkay()

template<class T >
bool ChaseMovementGenerator< T >::PositionOkay ( T *  owner,
Unit *  target,
Optional< float >  maxDistance,
Optional< ChaseAngle >  angle 
)
48{
49 float const distSq = owner->GetExactDistSq(target);
50
51 // Distance between owner(chaser) and target is greater than the allowed distance.
52 if (maxDistance && distSq > G3D::square(*maxDistance))
53 return false;
54
55 // owner's relative angle to its target is not within boundaries
56 if (angle && !angle->IsAngleOkay(target->GetRelativeAngle(owner)))
57 return false;
58
59 // owner cannot see its target
60 if (!owner->IsWithinLOSInMap(target))
61 return false;
62 return true;
63}
float GetRelativeAngle(Position const *pos) const
Definition Position.h:201

References Position::GetRelativeAngle().

◆ SetNewTarget()

template<class T >
template void ChaseMovementGenerator< T >::SetNewTarget ( Unit *  target)
76{
77 SetTarget(target);
79 _lastTargetPosition.reset();
80}
void SetTarget(Unit *unit)
Definition AbstractFollower.cpp:21

Referenced by MotionMaster::MoveChase().

◆ SetOffsetAndAngle()

template<class T >
template void ChaseMovementGenerator< T >::SetOffsetAndAngle ( std::optional< ChaseRange >  dist,
std::optional< ChaseAngle >  angle 
)
67{
68 _range = dist;
69 _angle = angle;
71 _lastTargetPosition.reset();
72}

Referenced by MotionMaster::MoveChase().

◆ unitSpeedChanged()

template<class T >
void ChaseMovementGenerator< T >::unitSpeedChanged ( )
inlinevirtual

Member Data Documentation

◆ _angle

template<class T >
Optional<ChaseAngle> ChaseMovementGenerator< T >::_angle
private

◆ _fallbackPositioning

template<class T >
bool ChaseMovementGenerator< T >::_fallbackPositioning = false
private

◆ _lastTargetPosition

template<class T >
Optional<Position> ChaseMovementGenerator< T >::_lastTargetPosition
private

◆ _movingTowards

template<class T >
bool ChaseMovementGenerator< T >::_movingTowards = true
private

◆ _mutualChase

template<class T >
bool ChaseMovementGenerator< T >::_mutualChase = true
private

◆ _range

template<class T >
Optional<ChaseRange> ChaseMovementGenerator< T >::_range
private

◆ i_leashExtensionTimer

template<class T >
TimeTrackerSmall ChaseMovementGenerator< T >::i_leashExtensionTimer
private

◆ i_path

template<class T >
std::unique_ptr<PathGenerator> ChaseMovementGenerator< T >::i_path
private

◆ i_recalculateTravel

template<class T >
bool ChaseMovementGenerator< T >::i_recalculateTravel
private

◆ i_recheckDistance

template<class T >
TimeTrackerSmall ChaseMovementGenerator< T >::i_recheckDistance
private

◆ m_currentMode

template<class T >
ChaseMovementMode ChaseMovementGenerator< T >::m_currentMode
private

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