TrinityCore
Loading...
Searching...
No Matches
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 "MoveSplineFlag.h"
19#include <cmath>
20
21namespace Movement
22{
23 float gravity = static_cast<float>(19.29110527038574);
25
27 float terminalVelocity = 60.148003f;
29
30 const float terminal_length = float(terminalVelocity * terminalVelocity) / (2.0f * gravity);
32 const float terminal_fallTime = float(terminalVelocity / gravity); // the time that needed to reach terminalVelocity
33 const float 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* g_MovementFlag_names[] =
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
97 STRINGIZE(Walk ), // 0x00000100, // Walking
98 STRINGIZE(Ontransport ), // 0x00000200,
99 STRINGIZE(Levitation ), // 0x00000400,
100 STRINGIZE(Root ), // 0x00000800,
101 STRINGIZE(Falling ), // 0x00001000,
102 STRINGIZE(Fallingfar ), // 0x00002000,
103 STRINGIZE(Pendingstop ), // 0x00004000,
104 STRINGIZE(PendingStrafeStop ), // 0x00008000,
105 STRINGIZE(PendingForward ), // 0x00010000,
106 STRINGIZE(PendingBackward ), // 0x00020000,
107 STRINGIZE(PendingStrafeReft ), // 0x00040000,
108 STRINGIZE(PendingStrafeRight), // 0x00080000,
109 STRINGIZE(PendingRoot ), // 0x00100000,
110 STRINGIZE(Swimming ), // 0x00200000, // Appears With Fly Flag Also
111 STRINGIZE(Ascending ), // 0x00400000, // Swim Up Also
112 STRINGIZE(Descending ), // 0x00800000, // Swim Down Also
113 STRINGIZE(Can_Fly ), // 0x01000000, // Can Fly In 3.3?
114 STRINGIZE(Flying ), // 0x02000000, // Actual Flying Mode
115 STRINGIZE(Spline_Elevation ), // 0x04000000, // Used For Flight Paths
116 STRINGIZE(Spline_Enabled ), // 0x08000000, // Used For Flight Paths
117 STRINGIZE(Waterwalking ), // 0x10000000, // Prevent Unit From Falling Through Water
118 STRINGIZE(Safe_Fall ), // 0x20000000, // Active Rogue Safe Fall Spell (Passive)
119 STRINGIZE(Hover ), // 0x40000000
120 STRINGIZE(Unknown13 ), // 0x80000000
121 STRINGIZE(NoStrafe ),
122 STRINGIZE(NoJump ),
123 STRINGIZE(Unk3 ),
124 STRINGIZE(FullSpeedTurning ),
125 STRINGIZE(FullSpeedPitching ),
126 STRINGIZE(Allow_Pitching ),
127 STRINGIZE(Unk4 ),
128 STRINGIZE(Unk5 ),
129 STRINGIZE(Unk6 ),
130 STRINGIZE(Unk7 ),
131 STRINGIZE(Interp_Move ),
132 STRINGIZE(Interp_Turning ),
133 STRINGIZE(Interp_Pitching ),
134 STRINGIZE(Unk8 ),
135 STRINGIZE(Unk9 ),
136 STRINGIZE(Unk10 ),
137 };
138
139 char const* g_SplineFlag_names[32] =
140 {
141 STRINGIZE(AnimBit1 ), // 0x00000001,
142 STRINGIZE(AnimBit2 ), // 0x00000002,
143 STRINGIZE(AnimBit3 ), // 0x00000004,
144 STRINGIZE(AnimBit4 ), // 0x00000008,
145 STRINGIZE(AnimBit5 ), // 0x00000010,
146 STRINGIZE(AnimBit6 ), // 0x00000020,
147 STRINGIZE(AnimBit7 ), // 0x00000040,
148 STRINGIZE(AnimBit8 ), // 0x00000080,
149 STRINGIZE(Done ), // 0x00000100,
150 STRINGIZE(Falling ), // 0x00000200, // Not Compartible With Trajectory Movement
151 STRINGIZE(No_Spline ), // 0x00000400,
152 STRINGIZE(Trajectory ), // 0x00000800, // Not Compartible With Fall Movement
153 STRINGIZE(CanSwim ), // 0x00001000,
154 STRINGIZE(Flying ), // 0x00002000, // Smooth Movement(Catmullrom Interpolation Mode), Flying Animation
155 STRINGIZE(Knockback ), // 0x00004000, // Model Orientation Fixed
156 STRINGIZE(Final_Point ), // 0x00008000,
157 STRINGIZE(Final_Target ), // 0x00010000,
158 STRINGIZE(Final_Angle ), // 0x00020000,
159 STRINGIZE(Catmullrom ), // 0x00040000, // Used Catmullrom Interpolation Mode
160 STRINGIZE(Cyclic ), // 0x00080000, // Movement By Cycled Spline
161 STRINGIZE(Enter_Cycle ), // 0x00100000, // Everytime Appears With Cyclic Flag In Monster Move Packet
162 STRINGIZE(Animation ), // 0x00200000, // Animationid (0...3), Uint32 Time, Not Compartible With Trajectory And Fall Movement
163 STRINGIZE(Frozen ), // 0x00400000, // Disables Movement By Path
164 STRINGIZE(TransportEnter), // 0x00800000,
165 STRINGIZE(TransportExit ), // 0x01000000,
166 STRINGIZE(Unknown7 ), // 0x02000000,
167 STRINGIZE(Unknown8 ), // 0x04000000,
168 STRINGIZE(Backward ), // 0x08000000, // Appears With Runmode Flag, Nodes ), // 1, Handles Orientation
169 STRINGIZE(Unknown10 ), // 0x10000000,
170 STRINGIZE(Unknown11 ), // 0x20000000,
171 STRINGIZE(Unknown12 ), // 0x40000000,
172 STRINGIZE(Unknown13 ), // 0x80000000,
173 };
174
175 template<class Flags, int N>
176 void PrintFlags(Flags t, char const* (&names)[N], std::string& str)
177 {
178 for (int i = 0; i < N; ++i)
179 {
180 if ((t & Flags(1 << i)) && names[i] != nullptr)
181 str.append(" ").append(names[i]);
182 }
183 }
184
185 std::string MoveSplineFlag::ToString() const
186 {
187 std::string str;
189 return str;
190 }
191}
#define STRINGIZE(a)
Definition Common.h:25
std::string ToString() const
TC_GAME_API float gravity
char const * g_MovementFlag_names[]
const float terminal_safeFall_fallTime
float computeFallTime(float path_length, bool isSafeFall)
const float terminal_safeFall_length
TC_GAME_API UInt32Counter splineIdGen
float terminalSafefallVelocity
const float terminal_length
float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity=0.0f)
float terminalVelocity
Velocity bounds that makes fall speed limited.
char const * g_SplineFlag_names[32]
void PrintFlags(Flags t, char const *(&names)[N], std::string &str)
const float terminal_fallTime