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

#include <FleeingMovementGenerator.h>

Public Member Functions

 FleeingMovementGenerator (ObjectGuid fright)
 
void DoInitialize (T *)
 
void DoFinalize (T *)
 
void DoReset (T *)
 
bool DoUpdate (T *, uint32)
 
MovementGeneratorType GetMovementGeneratorType () const override
 
template<>
void DoFinalize (Player *owner)
 
- Public Member Functions inherited from MovementGeneratorMedium< T, FleeingMovementGenerator< T > >
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 void unitSpeedChanged ()
 
virtual bool GetResetPosition (Unit *, float &, float &, float &)
 

Private Member Functions

void _setTargetLocation (T *)
 
void _getPoint (T *, float &x, float &y, float &z)
 

Private Attributes

ObjectGuid i_frightGUID
 
TimeTracker i_nextCheckTime
 

Constructor & Destructor Documentation

template<class T>
FleeingMovementGenerator< T >::FleeingMovementGenerator ( ObjectGuid  fright)
inline
28 : i_frightGUID(fright), i_nextCheckTime(0) { }
ObjectGuid i_frightGUID
Definition: FleeingMovementGenerator.h:41
TimeTracker i_nextCheckTime
Definition: FleeingMovementGenerator.h:42

Member Function Documentation

template<class T>
template void FleeingMovementGenerator< T >::_getPoint ( T *  ,
float &  x,
float &  y,
float &  z 
)
private
77 {
78  float dist_from_caster, angle_to_caster;
79  if (Unit* fright = ObjectAccessor::GetUnit(*owner, i_frightGUID))
80  {
81  dist_from_caster = fright->GetDistance(owner);
82  if (dist_from_caster > 0.2f)
83  angle_to_caster = fright->GetAngle(owner);
84  else
85  angle_to_caster = frand(0, 2 * static_cast<float>(M_PI));
86  }
87  else
88  {
89  dist_from_caster = 0.0f;
90  angle_to_caster = frand(0, 2 * static_cast<float>(M_PI));
91  }
92 
93  float dist, angle;
94  if (dist_from_caster < MIN_QUIET_DISTANCE)
95  {
96  dist = frand(0.4f, 1.3f)*(MIN_QUIET_DISTANCE - dist_from_caster);
97  angle = angle_to_caster + frand(-static_cast<float>(M_PI)/8, static_cast<float>(M_PI)/8);
98  }
99  else if (dist_from_caster > MAX_QUIET_DISTANCE)
100  {
101  dist = frand(0.4f, 1.0f)*(MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE);
102  angle = -angle_to_caster + frand(-static_cast<float>(M_PI)/4, static_cast<float>(M_PI)/4);
103  }
104  else // we are inside quiet range
105  {
106  dist = frand(0.6f, 1.2f)*(MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE);
107  angle = frand(0, 2*static_cast<float>(M_PI));
108  }
109 
110  Position pos = owner->GetFirstCollisionPosition(dist, angle);
111  x = pos.m_positionX;
112  y = pos.m_positionY;
113  z = pos.m_positionZ;
114 }
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:163
ObjectGuid i_frightGUID
Definition: FleeingMovementGenerator.h:41
#define M_PI
Definition: Common.h:163
float m_positionY
Definition: Position.h:53
double frand()
Definition: Vector3.cpp:170
#define MAX_QUIET_DISTANCE
Definition: FleeingMovementGenerator.cpp:30
float m_positionX
Definition: Position.h:52
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
float m_positionZ
Definition: Position.h:54
Definition: Position.h:27
G3D::int16 x
Definition: Vector2int16.h:37
Definition: Unit.h:1305
#define MIN_QUIET_DISTANCE
Definition: FleeingMovementGenerator.cpp:29

+ Here is the call graph for this function:

