AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Movement::MoveSplineInit Class Reference

#include "MoveSplineInit.h"

Public Member Functions

 MoveSplineInit (Unit *m)
 
int32 Launch ()
 
void Stop ()
 
void SetParabolic (float amplitude, float start_time)
 
void SetAnimation (AnimType anim)
 
void SetFacing (float angle)
 
void SetFacing (Vector3 const &point)
 
void SetFacing (Unit const *target)
 
void MovebyPath (const PointsArray &path, int32 pointId=0)
 
void MoveTo (const Vector3 &destination, bool generatePath=false, bool forceDestination=false)
 
void MoveTo (float x, float y, float z, bool generatePath=false, bool forceDestination=false)
 
void SetFirstPointId (int32 pointId)
 
void SetSmooth ()
 
void SetFly ()
 
void SetWalk (bool enable)
 
void SetCyclic ()
 
void SetFall ()
 
void SetTransportEnter ()
 
void SetTransportExit ()
 
void SetOrientationInversed ()
 
void SetOrientationFixed (bool enable)
 
void SetVelocity (float velocity)
 
PointsArrayPath ()
 
void DisableTransportPathTransformations ()
 

Protected Attributes

MoveSplineInitArgs args
 
Unitunit
 

Detailed Description

Constructor & Destructor Documentation

◆ MoveSplineInit()

Movement::MoveSplineInit::MoveSplineInit ( Unit m)
explicit
190 : unit(m)
191 {
194 // mix existing state into new
197 }
MovementFlags
Definition: UnitDefines.h:342
@ MOVEMENTFLAG_ONTRANSPORT
Definition: UnitDefines.h:353
@ MOVEMENTFLAG_DISABLE_GRAVITY
Definition: UnitDefines.h:354
@ MOVEMENTFLAG_CAN_FLY
Definition: UnitDefines.h:368
@ MOVEMENTFLAG_WALKING
Definition: UnitDefines.h:352
UInt32Counter splineIdGen
Definition: MovementUtil.cpp:25
bool HasMovementFlag(uint32 flag) const
Definition: Object.h:334
MovementInfo m_movementInfo
Definition: Object.h:609
bool HasUnitMovementFlag(uint32 f) const
Definition: Unit.h:736
ObjectGuid GetTransGUID() const override
Definition: Unit.cpp:18757
T NewId()
Definition: MovementTypedefs.h:63
bool flying
Definition: MoveSplineFlag.h:121
bool walkmode
Definition: MoveSplineFlag.h:120
MoveSplineInitArgs args
Definition: MoveSplineInit.h:160
Unit * unit
Definition: MoveSplineInit.h:161
MoveSplineFlag flags
Definition: MoveSplineInitArgs.h:53
uint32 splineId
Definition: MoveSplineInitArgs.h:58
bool TransformForTransport
Definition: MoveSplineInitArgs.h:61

References args, Movement::MoveSplineInitArgs::flags, Movement::MoveSplineFlag::flying, Unit::GetTransGUID(), MovementInfo::HasMovementFlag(), Unit::HasUnitMovementFlag(), WorldObject::m_movementInfo, MOVEMENTFLAG_CAN_FLY, MOVEMENTFLAG_DISABLE_GRAVITY, MOVEMENTFLAG_ONTRANSPORT, MOVEMENTFLAG_WALKING, Movement::counter< T, limit >::NewId(), Movement::MoveSplineInitArgs::splineId, Movement::splineIdGen, Movement::MoveSplineInitArgs::TransformForTransport, unit, and Movement::MoveSplineFlag::walkmode.

Member Function Documentation

◆ DisableTransportPathTransformations()

◆ Launch()

