TrinityCore
MovementUtil.cpp
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#include "MovementTypedefs.h"
19#include "MoveSplineFlag.h"
20#include <cmath>
21
22namespace Movement
23{
25
27 float constexpr terminalVelocity = 60.148003f;
28 float constexpr terminalSafefallVelocity = 7.0f;
29
30 float constexpr terminal_length = float(terminalVelocity * terminalVelocity) / (2.0f * gravity);
32 float constexpr terminal_fallTime = float(terminalVelocity / gravity); // the time that needed to reach terminalVelocity
33 float constexpr terminal_safeFall_fallTime = float(terminalSafefallVelocity / gravity); // the time that needed to reach terminalVelocity with safefall
34
35 float computeFallTime(float path_length, bool isSafeFall)
36 {
37 if (path_length < 0.0f)
38 return 0.0f;
39
40 float time;
41 if (isSafeFall)
42 {
43 if (path_length >= terminal_safeFall_length)
45 else
46 time = std::sqrt(2.0f * path_length / gravity);
47 }
48 else
49 {
50 if (path_length >= terminal_length)
51 time = (path_length - terminal_length) / terminalVelocity + terminal_fallTime;
52 else
53 time = std::sqrt(2.0f * path_length / gravity);
54 }
55
56 return time;
57 }
58
59 float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity /*= 0.0f*/)
60 {
61 float termVel;
62 float result;
63
64 if (isSafeFall)
66 else
67 termVel = terminalVelocity;
68
69 if (start_velocity > termVel)
70 start_velocity = termVel;
71
72 float terminal_time = (isSafeFall ? terminal_safeFall_fallTime : terminal_fallTime) - start_velocity / gravity; // the time that needed to reach terminalVelocity
73
74 if (t_passed > terminal_time)
75 {
76 result = termVel * (t_passed - terminal_time) +
77 start_velocity * terminal_time +
78 gravity * terminal_time * terminal_time * 0.5f;
79 }
80 else
81 result = t_passed * (start_velocity + t_passed * gravity * 0.5f);
82
83 return result;
84 }
85
86 char const* MovementFlagNames[] =
87 {
88 STRINGIZE(Forward ), // 0x00000001
89 STRINGIZE(Backward ), // 0x00000002
90 STRINGIZE(Strafe_Left ), // 0x00000004
91 STRINGIZE(Strafe_Right ), // 0x00000008
92 STRINGIZE(Turn_Left ), // 0x00000010
93 STRINGIZE(Turn_Right ), // 0x00000020
94 STRINGIZE(Pitch_Up ), // 0x00000040
95 STRINGIZE(Pitch_Down ), // 0x00000080
96 STRINGIZE(Walking ), // 0x00000100 // Walking
97 STRINGIZE(DisableGravity ), // 0x00000200
98 STRINGIZE(Root ), // 0x00000400
99 STRINGIZE(Falling ), // 0x00000800
100 STRINGIZE(FallingFar ), // 0x00001000
101 STRINGIZE(PendingStop ), // 0x00002000
102 STRINGIZE(PendingStrafeStop ), // 0x00004000
103 STRINGIZE(PendingForward ), // 0x00008000
104 STRINGIZE(PendingBackward ), // 0x00010000
105 STRINGIZE(PendingStrafeLeft ), // 0x00020000
106 STRINGIZE(PendingStrafeRight), // 0x00040000
107 STRINGIZE(PendingRoot ), // 0x00080000
108 STRINGIZE(Swimming ), // 0x00100000 // Appears With Fly Flag Also
109 STRINGIZE(Ascending ), // 0x00200000 // Swim Up Also
110 STRINGIZE(Descending ), // 0x00400000 // Swim Down Also
111 STRINGIZE(Can_Fly ), // 0x00800000 // Can Fly In 3.3?
112 STRINGIZE(Flying ), // 0x01000000 // Actual Flying Mode
113 STRINGIZE(Spline_Elevation ), // 0x02000000 // Used For Flight Paths
114 STRINGIZE(Waterwalking ), // 0x04000000 // Prevent Unit From Falling Through Water
115 STRINGIZE(Safe_Fall ), // 0x08000000 // Active Rogue Safe Fall Spell (Passive)
116 STRINGIZE(Hover ), // 0x10000000
117 STRINGIZE(Local_Dirty ), // 0x20000000
118 STRINGIZE(None31 ), // 0x40000000
119 STRINGIZE(None32 ), // 0x80000000
120 };
121
123 {
124 STRINGIZE(NoStrafe ), // 0x00000001
125 STRINGIZE(NoJump ), // 0x00000002
126 STRINGIZE(FullSpeedTurning ), // 0x00000004
127 STRINGIZE(FullSpeedPitching ), // 0x00000008
128 STRINGIZE(Allow_Pitching ), // 0x00000010
129 STRINGIZE(VehicleExitVoluntary ), // 0x00000020
130 STRINGIZE(WaterwalkingFullPitch ), // 0x00000040
131 STRINGIZE(VehiclePassengerIsTransitionAllowed), // 0x00000080
132 STRINGIZE(CanSwimToFlyTrans ), // 0x00000100
133 STRINGIZE(Unk9 ), // 0x00000200
134 STRINGIZE(CanTurnWhileFalling ), // 0x00000400
135 STRINGIZE(IgnoreMovementForces ), // 0x00000800
136 STRINGIZE(CanDoubleJump ), // 0x00001000
137 STRINGIZE(DoubleJump ), // 0x00002000
138 STRINGIZE(Unk14 ), // 0x00004000
139 STRINGIZE(Unk15 ), // 0x00008000
140 STRINGIZE(AwaitingLoad ), // 0x00010000
141 STRINGIZE(InterpolatedMovement ), // 0x00020000
142 STRINGIZE(InterpolatedTurning ), // 0x00040000
143 STRINGIZE(InterpolatedPitching ), // 0x00080000
144 };
145
146 char const* SplineFlagNames[32] =
147 {
148 STRINGIZE(Unknown_0x1 ), // 0x00000001
149 STRINGIZE(Unknown_0x2 ), // 0x00000002
150 STRINGIZE(Unknown_0x4 ), // 0x00000004
151 STRINGIZE(Unknown_0x8 ), // 0x00000008
152 STRINGIZE(FallingSlow ), // 0x00000010
153 STRINGIZE(Done ), // 0x00000020
154 STRINGIZE(Falling ), // 0x00000040 // Not Compartible With Trajectory Movement
155 STRINGIZE(No_Spline ), // 0x00000080
156 STRINGIZE(Unknown_0x100 ), // 0x00000100
157 STRINGIZE(Flying ), // 0x00000200 // Smooth Movement(Catmullrom Interpolation Mode), Flying Animation
158 STRINGIZE(OrientationFixed ), // 0x00000400 // Model Orientation Fixed
159 STRINGIZE(Catmullrom ), // 0x00000800 // Used Catmullrom Interpolation Mode
160 STRINGIZE(Cyclic ), // 0x00001000 // Movement By Cycled Spline
161 STRINGIZE(Enter_Cycle ), // 0x00002000 // Everytime Appears With Cyclic Flag In Monster Move Packet
162 STRINGIZE(Frozen ), // 0x00004000
163 STRINGIZE(TransportEnter ), // 0x00008000
164 STRINGIZE(TransportExit ), // 0x00010000
165 STRINGIZE(Unknown_0x20000 ), // 0x00020000
166 STRINGIZE(Unknown_0x40000 ), // 0x00040000
167 STRINGIZE(Backward ), // 0x00080000 // Appears With Runmode Flag, Nodes ), // 1, Handles Orientation
168 STRINGIZE(SmoothGroundPath ), // 0x00100000
169 STRINGIZE(CanSwim ), // 0x00200000
170 STRINGIZE(UncompressedPath ), // 0x00400000
171 STRINGIZE(Unknown_0x800000 ), // 0x00800000
172 STRINGIZE(Unknown_0x1000000 ), // 0x01000000
173 STRINGIZE(Animation ), // 0x02000000 // Animationid (0...3), Uint32 Time, Not Compartible With Trajectory And Fall Movement
174 STRINGIZE(Parabolic ), // 0x04000000 // Not Compartible With Fall Movement
175 STRINGIZE(FadeObject ), // 0x08000000
176 STRINGIZE(Steering ), // 0x10000000
177 STRINGIZE(UnlimitedSpeed ), // 0x20000000
178 STRINGIZE(Unknown_0x40000000), // 0x40000000
179 STRINGIZE(Unknown_0x80000000), // 0x80000000
180 };
181
182 template<class Flags, int N>
183 void PrintFlags(Flags t, char const* (&names)[N], std::string& str)
184 {
185 for (int i = 0; i < N; ++i)
186 {
187 if ((t & Flags(1 << i)) && names[i] != nullptr)
188 str.append(" ").append(names[i]);
189 }
190 }
191
192 std::string MoveSplineFlag::ToString() const
193 {
194 std::string str;
196 return str;
197 }
198
200 {
201 std::string str;
203 return str;
204 }
205
207 {
208 std::string str;
210 return str;
211 }
212}
#define STRINGIZE(a)
Definition: Common.h:25
uint32_t uint32
Definition: Define.h:142
uint16 flags
Definition: DisableMgr.cpp:49
std::string ToString() const
float constexpr terminalVelocity
Velocity bounds that makes fall speed limited.
float constexpr gravity
char const * SplineFlagNames[32]
char const * MovementFlagNames[]
float computeFallTime(float path_length, bool isSafeFall)
TC_GAME_API UInt32Counter splineIdGen
float constexpr terminalSafefallVelocity
float constexpr terminal_safeFall_length
float constexpr terminal_fallTime
float constexpr terminal_safeFall_fallTime
TC_GAME_API std::string MovementFlags_ToString(uint32 flags)
float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity=0.0f)
TC_GAME_API std::string MovementFlagsExtra_ToString(uint32 flags)
void PrintFlags(Flags t, char const *(&names)[N], std::string &str)
char const * MovementFlagExtraNames[]
float constexpr terminal_length