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 *  )
92{
93 unit->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
94}
@ 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 *  )
26{
27 if (!unit->IsStopped())
28 unit->StopMoving();
29
30 unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
31 i_recalculateSpeed = false;
32 Movement::MoveSplineInit init(unit);
33
34 if (m_precomputedPath.size() == 2) // xinef: simple case, just call move to
35 init.MoveTo(m_precomputedPath[1].x, m_precomputedPath[1].y, m_precomputedPath[1].z, true);
36 else if (m_precomputedPath.size())
37 init.MovebyPath(m_precomputedPath);
38
39 init.Launch();
40
41 _splineId = unit->movespline->GetId();
42}
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 *  )
98{
99 if (!unit->IsStopped())
100 unit->StopMoving();
101
102 unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
103}

References UNIT_STATE_ROAMING, and UNIT_STATE_ROAMING_MOVE.

◆ DoUpdate()

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

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