int32 Movement::MoveSplineInit::Launch ( )
59 {
60 MoveSpline& move_spline = *unit->movespline;
61
63 Location real_position;
64 // there is a big chance that current position is unknown if current state is not finalized, need compute it
65 // this also allows CalculatePath spline position and update map position in much greater intervals
66 // Don't compute for transport movement if the unit is in a motion between two transports
67 if (!move_spline.Finalized() && move_spline.onTransport == transport)
68 real_position = move_spline.ComputePosition();
69 else
70 {
71 Position const* pos;
72 if (!transport)
73 pos = unit;
74 else
76
77 real_position.x = pos->GetPositionX();
78 real_position.y = pos->GetPositionY();
79 real_position.z = pos->GetPositionZ();
80 real_position.orientation = unit->GetOrientation();
81 }
82
83 // should i do the things that user should do? - no.
84 if (args.path.empty())
85 return 0;
86
87 // corrent first vertex
88 args.path[0] = real_position;
89 args.initialOrientation = real_position.orientation;
90 move_spline.onTransport = transport;
91
93 moveFlags |= MOVEMENTFLAG_SPLINE_ENABLED;
94
96 {
97 moveFlags = (moveFlags & ~(MOVEMENTFLAG_BACKWARD)) | MOVEMENTFLAG_FORWARD;
98 }
99 else
100 {
101 moveFlags = (moveFlags & ~(MOVEMENTFLAG_FORWARD)) | MOVEMENTFLAG_BACKWARD;
102 }
103
104 bool isOrientationOnly = args.path.size() == 2 && args.path[0] == args.path[1];
105
106 if ((moveFlags & MOVEMENTFLAG_ROOT) || isOrientationOnly)
107 moveFlags &= ~MOVEMENTFLAG_MASK_MOVING;
108
109 if (!args.HasVelocity)
110 {
111 // If spline is initialized with SetWalk method it only means we need to select
112 // walk move speed for it but not add walk flag to unit
113 uint32 moveFlagsForSpeed = moveFlags;
114 if (args.flags.walkmode)
115 moveFlagsForSpeed |= MOVEMENTFLAG_WALKING;
116 else
117 moveFlagsForSpeed &= ~MOVEMENTFLAG_WALKING;
118
119 args.velocity = unit->GetSpeed(SelectSpeedType(moveFlagsForSpeed));
120 }
121
122 // limit the speed in the same way the client does
123 args.velocity = std::min(args.velocity, args.flags.catmullrom || args.flags.flying ? 50.0f : std::max(28.0f, unit->GetSpeed(MOVE_RUN) * 4.0f));
124
125 if (!args.Validate(unit))
126 return 0;
127
129 move_spline.Initialize(args);
130
132 data << unit->GetPackGUID();
133 if (transport)
134 {
135 data.SetOpcode(SMSG_MONSTER_MOVE_TRANSPORT);
136 data << unit->GetTransGUID().WriteAsPacked();
137 data << int8(unit->GetTransSeat());
138 }
139
140 PacketBuilder::WriteMonsterMove(move_spline, data);
141 unit->SendMessageToSet(&data, true);
142
143 return move_spline.Duration();
144 }
std::uint32_t uint32
Definition: Define.h:107
std::int8_t int8
Definition: Define.h:105
@ MOVEMENTFLAG_SPLINE_ENABLED
Definition: UnitDefines.h:371
@ MOVEMENTFLAG_FORWARD
Definition: UnitDefines.h:344
@ MOVEMENTFLAG_BACKWARD
Definition: UnitDefines.h:345
@ MOVEMENTFLAG_MASK_MOVING
Definition: UnitDefines.h:377
@ MOVEMENTFLAG_ROOT
Definition: UnitDefines.h:355
@ MOVE_RUN
Definition: UnitDefines.h:329
@ SMSG_MONSTER_MOVE
Definition: Opcodes.h:251
@ SMSG_MONSTER_MOVE_TRANSPORT
Definition: Opcodes.h:716
UnitMoveType SelectSpeedType(uint32 moveFlags)
Definition: MoveSplineInit.cpp:29
PackedGuid const & GetPackGUID() const
Definition: Object.h:111
struct MovementInfo::TransportInfo transport
void SetMovementFlags(uint32 flag)
Definition: Object.h:331
uint32 GetMovementFlags() const
Definition: Object.h:330
Position pos
Definition: Object.h:297
int8 GetTransSeat() const
Definition: Object.h:605
virtual void SendMessageToSet(WorldPacket const *data, bool self) const
Definition: Object.cpp:2080
PackedGuid WriteAsPacked() const
Definition: ObjectGuid.h:316
Definition: Position.h:27
float GetPositionZ() const
Definition: Position.h:118
float GetOrientation() const
Definition: Position.h:119
float GetPositionX() const
Definition: Position.h:116
float GetPositionY() const
Definition: Position.h:117
Movement::MoveSpline * movespline
Definition: Unit.h:1982
float GetSpeed(UnitMoveType mtype) const
Definition: Unit.cpp:14424
static void WriteMonsterMove(const MoveSpline &mov, ByteBuffer &data)
Definition: MovementPacketBuilder.cpp:142
bool catmullrom
Definition: MoveSplineFlag.h:126
bool orientationInversed
Definition: MoveSplineFlag.h:135
bool Validate(Unit *unit) const
============================================================================================
Definition: MoveSpline.cpp:201
PointsArray path
Definition: MoveSplineInitArgs.h:51
float initialOrientation
Definition: MoveSplineInitArgs.h:59
bool HasVelocity
Definition: MoveSplineInitArgs.h:60
float velocity
Definition: MoveSplineInitArgs.h:55
Definition: WorldPacket.h:26
Definition: zone_shadowmoon_valley.cpp:839
float y
Definition: zone_shadowmoon_valley.cpp:840
float z
Definition: zone_shadowmoon_valley.cpp:840
float x
Definition: zone_shadowmoon_valley.cpp:840

