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 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().

◆ GetVelocity()

static Optional< float > GetVelocity ( Unit owner,
Unit target,
G3D::Vector3 const &  dest,
bool  playerPet 
)
static
434{
435 Optional<float> speed = {};
436 if (!owner->IsInCombat() && !owner->IsVehicle() && !owner->HasUnitFlag(UNIT_FLAG_POSSESSED) &&
437 (owner->IsPet() || owner->IsGuardian() || owner->GetGUID() == target->GetCritterGUID() || owner->GetCharmerOrOwnerGUID() == target->GetGUID()))
438 {
439 uint32 moveFlags = target->GetUnitMovementFlags();
440 if (target->IsWalking())
441 {
442 moveFlags |= MOVEMENTFLAG_WALKING;
443 }
444
445 UnitMoveType moveType = Movement::SelectSpeedType(moveFlags);
446 speed = target->GetSpeed(moveType);
447 if (playerPet)
448 {
449 float distance = owner->GetDistance2d(dest.x, dest.y) - target->GetObjectSize() - (*speed / 2.f);
450 if (distance > 0.f)
451 {
452 float multiplier = 1.f + (distance / 10.f);
453 *speed *= multiplier;
454 }
455 }
456 }
457
458 return speed;
459}
std::uint32_t uint32
Definition Define.h:107
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
@ MOVEMENTFLAG_WALKING
Definition UnitDefines.h:377
UnitMoveType
Definition UnitDefines.h:352
@ UNIT_FLAG_POSSESSED
Definition UnitDefines.h:278
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:113
bool IsVehicle() const
Definition Unit.h:790
uint32 GetUnitMovementFlags() const
Definition Unit.h:765
float GetSpeed(UnitMoveType mtype) const
Definition Unit.cpp:14601
bool IsPet() const
Definition Unit.h:787
bool HasUnitFlag(UnitFlags flags) const
Definition Unit.h:737
ObjectGuid GetCritterGUID() const
Definition Unit.h:715
bool IsGuardian() const
Definition Unit.h:785
bool IsInCombat() const
Definition Unit.h:924
bool IsWalking() const
Definition Unit.h:1687
ObjectGuid GetCharmerOrOwnerGUID() const
Definition Unit.h:1280
float GetDistance2d(WorldObject const *obj) const
Definition Object.cpp:1289
float GetObjectSize() const
Definition Object.cpp:2782
UnitMoveType SelectSpeedType(uint32 moveFlags)
Definition MoveSplineInit.cpp:30

References Unit::GetCharmerOrOwnerGUID(), Unit::GetCritterGUID(), WorldObject::GetDistance2d(), Object::GetGUID(), WorldObject::GetObjectSize(), Unit::GetSpeed(), Unit::GetUnitMovementFlags(), Unit::HasUnitFlag(), Unit::IsGuardian(), Unit::IsInCombat(), Unit::IsPet(), Unit::IsVehicle(), Unit::IsWalking(), MOVEMENTFLAG_WALKING, Movement::SelectSpeedType(), 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:949
MotionMaster * GetMotionMaster()
Definition Unit.h:1738
Unit * GetVictim() const
Definition Unit.h:893

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
494{
495 Position current = target->GetPosition();
496
497 if (current.GetExactDist2d(&predicted) > 15.0f)
498 return false;
499
500 // Check line of sight from current to predicted to avoid clipping through geometry
501 if (!target->IsWithinLOS(predicted.GetPositionX(), predicted.GetPositionY(), predicted.GetPositionZ()))
502 return false;
503
504 return true;
505}
bool IsWithinLOS(float x, float y, float z, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS) const
Definition Object.cpp:1352
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
462{
463 Position pos = target->GetPosition();
464 // 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
465 float speed = target->GetSpeed(Movement::SelectSpeedType(target->GetUnitMovementFlags())) * 0.5f;
466 float orientation = target->GetOrientation();
467
469 {
470 pos.m_positionX += cos(orientation) * speed;
471 pos.m_positionY += std::sin(orientation) * speed;
472 }
474 {
475 pos.m_positionX -= cos(orientation) * speed;
476 pos.m_positionY -= std::sin(orientation) * speed;
477 }
478
480 {
481 pos.m_positionX += cos(orientation + M_PI / 2.f) * speed;
482 pos.m_positionY += std::sin(orientation + M_PI / 2.f) * speed;
483 }
485 {
486 pos.m_positionX += cos(orientation - M_PI / 2.f) * speed;
487 pos.m_positionY += std::sin(orientation - M_PI / 2.f) * speed;
488 }
489
490 return pos;
491}
@ MOVEMENTFLAG_FORWARD
Definition UnitDefines.h:369
@ MOVEMENTFLAG_STRAFE_LEFT
Definition UnitDefines.h:371
@ MOVEMENTFLAG_BACKWARD
Definition UnitDefines.h:370
@ MOVEMENTFLAG_STRAFE_RIGHT
Definition UnitDefines.h:372
MovementInfo m_movementInfo
Definition Object.h:692
bool HasMovementFlag(uint32 flag) const
Definition Object.h:345
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(), Unit::GetUnitMovementFlags(), MovementInfo::HasMovementFlag(), WorldObject::m_movementInfo, Position::m_positionX, Position::m_positionY, MOVEMENTFLAG_BACKWARD, MOVEMENTFLAG_FORWARD, MOVEMENTFLAG_STRAFE_LEFT, MOVEMENTFLAG_STRAFE_RIGHT, and Movement::SelectSpeedType().

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