TrinityCore
Loading...
Searching...
No Matches
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 "Duration.h"
22#include "MoveSplineInitArgs.h"
23#include <span>
24#include <variant>
25
26class ObjectGuid;
27class Unit;
28
29struct Position;
30enum class AnimTier : uint8;
31
32namespace Movement
33{
34 /* Initializes and launches spline movement
35 */
37 {
38 public:
39
40 explicit MoveSplineInit(Unit* m);
41
43
48
49 /* Final pass of initialization that launches spline movement.
50 */
51 int32 Launch();
52
53 /* Final pass of initialization that stops movement.
54 */
55 void Stop();
56
62 void SetParabolic(float amplitude, int32 start_point);
63 /* Plays animation after movement done
64 * can't be combined with parabolic movement or fade object
65 */
66 void SetAnimation(AnimTier anim, uint32 tierTransitionId = 0, int32 transitionStartPoint = 0);
67
68 /* Plays fading animation while moving
69 * can't be combined with parabolic|animation movement
70 */
71 void SetFadeObject(Milliseconds fadeDuration = 1s);
72
73 /* Adds final facing animation
74 * sets unit's facing to specified point/angle after all path done
75 * you can have only one final facing: previous will be overriden
76 */
77 void SetFacing(float angle);
78 void SetFacing(Vector3 const& spot);
79 void SetFacing(float x, float y, float z);
80 void SetFacing(Unit const* target);
81
82 /* Initializes movement by path
83 * @param path - array of points, shouldn't be empty
84 * @param pointId - Id of fisrt point of the path. Example: when third path point will be done it will notify that pointId + 3 done
85 */
86 void MovebyPath(std::span<Vector3 const> path, int32 pointId = 0);
87
88 /* Initializes simple A to B motion, A is current unit's position, B is destination
89 */
90 void MoveTo(Vector3 const& destination, bool generatePath = true, bool forceDestination = false);
91 void MoveTo(float x, float y, float z, bool generatePath = true, bool forceDestination = false);
92
93 /* Sets Id of fisrt point of the path. When N-th path point will be done ILisener will notify that pointId + N done
94 * Needed for waypoint movement where path splitten into parts
95 */
96 void SetFirstPointId(int32 pointId) { args.path_Idx_offset = pointId; }
97
98 /* Enables CatmullRom spline interpolation mode(makes path smooth)
99 * if not enabled linear spline mode will be choosen. Disabled by default
100 */
101 void SetSmooth();
102
103 /* Waypoints in packets will be sent without compression
104 */
105 void SetUncompressed();
106
107 /* Enables flying animation. Disabled by default
108 */
109 void SetFly();
110
111 /* Enables walk mode. Disabled by default
112 */
113 void SetWalk(bool enable);
114
115 /* Makes movement cyclic. Disabled by default
116 */
117 void SetCyclic();
118
119 /* Enables falling mode. Disabled by default
120 */
121 void SetFall();
122
123 /* Enters transport. Disabled by default
124 */
125 void SetTransportEnter();
126
127 /* Exits transport. Disabled by default
128 */
129 void SetTransportExit();
130
131 /* Inverses unit model orientation. Disabled by default
132 */
133 void SetBackward();
134
135 /* Fixes unit's model rotation (plays knockback animation). Disabled by default
136 */
137 void SetOrientationFixed(bool enable);
138
139 /* Fixes unit's model rotation (plays jump animation). Disabled by default
140 */
141 void SetJumpOrientationFixed(bool enable);
142
143 /* Enables avoiding minor obstacles clientside (might cause visual position on client to not be accurate with the serverside one). Disabled by default
144 */
145 void SetSteering();
146
147 /* Enables no-speed limit
148 * if not set, the speed will be limited by certain flags to 50.0f, and otherwise 28.0f
149 */
150 void SetUnlimitedSpeed();
151
152 /* Sets the velocity (in case you want to have custom movement velocity)
153 * if no set, speed will be selected based on unit's speeds and current movement mode
154 * Has no effect if falling mode enabled
155 * velocity shouldn't be negative
156 */
157 void SetVelocity(float velocity);
158
159 void SetSpellEffectExtraData(SpellEffectExtraData const& spellEffectExtraData);
160
161 void SetTurning(float startFacing, float totalTurnRads, float radsPerSec);
162
163 PointsArray& Path() { return args.path; }
164
165 /* Disables transport coordinate transformations for cases where raw offsets are available
166 */
167 void DisableTransportPathTransformations();
168 protected:
169
172 };
173
174 inline void MoveSplineInit::SetFly() { args.flags.Flying = true; }
175 inline void MoveSplineInit::SetWalk(bool enable) { args.walk = enable; }
176 inline void MoveSplineInit::SetSmooth() { args.flags.Catmullrom = true; }
177 inline void MoveSplineInit::SetUncompressed() { args.flags.UncompressedPath = true; }
178 inline void MoveSplineInit::SetCyclic() { args.flags.Cyclic = true; }
179 inline void MoveSplineInit::SetVelocity(float vel) { args.velocity = vel; args.HasVelocity = true; }
180 inline void MoveSplineInit::SetBackward() { args.flags.Backward = true; }
181 inline void MoveSplineInit::SetTransportEnter() { args.flags.TransportEnter = true; }
182 inline void MoveSplineInit::SetTransportExit() { args.flags.TransportExit = true; }
183 inline void MoveSplineInit::SetOrientationFixed(bool enable) { args.flags.OrientationFixed = enable; }
184 inline void MoveSplineInit::SetJumpOrientationFixed(bool enable) { args.flags.JumpOrientationFixed = enable; }
185 inline void MoveSplineInit::SetSteering() { args.flags.Steering = true; }
186 inline void MoveSplineInit::SetUnlimitedSpeed() { args.flags.UnlimitedSpeed = true; }
187
188 inline void MoveSplineInit::SetParabolic(float amplitude, int32 start_point)
189 {
190 args.effect_start_point = start_point;
191 args.parabolic_amplitude = amplitude;
192 args.flags.Parabolic = true;
193 args.animTier.reset();
194 }
195
196 inline void MoveSplineInit::SetAnimation(AnimTier anim, uint32 tierTransitionId /*= 0*/, int32 transitionStartPoint /*= 0*/)
197 {
198 args.effect_start_point = transitionStartPoint;
199 AnimTierTransition& animTier = args.animTier.emplace();
200 animTier.TierTransitionId = tierTransitionId;
201 animTier.AnimTier = anim;
202 args.flags.Raw &= ~args.flags.Animation.DisallowedFlag;
203 args.flags.Animation = tierTransitionId == 0;
204 }
205
207 {
208 args.fade_object_duration_ms = fadeDuration.count();
209 args.flags.FadeObject = true;
210 args.animTier.reset();
211 }
212
214
215 inline void MoveSplineInit::SetSpellEffectExtraData(SpellEffectExtraData const& spellEffectExtraData)
216 {
217 args.spellEffectExtra = spellEffectExtraData;
218 }
219
220 inline void MoveSplineInit::SetTurning(float startFacing, float totalTurnRads, float radsPerSec)
221 {
222 args.flags.Turning = true;
223
224 TurnData& turn = args.turnData.emplace();
225 turn.StartFacing = startFacing;
226 turn.TotalTurnRads = totalTurnRads;
227 turn.RadsPerSec = radsPerSec;
228 }
229
231 {
233
234 void operator()(std::monostate) const { }
235 void operator()(Position const& point) const;
236 void operator()(Unit const* target) const { _init.SetFacing(target); }
237 void operator()(float angle) const { _init.SetFacing(angle); }
238
240 };
241}
242
243#endif // TRINITYSERVER_MOVESPLINEINIT_H
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition Duration.h:24
AnimTier
Definition UnitDefines.h:69
void SetWalk(bool enable)
void SetFirstPointId(int32 pointId)
void SetVelocity(float velocity)
void SetFacing(float angle)
void SetFadeObject(Milliseconds fadeDuration=1s)
MoveSplineInit & operator=(MoveSplineInit &&)=delete
MoveSplineInit(MoveSplineInit &&init)=delete
void SetSpellEffectExtraData(SpellEffectExtraData const &spellEffectExtraData)
MoveSplineInitArgs args
void SetTurning(float startFacing, float totalTurnRads, float radsPerSec)
MoveSplineInit(MoveSplineInit const &)=delete
void SetAnimation(AnimTier anim, uint32 tierTransitionId=0, int32 transitionStartPoint=0)
MoveSplineInit & operator=(MoveSplineInit const &)=delete
void SetParabolic(float amplitude, int32 start_point)
void SetJumpOrientationFixed(bool enable)
void SetOrientationFixed(bool enable)
Definition Unit.h:635
std::vector< Vector3 > PointsArray
Optional< AnimTierTransition > animTier
Optional< SpellEffectExtraData > spellEffectExtra
MoveSplineInitFacingVisitor(MoveSplineInit &init)
void operator()(Unit const *target) const
void operator()(std::monostate) const
EnumFlag< MoveSplineFlagEnum > Raw