References args, Movement::MoveSplineFlag::catmullrom, Movement::MoveSpline::ComputePosition(), Movement::MoveSpline::Duration(), Movement::MoveSpline::Finalized(), Movement::MoveSplineInitArgs::flags, Movement::MoveSplineFlag::flying, MovementInfo::GetMovementFlags(), Position::GetOrientation(), Object::GetPackGUID(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), Unit::GetSpeed(), Unit::GetTransGUID(), WorldObject::GetTransSeat(), Unit::HasUnitMovementFlag(), Movement::MoveSplineInitArgs::HasVelocity, Movement::MoveSpline::Initialize(), Movement::MoveSplineInitArgs::initialOrientation, WorldObject::m_movementInfo, MOVE_RUN, MOVEMENTFLAG_BACKWARD, MOVEMENTFLAG_FORWARD, MOVEMENTFLAG_MASK_MOVING, MOVEMENTFLAG_ONTRANSPORT, MOVEMENTFLAG_ROOT, MOVEMENTFLAG_SPLINE_ENABLED, MOVEMENTFLAG_WALKING, Unit::movespline, Movement::MoveSpline::onTransport, Movement::Location::orientation, Movement::MoveSplineFlag::orientationInversed, Movement::MoveSplineInitArgs::path, MovementInfo::TransportInfo::pos, Movement::SelectSpeedType(), WorldObject::SendMessageToSet(), MovementInfo::SetMovementFlags(), WorldPacket::SetOpcode(), SMSG_MONSTER_MOVE, SMSG_MONSTER_MOVE_TRANSPORT, MovementInfo::transport, unit, Movement::MoveSplineInitArgs::Validate(), Movement::MoveSplineInitArgs::velocity, Movement::MoveSplineFlag::walkmode, ObjectGuid::WriteAsPacked(), and Movement::PacketBuilder::WriteMonsterMove().

