TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TargetedMovementGeneratorMedium< T, D > Class Template Reference

#include <TargetedMovementGenerator.h>

Public Member Functions

bool DoUpdate (T *, uint32)
 
UnitGetTarget () const
 
void unitSpeedChanged () override
 
bool IsReachable () const
 
- Public Member Functions inherited from MovementGeneratorMedium< T, D >
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 MovementGeneratorType GetMovementGeneratorType () const =0
 
virtual bool GetResetPosition (Unit *, float &, float &, float &)
 
- Public Member Functions inherited from TargetedMovementGeneratorBase
 TargetedMovementGeneratorBase (Unit *target)
 
void stopFollowing ()
 

Protected Member Functions

 TargetedMovementGeneratorMedium (Unit *target, float offset, float angle)
 
 ~TargetedMovementGeneratorMedium ()
 
void _setTargetLocation (T *owner, bool updateDestination)
 

Protected Attributes

PathGeneratori_path
 
TimeTrackerSmall i_recheckDistance
 
float i_offset
 
float i_angle
 
bool i_recalculateTravel: 1
 
bool i_targetReached: 1
 
- Protected Attributes inherited from TargetedMovementGeneratorBase
FollowerReference i_target
 

Constructor & Destructor Documentation

template<class T, typename D>
TargetedMovementGeneratorMedium< T, D >::TargetedMovementGeneratorMedium ( Unit target,
float  offset,
float  angle 
)
inlineprotected
41  :
43  i_recheckDistance(0), i_offset(offset), i_angle(angle),
45  {
46  }
arena_t NULL
Definition: jemalloc_internal.h:624
float i_offset
Definition: TargetedMovementGenerator.h:60
bool i_targetReached
Definition: TargetedMovementGenerator.h:63
float i_angle
Definition: TargetedMovementGenerator.h:61
PathGenerator * i_path
Definition: TargetedMovementGenerator.h:58
TimeTrackerSmall i_recheckDistance
Definition: TargetedMovementGenerator.h:59
TargetedMovementGeneratorBase(Unit *target)
Definition: TargetedMovementGenerator.h:31
bool i_recalculateTravel
Definition: TargetedMovementGenerator.h:62
template<class T, typename D>
TargetedMovementGeneratorMedium< T, D >::~TargetedMovementGeneratorMedium ( )
inlineprotected
47 { delete i_path; }
PathGenerator * i_path
Definition: TargetedMovementGenerator.h:58

Member Function Documentation

