Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
MoveSplineInit.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#include "
MovementPacketBuilder.h
"
7
#include "
MoveSpline.h
"
8
#include "
MoveSplineInit.h
"
9
#include "
Opcodes.h
"
10
#include "
Transport.h
"
11
#include "
Unit.h
"
12
#include "
Vehicle.h
"
13
#include "
WorldPacket.h
"
14
15
namespace
Movement
16
{
17
UnitMoveType
SelectSpeedType
(
uint32
moveFlags)
18
{
19
if
(moveFlags &
MOVEMENTFLAG_FLYING
)
20
{
21
if
(moveFlags &
MOVEMENTFLAG_BACKWARD
/*&& speed_obj.flight >= speed_obj.flight_back*/
)
22
return
MOVE_FLIGHT_BACK
;
23
else
24
return
MOVE_FLIGHT
;
25
}
26
else
if
(moveFlags &
MOVEMENTFLAG_SWIMMING
)
27
{
28
if
(moveFlags &
MOVEMENTFLAG_BACKWARD
/*&& speed_obj.swim >= speed_obj.swim_back*/
)
29
return
MOVE_SWIM_BACK
;
30
else
31
return
MOVE_SWIM
;
32
}
33
else
if
(moveFlags &
MOVEMENTFLAG_WALKING
)
34
{
35
//if (speed_obj.run > speed_obj.walk)
36
return
MOVE_WALK
;
37
}
38
else
if
(moveFlags &
MOVEMENTFLAG_BACKWARD
/*&& speed_obj.run >= speed_obj.run_back*/
)
39
return
MOVE_RUN_BACK
;
40
41
// Flying creatures use MOVEMENTFLAG_CAN_FLY or MOVEMENTFLAG_DISABLE_GRAVITY
42
// Run speed is their default flight speed.
43
return
MOVE_RUN
;
44
}
45
46
int32
MoveSplineInit::Launch
()
47
{
48
MoveSpline
& move_spline = *
unit
->movespline;
49
50
Location
real_position(
unit
->GetPositionX(),
unit
->GetPositionY(),
unit
->GetPositionZMinusOffset(),
unit
->GetOrientation());
51
// Elevators also use MOVEMENTFLAG_ONTRANSPORT but we do not keep track of their position changes
52
if
(
unit
->GetTransGUID())
53
{
54
real_position.x =
unit
->GetTransOffsetX();
55
real_position.y =
unit
->GetTransOffsetY();
56
real_position.z =
unit
->GetTransOffsetZ();
57
real_position.
orientation
=
unit
->GetTransOffsetO();
58
}
59
60
// there is a big chance that current position is unknown if current state is not finalized, need compute it
61
// this also allows calculate spline position and update map position in much greater intervals
62
// Don't compute for transport movement if the unit is in a motion between two transports
63
if
(!move_spline.
Finalized
() && move_spline.
onTransport
== (
unit
->GetTransGUID() != 0))
64
real_position = move_spline.
ComputePosition
();
65
66
// should i do the things that user should do? - no.
67
if
(
args
.path.empty())
68
return
0;
69
70
// correct first vertex
71
args
.path[0] = real_position;
72
args
.initialOrientation = real_position.
orientation
;
73
move_spline.
onTransport
= (
unit
->GetTransGUID() != 0);
74
75
uint32
moveFlags =
unit
->m_movementInfo.GetMovementFlags();
76
moveFlags |=
MOVEMENTFLAG_FORWARD
;
77
78
if
(moveFlags &
MOVEMENTFLAG_ROOT
)
79
moveFlags &=
~MOVEMENTFLAG_MASK_MOVING
;
80
81
if
(!
args
.HasVelocity)
82
{
83
// If spline is initialized with SetWalk method it only means we need to select
84
// walk move speed for it but not add walk flag to unit
85
uint32
moveFlagsForSpeed = moveFlags;
86
if
(
args
.flags.walkmode)
87
moveFlagsForSpeed |=
MOVEMENTFLAG_WALKING
;
88
else
89
moveFlagsForSpeed &=
~MOVEMENTFLAG_WALKING
;
90
91
args
.velocity =
unit
->GetSpeed(
SelectSpeedType
(moveFlagsForSpeed));
92
}
93
94
if
(!
args
.Validate(
unit
))
95
return
0;
96
97
unit
->m_movementInfo.SetMovementFlags(moveFlags);
98
move_spline.
Initialize
(
args
);
99
100
WorldPacket
data(
SMSG_ON_MONSTER_MOVE
, 64);
101
PacketBuilder::WriteMonsterMove
(move_spline, data,
unit
);
102
unit
->SendMessageToSet(&data,
true
);
103
104
return
move_spline.
Duration
();
105
}
106
107
void
MoveSplineInit::Stop
()
108
{
109
MoveSpline
& move_spline = *
unit
->movespline;
110
111
// No need to stop if we are not moving
112
if
(move_spline.
Finalized
())
113
return
;
114
115
Location
loc = move_spline.
ComputePosition
();
116
args
.flags =
MoveSplineFlag::Done
;
117
unit
->m_movementInfo.RemoveMovementFlag(
MOVEMENTFLAG_FORWARD
);
118
move_spline.
Initialize
(
args
);
119
120
WorldPacket
data(
SMSG_ON_MONSTER_MOVE
, 64);
121
122
PacketBuilder::WriteStopMovement
(loc,
args
.splineId, data,
unit
);
123
unit
->SendMessageToSet(&data,
true
);
124
}
125
126
MoveSplineInit::MoveSplineInit
(
Unit
* m) :
unit
(m)
127
{
128
args
.splineId =
splineIdGen
.NewId();
129
// Elevators also use MOVEMENTFLAG_ONTRANSPORT but we do not keep track of their position changes
130
args
.TransformForTransport =
unit
->GetTransGUID();
131
// mix existing state into new
132
args
.flags.walkmode =
unit
->m_movementInfo.HasMovementFlag(
MOVEMENTFLAG_WALKING
);
133
args
.flags.flying =
unit
->m_movementInfo.HasMovementFlag(
MovementFlags
(
MOVEMENTFLAG_CAN_FLY
|
MOVEMENTFLAG_DISABLE_GRAVITY
));
134
args
.flags.smoothGroundPath =
true
;
// enabled by default, CatmullRom mode or client config "pathSmoothing" will disable this
135
}
136
137
void
MoveSplineInit::SetFacing
(
const
Unit
* target)
138
{
139
args
.flags.EnableFacingTarget();
140
args
.facing.target = target->
GetGUID
();
141
}
142
143
void
MoveSplineInit::SetFacing
(
float
angle)
144
{
145
if
(
args
.TransformForTransport)
146
{
147
if
(
Unit
* vehicle =
unit
->GetVehicleBase())
148
angle -= vehicle->GetOrientation();
149
else
if
(
Transport
* transport =
unit
->GetTransport())
150
angle -= transport->GetOrientation();
151
}
152
153
args
.facing.angle = G3D::wrap(angle, 0.f, (
float
)G3D::twoPi());
154
args
.flags.EnableFacingAngle();
155
}
156
157
void
MoveSplineInit::MoveTo
(
const
Vector3& dest,
bool
generatePath,
bool
forceDestination)
158
{
159
if
(generatePath)
160
{
161
PathGenerator
path(
unit
);
162
bool
result = path.
CalculatePath
(dest.x, dest.y, dest.z, forceDestination);
163
if
(result && !(path.
GetPathType
() &
PATHFIND_NOPATH
))
164
{
165
MovebyPath
(path.
GetPath
());
166
return
;
167
}
168
}
169
170
args
.path_Idx_offset = 0;
171
args
.path.resize(2);
172
TransportPathTransform
transform(
unit
,
args
.TransformForTransport);
173
args
.path[1] = transform(dest);
174
}
175
176
void
MoveSplineInit::SetFall
()
177
{
178
args
.flags.EnableFalling();
179
args
.flags.fallingSlow =
unit
->HasUnitMovementFlag(
MOVEMENTFLAG_FALLING_SLOW
);
180
}
181
182
Vector3
TransportPathTransform::operator()
(Vector3 input)
183
{
184
if
(
_transformForTransport
)
185
if
(
TransportBase
* transport =
_owner
->GetDirectTransport())
186
transport->CalculatePassengerOffset(input.x, input.y, input.z);
187
188
return
input;
189
}
190
}
int32
std::int32_t int32
Definition
Define.h:73
uint32
std::uint32_t uint32
Definition
Define.h:77
MoveSpline.h
MoveSplineInit.h
MovementPacketBuilder.h
Opcodes.h
PATHFIND_NOPATH
@ PATHFIND_NOPATH
Definition
PathGenerator.h:34
Transport.h
Unit.h
MovementFlags
MovementFlags
Definition
Unit.h:721
MOVEMENTFLAG_FORWARD
@ MOVEMENTFLAG_FORWARD
Definition
Unit.h:723
MOVEMENTFLAG_BACKWARD
@ MOVEMENTFLAG_BACKWARD
Definition
Unit.h:724
MOVEMENTFLAG_MASK_MOVING
@ MOVEMENTFLAG_MASK_MOVING
Definition
Unit.h:755
MOVEMENTFLAG_DISABLE_GRAVITY
@ MOVEMENTFLAG_DISABLE_GRAVITY
Definition
Unit.h:732
MOVEMENTFLAG_FLYING
@ MOVEMENTFLAG_FLYING
Definition
Unit.h:747
MOVEMENTFLAG_FALLING_SLOW
@ MOVEMENTFLAG_FALLING_SLOW
Definition
Unit.h:750
MOVEMENTFLAG_CAN_FLY
@ MOVEMENTFLAG_CAN_FLY
Definition
Unit.h:746
MOVEMENTFLAG_ROOT
@ MOVEMENTFLAG_ROOT
Definition
Unit.h:733
MOVEMENTFLAG_SWIMMING
@ MOVEMENTFLAG_SWIMMING
Definition
Unit.h:743
MOVEMENTFLAG_WALKING
@ MOVEMENTFLAG_WALKING
Definition
Unit.h:731
UnitMoveType
UnitMoveType
Definition
Unit.h:554
MOVE_FLIGHT
@ MOVE_FLIGHT
Definition
Unit.h:561
MOVE_SWIM
@ MOVE_SWIM
Definition
Unit.h:558
MOVE_FLIGHT_BACK
@ MOVE_FLIGHT_BACK
Definition
Unit.h:562
MOVE_SWIM_BACK
@ MOVE_SWIM_BACK
Definition
Unit.h:559
MOVE_RUN
@ MOVE_RUN
Definition
Unit.h:556
MOVE_RUN_BACK
@ MOVE_RUN_BACK
Definition
Unit.h:557
MOVE_WALK
@ MOVE_WALK
Definition
Unit.h:555
Vehicle.h
WorldPacket.h
Movement::MoveSplineFlag::Done
@ Done
Definition
MoveSplineFlag.h:29
Movement::MoveSpline
Definition
MoveSpline.h:28
Movement::MoveSpline::Initialize
void Initialize(const MoveSplineInitArgs &)
Definition
MoveSpline.cpp:142
Movement::MoveSpline::ComputePosition
Location ComputePosition() const
Definition
MoveSpline.cpp:13
Movement::MoveSpline::Finalized
bool Finalized() const
Definition
MoveSpline.h:104
Movement::MoveSpline::Duration
int32 Duration() const
Definition
MoveSpline.h:73
Movement::MoveSpline::onTransport
bool onTransport
Definition
MoveSpline.h:111
Movement::MoveSplineInit::MoveSplineInit
MoveSplineInit(Unit *m)
Definition
MoveSplineInit.cpp:126
Movement::MoveSplineInit::Launch
int32 Launch()
Definition
MoveSplineInit.cpp:46
Movement::MoveSplineInit::SetFacing
void SetFacing(float angle)
Definition
MoveSplineInit.cpp:143
Movement::MoveSplineInit::MoveTo
void MoveTo(const Vector3 &destination, bool generatePath=true, bool forceDestination=false)
Definition
MoveSplineInit.cpp:157
Movement::MoveSplineInit::Stop
void Stop()
Definition
MoveSplineInit.cpp:107
Movement::MoveSplineInit::args
MoveSplineInitArgs args
Definition
MoveSplineInit.h:142
Movement::MoveSplineInit::MovebyPath
void MovebyPath(const PointsArray &path, int32 pointId=0)
Definition
MoveSplineInit.h:157
Movement::MoveSplineInit::SetFall
void SetFall()
Definition
MoveSplineInit.cpp:176
Movement::MoveSplineInit::unit
Unit * unit
Definition
MoveSplineInit.h:143
Movement::PacketBuilder::WriteStopMovement
static void WriteStopMovement(Vector3 const &loc, uint32 splineId, ByteBuffer &data, Unit *unit)
Definition
MovementPacketBuilder.cpp:39
Movement::PacketBuilder::WriteMonsterMove
static void WriteMonsterMove(const MoveSpline &mov, WorldPacket &data, Unit *unit)
Definition
MovementPacketBuilder.cpp:140
Movement::TransportPathTransform
Definition
MoveSplineInit.h:26
Movement::TransportPathTransform::_owner
Unit * _owner
Definition
MoveSplineInit.h:33
Movement::TransportPathTransform::operator()
Vector3 operator()(Vector3 input)
Definition
MoveSplineInit.cpp:182
Movement::TransportPathTransform::_transformForTransport
bool _transformForTransport
Definition
MoveSplineInit.h:34
Object::GetGUID
uint64 GetGUID() const
Definition
Object.h:119
PathGenerator
Definition
PathGenerator.h:40
PathGenerator::GetPath
Movement::PointsArray const & GetPath() const
Definition
PathGenerator.h:58
PathGenerator::GetPathType
PathType GetPathType() const
Definition
PathGenerator.h:60
PathGenerator::CalculatePath
bool CalculatePath(float destX, float destY, float destZ, bool forceDest=false)
Definition
PathGenerator.cpp:42
TransportBase
Definition
VehicleDefines.h:121
Transport
Definition
Transport.h:16
Unit
Definition
Unit.h:1367
WorldPacket
Definition
WorldPacket.h:16
SMSG_ON_MONSTER_MOVE
@ SMSG_ON_MONSTER_MOVE
Definition
Opcodes.h:838
Movement
Definition
Unit.h:365
Movement::SelectSpeedType
UnitMoveType SelectSpeedType(uint32 moveFlags)
Definition
MoveSplineInit.cpp:17
Movement::splineIdGen
UInt32Counter splineIdGen
Definition
MovementUtil.cpp:13
Movement::Location
Definition
MoveSpline.h:15
Movement::Location::orientation
float orientation
Definition
MoveSpline.h:21
src
server
game
Movement
Spline
MoveSplineInit.cpp
Generated on
for Project SkyFire Core by
1.17.0