TrinityCore
Movement::MoveSplineInit Class Reference

#include <MoveSplineInit.h>

Public Member Functions

 MoveSplineInit (Unit *m)
 
 ~MoveSplineInit ()
 
 MoveSplineInit (MoveSplineInit const &)=delete
 
MoveSplineInitoperator= (MoveSplineInit const &)=delete
 
 MoveSplineInit (MoveSplineInit &&init)=delete
 
MoveSplineInitoperator= (MoveSplineInit &&)=delete
 
int32 Launch ()
 
void Stop ()
 
void SetParabolic (float amplitude, float start_time)
 
void SetParabolicVerticalAcceleration (float vertical_acceleration, float time_shift)
 
void SetAnimation (AnimTier anim, uint32 tierTransitionId=0, Milliseconds transitionStartTime=0ms)
 
void SetFacing (float angle)
 
void SetFacing (Vector3 const &point)
 
void SetFacing (float x, float y, float z)
 
void SetFacing (Unit const *target)
 
void MovebyPath (PointsArray const &path, int32 pointId=0)
 
void MoveTo (Vector3 const &destination, bool generatePath=true, bool forceDestination=false)
 
void MoveTo (float x, float y, float z, bool generatePath=true, bool forceDestination=false)
 
void SetFirstPointId (int32 pointId)
 
void SetSmooth ()
 
void SetUncompressed ()
 
void SetFly ()
 
void SetWalk (bool enable)
 
void SetCyclic ()
 
void SetFall ()
 
void SetTransportEnter ()
 
void SetTransportExit ()
 
void SetBackward ()
 
void SetOrientationFixed (bool enable)
 
void SetUnlimitedSpeed ()
 
void SetVelocity (float velocity)
 
void SetSpellEffectExtraData (SpellEffectExtraData const &spellEffectExtraData)
 
PointsArrayPath ()
 
void DisableTransportPathTransformations ()
 

Protected Attributes

MoveSplineInitArgs args
 
Unitunit
 

Detailed Description

Definition at line 46 of file MoveSplineInit.h.

Constructor & Destructor Documentation

◆ MoveSplineInit() [1/3]

Movement::MoveSplineInit::MoveSplineInit ( Unit m)
explicit

Definition at line 198 of file MoveSplineInit.cpp.

198 : unit(m)
199 {
201 // Elevators also use MOVEMENTFLAG_ONTRANSPORT but we do not keep track of their position changes
203 // mix existing state into new
207 args.flags.smoothGroundPath = true; // enabled by default, CatmullRom mode or client config "pathSmoothing" will disable this
209 }
MovementFlags
Definition: UnitDefines.h:356
@ MOVEMENTFLAG_DISABLE_GRAVITY
Definition: UnitDefines.h:367
@ MOVEMENTFLAG_CAN_FLY
Definition: UnitDefines.h:381
@ MOVEMENTFLAG_WALKING
Definition: UnitDefines.h:366
@ UNIT_NPC_FLAG_2_STEERING
Definition: UnitDefines.h:339
MoveSplineInitArgs args
bool IsEmpty() const
Definition: ObjectGuid.h:317
bool HasNpcFlag2(NPCFlags2 flags) const
Definition: Unit.h:982
bool HasUnitMovementFlag(uint32 f) const
Definition: Unit.h:1648
ObjectGuid GetTransGUID() const override
Definition: Unit.cpp:11433
virtual bool CanSwim() const
Definition: Unit.cpp:12236
TC_GAME_API UInt32Counter splineIdGen
+ Here is the call graph for this function:

◆ ~MoveSplineInit()

Movement::MoveSplineInit::~MoveSplineInit ( )
default

◆ MoveSplineInit() [2/3]

Movement::MoveSplineInit::MoveSplineInit ( MoveSplineInit const &  )
delete

◆ MoveSplineInit() [3/3]

Movement::MoveSplineInit::MoveSplineInit ( MoveSplineInit &&  init)
delete

Member Function Documentation

◆ DisableTransportPathTransformations()

void Movement::MoveSplineInit::DisableTransportPathTransformations ( )
inline

Definition at line 213 of file MoveSplineInit.h.

213{ args.TransformForTransport = false; }
+ Here is the caller graph for this function:

◆ Launch()

int32 Movement::MoveSplineInit::Launch ( )

Definition at line 57 of file MoveSplineInit.cpp.