template<class T>
template void FleeingMovementGenerator< T >::_setTargetLocation ( T *  )
private
34 {
35  if (!owner)
36  return;
37 
38  if (owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
39  return;
40 
41  owner->AddUnitState(UNIT_STATE_FLEEING_MOVE);
42 
43  float x, y, z;
44  _getPoint(owner, x, y, z);
45 
46  // Add LOS check for target point
47  Position mypos = owner->GetPosition();
48  bool isInLOS = VMAP::VMapFactory::createOrGetVMapManager()->isInLineOfSight(owner->GetMapId(),
49  mypos.m_positionX,
50  mypos.m_positionY,
51  mypos.m_positionZ + 2.0f,
52  x, y, z + 2.0f);
53  if (!isInLOS)
54  {
56  return;
57  }
58 
59  PathGenerator path(owner);
60  path.SetPathLengthLimit(30.0f);
61  bool result = path.CalculatePath(x, y, z);
62  if (!result || (path.GetPathType() & PATHFIND_NOPATH))
63  {
65  return;
66  }
67 
68  Movement::MoveSplineInit init(owner);
69  init.MovebyPath(path.GetPath());
70  init.SetWalk(false);
71  int32 traveltime = init.Launch();
72  i_nextCheckTime.Reset(traveltime + urand(800, 1500));
73 }
Definition: PathGenerator.h:47
float m_positionY
Definition: Position.h:53
Definition: Unit.h:574
float m_positionX
Definition: Position.h:52
void Reset(time_t interval)
Definition: Timer.h:119
void _getPoint(T *, float &x, float &y, float &z)
Definition: FleeingMovementGenerator.cpp:76
Definition: Unit.h:553
virtual bool isInLineOfSight(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2)=0
G3D::int16 z
Definition: Vector3int16.h:46
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
void GetPosition(float &x, float &y) const
Definition: Position.h:109
int32_t int32
Definition: Define.h:146
G3D::int16 y
Definition: Vector2int16.h:38
Definition: PathGenerator.h:52
float m_positionZ
Definition: Position.h:54
TimeTracker i_nextCheckTime
Definition: FleeingMovementGenerator.h:42
Definition: Unit.h:560
Definition: Position.h:27
static IVMapManager * createOrGetVMapManager()
Definition: VMapFactory.cpp:28
G3D::int16 x
Definition: Vector2int16.h:37
Definition: MoveSplineInit.h:52

+ Here is the call graph for this function:

template<class T>
void FleeingMovementGenerator< T >::DoFinalize ( T *  )
template<>
void FleeingMovementGenerator< Player >::DoFinalize ( Player owner)
129 {
130  owner->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
131  owner->ClearUnitState(UNIT_STATE_FLEEING | UNIT_STATE_FLEEING_MOVE);
132  owner->StopMoving();
133 }
Definition: Unit.h:574
Definition: Unit.h:557
Definition: Unit.h:696
Definition: UpdateFields.h:109
template<class T>
template void FleeingMovementGenerator< T >::DoInitialize ( T *  )
118 {
119  if (!owner)
120  return;
121 
122  owner->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
123  owner->AddUnitState(UNIT_STATE_FLEEING | UNIT_STATE_FLEEING_MOVE);
124  _setTargetLocation(owner);
125 }
Definition: Unit.h:574
Definition: Unit.h:557
void _setTargetLocation(T *)
Definition: FleeingMovementGenerator.cpp:33
Definition: Unit.h:696
Definition: UpdateFields.h:109
template<class T>
template void FleeingMovementGenerator< T >::DoReset ( T *  )
146 {
147  DoInitialize(owner);
148 }
void DoInitialize(T *)
Definition: FleeingMovementGenerator.cpp:117
template<class T>
template bool FleeingMovementGenerator< T >::DoUpdate ( T *  ,
uint32   
)
152 {
153  if (!owner || !owner->IsAlive())
154  return false;
155 
156  if (owner->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
157  {
158  owner->ClearUnitState(UNIT_STATE_FLEEING_MOVE);
159  return true;
160  }
161 
162  i_nextCheckTime.Update(time_diff);
163  if (i_nextCheckTime.Passed() && owner->movespline->Finalized())
164  _setTargetLocation(owner);
165 
166  return true;
167 }
Definition: Unit.h:574
void _setTargetLocation(T *)
Definition: FleeingMovementGenerator.cpp:33
Definition: Unit.h:553
void Update(time_t diff)
Definition: Timer.h:109
TimeTracker i_nextCheckTime
Definition: FleeingMovementGenerator.h:42
Definition: Unit.h:560
bool Passed() const
Definition: Timer.h:114
template<class T>
MovementGeneratorType FleeingMovementGenerator< T >::GetMovementGeneratorType ( ) const
inlineoverridevirtual

Implements MovementGenerator.

35 { return FLEEING_MOTION_TYPE; }
Definition: MotionMaster.h:47

Member Data Documentation

template<class T>
ObjectGuid FleeingMovementGenerator< T >::i_frightGUID
private
template<class T>
TimeTracker FleeingMovementGenerator< T >::i_nextCheckTime
private

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