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, std::optional< AnimTier > animTier=std::nullopt, 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 Pause (uint32 timer=0) override
 
void Resume (uint32 overrideTimer=0) override
 
void unitSpeedChanged () override
 
MovementGeneratorType GetMovementGeneratorType () override
 
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 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
 
std::optional< AnimTier_animTier
 
bool _stalled {}
 
bool _hasBeenStalled {}
 
std::optional< int32_pauseTime
 

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,
std::optional< AnimTier animTier = std::nullopt,
ObjectGuid  chargeTargetGUID = ObjectGuid::Empty,
bool  reverseOrientation = false,
ObjectGuid  facingTargetGuid = ObjectGuid() 
)
inline
32 : id(_id), i_x(_x), i_y(_y), i_z(_z), speed(_speed), i_orientation(orientation), _generatePath(generatePath), _forceDestination(forceDestination), _reverseOrientation(reverseOrientation),
33 _chargeTargetGUID(chargeTargetGUID), _forcedMovement(forcedMovement), _facingTargetGuid(facingTargetGuid), _animTier(animTier)
34 {
35 if (_path)
36 m_precomputedPath = *_path;
37 }
std::optional< AnimTier > _animTier
Definition PointMovementGenerator.h:68
ObjectGuid _chargeTargetGUID
Definition PointMovementGenerator.h:65
float i_z
Definition PointMovementGenerator.h:57
ForcedMovement _forcedMovement
Definition PointMovementGenerator.h:66
bool _generatePath
Definition PointMovementGenerator.h:62
float speed
Definition PointMovementGenerator.h:58
float i_orientation
Definition PointMovementGenerator.h:59
Movement::PointsArray m_precomputedPath
Definition PointMovementGenerator.h:61
float i_x
Definition PointMovementGenerator.h:57
ObjectGuid _facingTargetGuid
Definition PointMovementGenerator.h:67
bool _forceDestination
Definition PointMovementGenerator.h:63
bool _reverseOrientation
Definition PointMovementGenerator.h:64
uint32 id
Definition PointMovementGenerator.h:56
float i_y
Definition PointMovementGenerator.h:57

References PointMovementGenerator< T >::m_precomputedPath.

Member Function Documentation

◆ DoFinalize()

template<class T >
template void PointMovementGenerator< T >::DoFinalize ( T *  )
250{
251 unit->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
252 if (id == EVENT_CHARGE || id == EVENT_CHARGE_PREPATH)
253 {
254 unit->ClearUnitState(UNIT_STATE_CHARGING);
255
256 if (_chargeTargetGUID && _chargeTargetGUID == unit->GetTarget())
257 {
258 if (Unit* target = ObjectAccessor::GetUnit(*unit, _chargeTargetGUID))
259 {
260 unit->Attack(target, true);
261 }
262 }
263 }
264
265 // Only inform AI if this is a real arrival, not a finalize caused by a Pause/Stop
266 if (unit->movespline->Finalized() && !_hasBeenStalled)
267 MovementInform(unit);
268}
@ EVENT_CHARGE
Definition SharedDefines.h:3560
@ UNIT_STATE_ROAMING_MOVE
Definition UnitDefines.h:195
@ UNIT_STATE_CHARGING
Definition UnitDefines.h:190
@ UNIT_STATE_ROAMING
Definition UnitDefines.h:177
#define EVENT_CHARGE_PREPATH
Definition boss_icecrown_gunship_battle.cpp:108
void MovementInform(T *)
Definition PointMovementGenerator.cpp:308
bool _hasBeenStalled
Definition PointMovementGenerator.h:70
Definition Unit.h:664
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.
31{
32 _stalled = false;
33 _hasBeenStalled = false;
34 _pauseTime.reset();
35
36 if (unit->HasUnitState(UNIT_STATE_NOT_MOVE) || unit->IsMovementPreventedByCasting())
37 {
38 // the next line is to ensure that a new spline is created in DoUpdate() once the unit is no longer rooted/stunned
40 i_recalculateSpeed = true;
41 return;
42 }
43
44 if (!unit->IsStopped())
45 unit->StopMoving();
46
47 unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
48 if (id == EVENT_CHARGE || id == EVENT_CHARGE_PREPATH)
49 {
50 unit->AddUnitState(UNIT_STATE_CHARGING);
51 }
52
53 i_recalculateSpeed = false;
54 Movement::MoveSplineInit init(unit);
55 if (m_precomputedPath.size() > 2) // pussywizard: for charge
56 init.MovebyPath(m_precomputedPath);
57 else if (_generatePath)
58 {
59 PathGenerator path(unit);
60 bool result = path.CalculatePath(i_x, i_y, i_z, _forceDestination);
61 if (result && !(path.GetPathType() & PATHFIND_NOPATH) && path.GetPath().size() > 2)
62 {
63 m_precomputedPath = path.GetPath();
64 init.MovebyPath(m_precomputedPath);
65 }
66 else
67 {
68 // Xinef: fix strange client visual bug, moving on z coordinate only switches orientation by 180 degrees (visual only)
69 if (G3D::fuzzyEq(unit->GetPositionX(), i_x) && G3D::fuzzyEq(unit->GetPositionY(), i_y))
70 {
71 i_x += 0.2f * cos(unit->GetOrientation());
72 i_y += 0.2f * std::sin(unit->GetOrientation());
73 }
74
75 init.MoveTo(i_x, i_y, i_z, true);
76 }
77 }
78 else
79 {
80 // Xinef: fix strange client visual bug, moving on z coordinate only switches orientation by 180 degrees (visual only)
81 if (G3D::fuzzyEq(unit->GetPositionX(), i_x) && G3D::fuzzyEq(unit->GetPositionY(), i_y))
82 {
83 i_x += 0.2f * cos(unit->GetOrientation());
84 i_y += 0.2f * std::sin(unit->GetOrientation());
85 }
86
87 init.MoveTo(i_x, i_y, i_z, true);
88 }
89 if (speed > 0.0f)
90 init.SetVelocity(speed);
91
93 init.SetWalk(true);
95 init.SetWalk(false);
96
97 if (i_orientation > 0.0f)
98 {
99 init.SetFacing(i_orientation);
100 }
101
102 if (_animTier)
103 init.SetAnimation(*_animTier);
104
105 init.Launch();
106}
@ FORCED_MOVEMENT_WALK
Definition MotionMaster.h:87
@ FORCED_MOVEMENT_RUN
Definition MotionMaster.h:88
@ PATHFIND_NOPATH
Definition PathGenerator.h:50
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:225
Definition MoveSplineInit.h:63
Definition PathGenerator.h:59
bool i_recalculateSpeed
Definition PointMovementGenerator.h:60
bool _stalled
Definition PointMovementGenerator.h:69
std::optional< int32 > _pauseTime
Definition PointMovementGenerator.h:71

