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 #define STR(x) #x
87
88 char const* g_MovementFlag_names[] =
89 {
90 STR(Forward ), // 0x00000001,
91 STR(Backward ), // 0x00000002,
92 STR(Strafe_Left ), // 0x00000004,
93 STR(Strafe_Right ), // 0x00000008,
94 STR(Turn_Left ), // 0x00000010,
95 STR(Turn_Right ), // 0x00000020,
96 STR(Pitch_Up ), // 0x00000040,
97 STR(Pitch_Down ), // 0x00000080,
98
99 STR(Walk ), // 0x00000100, // Walking
100 STR(Ontransport ), // 0x00000200,
101 STR(Levitation ), // 0x00000400,
102 STR(Root ), // 0x00000800,
103 STR(Falling ), // 0x00001000,
104 STR(Fallingfar ), // 0x00002000,
105 STR(Pendingstop ), // 0x00004000,
106 STR(PendingStrafeStop ), // 0x00008000,
107 STR(PendingForward ), // 0x00010000,
108 STR(PendingBackward ), // 0x00020000,
109 STR(PendingStrafeReft ), // 0x00040000,
110 STR(PendingStrafeRight ), // 0x00080000,
111 STR(PendingRoot ), // 0x00100000,
112 STR(Swimming ), // 0x00200000, // Appears With Fly Flag Also
113 STR(Ascending ), // 0x00400000, // Swim Up Also
114 STR(Descending ), // 0x00800000, // Swim Down Also
115 STR(Can_Fly ), // 0x01000000, // Can Fly In 3.3?
116 STR(Flying ), // 0x02000000, // Actual Flying Mode
117 STR(Spline_Elevation ), // 0x04000000, // Used For Flight Paths
118 STR(Spline_Enabled ), // 0x08000000, // Used For Flight Paths
119 STR(Waterwalking ), // 0x10000000, // Prevent Unit From Falling Through Water
120 STR(Safe_Fall ), // 0x20000000, // Active Rogue Safe Fall Spell (Passive)
121 STR(Hover ), // 0x40000000
122 STR(Unknown13 ), // 0x80000000
123 STR(NoStrafe ),
124 STR(NoJump ),
125 STR(Unk3 ),
126 STR(FullSpeedTurning ),
127 STR(FullSpeedPitching ),
128 STR(Allow_Pitching ),
129 STR(Unk4 ),
130 STR(Unk5 ),
131 STR(Unk6 ),
132 STR(Unk7 ),
133 STR(Interp_Move ),
134 STR(Interp_Turning ),
135 STR(Interp_Pitching ),
136 STR(Unk8 ),
137 STR(Unk9 ),
138 STR(Unk10 ),
139 };
140
141 char const* g_SplineFlag_names[32] =
142 {
143 STR(AnimBit1 ), // 0x00000001,
144 STR(AnimBit2 ), // 0x00000002,
145 STR(AnimBit3 ), // 0x00000004,
146 STR(AnimBit4 ), // 0x00000008,
147 STR(AnimBit5 ), // 0x00000010,
148 STR(AnimBit6 ), // 0x00000020,
149 STR(AnimBit7 ), // 0x00000040,
150 STR(AnimBit8 ), // 0x00000080,
151 STR(Done ), // 0x00000100,
152 STR(Falling ), // 0x00000200, // Not Compartible With Trajectory Movement
153 STR(No_Spline ), // 0x00000400,
154 STR(Trajectory ), // 0x00000800, // Not Compartible With Fall Movement
155 STR(CanSwim ), // 0x00001000,
156 STR(Flying ), // 0x00002000, // Smooth Movement(Catmullrom Interpolation Mode), Flying Animation
157 STR(Knockback ), // 0x00004000, // Model Orientation Fixed
158 STR(Final_Point ), // 0x00008000,
159 STR(Final_Target ), // 0x00010000,
160 STR(Final_Angle ), // 0x00020000,
161 STR(Catmullrom ), // 0x00040000, // Used Catmullrom Interpolation Mode
162 STR(Cyclic ), // 0x00080000, // Movement By Cycled Spline
163 STR(Enter_Cycle ), // 0x00100000, // Everytime Appears With Cyclic Flag In Monster Move Packet
164 STR(Animation ), // 0x00200000, // Animationid (0...3), Uint32 Time, Not Compartible With Trajectory And Fall Movement
165 STR(Unknown4 ), // 0x00400000, // Disables Movement By Path
166 STR(Unknown5 ), // 0x00800000,
167 STR(Unknown6 ), // 0x01000000,
168 STR(Unknown7 ), // 0x02000000,
169 STR(Unknown8 ), // 0x04000000,
170 STR(Backward ), // 0x08000000, // Appears With Runmode Flag, Nodes ), // 1, Handles Orientation
171 STR(Unknown10 ), // 0x10000000,
172 STR(Unknown11 ), // 0x20000000,
173 STR(Unknown12 ), // 0x40000000,
174 STR(Unknown13 ), // 0x80000000,
175 };
176
177 template<class Flags, int N>
178 void print_flags(Flags t, char const* (&names)[N], std::string& str)
179 {
180 for (int i = 0; i < N; ++i)
181 {
182 if ((t & Flags(1 << i)) && names[i] != nullptr)
183 str.append(" ").append(names[i]);
184 }
185 }
186
187 std::string MoveSplineFlag::ToString() const
188 {
189 std::string str;
191 return str;
192 }
193}
#define STR(x)
std::string ToString() const
TC_GAME_API float gravity
void print_flags(Flags t, char const *(&names)[N], std::string &str)
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]
const float terminal_fallTime