Referenced by Unit::_ExitVehicle(), RandomMovementGenerator< T >::_setRandomLocation(), HomeMovementGenerator< Creature >::_setTargetLocation(), Vehicle::AddPassenger(), npc_high_overlord_saurfang_igb::npc_high_overlord_saurfang_igbAI::DoAction(), npc_muradin_bronzebeard_igb::npc_muradin_bronzebeard_igbAI::DoAction(), boss_algalon_the_observer::boss_algalon_the_observerAI::DoAction(), EscortMovementGenerator< T >::DoInitialize(), FlightPathMovementGenerator::DoReset(), ConfusedMovementGenerator< T >::DoUpdate(), EscortMovementGenerator< T >::DoUpdate(), PointMovementGenerator< T >::DoUpdate(), ChaseMovementGenerator< T >::DoUpdate(), FollowMovementGenerator< T >::DoUpdate(), MoveDelayed::Execute(), npc_kalecgos_kj::JustSummoned(), npc_medivh_bm::JustSummoned(), Unit::MonsterMoveWithSpeed(), MotionMaster::MoveBackwards(), MotionMaster::MoveCharge(), MotionMaster::MoveCircleTarget(), MotionMaster::MoveFall(), MotionMaster::MoveForwards(), MotionMaster::MoveJump(), MotionMaster::MoveKnockbackFrom(), MotionMaster::MoveLand(), MotionMaster::MoveTakeoff(), npc_cosmetic_toy_plane::Reset(), Unit::SetFacingTo(), Unit::SetFacingToObject(), FleeingMovementGenerator< T >::SetTargetLocation(), WaypointMovementGenerator< Creature >::StartMove(), Unit::StopMovingOnCurrentPos(), boss_malygos::boss_malygosAI::UpdateAI(), and npc_lord_arete::npc_lord_areteAI::UpdateAI().

◆ MovebyPath()

◆ MoveTo() [1/2]

void Movement::MoveSplineInit::MoveTo ( const Vector3 &  destination,
bool  generatePath = false,
bool  forceDestination = false 
)
220 {
221 if (generatePath)
222 {
223 PathGenerator path(unit);
224 bool result = path.CalculatePath(dest.x, dest.y, dest.z, forceDestination);
225 if (result && !(path.GetPathType() & PATHFIND_NOPATH))
226 {
227 MovebyPath(path.GetPath());
228 return;
229 }
230 }
231
233 args.path.resize(2);
234 TransportPathTransform transform(unit, args.TransformForTransport);
235 args.path[1] = transform(dest);
236 }
@ PATHFIND_NOPATH
Definition: PathGenerator.h:50
Definition: PathGenerator.h:59
void MovebyPath(const PointsArray &path, int32 pointId=0)
Definition: MoveSplineInit.h:175

References args, PathGenerator::CalculatePath(), PathGenerator::GetPath(), PathGenerator::GetPathType(), MovebyPath(), Movement::MoveSplineInitArgs::path, Movement::MoveSplineInitArgs::path_Idx_offset, PATHFIND_NOPATH, Movement::MoveSplineInitArgs::TransformForTransport, and unit.

Referenced by Unit::_ExitVehicle(), RandomMovementGenerator< T >::_setRandomLocation(), HomeMovementGenerator< Creature >::_setTargetLocation(), Vehicle::AddPassenger(), boss_algalon_the_observer::boss_algalon_the_observerAI::DoAction(), EscortMovementGenerator< T >::DoInitialize(), ConfusedMovementGenerator< T >::DoUpdate(), EscortMovementGenerator< T >::DoUpdate(), PointMovementGenerator< T >::DoUpdate(), MoveDelayed::Execute(), npc_kalecgos_kj::JustSummoned(), Unit::MonsterMoveWithSpeed(), MotionMaster::MoveBackwards(), MotionMaster::MoveCircleTarget(), MotionMaster::MoveFall(), MotionMaster::MoveForwards(), MotionMaster::MoveJump(), MotionMaster::MoveKnockbackFrom(), MotionMaster::MoveLand(), MotionMaster::MoveTakeoff(), MoveTo(), Unit::SetFacingTo(), Unit::SetFacingToObject(), WaypointMovementGenerator< Creature >::StartMove(), Unit::StopMovingOnCurrentPos(), boss_malygos::boss_malygosAI::UpdateAI(), and npc_lord_arete::npc_lord_areteAI::UpdateAI().

