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

#include "EscortMovementGenerator.h"

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

Public Member Functions

 EscortMovementGenerator (Movement::PointsArray *_path=nullptr)
 
void DoInitialize (T *)
 
void DoFinalize (T *)
 
void DoReset (T *)
 
bool DoUpdate (T *, uint32)
 
void unitSpeedChanged ()
 
MovementGeneratorType GetMovementGeneratorType ()
 
uint32 GetSplineId () const
 
- Public Member Functions inherited from MovementGeneratorMedium< T, EscortMovementGenerator< 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

bool i_recalculateSpeed
 
Movement::PointsArray m_precomputedPath
 
uint32 _splineId
 

Detailed Description

template<class T>
class EscortMovementGenerator< T >

Constructor & Destructor Documentation

◆ EscortMovementGenerator()

template<class T >
EscortMovementGenerator< T >::EscortMovementGenerator ( Movement::PointsArray _path = nullptr)
inline
27 : i_recalculateSpeed(false)
28 {
29 if (_path)
30 m_precomputedPath = *_path;
31 }
Movement::PointsArray m_precomputedPath
Definition: EscortMovementGenerator.h:46
bool i_recalculateSpeed
Definition: EscortMovementGenerator.h:45

References EscortMovementGenerator< T >::m_precomputedPath.

Member Function Documentation

◆ DoFinalize()

template<class T >
template void EscortMovementGenerator< T >::DoFinalize ( T *  )
94{
95 unit->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
96}
@ UNIT_STATE_ROAMING_MOVE
Definition: UnitDefines.h:171
@ UNIT_STATE_ROAMING
Definition: UnitDefines.h:153

References UNIT_STATE_ROAMING, and UNIT_STATE_ROAMING_MOVE.

◆ DoInitialize()

template<class T >
template void EscortMovementGenerator< T >::DoInitialize ( T *  )
28{
29 if (!unit->IsStopped())
30 unit->StopMoving();
31
32 unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
33 i_recalculateSpeed = false;
34 Movement::MoveSplineInit init(unit);
35
36 if (m_precomputedPath.size() == 2) // xinef: simple case, just call move to
37 init.MoveTo(m_precomputedPath[1].x, m_precomputedPath[1].y, m_precomputedPath[1].z, true);
38 else if (m_precomputedPath.size())
39 init.MovebyPath(m_precomputedPath);
40
41 init.Launch();
42
43 _splineId = unit->movespline->GetId();
44}
uint32 _splineId
Definition: EscortMovementGenerator.h:48
Definition: MoveSplineInit.h:71

References Movement::MoveSplineInit::Launch(), Movement::MoveSplineInit::MovebyPath(), Movement::MoveSplineInit::MoveTo(), UNIT_STATE_ROAMING, and UNIT_STATE_ROAMING_MOVE.

◆ DoReset()

template<class T >
template void EscortMovementGenerator< T >::DoReset ( T *  )
100{
101 if (!unit->IsStopped())
102 unit->StopMoving();
103
104 unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
105}

References UNIT_STATE_ROAMING, and UNIT_STATE_ROAMING_MOVE.

◆ DoUpdate()

template<class T >
template bool EscortMovementGenerator< T >::DoUpdate ( T *  ,
uint32   
)
48{
49 if (!unit)
50 return false;
51
52 if (unit->HasUnitState(UNIT_STATE_NOT_MOVE) || unit->IsMovementPreventedByCasting())
53 {
54 unit->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
55 return true;
56 }
57
58 unit->AddUnitState(UNIT_STATE_ROAMING_MOVE);
59
60 bool arrived = unit->movespline->Finalized();
61
62 if (i_recalculateSpeed && !arrived)
63 {
64 i_recalculateSpeed = false;
65 Movement::MoveSplineInit init(unit);
66
67 // xinef: speed changed during path execution, calculate remaining path and launch it once more
68 if (m_precomputedPath.size())
69 {
70 uint32 offset = std::min(uint32(unit->movespline->_currentSplineIdx()), uint32(m_precomputedPath.size()));
71 Movement::PointsArray::iterator offsetItr = m_precomputedPath.begin();
72 std::advance(offsetItr, offset);
73 m_precomputedPath.erase(m_precomputedPath.begin(), offsetItr);
74
75 // restore 0 element (current position)
76 m_precomputedPath.insert(m_precomputedPath.begin(), G3D::Vector3(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()));
77
78 if (m_precomputedPath.size() > 2)
79 init.MovebyPath(m_precomputedPath);
80 else if (m_precomputedPath.size() == 2)
81 init.MoveTo(m_precomputedPath[1].x, m_precomputedPath[1].y, m_precomputedPath[1].z, true);
82 }
83
84 init.Launch();
85 // Xinef: Override spline Id on recalculate launch
86 _splineId = unit->movespline->GetId();
87 }
88
89 return !arrived;
90}
std::uint32_t uint32
Definition: Define.h:107
@ UNIT_STATE_NOT_MOVE
Definition: UnitDefines.h:197

References Movement::MoveSplineInit::Launch(), Movement::MoveSplineInit::MovebyPath(), Movement::MoveSplineInit::MoveTo(), UNIT_STATE_NOT_MOVE, and UNIT_STATE_ROAMING_MOVE.

◆ GetMovementGeneratorType()

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

Implements MovementGenerator.

40{ return ESCORT_MOTION_TYPE; }
@ ESCORT_MOTION_TYPE
Definition: MotionMaster.h:55

References ESCORT_MOTION_TYPE.

◆ GetSplineId()

template<class T >
uint32 EscortMovementGenerator< T >::GetSplineId ( ) const
inlinevirtual

Reimplemented from MovementGenerator.

42{ return _splineId; }

References EscortMovementGenerator< T >::_splineId.

◆ unitSpeedChanged()

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

Member Data Documentation

◆ _splineId

template<class T >
uint32 EscortMovementGenerator< T >::_splineId
private

◆ i_recalculateSpeed

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

◆ m_precomputedPath

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