AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
PointMovementGenerator< T > Class Template Reference

#include "PointMovementGenerator.h"

Inheritance diagram for PointMovementGenerator< T >:
MovementGeneratorMedium< T, PointMovementGenerator< T > > MovementGenerator

Public Member Functions

 PointMovementGenerator (uint32 _id, float _x, float _y, float _z, float _speed=0.0f, float orientation=0.0f, const Movement::PointsArray *_path=nullptr, bool generatePath=false, bool forceDestination=false, ObjectGuid chargeTargetGUID=ObjectGuid::Empty)
 
void DoInitialize (T *)
 
void DoFinalize (T *)
 
void DoReset (T *)
 
bool DoUpdate (T *, uint32)
 
void MovementInform (T *)
 
void unitSpeedChanged ()
 
MovementGeneratorType GetMovementGeneratorType ()
 
bool GetDestination (float &x, float &y, float &z) const
 
- Public Member Functions inherited from MovementGeneratorMedium< T, PointMovementGenerator< 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 Initialize (Unit *)=0
 
virtual void Finalize (Unit *)=0
 
virtual void Reset (Unit *)=0
 
virtual bool Update (Unit *, uint32 time_diff)=0
 
virtual MovementGeneratorType GetMovementGeneratorType ()=0
 
virtual uint32 GetSplineId () const
 
virtual void unitSpeedChanged ()
 
virtual void Pause (uint32)
 
virtual void Resume (uint32)
 
virtual bool GetResetPosition (float &, float &, float &)
 

Private Attributes

uint32 id
 
float i_x
 
float i_y
 
float i_z
 
float speed
 
float i_orientation
 
bool i_recalculateSpeed
 
Movement::PointsArray m_precomputedPath
 
bool _generatePath
 
bool _forceDestination
 
ObjectGuid _chargeTargetGUID
 

Detailed Description

template<class T>
class PointMovementGenerator< T >

Constructor & Destructor Documentation

◆ PointMovementGenerator()

template<class T >
PointMovementGenerator< T >::PointMovementGenerator ( uint32  _id,
float  _x,
float  _y,
float  _z,
float  _speed = 0.0f,
float  orientation = 0.0f,
const Movement::PointsArray _path = nullptr,
bool  generatePath = false,
bool  forceDestination = false,
ObjectGuid  chargeTargetGUID = ObjectGuid::Empty 
)
inline
30 : id(_id), i_x(_x), i_y(_y), i_z(_z), speed(_speed), i_orientation(orientation), _generatePath(generatePath), _forceDestination(forceDestination),
31 _chargeTargetGUID(chargeTargetGUID)
32 {
33 if (_path)
34 m_precomputedPath = *_path;
35 }
ObjectGuid _chargeTargetGUID
Definition: PointMovementGenerator.h:58
float i_z
Definition: PointMovementGenerator.h:51
bool _generatePath
Definition: PointMovementGenerator.h:56
float speed
Definition: PointMovementGenerator.h:52
float i_orientation
Definition: PointMovementGenerator.h:53
Movement::PointsArray m_precomputedPath
Definition: PointMovementGenerator.h:55
float i_x
Definition: PointMovementGenerator.h:51
bool _forceDestination
Definition: PointMovementGenerator.h:57
uint32 id
Definition: PointMovementGenerator.h:50
float i_y
Definition: PointMovementGenerator.h:51

References PointMovementGenerator< T >::m_precomputedPath.

Member Function Documentation

◆ DoFinalize()