References UNIT_STATE_NOT_MOVE.

◆ DoReset()

template<class T >
template void PointMovementGenerator< T >::DoReset ( T *  )
296{
297 if (!unit->IsStopped())
298 unit->StopMoving();
299
300 unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
301 if (id == EVENT_CHARGE || id == EVENT_CHARGE_PREPATH)
302 {
303 unit->AddUnitState(UNIT_STATE_CHARGING);
304 }
305}

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   
)
110{
111 if (!unit)
112 return false;
113
114 if (unit->IsMovementPreventedByCasting())
115 {
116 unit->StopMoving();
117 return true;
118 }
119
120 if (unit->HasUnitState(UNIT_STATE_NOT_MOVE))
121 {
122 if (!unit->HasUnitState(UNIT_STATE_CHARGING))
123 unit->StopMoving();
124 return true;
125 }
126
127 unit->AddUnitState(UNIT_STATE_ROAMING_MOVE);
128
129 if (_pauseTime.has_value())
130 {
131 if (diff >= static_cast<uint32>(_pauseTime.value()))
132 _pauseTime.reset();
133 else
134 {
135 _pauseTime = static_cast<int32>(_pauseTime.value() - diff);
136 return true;
137 }
138
139 _hasBeenStalled = false;
140 _stalled = false;
141 i_recalculateSpeed = true;
142 }
143
144 // Relaunch path when speed changed or when resuming from a stall.
145 // Keep an indefinitely paused movement stalled until Resume() clears _stalled.
147 {
148 i_recalculateSpeed = false;
149 Movement::MoveSplineInit init(unit);
150 auto rebasePrecomputedPath = [this, unit](std::optional<uint32> offset = std::nullopt)
151 {
152 Movement::PointsArray rebasedPath;
153 G3D::Vector3 currentPos(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ());
154
155 if (m_precomputedPath.empty())
156 return rebasedPath;
157
158 if (offset.has_value())
159 {
160 if (offset.value() >= m_precomputedPath.size())
161 {
162 rebasedPath.push_back(currentPos);
163 rebasedPath.push_back(m_precomputedPath.back());
164 return rebasedPath;
165 }
166
167 rebasedPath.insert(rebasedPath.end(), m_precomputedPath.begin() + offset.value(), m_precomputedPath.end());
168 }
169 else
170 {
171 uint32 closestPointIndex = 0;
172 float closestPointDist = std::numeric_limits<float>::max();
173 for (uint32 pointIndex = 1; pointIndex < m_precomputedPath.size(); ++pointIndex)
174 {
175 float const sqDist = (currentPos - m_precomputedPath[pointIndex]).squaredLength();
176 if (sqDist < closestPointDist)
177 {
178 closestPointDist = sqDist;
179 closestPointIndex = pointIndex;
180 }
181 }
182
183 rebasedPath.insert(rebasedPath.end(), m_precomputedPath.begin() + closestPointIndex, m_precomputedPath.end());
184 }
185
186 // MovebyPath requires the first point to be the mover's current position.
187 rebasedPath.insert(rebasedPath.begin(), currentPos);
188 return rebasedPath;
189 };
190
191 if (m_precomputedPath.size())
192 {
193 if (!unit->movespline->Finalized())
194 {
195 uint32 offset = std::min(uint32(unit->movespline->_currentSplineIdx()), uint32(m_precomputedPath.size()));
196 m_precomputedPath = rebasePrecomputedPath(offset);
197
198 if (m_precomputedPath.size() > 2)
199 init.MovebyPath(m_precomputedPath);
200 else if (m_precomputedPath.size() == 2)
201 init.MoveTo(m_precomputedPath[1].x, m_precomputedPath[1].y, m_precomputedPath[1].z, true);
202 }
203 else
204 {
205 // Unit was stopped (finalized) due to Pause/StopMoving; trim path from current position.
206 m_precomputedPath = rebasePrecomputedPath();
207
208 if (m_precomputedPath.size() > 2)
209 init.MovebyPath(m_precomputedPath);
210 else if (m_precomputedPath.size() == 2)
211 init.MoveTo(m_precomputedPath[1].x, m_precomputedPath[1].y, m_precomputedPath[1].z, true);
212 else
213 init.MoveTo(i_x, i_y, i_z, true);
214 }
215 }
216 else
217 init.MoveTo(i_x, i_y, i_z, true);
218
219 if (speed > 0.0f) // Default value for point motion type is 0.0, if 0.0 spline will use GetSpeed on unit
220 init.SetVelocity(speed);
221
223 init.SetWalk(true);
225 init.SetWalk(false);
226
227 if (_animTier)
228 init.SetAnimation(*_animTier);
229
230 if (i_orientation > 0.0f)
231 init.SetFacing(i_orientation);
232
233 init.Launch();
234 }
235
236 // If finalized but we were stalled (paused) keep generator active so Finalize() won't be called
237 if (unit->movespline->Finalized())
238 {
239 if (_hasBeenStalled)
240 return true;
241
242 return false;
243 }
244
245 return true;
246}
std::int32_t int32
Definition Define.h:103
std::uint32_t uint32
Definition Define.h:107
std::vector< Vector3 > PointsArray
Definition MoveSplineInitArgs.h:28

