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
454{
455 if (!target->movespline->Finalized())
456 return target->movespline->Velocity();
457
458 return target->GetSpeed(target->m_movementInfo.GetSpeedType());
459}
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:11299
MovementInfo m_movementInfo
Definition Object.h:704
UnitMoveType GetSpeedType() const
Definition Object.h:349

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
462{
463 Optional<float> speed = {};
464 if (owner->IsInCombat() || owner->IsVehicle() || owner->HasUnitFlag(UNIT_FLAG_POSSESSED))
465 return speed;
466
467 bool isPetLike = owner->IsPet() || owner->IsGuardian() || owner->GetGUID() == target->GetCritterGUID() || owner->GetCharmerOrOwnerGUID() == target->GetGUID();
468
469 // For pets/guardians/critters or creature-to-creature follow: sync with target's speed
470 if (isPetLike || (owner->IsCreature() && target->IsCreature()))
471 {
472 speed = GetTargetSpeedInMotion(target);
473
474 if (playerPet)
475 {
476 float distance = owner->GetDistance2d(dest.x, dest.y) - target->GetObjectSize() - (*speed / 2.f);
477 if (distance > 0.f)
478 {
479 float multiplier = 1.f + (distance / 10.f);
480 *speed *= multiplier;
481 }
482 }
483 }
484
485 return speed;
486}
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
static float GetTargetSpeedInMotion(Unit *target)
Definition TargetedMovementGenerator.cpp:453
@ 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:801
bool IsPet() const
Definition Unit.h:798
bool HasUnitFlag(UnitFlags flags) const
Definition Unit.h:748
ObjectGuid GetCritterGUID() const
Definition Unit.h:726
bool IsGuardian() const
Definition Unit.h:796
bool IsInCombat() const
Definition Unit.h:936
ObjectGuid GetCharmerOrOwnerGUID() const
Definition Unit.h:1296
float GetDistance2d(WorldObject const *obj) const
Definition Object.cpp:1317
float GetObjectSize() const
Definition Object.cpp:2892

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:981
MotionMaster * GetMotionMaster()
Definition Unit.h:1758
Unit * GetVictim() const
Definition Unit.h:904

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
521{
522 Position current = target->GetPosition();
523
524 if (current.GetExactDist2d(&predicted) > 15.0f)
525 return false;
526
527 // Check line of sight from current to predicted to avoid clipping through geometry
528 if (!target->IsWithinLOS(predicted.GetPositionX(), predicted.GetPositionY(), predicted.GetPositionZ()))
529 return false;
530
531 return true;
532}
bool IsWithinLOS(float x, float y, float z, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS) const
Definition Object.cpp:1386
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
489{
490 Position pos = target->GetPosition();
491 // 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
492 float speed = target->GetSpeed(target->m_movementInfo.GetSpeedType()) * 0.5f;
493 float orientation = target->GetOrientation();
494
496 {
497 pos.m_positionX += cos(orientation) * speed;
498 pos.m_positionY += std::sin(orientation) * speed;
499 }
501 {
502 pos.m_positionX -= cos(orientation) * speed;
503 pos.m_positionY -= std::sin(orientation) * speed;
504 }
505
507 {
508 pos.m_positionX += cos(orientation + M_PI / 2.f) * speed;
509 pos.m_positionY += std::sin(orientation + M_PI / 2.f) * speed;
510 }
512 {
513 pos.m_positionX += cos(orientation - M_PI / 2.f) * speed;
514 pos.m_positionY += std::sin(orientation - M_PI / 2.f) * speed;
515 }
516
517 return pos;
518}
@ 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:347
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().