58 {
59 MoveSpline& move_spline = *unit->movespline;
60
61 bool transport = !unit->GetTransGUID().IsEmpty();
62 Location real_position;
63 // there is a big chance that current position is unknown if current state is not finalized, need compute it
64 // this also allows calculate spline position and update map position in much greater intervals
65 // Don't compute for transport movement if the unit is in a motion between two transports
66 if (!move_spline.Finalized() && move_spline.onTransport == transport)
67 real_position = move_spline.ComputePosition();
68 else
69 {
70 Position const* pos;
71 if (!transport)
72 pos = unit;
73 else
75
76 real_position.x = pos->GetPositionX();
77 real_position.y = pos->GetPositionY();
78 real_position.z = pos->GetPositionZ();
79 real_position.orientation = unit->GetOrientation();
80 }
81
82 // should i do the things that user should do? - no.
83 if (args.path.empty())
84 return 0;
85
86 // correct first vertex
87 args.path[0] = real_position;
88 args.initialOrientation = real_position.orientation;
90 move_spline.onTransport = transport;
91
93 if (!args.flags.backward)
94 moveFlags = (moveFlags & ~MOVEMENTFLAG_BACKWARD) | MOVEMENTFLAG_FORWARD;
95 else
96 moveFlags = (moveFlags & ~MOVEMENTFLAG_FORWARD) | MOVEMENTFLAG_BACKWARD;
97
98 if (moveFlags & MOVEMENTFLAG_ROOT)
99 moveFlags &= ~MOVEMENTFLAG_MASK_MOVING;
100
101 if (!args.HasVelocity)
102 {
103 // If spline is initialized with SetWalk method it only means we need to select
104 // walk move speed for it but not add walk flag to unit
105 uint32 moveFlagsForSpeed = moveFlags;
106 if (args.walk)
107 moveFlagsForSpeed |= MOVEMENTFLAG_WALKING;
108 else
109 moveFlagsForSpeed &= ~MOVEMENTFLAG_WALKING;
110
111 args.velocity = unit->GetSpeed(SelectSpeedType(moveFlagsForSpeed));
112 if (Creature* creature = unit->ToCreature())
113 if (creature->HasSearchedAssistance())
114 args.velocity *= 0.66f;
115 }
116
117 // limit the speed in the same way the client does
118 float speedLimit = [&]()
119 {
121 return std::numeric_limits<float>::max();
122
124 return 50.0f;
125
126 return std::max(28.0f, unit->GetSpeed(MOVE_RUN) * 4.0f);
127 }();
128
129 args.velocity = std::min(args.velocity, speedLimit);
130
131 if (!args.Validate(unit))
132 return 0;
133
135 move_spline.Initialize(args);
136
138 packet.MoverGUID = unit->GetGUID();
139 packet.Pos = Position(real_position.x, real_position.y, real_position.z, real_position.orientation);
140 packet.InitializeSplineData(move_spline);
141 if (transport)
142 {
145 }
146
147 unit->SendMessageToSet(packet.Write(), true);
148
149 return move_spline.Duration();
150 }
uint32_t uint32
Definition: Define.h:143
@ MOVE_RUN
Definition: UnitDefines.h:118
@ MOVEMENTFLAG_FORWARD
Definition: UnitDefines.h:358
@ MOVEMENTFLAG_BACKWARD
Definition: UnitDefines.h:359
@ MOVEMENTFLAG_ROOT
Definition: UnitDefines.h:368
static Creature * ToCreature(Object *o)
Definition: Object.h:206
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:158
float GetSpeed(UnitMoveType mtype) const
Definition: Unit.cpp:8488
std::unique_ptr< Movement::MoveSpline > movespline
Definition: Unit.h:1753
int8 GetTransSeat() const
Definition: Object.h:737
virtual void SendMessageToSet(WorldPacket const *data, bool self) const
Definition: Object.cpp:1732
MovementInfo m_movementInfo
Definition: Object.h:741
WorldPacket const * Write() override
TaggedPosition< Position::XYZ > Pos
void InitializeSplineData(::Movement::MoveSpline const &moveSpline)
UnitMoveType SelectSpeedType(uint32 moveFlags)
struct MovementInfo::TransportInfo transport
void SetMovementFlags(uint32 flag)
Definition: MovementInfo.h:109
uint32 GetMovementFlags() const
Definition: MovementInfo.h:108
bool Validate(Unit *unit) const
============================================================================================
Definition: MoveSpline.cpp:241
float GetPositionZ() const
Definition: Position.h:78
float GetOrientation() const
Definition: Position.h:79
float GetPositionX() const
Definition: Position.h:76
float GetPositionY() const
Definition: Position.h:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MovebyPath()

void Movement::MoveSplineInit::MovebyPath ( PointsArray const &  path,
int32  pointId = 0 
)

Definition at line 249 of file MoveSplineInit.cpp.

250 {
251 args.path_Idx_offset = path_offset;
252 args.path.reserve(controls.size());
253 std::transform(controls.begin(), controls.end(), std::back_inserter(args.path), TransportPathTransform(unit, args.TransformForTransport));
254 }
+ Here is the caller graph for this function:

◆ MoveTo() [1/2]

void Movement::MoveSplineInit::MoveTo ( float  x,
float  y,
float  z,
bool  generatePath = true,
bool  forceDestination = false 
)

Definition at line 256 of file MoveSplineInit.cpp.

257 {
258 MoveTo(G3D::Vector3(x, y, z), generatePath, forceDestination);
259 }
void MoveTo(Vector3 const &destination, bool generatePath=true, bool forceDestination=false)
+ Here is the call graph for this function:

◆ MoveTo() [2/2]

void Movement::MoveSplineInit::MoveTo ( Vector3 const &  destination,
bool  generatePath = true,
bool  forceDestination = false 
)

Definition at line 261 of file MoveSplineInit.cpp.

262 {
263 if (generatePath)
264 {
265 PathGenerator path(unit);
266 bool result = path.CalculatePath(dest.x, dest.y, dest.z, forceDestination);
267 if (result && !(path.GetPathType() & PATHFIND_NOPATH))
268 {
269 MovebyPath(path.GetPath());
270 return;
271 }
272 }
273
275 args.path.resize(2);
276 TransportPathTransform transform(unit, args.TransformForTransport);
277 args.path[1] = transform(dest);
278 }
@ PATHFIND_NOPATH
Definition: PathGenerator.h:47
void MovebyPath(PointsArray const &path, int32 pointId=0)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=() [1/2]

MoveSplineInit & Movement::MoveSplineInit::operator= ( MoveSplineInit &&  )
delete

◆ operator=() [2/2]

MoveSplineInit & Movement::MoveSplineInit::operator= ( MoveSplineInit const &  )
delete

◆ Path()

PointsArray & Movement::MoveSplineInit::Path ( )
inline

Definition at line 164 of file MoveSplineInit.h.

164{ return args.path; }
+ Here is the caller graph for this function:

◆ SetAnimation()

void Movement::MoveSplineInit::SetAnimation ( AnimTier  anim,
uint32  tierTransitionId = 0,
Milliseconds  transitionStartTime = 0ms 
)
inline

Definition at line 203 of file MoveSplineInit.h.

204 {
206 args.effect_start_time = transitionStartTime;
207 args.animTier.emplace();
208 args.animTier->TierTransitionId = tierTransitionId;
209 args.animTier->AnimTier = anim;
211 }
Optional< AnimTierTransition > animTier
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetBackward()

void Movement::MoveSplineInit::SetBackward ( )
inline

Definition at line 181 of file MoveSplineInit.h.

181{ args.flags.backward = true; }

◆ SetCyclic()

void Movement::MoveSplineInit::SetCyclic ( )
inline

Definition at line 179 of file MoveSplineInit.h.

179{ args.flags.cyclic = true; }

◆ SetFacing() [1/4]

void Movement::MoveSplineInit::SetFacing ( float  angle)

Definition at line 235 of file MoveSplineInit.cpp.

236 {
238 {
239 if (Unit* vehicle = unit->GetVehicleBase())
240 angle -= vehicle->GetOrientation();
241 else if (TransportBase* transport = unit->GetTransport())
242 angle -= transport->GetTransportOrientation();
243 }
244
245 args.facing.angle = G3D::wrap(angle, 0.f, (float)G3D::twoPi());
247 }
Definition: Unit.h:622
Unit * GetVehicleBase() const
Definition: Unit.cpp:11403
TransportBase * GetTransport() const
Definition: Object.h:730
@ MONSTER_MOVE_FACING_ANGLE
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetFacing() [2/4]

void Movement::MoveSplineInit::SetFacing ( float  x,
float  y,
float  z 
)

Definition at line 223 of file MoveSplineInit.cpp.

224 {
225 SetFacing({ x, y, z });
226 }
void SetFacing(float angle)
+ Here is the call graph for this function:

◆ SetFacing() [3/4]

void Movement::MoveSplineInit::SetFacing ( Unit const *  target)

Definition at line 228 of file MoveSplineInit.cpp.

229 {
231 args.facing.target = target->GetGUID();
233 }
@ MONSTER_MOVE_FACING_TARGET
float GetAbsoluteAngle(float x, float y) const
Definition: Position.h:125
+ Here is the call graph for this function:

◆ SetFacing() [4/4]

void Movement::MoveSplineInit::SetFacing ( Vector3 const &  point)

Definition at line 213 of file MoveSplineInit.cpp.

214 {
215 TransportPathTransform transform(unit, args.TransformForTransport);
216 Vector3 finalSpot = transform(spot);
217 args.facing.f.x = finalSpot.x;
218 args.facing.f.y = finalSpot.y;
219 args.facing.f.z = finalSpot.z;
221 }
@ MONSTER_MOVE_FACING_SPOT
struct Movement::FacingInfo::@321 f

