Project SkyFire Core
SkyFire 5.4.8 server core API documentation
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
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
15namespace Movement
16{
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
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
101 PacketBuilder::WriteMonsterMove(move_spline, data, unit);
102 unit->SendMessageToSet(&data, true);
103
104 return move_spline.Duration();
105 }
106
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();
117 unit->m_movementInfo.RemoveMovementFlag(MOVEMENTFLAG_FORWARD);
118 move_spline.Initialize(args);
119
121
122 PacketBuilder::WriteStopMovement(loc, args.splineId, data, unit);
123 unit->SendMessageToSet(&data, true);
124 }
125
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
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
177 {
178 args.flags.EnableFalling();
179 args.flags.fallingSlow = unit->HasUnitMovementFlag(MOVEMENTFLAG_FALLING_SLOW);
180 }
181
183 {
185 if (TransportBase* transport = _owner->GetDirectTransport())
186 transport->CalculatePassengerOffset(input.x, input.y, input.z);
187
188 return input;
189 }
190}
std::int32_t int32
Definition Define.h:73
std::uint32_t uint32
Definition Define.h:77
@ PATHFIND_NOPATH
MovementFlags
Definition Unit.h:721
@ MOVEMENTFLAG_FORWARD
Definition Unit.h:723
@ MOVEMENTFLAG_BACKWARD
Definition Unit.h:724
@ MOVEMENTFLAG_MASK_MOVING
Definition Unit.h:755
@ MOVEMENTFLAG_DISABLE_GRAVITY
Definition Unit.h:732
@ MOVEMENTFLAG_FLYING
Definition Unit.h:747
@ MOVEMENTFLAG_FALLING_SLOW
Definition Unit.h:750
@ MOVEMENTFLAG_CAN_FLY
Definition Unit.h:746
@ MOVEMENTFLAG_ROOT
Definition Unit.h:733
@ MOVEMENTFLAG_SWIMMING
Definition Unit.h:743
@ MOVEMENTFLAG_WALKING
Definition Unit.h:731
UnitMoveType
Definition Unit.h:554
@ MOVE_FLIGHT
Definition Unit.h:561
@ MOVE_SWIM
Definition Unit.h:558
@ MOVE_FLIGHT_BACK
Definition Unit.h:562
@ MOVE_SWIM_BACK
Definition Unit.h:559
@ MOVE_RUN
Definition Unit.h:556
@ MOVE_RUN_BACK
Definition Unit.h:557
@ MOVE_WALK
Definition Unit.h:555
void Initialize(const MoveSplineInitArgs &)
Location ComputePosition() const
bool Finalized() const
Definition MoveSpline.h:104
int32 Duration() const
Definition MoveSpline.h:73
void SetFacing(float angle)
void MoveTo(const Vector3 &destination, bool generatePath=true, bool forceDestination=false)
MoveSplineInitArgs args
void MovebyPath(const PointsArray &path, int32 pointId=0)
static void WriteStopMovement(Vector3 const &loc, uint32 splineId, ByteBuffer &data, Unit *unit)
static void WriteMonsterMove(const MoveSpline &mov, WorldPacket &data, Unit *unit)
Vector3 operator()(Vector3 input)
uint64 GetGUID() const
Definition Object.h:119
Movement::PointsArray const & GetPath() const
PathType GetPathType() const
bool CalculatePath(float destX, float destY, float destZ, bool forceDest=false)
Definition Unit.h:1367
@ SMSG_ON_MONSTER_MOVE
Definition Opcodes.h:838
UnitMoveType SelectSpeedType(uint32 moveFlags)
UInt32Counter splineIdGen