AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
TargetedMovementGenerator.cpp File Reference
#include "TargetedMovementGenerator.h"
#include "Creature.h"
#include "CreatureAI.h"
#include "MoveSplineInit.h"
#include "Pet.h"
#include "Player.h"
#include "Spell.h"
#include "Transport.h"

Go to the source code of this file.

Functions

static bool IsMutualChase (Unit *owner, Unit *target)
 
float GetChaseRange (Unit const *owner, Unit const *target)
 
static float GetTargetSpeedInMotion (Unit *target)
 
static Optional< float > GetVelocity (Unit *owner, Unit *target, G3D::Vector3 const &dest, bool playerPet)
 
static Position const PredictPosition (Unit *target)
 
static bool IsValidPredictedPosition (Unit *target, Position const &predicted)
 

Function Documentation

◆ GetChaseRange()

float GetChaseRange ( Unit const *  owner,
Unit const *  target 
)
inline
36{
37 float hitboxSum = owner->GetCombatReach() + target->GetCombatReach();
38
39 float hoverDelta = owner->GetHoverHeight() - target->GetHoverHeight();
40 if (hoverDelta != 0.0f)
41 return std::sqrt(std::max(hitboxSum * hitboxSum - hoverDelta * hoverDelta, 0.0f));
42
43 return hitboxSum;
44}

References Unit::GetCombatReach(), and Unit::GetHoverHeight().

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

◆ GetTargetSpeedInMotion()

static float GetTargetSpeedInMotion ( Unit target)
static
436{
437 if (!target->movespline->Finalized())
438 return target->movespline->Velocity();
439
440 return target->GetSpeed(target->m_movementInfo.GetSpeedType());
441}
float Velocity() const
Definition MoveSpline.h:89
bool Finalized() const
Definition MoveSpline.h:118
Movement::MoveSpline * movespline
Definition Unit.h:2114
float GetSpeed(UnitMoveType mtype) const
Definition Unit.cpp:11265
MovementInfo m_movementInfo
Definition Object.h:698
UnitMoveType GetSpeedType() const
Definition Object.h:348

References Movement::MoveSpline::Finalized(), Unit::GetSpeed(), MovementInfo::GetSpeedType(), WorldObject::m_movementInfo, Unit::movespline, and Movement::MoveSpline::Velocity().

Referenced by GetVelocity().

◆ GetVelocity()

static Optional< float > GetVelocity ( Unit owner,
Unit target,
G3D::Vector3 const &  dest,
bool  playerPet 
)
static
444{
445 Optional<float> speed = {};
446 if (owner->IsInCombat() || owner->IsVehicle() || owner->HasUnitFlag(UNIT_FLAG_POSSESSED))
447 return speed;
448
449 bool isPetLike = owner->IsPet() || owner->IsGuardian() || owner->GetGUID() == target->GetCritterGUID() || owner->GetCharmerOrOwnerGUID() == target->GetGUID();
450
451 // For pets/guardians/critters or creature-to-creature follow: sync with target's speed
452 if (isPetLike || (owner->IsCreature() && target->IsCreature()))
453 {
454 speed = GetTargetSpeedInMotion(target);
455
456 if (playerPet)
457 {
458 float distance = owner->GetDistance2d(dest.x, dest.y) - target->GetObjectSize() - (*speed / 2.f);
459 if (distance > 0.f)
460 {
461 float multiplier = 1.f + (distance / 10.f);
462 *speed *= multiplier;
463 }
464 }
465 }
466
467 return speed;
468}
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
static float GetTargetSpeedInMotion(Unit *target)
Definition TargetedMovementGenerator.cpp:435
@ UNIT_FLAG_POSSESSED
Definition UnitDefines.h:281
bool IsCreature() const
Definition Object.h:205
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
bool IsVehicle() const
Definition Unit.h:800
bool IsPet() const
Definition Unit.h:797
bool HasUnitFlag(UnitFlags flags) const
Definition Unit.h:747
ObjectGuid GetCritterGUID() const
Definition Unit.h:725
bool IsGuardian() const
Definition Unit.h:795
bool IsInCombat() const
Definition Unit.h:935
ObjectGuid GetCharmerOrOwnerGUID() const
Definition Unit.h:1295
float GetDistance2d(WorldObject const *obj) const
Definition Object.cpp:1313
float GetObjectSize() const
Definition Object.cpp:2838

