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 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
 
std::optional< AnimTier_animTier
 

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:64
ObjectGuid _chargeTargetGUID
Definition PointMovementGenerator.h:61
float i_z
Definition PointMovementGenerator.h:53
ForcedMovement _forcedMovement
Definition PointMovementGenerator.h:62
bool _generatePath
Definition PointMovementGenerator.h:58
float speed
Definition PointMovementGenerator.h:54
float i_orientation
Definition PointMovementGenerator.h:55
Movement::PointsArray m_precomputedPath
Definition PointMovementGenerator.h:57
float i_x
Definition PointMovementGenerator.h:53
ObjectGuid _facingTargetGuid
Definition PointMovementGenerator.h:63
bool _forceDestination
Definition PointMovementGenerator.h:59
bool _reverseOrientation
Definition PointMovementGenerator.h:60
uint32 id
Definition PointMovementGenerator.h:52
float i_y
Definition PointMovementGenerator.h:53

References PointMovementGenerator< T >::m_precomputedPath.

Member Function Documentation

◆ DoFinalize()

template<class T >
template void PointMovementGenerator< T >::DoFinalize ( T *  )
174{
175 unit->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
176 if (id == EVENT_CHARGE || id == EVENT_CHARGE_PREPATH)
177 {
178 unit->ClearUnitState(UNIT_STATE_CHARGING);
179
180 if (_chargeTargetGUID && _chargeTargetGUID == unit->GetTarget())
181 {
182 if (Unit* target = ObjectAccessor::GetUnit(*unit, _chargeTargetGUID))
183 {
184 unit->Attack(target, true);
185 }
186 }
187 }
188
189 if (unit->movespline->Finalized())
190 MovementInform(unit);
191}
@ 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:207
Definition Unit.h:655
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 if (_animTier)
98 init.SetAnimation(*_animTier);
99
100 init.Launch();
101}
@ 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:63
Definition PathGenerator.h:59
bool i_recalculateSpeed
Definition PointMovementGenerator.h:56

References UNIT_STATE_NOT_MOVE.

◆ DoReset()

template<class T >
template void PointMovementGenerator< T >::DoReset ( T *  )
195{
196 if (!unit->IsStopped())
197 unit->StopMoving();
198
199 unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
200 if (id == EVENT_CHARGE || id == EVENT_CHARGE_PREPATH)
201 {
202 unit->AddUnitState(UNIT_STATE_CHARGING);
203 }
204}

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

Implements MovementGenerator.

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

References POINT_MOTION_TYPE.

◆ MovementInform()

template<class T >
void PointMovementGenerator< T >::MovementInform ( T *  )
208{
209}

◆ unitSpeedChanged()

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

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

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