References EVENT_CHARGE_PREPATH, FORCED_MOVEMENT_RUN, FORCED_MOVEMENT_WALK, Movement::MoveSplineInit::Launch(), Movement::MoveSplineInit::MovebyPath(), Movement::MoveSplineInit::MoveTo(), Movement::MoveSplineInit::SetAnimation(), 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 ( )
inlineoverridevirtual

Implements MovementGenerator.

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

References POINT_MOTION_TYPE.

◆ MovementInform()

template<class T >
void PointMovementGenerator< T >::MovementInform ( T *  )
309{
310}

◆ Pause()

template<class T >
template void PointMovementGenerator< T >::Pause ( uint32  timer = 0)
overridevirtual

Reimplemented from MovementGenerator.

272{
273 _stalled = timer ? false : true;
274 _hasBeenStalled = true;
275 if (timer)
276 _pauseTime = static_cast<int32>(timer);
277 else
278 _pauseTime.reset();
279}

◆ Resume()

template<class T >
template void PointMovementGenerator< T >::Resume ( uint32  overrideTimer = 0)
overridevirtual

Reimplemented from MovementGenerator.

283{
284 _hasBeenStalled = false;
285 _stalled = false;
286 if (overrideTimer)
287 _pauseTime = static_cast<int32>(overrideTimer);
288 else
289 _pauseTime.reset();
290
291 i_recalculateSpeed = true;
292}

◆ unitSpeedChanged()

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

Member Data Documentation

◆ _animTier

template<class T >
std::optional<AnimTier> PointMovementGenerator< T >::_animTier
private

◆ _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

◆ _hasBeenStalled

template<class T >
bool PointMovementGenerator< T >::_hasBeenStalled {}
private
70{};

◆ _pauseTime

template<class T >
std::optional<int32> PointMovementGenerator< T >::_pauseTime
private

◆ _reverseOrientation

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

◆ _stalled

template<class T >
bool PointMovementGenerator< T >::_stalled {}
private
69{};

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