References Unit::GetCharmerOrOwnerGUID(), Unit::GetCritterGUID(), WorldObject::GetDistance2d(), Object::GetGUID(), WorldObject::GetObjectSize(), GetTargetSpeedInMotion(), Unit::HasUnitFlag(), Object::IsCreature(), Unit::IsGuardian(), Unit::IsInCombat(), Unit::IsPet(), Unit::IsVehicle(), and UNIT_FLAG_POSSESSED.

Referenced by FollowMovementGenerator< T >::DoUpdate().

◆ IsMutualChase()

static bool IsMutualChase ( Unit owner,
Unit target 
)
static
28{
30 return false;
31
32 return target->GetVictim() == owner;
33}
@ CHASE_MOTION_TYPE
Definition MotionMaster.h:45
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition MotionMaster.cpp:961
MotionMaster * GetMotionMaster()
Definition Unit.h:1758
Unit * GetVictim() const
Definition Unit.h:903

References CHASE_MOTION_TYPE, MotionMaster::GetCurrentMovementGeneratorType(), Unit::GetMotionMaster(), and Unit::GetVictim().

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

◆ IsValidPredictedPosition()

static bool IsValidPredictedPosition ( Unit target,
Position const &  predicted 
)
static
503{
504 Position current = target->GetPosition();
505
506 if (current.GetExactDist2d(&predicted) > 15.0f)
507 return false;
508
509 // Check line of sight from current to predicted to avoid clipping through geometry
510 if (!target->IsWithinLOS(predicted.GetPositionX(), predicted.GetPositionY(), predicted.GetPositionZ()))
511 return false;
512
513 return true;
514}
bool IsWithinLOS(float x, float y, float z, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS) const
Definition Object.cpp:1382
Definition Position.h:27
float GetExactDist2d(const float x, const float y) const
Definition Position.h:170
void GetPosition(float &x, float &y) const
Definition Position.h:126

References Position::GetExactDist2d(), Position::GetPosition(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), and WorldObject::IsWithinLOS().

Referenced by FollowMovementGenerator< T >::DoUpdate().

◆ PredictPosition()

static Position const PredictPosition ( Unit target)
static
471{
472 Position pos = target->GetPosition();
473 // 0.5 - it's time (0.5 sec) between starting movement opcode (e.g. MSG_MOVE_START_FORWARD) and MSG_MOVE_HEARTBEAT sent by client
474 float speed = target->GetSpeed(target->m_movementInfo.GetSpeedType()) * 0.5f;
475 float orientation = target->GetOrientation();
476
478 {
479 pos.m_positionX += cos(orientation) * speed;
480 pos.m_positionY += std::sin(orientation) * speed;
481 }
483 {
484 pos.m_positionX -= cos(orientation) * speed;
485 pos.m_positionY -= std::sin(orientation) * speed;
486 }
487
489 {
490 pos.m_positionX += cos(orientation + M_PI / 2.f) * speed;
491 pos.m_positionY += std::sin(orientation + M_PI / 2.f) * speed;
492 }
494 {
495 pos.m_positionX += cos(orientation - M_PI / 2.f) * speed;
496 pos.m_positionY += std::sin(orientation - M_PI / 2.f) * speed;
497 }
498
499 return pos;
500}
@ MOVEMENTFLAG_FORWARD
Definition UnitDefines.h:372
@ MOVEMENTFLAG_STRAFE_LEFT
Definition UnitDefines.h:374
@ MOVEMENTFLAG_BACKWARD
Definition UnitDefines.h:373
@ MOVEMENTFLAG_STRAFE_RIGHT
Definition UnitDefines.h:375
bool HasMovementFlag(uint32 flag) const
Definition Object.h:346
float m_positionX
Definition Position.h:55
float m_positionY
Definition Position.h:56
float GetOrientation() const
Definition Position.h:124

References Position::GetOrientation(), Position::GetPosition(), Unit::GetSpeed(), MovementInfo::GetSpeedType(), MovementInfo::HasMovementFlag(), WorldObject::m_movementInfo, Position::m_positionX, Position::m_positionY, MOVEMENTFLAG_BACKWARD, MOVEMENTFLAG_FORWARD, MOVEMENTFLAG_STRAFE_LEFT, and MOVEMENTFLAG_STRAFE_RIGHT.

Referenced by FollowMovementGenerator< T >::DoUpdate().