template<class T, typename D >
template void TargetedMovementGeneratorMedium< T, D >::_setTargetLocation ( T *  owner,
bool  updateDestination 
)
protected
32 {
33  if (!i_target.isValid() || !i_target->IsInWorld())
34  return;
35 
36  if (owner->HasUnitState(UNIT_STATE_NOT_MOVE))
37  return;
38 
39  if (owner->GetTypeId() == TYPEID_UNIT && !i_target->isInAccessiblePlaceFor(owner->ToCreature()))
40  return;
41 
42  if (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->IsFocusing(nullptr, true))
43  return;
44 
45  float x, y, z;
46 
47  if (updateDestination || !i_path)
48  {
49  if (!i_offset)
50  {
51  // to nearest contact position
52  i_target->GetContactPoint(owner, x, y, z);
53  }
54  else
55  {
56  float dist;
57  float size;
58 
59  // Pets need special handling.
60  // We need to subtract GetObjectSize() because it gets added back further down the chain
61  // and that makes pets too far away. Subtracting it allows pets to properly
62  // be (GetCombatReach() + i_offset) away.
63  // Only applies when i_target is pet's owner otherwise pets and mobs end up
64  // doing a "dance" while fighting
65  if (owner->IsPet() && i_target->GetTypeId() == TYPEID_PLAYER)
66  {
67  dist = i_target->GetCombatReach();
68  size = i_target->GetCombatReach() - i_target->GetObjectSize();
69  }
70  else
71  {
72  dist = i_offset + 1.0f;
73  size = owner->GetObjectSize();
74  }
75 
76  if (i_target->IsWithinDistInMap(owner, dist))
77  return;
78 
79  // to at i_offset distance from target and i_angle from target facing
80  i_target->GetClosePoint(x, y, z, size, i_offset, i_angle);
81  }
82  }
83  else
84  {
85  // the destination has not changed, we just need to refresh the path (usually speed change)
87  x = end.x;
88  y = end.y;
89  z = end.z;
90  }
91 
92  if (!i_path)
93  i_path = new PathGenerator(owner);
94 
95  // allow pets to use shortcut if no path found when following their master
96  bool forceDest = (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->IsPet()
97  && owner->HasUnitState(UNIT_STATE_FOLLOW));
98 
99  bool result = i_path->CalculatePath(x, y, z, forceDest);
100  if (!result || (i_path->GetPathType() & PATHFIND_NOPATH))
101  {
102  // Cant reach target
103  i_recalculateTravel = true;
104  return;
105  }
106 
107  D::_addUnitStateMove(owner);
108  i_targetReached = false;
109  i_recalculateTravel = false;
110  owner->AddUnitState(UNIT_STATE_CHASE);
111 
112  Movement::MoveSplineInit init(owner);
113  init.MovebyPath(i_path->GetPath());
114  init.SetWalk(((D*)this)->EnableWalking());
115  // Using the same condition for facing target as the one that is used for SetInFront on movement end
116  // - applies to ChaseMovementGenerator mostly
117  if (i_angle == 0.f)
118  init.SetFacing(i_target.getTarget());
119 
120  init.Launch();
121 }
float x
Definition: Vector3.h:62
Definition: PathGenerator.h:47
G3D::Vector3 const & GetEndPosition() const
Definition: PathGenerator.h:68
FollowerReference i_target
Definition: TargetedMovementGenerator.h:34
Definition: ObjectGuid.h:32
float i_offset
Definition: TargetedMovementGenerator.h:60
float y
Definition: Vector3.h:62
Definition: Vector3.h:58
bool CalculatePath(float destX, float destY, float destZ, bool forceDest=false, bool straightLine=false)
Definition: PathGenerator.cpp:57
bool i_targetReached
Definition: TargetedMovementGenerator.h:63
float i_angle
Definition: TargetedMovementGenerator.h:61
Definition: Unit.h:593
Definition: Unit.h:559
G3D::int16 z
Definition: Vector3int16.h:46
Movement::PointsArray const & GetPath() const
Definition: PathGenerator.h:71
G3D::int16 y
Definition: Vector2int16.h:38
Definition: PathGenerator.h:52
PathGenerator * i_path
Definition: TargetedMovementGenerator.h:58
float z
Definition: Vector3.h:62
Definition: ObjectGuid.h:33
bool isValid() const
Definition: Reference.h:78
G3D::int16 x
Definition: Vector2int16.h:37
Definition: MoveSplineInit.h:52
PathType GetPathType() const
Definition: PathGenerator.h:73
TO * getTarget() const
Definition: Reference.h:94
Definition: Unit.h:555
bool i_recalculateTravel
Definition: TargetedMovementGenerator.h:62

+ Here is the call graph for this function:

template<class T, typename D >
template bool TargetedMovementGeneratorMedium< T, D >::DoUpdate ( T *  ,
uint32   
)
125 {
126  if (!i_target.isValid() || !i_target->IsInWorld())
127  return false;
128 
129  if (!owner || !owner->IsAlive())
130  return false;
131 
132  if (owner->HasUnitState(UNIT_STATE_NOT_MOVE))
133  {
134  D::_clearUnitStateMove(owner);
135  return true;
136  }
137 
138  // prevent movement while casting spells with cast time or channel time
139  if (owner->HasUnitState(UNIT_STATE_CASTING))
140  {
141  if (!owner->IsStopped())
142  owner->StopMoving();
143  return true;
144  }
145 
146  // prevent crash after creature killed pet
147  if (static_cast<D*>(this)->_lostTarget(owner))
148  {
149  D::_clearUnitStateMove(owner);
150  return true;
151  }
152 
153  bool targetMoved = false;
154  i_recheckDistance.Update(time_diff);
156  {
158  //More distance let have better performance, less distance let have more sensitive reaction at target move.
159  float allowed_dist = owner->GetCombatReach() + sWorld->getRate(RATE_TARGET_POS_RECALCULATION_RANGE);
160  G3D::Vector3 dest = owner->movespline->FinalDestination();
161  if (owner->movespline->onTransport)
162  if (TransportBase* transport = owner->GetDirectTransport())
163  transport->CalculatePassengerPosition(dest.x, dest.y, dest.z);
164 
165  // First check distance
166  if (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature()->CanFly())
167  targetMoved = !i_target->IsWithinDist3d(dest.x, dest.y, dest.z, allowed_dist);
168  else
169  targetMoved = !i_target->IsWithinDist2d(dest.x, dest.y, allowed_dist);
170 
171  // then, if the target is in range, check also Line of Sight.
172  if (!targetMoved)
173  targetMoved = !i_target->IsWithinLOSInMap(owner);
174  }
175 
176  if (i_recalculateTravel || targetMoved)
177  _setTargetLocation(owner, targetMoved);
178 
179  if (owner->movespline->Finalized())
180  {
181  static_cast<D*>(this)->MovementInform(owner);
182  if (i_angle == 0.f && !owner->HasInArc(0.01f, i_target.getTarget()))
183  owner->SetInFront(i_target.getTarget());
184 
185  if (!i_targetReached)
186  {
187  i_targetReached = true;
188  static_cast<D*>(this)->_reachTarget(owner);
189  }
190  }
191 
192  return true;
193 }
float x
Definition: Vector3.h:62
Definition: Unit.h:565
FollowerReference i_target
Definition: TargetedMovementGenerator.h:34
Definition: ObjectGuid.h:32
#define sWorld
Definition: World.h:887
float y
Definition: Vector3.h:62
Definition: Vector3.h:58
Definition: VehicleDefines.h:119
bool i_targetReached
Definition: TargetedMovementGenerator.h:63
void Update(int32 diff)
Definition: Timer.h:143
float i_angle
Definition: TargetedMovementGenerator.h:61
Definition: Unit.h:593
void Reset(uint32 interval)
Definition: Timer.h:153
float z
Definition: Vector3.h:62
TimeTrackerSmall i_recheckDistance
Definition: TargetedMovementGenerator.h:59
bool isValid() const
Definition: Reference.h:78
TO * getTarget() const
Definition: Reference.h:94
void _setTargetLocation(T *owner, bool updateDestination)
Definition: TargetedMovementGenerator.cpp:31
bool Passed() const
Definition: Timer.h:148
bool i_recalculateTravel
Definition: TargetedMovementGenerator.h:62
template<class T, typename D>
Unit* TargetedMovementGeneratorMedium< T, D >::GetTarget ( ) const
inline
51 { return i_target.getTarget(); }
FollowerReference i_target
Definition: TargetedMovementGenerator.h:34
TO * getTarget() const
Definition: Reference.h:94
template<class T, typename D>
bool TargetedMovementGeneratorMedium< T, D >::IsReachable ( ) const
inline
54 { return (i_path) ? (i_path->GetPathType() & PATHFIND_NORMAL) : true; }
Definition: PathGenerator.h:44
PathGenerator * i_path
Definition: TargetedMovementGenerator.h:58
PathType GetPathType() const
Definition: PathGenerator.h:73
template<class T, typename D>
void TargetedMovementGeneratorMedium< T, D >::unitSpeedChanged ( )
inlineoverridevirtual

Reimplemented from MovementGenerator.

53 { i_recalculateTravel = true; }
bool i_recalculateTravel
Definition: TargetedMovementGenerator.h:62

Member Data Documentation

template<class T, typename D>
float TargetedMovementGeneratorMedium< T, D >::i_angle
protected
template<class T, typename D>
float TargetedMovementGeneratorMedium< T, D >::i_offset
protected
template<class T, typename D>
PathGenerator* TargetedMovementGeneratorMedium< T, D >::i_path
protected
template<class T, typename D>
bool TargetedMovementGeneratorMedium< T, D >::i_recalculateTravel
protected
template<class T, typename D>
TimeTrackerSmall TargetedMovementGeneratorMedium< T, D >::i_recheckDistance
protected
template<class T, typename D>
bool TargetedMovementGeneratorMedium< T, D >::i_targetReached
protected

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