template<class T >
template void PointMovementGenerator< T >::DoFinalize ( T *  )
159{
160 unit->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
161 if (id == EVENT_CHARGE || id == EVENT_CHARGE_PREPATH)
162 {
163 unit->ClearUnitState(UNIT_STATE_CHARGING);
164
165 if (_chargeTargetGUID && _chargeTargetGUID == unit->GetTarget())
166 {
167 if (Unit* target = ObjectAccessor::GetUnit(*unit, _chargeTargetGUID))
168 {
169 unit->Attack(target, true);
170 }
171 }
172 }
173
174 if (unit->movespline->Finalized())
175 MovementInform(unit);
176}
@ UNIT_STATE_ROAMING_MOVE
Definition: Unit.h:347
@ UNIT_STATE_CHARGING
Definition: Unit.h:342
@ UNIT_STATE_ROAMING
Definition: Unit.h:329
#define EVENT_CHARGE_PREPATH
Definition: boss_icecrown_gunship_battle.cpp:102
@ EVENT_CHARGE
Definition: SharedDefines.h:3283
Unit * GetUnit(WorldObject const &, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:204
Definition: Unit.h:1290
void MovementInform(T *)
Definition: PointMovementGenerator.cpp:192

References EVENT_CHARGE, EVENT_CHARGE_PREPATH, ObjectAccessor::GetUnit(), UNIT_STATE_CHARGING, UNIT_STATE_ROAMING, and UNIT_STATE_ROAMING_MOVE.

◆ DoInitialize()

template<class T >
template void PointMovementGenerator< T >::DoInitialize ( T *  )
Todo:
: rename this flag to something more appropriate since it is set to true even without speed change now.
31{
32 if (unit->HasUnitState(UNIT_STATE_NOT_MOVE) || unit->IsMovementPreventedByCasting())
33 {
34 // the next line is to ensure that a new spline is created in DoUpdate() once the unit is no longer rooted/stunned
36 i_recalculateSpeed = true;
37 return;
38 }
39
40 if (!unit->IsStopped())
41 unit->StopMoving();
42
43 unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
44 if (id == EVENT_CHARGE || id == EVENT_CHARGE_PREPATH)
45 {
46 unit->AddUnitState(UNIT_STATE_CHARGING);
47 }
48
49 i_recalculateSpeed = false;
50 Movement::MoveSplineInit init(unit);
51 if (m_precomputedPath.size() > 2) // pussywizard: for charge
52 init.MovebyPath(m_precomputedPath);
53 else if (_generatePath)
54 {
55 PathGenerator path(unit);
56 bool result = path.CalculatePath(i_x, i_y, i_z, _forceDestination);
57 if (result && !(path.GetPathType() & PATHFIND_NOPATH) && path.GetPath().size() > 2)
58 {
59 m_precomputedPath = path.GetPath();
60 init.MovebyPath(m_precomputedPath);
61 }
62 else
63 {
64 // Xinef: fix strange client visual bug, moving on z coordinate only switches orientation by 180 degrees (visual only)
65 if (G3D::fuzzyEq(unit->GetPositionX(), i_x) && G3D::fuzzyEq(unit->GetPositionY(), i_y))
66 {
67 i_x += 0.2f * cos(unit->GetOrientation());
68 i_y += 0.2f * std::sin(unit->GetOrientation());
69 }
70
71 init.MoveTo(i_x, i_y, i_z, true);
72 }
73 }
74 else
75 {
76 // Xinef: fix strange client visual bug, moving on z coordinate only switches orientation by 180 degrees (visual only)
77 if (G3D::fuzzyEq(unit->GetPositionX(), i_x) && G3D::fuzzyEq(unit->GetPositionY(), i_y))
78 {
79 i_x += 0.2f * cos(unit->GetOrientation());
80 i_y += 0.2f * std::sin(unit->GetOrientation());
81 }
82
83 init.MoveTo(i_x, i_y, i_z, true);
84 }
85 if (speed > 0.0f)
86 init.SetVelocity(speed);
87
88 if (i_orientation > 0.0f)
89 {
90 init.SetFacing(i_orientation);
91 }
92
93 init.Launch();
94}
@ UNIT_STATE_NOT_MOVE
Definition: Unit.h:371
@ PATHFIND_NOPATH
Definition: PathGenerator.h:51
Definition: PathGenerator.h:60
bool i_recalculateSpeed
Definition: PointMovementGenerator.h:54
Definition: MoveSplineInit.h:71

References UNIT_STATE_NOT_MOVE.

◆ DoReset()

template<class T >
template void PointMovementGenerator< T >::DoReset ( T *  )
180{
181 if (!unit->IsStopped())
182 unit->StopMoving();
183
184 unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
185 if (id == EVENT_CHARGE || id == EVENT_CHARGE_PREPATH)
186 {
187 unit->AddUnitState(UNIT_STATE_CHARGING);
188 }
189}

References EVENT_CHARGE, EVENT_CHARGE_PREPATH, UNIT_STATE_CHARGING, UNIT_STATE_ROAMING, and UNIT_STATE_ROAMING_MOVE.

◆ DoUpdate()

template<class T >
template bool PointMovementGenerator< T >::DoUpdate ( T *  ,
uint32   
)
98{
99 if (!unit)
100 return false;
101
102 if (unit->IsMovementPreventedByCasting())
103 {
104 unit->StopMoving();
105 return true;
106 }
107
108 if (unit->HasUnitState(UNIT_STATE_NOT_MOVE))
109 {
110 if (!unit->HasUnitState(UNIT_STATE_CHARGING))
111 {
112 unit->StopMoving();
113 }
114
115 return true;
116 }
117
118 unit->AddUnitState(UNIT_STATE_ROAMING_MOVE);
119
120 if (id != EVENT_CHARGE_PREPATH && i_recalculateSpeed && !unit->movespline->Finalized())
121 {
122 i_recalculateSpeed = false;
123 Movement::MoveSplineInit init(unit);
124
125 // xinef: speed changed during path execution, calculate remaining path and launch it once more
126 if (m_precomputedPath.size())
127 {
128 uint32 offset = std::min(uint32(unit->movespline->_currentSplineIdx()), uint32(m_precomputedPath.size()));
129 Movement::PointsArray::iterator offsetItr = m_precomputedPath.begin();
130 std::advance(offsetItr, offset);
131 m_precomputedPath.erase(m_precomputedPath.begin(), offsetItr);
132
133 // restore 0 element (current position)
134 m_precomputedPath.insert(m_precomputedPath.begin(), G3D::Vector3(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()));
135
136 if (m_precomputedPath.size() > 2)
137 init.MovebyPath(m_precomputedPath);
138 else if (m_precomputedPath.size() == 2)
139 init.MoveTo(m_precomputedPath[1].x, m_precomputedPath[1].y, m_precomputedPath[1].z, true);
140 }
141 else
142 init.MoveTo(i_x, i_y, i_z, true);
143 if (speed > 0.0f) // Default value for point motion type is 0.0, if 0.0 spline will use GetSpeed on unit
144 init.SetVelocity(speed);
145
146 if (i_orientation > 0.0f)
147 {
148 init.SetFacing(i_orientation);
149 }
150
151 init.Launch();
152 }
153
154 return !unit->movespline->Finalized();
155}
std::uint32_t uint32
Definition: Define.h:108

References EVENT_CHARGE_PREPATH, Movement::MoveSplineInit::Launch(), Movement::MoveSplineInit::MovebyPath(), Movement::MoveSplineInit::MoveTo(), Movement::MoveSplineInit::SetFacing(), Movement::MoveSplineInit::SetVelocity(), UNIT_STATE_CHARGING, UNIT_STATE_NOT_MOVE, and UNIT_STATE_ROAMING_MOVE.

◆ GetDestination()

template<class T >
bool PointMovementGenerator< T >::GetDestination ( float &  x,
float &  y,
float &  z 
) const
inline

◆ GetMovementGeneratorType()

template<class T >
MovementGeneratorType PointMovementGenerator< T >::GetMovementGeneratorType ( )
inlinevirtual

Implements MovementGenerator.

46{ return POINT_MOTION_TYPE; }
@ POINT_MOTION_TYPE
Definition: MotionMaster.h:46

References POINT_MOTION_TYPE.

◆ MovementInform()

template<class T >
void PointMovementGenerator< T >::MovementInform ( T *  )
193{
194}

◆ unitSpeedChanged()

template<class T >
void PointMovementGenerator< T >::unitSpeedChanged ( )
inlinevirtual

Member Data Documentation

◆ _chargeTargetGUID

template<class T >
ObjectGuid PointMovementGenerator< T >::_chargeTargetGUID
private

◆ _forceDestination

template<class T >
bool PointMovementGenerator< T >::_forceDestination
private

◆ _generatePath

template<class T >
bool PointMovementGenerator< T >::_generatePath
private

◆ i_orientation

template<class T >
float PointMovementGenerator< T >::i_orientation
private

◆ i_recalculateSpeed

template<class T >
bool PointMovementGenerator< T >::i_recalculateSpeed
private

◆ i_x

template<class T >
float PointMovementGenerator< T >::i_x
private

◆ i_y

template<class T >
float PointMovementGenerator< T >::i_y
private

◆ i_z

template<class T >
float PointMovementGenerator< T >::i_z
private

◆ id

template<class T >
uint32 PointMovementGenerator< T >::id
private

◆ m_precomputedPath

template<class T >
Movement::PointsArray PointMovementGenerator< T >::m_precomputedPath
private

◆ speed

template<class T >
float PointMovementGenerator< T >::speed
private