◆ MoveTo() [2/2]

void Movement::MoveSplineInit::MoveTo ( float  x,
float  y,
float  z,
bool  generatePath = false,
bool  forceDestination = false 
)
inline
183 {
184 MoveTo(G3D::Vector3(x, y, z), generatePath, forceDestination);
185 }
void MoveTo(const Vector3 &destination, bool generatePath=false, bool forceDestination=false)
Definition: MoveSplineInit.cpp:219

References MoveTo().

◆ Path()

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

◆ SetAnimation()

void Movement::MoveSplineInit::SetAnimation ( AnimType  anim)
inline
195 {
196 args.time_perc = 0.f;
198 }
std::uint8_t uint8
Definition: Define.h:109
void EnableAnimation(uint8 anim)
Definition: MoveSplineFlag.h:104
float time_perc
Definition: MoveSplineInitArgs.h:57

References args, Movement::MoveSplineFlag::EnableAnimation(), Movement::MoveSplineInitArgs::flags, and Movement::MoveSplineInitArgs::time_perc.

Referenced by MotionMaster::MoveLand(), MotionMaster::MoveTakeoff(), and WaypointMovementGenerator< Creature >::StartMove().

◆ SetCyclic()

void Movement::MoveSplineInit::SetCyclic ( )
inline

◆ SetFacing() [1/3]

void Movement::MoveSplineInit::SetFacing ( float  angle)
206 {
208 {
209 if (Unit* vehicle = unit->GetVehicleBase())
210 angle -= vehicle->GetOrientation();
211 else if (Transport* transport = unit->GetTransport())
212 angle -= transport->GetOrientation();
213 }
214
215 args.facing.angle = G3D::wrap(angle, 0.f, (float)G3D::twoPi());
217 }
Transport * GetTransport() const
Definition: Object.h:599
Definition: Transport.h:29
Definition: Unit.h:630
Unit * GetVehicleBase() const
Definition: Unit.cpp:18743
void EnableFacingAngle()
Definition: MoveSplineFlag.h:110
float angle
Definition: MoveSplineInitArgs.h:37
FacingInfo facing
Definition: MoveSplineInitArgs.h:52

References Movement::FacingInfo::angle, args, Movement::MoveSplineFlag::EnableFacingAngle(), Movement::MoveSplineInitArgs::facing, Movement::MoveSplineInitArgs::flags, WorldObject::GetTransport(), Unit::GetVehicleBase(), Movement::MoveSplineInitArgs::TransformForTransport, and unit.

Referenced by Unit::_ExitVehicle(), HomeMovementGenerator< Creature >::_setTargetLocation(), Vehicle::AddPassenger(), PointMovementGenerator< T >::DoUpdate(), ChaseMovementGenerator< T >::DoUpdate(), MoveDelayed::Execute(), npc_kalecgos_kj::JustSummoned(), MotionMaster::MoveBackwards(), MotionMaster::MoveCircleTarget(), MotionMaster::MoveForwards(), MotionMaster::MoveJump(), Unit::SetFacingTo(), Unit::SetFacingToObject(), WaypointMovementGenerator< Creature >::StartMove(), Unit::StopMovingOnCurrentPos(), and boss_malygos::boss_malygosAI::UpdateAI().

◆ SetFacing() [2/3]

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

◆ SetFacing() [3/3]

void Movement::MoveSplineInit::SetFacing ( Vector3 const &  point)
inline
201 {
202 TransportPathTransform transform(unit, args.TransformForTransport);
203 Vector3 finalSpot = transform(spot);
204 args.facing.f.x = finalSpot.x;
205 args.facing.f.y = finalSpot.y;
206 args.facing.f.z = finalSpot.z;
208 }
void EnableFacingPoint()
Definition: MoveSplineFlag.h:109
struct Movement::FacingInfo::@299 f
float z
Definition: MoveSplineInitArgs.h:34
float x
Definition: MoveSplineInitArgs.h:34
float y
Definition: MoveSplineInitArgs.h:34