◆ SetFall()

void Movement::MoveSplineInit::SetFall ( )

Definition at line 280 of file MoveSplineInit.cpp.

+ Here is the call graph for this function:

◆ SetFirstPointId()

void Movement::MoveSplineInit::SetFirstPointId ( int32  pointId)
inline

Definition at line 107 of file MoveSplineInit.h.

107{ args.path_Idx_offset = pointId; }
+ Here is the caller graph for this function:

◆ SetFly()

void Movement::MoveSplineInit::SetFly ( )
inline

Definition at line 175 of file MoveSplineInit.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetOrientationFixed()

void Movement::MoveSplineInit::SetOrientationFixed ( bool  enable)
inline

Definition at line 184 of file MoveSplineInit.h.

+ Here is the caller graph for this function:

◆ SetParabolic()

void Movement::MoveSplineInit::SetParabolic ( float  amplitude,
float  start_time 
)
inline

Definition at line 187 of file MoveSplineInit.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetParabolicVerticalAcceleration()

void Movement::MoveSplineInit::SetParabolicVerticalAcceleration ( float  vertical_acceleration,
float  time_shift 
)
inline

Definition at line 195 of file MoveSplineInit.h.

196 {
197 args.effect_start_time_percent = time_shift;
199 args.vertical_acceleration = vertical_acceleration;
201 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetSmooth()

void Movement::MoveSplineInit::SetSmooth ( )
inline

Definition at line 177 of file MoveSplineInit.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetSpellEffectExtraData()

void Movement::MoveSplineInit::SetSpellEffectExtraData ( SpellEffectExtraData const &  spellEffectExtraData)
inline

Definition at line 215 of file MoveSplineInit.h.

216 {
217 args.spellEffectExtra = spellEffectExtraData;
218 }
Optional< SpellEffectExtraData > spellEffectExtra
+ Here is the caller graph for this function:

◆ SetTransportEnter()

void Movement::MoveSplineInit::SetTransportEnter ( )
inline

Definition at line 182 of file MoveSplineInit.h.

+ Here is the call graph for this function:

◆ SetTransportExit()

void Movement::MoveSplineInit::SetTransportExit ( )
inline

Definition at line 183 of file MoveSplineInit.h.

+ Here is the call graph for this function:

◆ SetUncompressed()

void Movement::MoveSplineInit::SetUncompressed ( )
inline

Definition at line 178 of file MoveSplineInit.h.

+ Here is the caller graph for this function:

◆ SetUnlimitedSpeed()

void Movement::MoveSplineInit::SetUnlimitedSpeed ( )
inline

Definition at line 185 of file MoveSplineInit.h.

185{ args.flags.unlimitedSpeed = true; }
+ Here is the caller graph for this function:

◆ SetVelocity()

void Movement::MoveSplineInit::SetVelocity ( float  velocity)
inline

Definition at line 180 of file MoveSplineInit.h.

180{ args.velocity = vel; args.HasVelocity = true; }
+ Here is the caller graph for this function:

◆ SetWalk()

void Movement::MoveSplineInit::SetWalk ( bool  enable)
inline

Definition at line 176 of file MoveSplineInit.h.

176{ args.walk = enable; }
+ Here is the caller graph for this function:

◆ Stop()

void Movement::MoveSplineInit::Stop ( )

Definition at line 152 of file MoveSplineInit.cpp.

153 {
154 MoveSpline& move_spline = *unit->movespline;
155
156 // No need to stop if we are not moving
157 if (move_spline.Finalized())
158 return;
159
160 bool transport = !unit->GetTransGUID().IsEmpty();
161 Location loc;
162 if (move_spline.onTransport == transport)
163 loc = move_spline.ComputePosition();
164 else
165 {
166 Position const* pos;
167 if (!transport)
168 pos = unit;
169 else
171
172 loc.x = pos->GetPositionX();
173 loc.y = pos->GetPositionY();
174 loc.z = pos->GetPositionZ();
175 loc.orientation = unit->GetOrientation();
176 }
177
180 move_spline.onTransport = transport;
181 move_spline.Initialize(args);
182
184 packet.MoverGUID = unit->GetGUID();
185 packet.Pos = Position(loc.x, loc.y, loc.z, loc.orientation);
187 packet.SplineData.ID = move_spline.GetId();
188
189 if (transport)
190 {
193 }
194
195 unit->SendMessageToSet(packet.Write(), true);
196 }
void RemoveMovementFlag(uint32 flag)
Definition: MovementInfo.h:111
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ args

MoveSplineInitArgs Movement::MoveSplineInit::args
protected

Definition at line 171 of file MoveSplineInit.h.

◆ unit

Unit* Movement::MoveSplineInit::unit
protected

Definition at line 172 of file MoveSplineInit.h.


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