TrinityCore
MoveSplineInit.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITYSERVER_MOVESPLINEINIT_H
19#define TRINITYSERVER_MOVESPLINEINIT_H
20
21#include "MoveSplineInitArgs.h"
22#include <variant>
23
24class ObjectGuid;
25class Unit;
26
27struct Position;
28enum class AnimTier : uint8;
29
30namespace Movement
31{
32
33 // Transforms coordinates from global to transport offsets
35 {
36 public:
37 TransportPathTransform(Unit* owner, bool transformForTransport)
38 : _owner(owner), _transformForTransport(transformForTransport) { }
39 Vector3 operator()(Vector3 input);
40
41 private:
44 };
45
46 /* Initializes and launches spline movement
47 */
49 {
50 public:
51
52 explicit MoveSplineInit(Unit* m);
53
55
60
61 /* Final pass of initialization that launches spline movement.
62 */
63 int32 Launch();
64
65 /* Final pass of initialization that stops movement.
66 */
67 void Stop();
68
69 /* Adds movement by parabolic trajectory
70 * @param amplitude - the maximum height of parabola, value could be negative and positive
71 * @param start_time - delay between movement starting time and beginning to move by parabolic trajectory
72 * can't be combined with final animation
73 */
74 void SetParabolic(float amplitude, float start_time);
75 /* Adds movement by parabolic trajectory
76 * @param vertical_acceleration - vertical acceleration
77 * @param start_time - delay between movement starting time and beginning to move by parabolic trajectory
78 * can't be combined with final animation
79 */
80 void SetParabolicVerticalAcceleration(float vertical_acceleration, float time_shift);
81 /* Plays animation after movement done
82 * can't be combined with parabolic movement
83 */
84 void SetAnimation(AnimTier anim, uint32 tierTransitionId = 0, Milliseconds transitionStartTime = 0ms);
85
86 /* Adds final facing animation
87 * sets unit's facing to specified point/angle after all path done
88 * you can have only one final facing: previous will be overriden
89 */
90 void SetFacing(float angle);
91 void SetFacing(Vector3 const& point);
92 void SetFacing(float x, float y, float z);
93 void SetFacing(Unit const* target);
94
95 /* Initializes movement by path
96 * @param path - array of points, shouldn't be empty
97 * @param pointId - Id of fisrt point of the path. Example: when third path point will be done it will notify that pointId + 3 done
98 */
99 void MovebyPath(PointsArray const& path, int32 pointId = 0);
100
101 /* Initializes simple A to B motion, A is current unit's position, B is destination
102 */
103 void MoveTo(Vector3 const& destination, bool generatePath = true, bool forceDestination = false);
104 void MoveTo(float x, float y, float z, bool generatePath = true, bool forceDestination = false);
105
106 /* Sets Id of fisrt point of the path. When N-th path point will be done ILisener will notify that pointId + N done
107 * Needed for waypoint movement where path splitten into parts
108 */
109 void SetFirstPointId(int32 pointId) { args.path_Idx_offset = pointId; }
110
111 /* Enables CatmullRom spline interpolation mode(makes path smooth)
112 * if not enabled linear spline mode will be choosen. Disabled by default
113 */
114 void SetSmooth();
115
116 /* Waypoints in packets will be sent without compression
117 */
118 void SetUncompressed();
119
120 /* Enables flying animation. Disabled by default
121 */
122 void SetFly();
123
124 /* Enables walk mode. Disabled by default
125 */
126 void SetWalk(bool enable);
127
128 /* Makes movement cyclic. Disabled by default
129 */
130 void SetCyclic();
131
132 /* Enables falling mode. Disabled by default
133 */
134 void SetFall();
135
136 /* Enters transport. Disabled by default
137 */
138 void SetTransportEnter();
139
140 /* Exits transport. Disabled by default
141 */
142 void SetTransportExit();
143
144 /* Inverses unit model orientation. Disabled by default
145 */
146 void SetBackward();
147
148 /* Fixes unit's model rotation (plays knockback animation). Disabled by default
149 */
150 void SetOrientationFixed(bool enable);
151
152 /* Fixes unit's model rotation (plays jump animation). Disabled by default
153 */
154 void SetJumpOrientationFixed(bool enable);
155
156 /* Enables avoiding minor obstacles clientside (might cause visual position on client to not be accurate with the serverside one). Disabled by default
157 */
158 void SetSteering();
159
160 /* Enables no-speed limit
161 * if not set, the speed will be limited by certain flags to 50.0f, and otherwise 28.0f
162 */
163 void SetUnlimitedSpeed();
164
165 /* Sets the velocity (in case you want to have custom movement velocity)
166 * if no set, speed will be selected based on unit's speeds and current movement mode
167 * Has no effect if falling mode enabled
168 * velocity shouldn't be negative
169 */
170 void SetVelocity(float velocity);
171
172 void SetSpellEffectExtraData(SpellEffectExtraData const& spellEffectExtraData);
173
174 PointsArray& Path() { return args.path; }
175
176 /* Disables transport coordinate transformations for cases where raw offsets are available
177 */
178 void DisableTransportPathTransformations();
179 protected:
180
183 };
184
185 inline void MoveSplineInit::SetFly() { args.flags.Flying = true; }
186 inline void MoveSplineInit::SetWalk(bool enable) { args.walk = enable; }
187 inline void MoveSplineInit::SetSmooth() { args.flags.Catmullrom = true; }
188 inline void MoveSplineInit::SetUncompressed() { args.flags.UncompressedPath = true; }
189 inline void MoveSplineInit::SetCyclic() { args.flags.Cyclic = true; }
190 inline void MoveSplineInit::SetVelocity(float vel) { args.velocity = vel; args.HasVelocity = true; }
191 inline void MoveSplineInit::SetBackward() { args.flags.Backward = true; }
192 inline void MoveSplineInit::SetTransportEnter() { args.flags.TransportEnter = true; }
193 inline void MoveSplineInit::SetTransportExit() { args.flags.TransportExit = true; }
194 inline void MoveSplineInit::SetOrientationFixed(bool enable) { args.flags.OrientationFixed = enable; }
195 inline void MoveSplineInit::SetJumpOrientationFixed(bool enable) { args.flags.JumpOrientationFixed = enable; }
196 inline void MoveSplineInit::SetSteering() { args.flags.Steering = true; }
197 inline void MoveSplineInit::SetUnlimitedSpeed() { args.flags.UnlimitedSpeed = true; }
198
199 inline void MoveSplineInit::SetParabolic(float amplitude, float time_shift)
200 {
201 args.effect_start_time_percent = time_shift;
202 args.parabolic_amplitude = amplitude;
204 args.flags.Parabolic = true;
205 }
206
207 inline void MoveSplineInit::SetParabolicVerticalAcceleration(float vertical_acceleration, float time_shift)
208 {
209 args.effect_start_time_percent = time_shift;
211 args.vertical_acceleration = vertical_acceleration;
212 args.flags.Parabolic = true;
213 }
214
215 inline void MoveSplineInit::SetAnimation(AnimTier anim, uint32 tierTransitionId /*= 0*/, Milliseconds transitionStartTime /*= 0ms*/)
216 {
218 args.effect_start_time = transitionStartTime;
219 args.animTier.emplace();
220 args.animTier->TierTransitionId = tierTransitionId;
221 args.animTier->AnimTier = anim;
222 if (!tierTransitionId)
223 args.flags.Animation = true;
224 }
225
227
228 inline void MoveSplineInit::SetSpellEffectExtraData(SpellEffectExtraData const& spellEffectExtraData)
229 {
230 args.spellEffectExtra = spellEffectExtraData;
231 }
232
234 {
235 explicit MoveSplineInitFacingVisitor(MoveSplineInit& init) : _init(init) { }
236
237 void operator()(std::monostate) const { }
238 void operator()(Position const& point) const;
239 void operator()(Unit const* target) const { _init.SetFacing(target); }
240 void operator()(float angle) const { _init.SetFacing(angle); }
241
243 };
244}
245#endif // TRINITYSERVER_MOVESPLINEINIT_H
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition: Duration.h:24
AnimTier
Definition: UnitDefines.h:69
void DisableTransportPathTransformations()
void SetWalk(bool enable)
void SetFirstPointId(int32 pointId)
void SetParabolic(float amplitude, float start_time)
void SetVelocity(float velocity)
MoveSplineInit & operator=(MoveSplineInit &&)=delete
MoveSplineInit(MoveSplineInit &&init)=delete
void SetSpellEffectExtraData(SpellEffectExtraData const &spellEffectExtraData)
MoveSplineInitArgs args
MoveSplineInit(MoveSplineInit const &)=delete
void SetParabolicVerticalAcceleration(float vertical_acceleration, float time_shift)
void SetAnimation(AnimTier anim, uint32 tierTransitionId=0, Milliseconds transitionStartTime=0ms)
MoveSplineInit & operator=(MoveSplineInit const &)=delete
void SetJumpOrientationFixed(bool enable)
void SetOrientationFixed(bool enable)
TransportPathTransform(Unit *owner, bool transformForTransport)
Definition: Unit.h:630
std::vector< Vector3 > PointsArray
Optional< AnimTierTransition > animTier
Optional< SpellEffectExtraData > spellEffectExtra
MoveSplineInitFacingVisitor(MoveSplineInit &init)
void operator()(Unit const *target) const
void operator()(float angle) const
void operator()(std::monostate) const