References args, Movement::MoveSplineFlag::EnableFacingPoint(), Movement::FacingInfo::f, Movement::MoveSplineInitArgs::facing, Movement::MoveSplineInitArgs::flags, Movement::MoveSplineInitArgs::TransformForTransport, unit, Movement::FacingInfo::x, Movement::FacingInfo::y, and Movement::FacingInfo::z.

◆ SetFall()

void Movement::MoveSplineInit::SetFall ( )
inline

◆ SetFirstPointId()

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

◆ SetFly()

void Movement::MoveSplineInit::SetFly ( )
inline

◆ SetOrientationFixed()

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

◆ SetOrientationInversed()

void Movement::MoveSplineInit::SetOrientationInversed ( )
inline

◆ SetParabolic()

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

◆ SetSmooth()

void Movement::MoveSplineInit::SetSmooth ( )
inline

◆ SetTransportEnter()

void Movement::MoveSplineInit::SetTransportEnter ( )
inline

◆ SetTransportExit()

void Movement::MoveSplineInit::SetTransportExit ( )
inline

◆ SetVelocity()

◆ SetWalk()

◆ Stop()

void Movement::MoveSplineInit::Stop ( )
147 {
148 MoveSpline& move_spline = *unit->movespline;
149
150 // No need to stop if we are not moving
151 if (move_spline.Finalized())
152 return;
153
155 Location loc;
156 if (move_spline.onTransport == transport)
157 loc = move_spline.ComputePosition();
158 else
159 {
160 Position const* pos;
161 if (!transport)
162 pos = unit;
163 else
165
166 loc.x = pos->GetPositionX();
167 loc.y = pos->GetPositionY();
168 loc.z = pos->GetPositionZ();
169 loc.orientation = unit->GetOrientation();
170 }
171
174 move_spline.onTransport = transport;
175 move_spline.Initialize(args);
176
178 data << unit->GetPackGUID();
179 if (transport)
180 {
181 data.SetOpcode(SMSG_MONSTER_MOVE_TRANSPORT);
182 data << unit->GetTransGUID().WriteAsPacked();
183 data << int8(unit->GetTransSeat());
184 }
185
187 unit->SendMessageToSet(&data, true);
188 }
void RemoveMovementFlag(uint32 flag)
Definition: Object.h:333
static void WriteStopMovement(Vector3 const &loc, uint32 splineId, ByteBuffer &data)
Definition: MovementPacketBuilder.cpp:91
@ Done
Definition: MoveSplineFlag.h:39

References args, Movement::MoveSpline::ComputePosition(), Movement::MoveSplineFlag::Done, Movement::MoveSpline::Finalized(), Movement::MoveSplineInitArgs::flags, Position::GetOrientation(), Object::GetPackGUID(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), Unit::GetTransGUID(), WorldObject::GetTransSeat(), Unit::HasUnitMovementFlag(), Movement::MoveSpline::Initialize(), WorldObject::m_movementInfo, MOVEMENTFLAG_BACKWARD, MOVEMENTFLAG_FORWARD, MOVEMENTFLAG_ONTRANSPORT, MOVEMENTFLAG_SPLINE_ENABLED, Unit::movespline, Movement::MoveSpline::onTransport, Movement::Location::orientation, MovementInfo::TransportInfo::pos, MovementInfo::RemoveMovementFlag(), WorldObject::SendMessageToSet(), WorldPacket::SetOpcode(), SMSG_MONSTER_MOVE, SMSG_MONSTER_MOVE_TRANSPORT, Movement::MoveSplineInitArgs::splineId, MovementInfo::transport, unit, ObjectGuid::WriteAsPacked(), and Movement::PacketBuilder::WriteStopMovement().

Referenced by Unit::StopMoving().

Member Data Documentation

◆ args

◆ unit

Unit* Movement::MoveSplineInit::unit
protected