Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
MoveSplineInit.h
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#ifndef SKYFIRESERVER_MOVESPLINEINIT_H
7#define SKYFIRESERVER_MOVESPLINEINIT_H
8
10#include "PathGenerator.h"
11
12class Unit;
13
14namespace Movement
15{
17 {
18 ToGround = 0, // 460 = ToGround, index of AnimationData.dbc
19 FlyToFly = 1, // 461 = FlyToFly?
20 ToFly = 2, // 458 = ToFly
21 FlyToGround = 3 // 463 = FlyToGround
22 };
23
24 // Transforms coordinates from global to transport offsets
26 {
27 public:
28 TransportPathTransform(Unit* owner, bool transformForTransport)
29 : _owner(owner), _transformForTransport(transformForTransport) { }
30 Vector3 operator()(Vector3 input);
31
32 private:
35 };
36
37 /* Initializes and launches spline movement
38 */
40 {
41 public:
42 explicit MoveSplineInit(Unit* m);
43
44 /* Final pass of initialization that launches spline movement.
45 */
46 int32 Launch();
47
48 /* Final pass of initialization that stops movement.
49 */
50 void Stop();
51
52 /* Adds movement by parabolic trajectory
53 * @param amplitude - the maximum height of parabola, value could be negative and positive
54 * @param start_time - delay between movement starting time and beginning to move by parabolic trajectory
55 * can't be combined with final animation
56 */
57 void SetParabolic(float amplitude, float start_time);
58 /* Plays animation after movement done
59 * can't be combined with parabolic movement
60 */
61 void SetAnimation(AnimType anim);
62
63 /* Adds final facing animation
64 * sets unit's facing to specified point/angle after all path done
65 * you can have only one final facing: previous will be overriden
66 */
67 void SetFacing(float angle);
68 void SetFacing(Vector3 const& point);
69 void SetFacing(const Unit* target);
70
71 /* Initializes movement by path
72 * @param path - array of points, shouldn't be empty
73 * @param pointId - Id of fisrt point of the path. Example: when third path point will be done it will notify that pointId + 3 done
74 */
75 void MovebyPath(const PointsArray& path, int32 pointId = 0);
76
77 /* Initializes simple A to B motion, A is current unit's position, B is destination
78 */
79 void MoveTo(const Vector3& destination, bool generatePath = true, bool forceDestination = false);
80 void MoveTo(float x, float y, float z, bool generatePath = true, bool forceDestination = false);
81
82 /* Sets Id of fisrt point of the path. When N-th path point will be done ILisener will notify that pointId + N done
83 * Needed for waypoint movement where path splitten into parts
84 */
85 void SetFirstPointId(int32 pointId) { args.path_Idx_offset = pointId; }
86
87 /* Enables CatmullRom spline interpolation mode(makes path smooth)
88 * if not enabled linear spline mode will be choosen. Disabled by default
89 */
90 void SetSmooth();
91
92 /* Waypoints in packets will be sent without compression
93 */
94 void SetUncompressed();
95
96 /* Enables flying animation. Disabled by default
97 */
98 void SetFly();
99
100 /* Enables walk mode. Disabled by default
101 */
102 void SetWalk(bool enable);
103
104 /* Makes movement cyclic. Disabled by default
105 */
106 void SetCyclic();
107
108 /* Enables falling mode. Disabled by default
109 */
110 void SetFall();
111
112 /* Enters transport. Disabled by default
113 */
114 void SetTransportEnter();
115
116 /* Exits transport. Disabled by default
117 */
118 void SetTransportExit();
119
120 /* Inverses unit model orientation. Disabled by default
121 */
123
124 /* Fixes unit's model rotation. Disabled by default
125 */
126 void SetOrientationFixed(bool enable);
127
128 /* Sets the velocity (in case you want to have custom movement velocity)
129 * if no set, speed will be selected based on unit's speeds and current movement mode
130 * Has no effect if falling mode enabled
131 * velocity shouldn't be negative
132 */
133 void SetVelocity(float velocity);
134
135 PointsArray& Path() { return args.path; }
136
137 /* Disables transport coordinate transformations for cases where raw offsets are available
138 */
140
141 protected:
144 };
145
146 inline void MoveSplineInit::SetFly() { args.flags.EnableFlying(); }
147 inline void MoveSplineInit::SetWalk(bool enable) { args.flags.walkmode = enable; }
148 inline void MoveSplineInit::SetSmooth() { args.flags.EnableCatmullRom(); }
149 inline void MoveSplineInit::SetUncompressed() { args.flags.uncompressedPath = true; }
150 inline void MoveSplineInit::SetCyclic() { args.flags.cyclic = true; }
151 inline void MoveSplineInit::SetVelocity(float vel) { args.velocity = vel; args.HasVelocity = true; }
152 inline void MoveSplineInit::SetOrientationInversed() { args.flags.orientationInversed = true; }
153 inline void MoveSplineInit::SetTransportEnter() { args.flags.EnableTransportEnter(); }
154 inline void MoveSplineInit::SetTransportExit() { args.flags.EnableTransportExit(); }
155 inline void MoveSplineInit::SetOrientationFixed(bool enable) { args.flags.orientationFixed = enable; }
156
157 inline void MoveSplineInit::MovebyPath(const PointsArray& controls, int32 path_offset)
158 {
159 args.path_Idx_offset = path_offset;
160 args.path.resize(controls.size());
161 std::transform(controls.begin(), controls.end(), args.path.begin(), TransportPathTransform(unit, args.TransformForTransport));
162 }
163
164 inline void MoveSplineInit::MoveTo(float x, float y, float z, bool generatePath, bool forceDestination)
165 {
166 MoveTo(G3D::Vector3(x, y, z), generatePath, forceDestination);
167 }
168
169 inline void MoveSplineInit::SetParabolic(float amplitude, float time_shift)
170 {
171 args.time_perc = time_shift;
172 args.parabolic_amplitude = amplitude;
173 args.flags.EnableParabolic();
174 }
175
177 {
178 args.time_perc = 0.f;
179 args.flags.EnableAnimation((uint8)anim);
180 }
181
182 inline void MoveSplineInit::SetFacing(Vector3 const& spot)
183 {
184 TransportPathTransform transform(unit, args.TransformForTransport);
185 Vector3 finalSpot = transform(spot);
186 args.facing.f.x = finalSpot.x;
187 args.facing.f.y = finalSpot.y;
188 args.facing.f.z = finalSpot.z;
189 args.flags.EnableFacingPoint();
190 }
191
192 inline void MoveSplineInit::DisableTransportPathTransformations() { args.TransformForTransport = false; }
193}
194#endif // SKYFIRESERVER_MOVESPLINEINIT_H
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
void SetAnimation(AnimType anim)
void SetWalk(bool enable)
void SetFirstPointId(int32 pointId)
void SetParabolic(float amplitude, float start_time)
void SetVelocity(float velocity)
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)
void SetOrientationFixed(bool enable)
Vector3 operator()(Vector3 input)
TransportPathTransform(Unit *owner, bool transformForTransport)
Definition Unit.h:1367
std::vector< Vector3 > PointsArray