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 *  )
158{
159 unit->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
160 if (id == EVENT_CHARGE || id == EVENT_CHARGE_PREPATH)
161 {
162 unit->ClearUnitState(UNIT_STATE_CHARGING);
163
164 if (_chargeTargetGUID && _chargeTargetGUID == unit->GetTarget())
165 {
166 if (Unit* target = ObjectAccessor::GetUnit(*unit, _chargeTargetGUID))
167 {
168 unit->Attack(target, true);
169 }
170 }
171 }
172
173 if (unit->movespline->Finalized())
174 MovementInform(unit);
175}
#define EVENT_CHARGE_PREPATH
Definition: boss_icecrown_gunship_battle.cpp:107
@ EVENT_CHARGE
Definition: SharedDefines.h:3311
@ UNIT_STATE_ROAMING_MOVE
Definition: UnitDefines.h:171
@ UNIT_STATE_CHARGING
Definition: UnitDefines.h:166
@ UNIT_STATE_ROAMING
Definition: UnitDefines.h:153
Unit * GetUnit(WorldObject const &, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:199
Definition: Unit.h:630
void MovementInform(T *)
Definition: PointMovementGenerator.cpp:191

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

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

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:48

References POINT_MOTION_TYPE.

◆ MovementInform()

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

◆ 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