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, ForcedMovement forcedMovement, float _speed=0.0f, float orientation=0.0f, const Movement::PointsArray *_path=nullptr, bool generatePath=false, bool forceDestination=false, ObjectGuid chargeTargetGUID=ObjectGuid::Empty, bool reverseOrientation=false, ObjectGuid facingTargetGuid=ObjectGuid())
 
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 uint32 GetSplineId () const
 
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
 
bool _reverseOrientation
 
ObjectGuid _chargeTargetGUID
 
ForcedMovement _forcedMovement
 
ObjectGuid _facingTargetGuid
 

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,
ForcedMovement  forcedMovement,
float  _speed = 0.0f,
float  orientation = 0.0f,
const Movement::PointsArray _path = nullptr,
bool  generatePath = false,
bool  forceDestination = false,
ObjectGuid  chargeTargetGUID = ObjectGuid::Empty,
bool  reverseOrientation = false,
ObjectGuid  facingTargetGuid = ObjectGuid() 
)
inline
31 : id(_id), i_x(_x), i_y(_y), i_z(_z), speed(_speed), i_orientation(orientation), _generatePath(generatePath), _forceDestination(forceDestination), _reverseOrientation(reverseOrientation),
32 _chargeTargetGUID(chargeTargetGUID), _forcedMovement(forcedMovement), _facingTargetGuid(facingTargetGuid)
33 {
34 if (_path)
35 m_precomputedPath = *_path;
36 }
ObjectGuid _chargeTargetGUID
Definition PointMovementGenerator.h:60
float i_z
Definition PointMovementGenerator.h:52
ForcedMovement _forcedMovement
Definition PointMovementGenerator.h:61
bool _generatePath
Definition PointMovementGenerator.h:57
float speed
Definition PointMovementGenerator.h:53
float i_orientation
Definition PointMovementGenerator.h:54
Movement::PointsArray m_precomputedPath
Definition PointMovementGenerator.h:56
float i_x
Definition PointMovementGenerator.h:52
ObjectGuid _facingTargetGuid
Definition PointMovementGenerator.h:62
bool _forceDestination
Definition PointMovementGenerator.h:58
bool _reverseOrientation
Definition PointMovementGenerator.h:59
uint32 id
Definition PointMovementGenerator.h:51
float i_y
Definition PointMovementGenerator.h:52

References PointMovementGenerator< T >::m_precomputedPath.

Member Function Documentation

◆ DoFinalize()

template<class T >
template void PointMovementGenerator< T >::DoFinalize ( T *  )
168{
169 unit->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
170 if (id == EVENT_CHARGE || id == EVENT_CHARGE_PREPATH)
171 {
172 unit->ClearUnitState(UNIT_STATE_CHARGING);
173
174 if (_chargeTargetGUID && _chargeTargetGUID == unit->GetTarget())
175 {
176 if (Unit* target = ObjectAccessor::GetUnit(*unit, _chargeTargetGUID))
177 {
178 unit->Attack(target, true);
179 }
180 }
181 }
182
183 if (unit->movespline->Finalized())
184 MovementInform(unit);
185}
@ EVENT_CHARGE
Definition SharedDefines.h:3577
@ UNIT_STATE_ROAMING_MOVE
Definition UnitDefines.h:192
@ UNIT_STATE_CHARGING
Definition UnitDefines.h:187
@ UNIT_STATE_ROAMING
Definition UnitDefines.h:174
#define EVENT_CHARGE_PREPATH
Definition boss_icecrown_gunship_battle.cpp:108
void MovementInform(T *)
Definition PointMovementGenerator.cpp:201
Definition Unit.h:650
Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition ObjectAccessor.cpp:199

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
88 init.SetWalk(true);
90 init.SetWalk(false);
91
92 if (i_orientation > 0.0f)
93 {
94 init.SetFacing(i_orientation);
95 }
96
97 init.Launch();
98}
@ FORCED_MOVEMENT_WALK
Definition MotionMaster.h:86
@ FORCED_MOVEMENT_RUN
Definition MotionMaster.h:87
@ PATHFIND_NOPATH
Definition PathGenerator.h:50
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:222
Definition MoveSplineInit.h:71
Definition PathGenerator.h:59
bool i_recalculateSpeed
Definition PointMovementGenerator.h:55

References UNIT_STATE_NOT_MOVE.

◆ DoReset()

template<class T >
template void PointMovementGenerator< T >::DoReset ( T *  )
189{
190 if (!unit->IsStopped())
191 unit->StopMoving();
192
193 unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
194 if (id == EVENT_CHARGE || id == EVENT_CHARGE_PREPATH)
195 {
196 unit->AddUnitState(UNIT_STATE_CHARGING);
197 }
198}

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

References EVENT_CHARGE_PREPATH, FORCED_MOVEMENT_RUN, FORCED_MOVEMENT_WALK, Movement::MoveSplineInit::Launch(), Movement::MoveSplineInit::MovebyPath(), Movement::MoveSplineInit::MoveTo(), Movement::MoveSplineInit::SetFacing(), Movement::MoveSplineInit::SetVelocity(), Movement::MoveSplineInit::SetWalk(), 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.

47{ return POINT_MOTION_TYPE; }
@ POINT_MOTION_TYPE
Definition MotionMaster.h:48

References POINT_MOTION_TYPE.

◆ MovementInform()

template<class T >
void PointMovementGenerator< T >::MovementInform ( T *  )
202{
203}

◆ unitSpeedChanged()

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

Member Data Documentation

◆ _chargeTargetGUID

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

◆ _facingTargetGuid

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

◆ _forceDestination

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

◆ _forcedMovement

template<class T >
ForcedMovement PointMovementGenerator< T >::_forcedMovement
private

◆ _generatePath

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

◆ _reverseOrientation

template<class T >
bool PointMovementGenerator< T >::_reverseOrientation
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

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