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)
 

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
335{
336 Optional<float> speed = {};
337 if (!owner->IsInCombat() && !owner->IsVehicle() && !owner->HasUnitFlag(UNIT_FLAG_POSSESSED) &&
338 (owner->IsPet() || owner->IsGuardian() || owner->GetGUID() == target->GetCritterGUID() || owner->GetCharmerOrOwnerGUID() == target->GetGUID()))
339 {
340 uint32 moveFlags = target->GetUnitMovementFlags();
341 if (target->movespline->isWalking())
342 {
343 moveFlags |= MOVEMENTFLAG_WALKING;
344 }
345
346 UnitMoveType moveType = Movement::SelectSpeedType(moveFlags);
347 speed = target->GetSpeed(moveType);
348 if (playerPet)
349 {
350 float distance = owner->GetDistance2d(dest.x, dest.y) - target->GetObjectSize() - (*speed / 2.f);
351 if (distance > 0.f)
352 {
353 float multiplier = 1.f + (distance / 10.f);
354 *speed *= multiplier;
355 }
356 }
357 }
358
359 return speed;
360}
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
std::uint32_t uint32
Definition: Define.h:107
@ MOVEMENTFLAG_WALKING
Definition: UnitDefines.h:352
UnitMoveType
Definition: UnitDefines.h:327
@ UNIT_FLAG_POSSESSED
Definition: UnitDefines.h:253
UnitMoveType SelectSpeedType(uint32 moveFlags)
Definition: MoveSplineInit.cpp:29
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
float GetDistance2d(WorldObject const *obj) const
Definition: Object.cpp:1274
float GetObjectSize() const
Definition: Object.cpp:2782
bool IsVehicle() const
Definition: Unit.h:757
uint32 GetUnitMovementFlags() const
Definition: Unit.h:737
Movement::MoveSpline * movespline
Definition: Unit.h:1979
float GetSpeed(UnitMoveType mtype) const
Definition: Unit.cpp:14424
bool IsPet() const
Definition: Unit.h:754
bool HasUnitFlag(UnitFlags flags) const
Definition: Unit.h:712
ObjectGuid GetCritterGUID() const
Definition: Unit.h:690
bool IsGuardian() const
Definition: Unit.h:752
bool IsInCombat() const
Definition: Unit.h:884
ObjectGuid GetCharmerOrOwnerGUID() const
Definition: Unit.h:1220
bool isWalking() const
Definition: MoveSpline.h:119

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(), Movement::MoveSpline::isWalking(), MOVEMENTFLAG_WALKING, Unit::movespline, 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
MotionMaster * GetMotionMaster()
Definition: Unit.h:1620
Unit * GetVictim() const
Definition: Unit.h:853
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition: MotionMaster.cpp:913

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

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

◆ PredictPosition()

static Position const PredictPosition ( Unit target)
static
363{
364 Position pos = target->GetPosition();
365
366 // 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
367 float speed = target->GetSpeed(Movement::SelectSpeedType(target->GetUnitMovementFlags())) * 0.5f;
368 float orientation = target->GetOrientation();
369
371 {
372 pos.m_positionX += cos(orientation) * speed;
373 pos.m_positionY += std::sin(orientation) * speed;
374 }
376 {
377 pos.m_positionX -= cos(orientation) * speed;
378 pos.m_positionY -= std::sin(orientation) * speed;
379 }
380
382 {
383 pos.m_positionX += cos(orientation + M_PI / 2.f) * speed;
384 pos.m_positionY += std::sin(orientation + M_PI / 2.f) * speed;
385 }
387 {
388 pos.m_positionX += cos(orientation - M_PI / 2.f) * speed;
389 pos.m_positionY += std::sin(orientation - M_PI / 2.f) * speed;
390 }
391
392 return pos;
393}
@ MOVEMENTFLAG_FORWARD
Definition: UnitDefines.h:344
@ MOVEMENTFLAG_STRAFE_LEFT
Definition: UnitDefines.h:346
@ MOVEMENTFLAG_BACKWARD
Definition: UnitDefines.h:345
@ MOVEMENTFLAG_STRAFE_RIGHT
Definition: UnitDefines.h:347
bool HasMovementFlag(uint32 flag) const
Definition: Object.h:339
MovementInfo m_movementInfo
Definition: Object.h:614
Definition: Position.h:27
float m_positionX
Definition: Position.h:55
float m_positionY
Definition: Position.h:56
float GetOrientation() const
Definition: Position.h:119
void GetPosition(float &x, float &y) const
Definition: Position.h:121

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