Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
MovementUtil.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "MoveSplineFlag.h"
7#include <math.h>
8#include <string>
9
10namespace Movement
11{
12 double gravity = 19.29110527038574;
14
16 float terminalVelocity = 60.148003f;
18
19 const float terminal_length = float(terminalVelocity * terminalVelocity) / (2.0f * gravity);
21 const float terminal_fallTime = float(terminalVelocity / gravity); // the time that needed to reach terminalVelocity
22 const float terminal_safeFall_fallTime = float(terminalSafefallVelocity / gravity); // the time that needed to reach terminalVelocity with safefall
23
24 float computeFallTime(float path_length, bool isSafeFall)
25 {
26 if (path_length < 0.0f)
27 return 0.0f;
28
29 float time;
30 if (isSafeFall)
31 {
32 if (path_length >= terminal_safeFall_length)
34 else
35 time = sqrtf(2.0f * path_length / gravity);
36 }
37 else
38 {
39 if (path_length >= terminal_length)
40 time = (path_length - terminal_length) / terminalVelocity + terminal_fallTime;
41 else
42 time = sqrtf(2.0f * path_length / gravity);
43 }
44
45 return time;
46 }
47
48 float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity /*= 0.0f*/)
49 {
50 float termVel;
51 float result;
52
53 if (isSafeFall)
55 else
56 termVel = terminalVelocity;
57
58 if (start_velocity > termVel)
59 start_velocity = termVel;
60
61 float terminal_time = (isSafeFall ? terminal_safeFall_fallTime : terminal_fallTime) - start_velocity / gravity; // the time that needed to reach terminalVelocity
62
63 if (t_passed > terminal_time)
64 {
65 result = termVel * (t_passed - terminal_time) +
66 start_velocity * terminal_time +
67 gravity * terminal_time * terminal_time * 0.5f;
68 }
69 else
70 result = t_passed * (start_velocity + t_passed * gravity * 0.5f);
71
72 return result;
73 }
74
75#define STR(x) #x
76
77 char const* g_MovementFlag_names[] =
78 {
79 STR(Forward), // 0x00000001,
80 STR(Backward), // 0x00000002,
81 STR(Strafe_Left), // 0x00000004,
82 STR(Strafe_Right), // 0x00000008,
83 STR(Turn_Left), // 0x00000010,
84 STR(Turn_Right), // 0x00000020,
85 STR(Pitch_Up), // 0x00000040,
86 STR(Pitch_Down), // 0x00000080,
87
88 STR(Walking), // 0x00000100, // Walking
89 STR(DisableGravity), // 0x00000200,
90 STR(Root), // 0x00000400,
91 STR(Falling), // 0x00000800,
92 STR(FallingFar), // 0x00001000,
93 STR(PendingStop), // 0x00002000,
94 STR(PendingStrafeStop), // 0x00004000,
95 STR(PendingForward), // 0x00008000,
96 STR(PendingBackward), // 0x00010000,
97 STR(PendingStrafeLeft), // 0x00020000,
98 STR(PendingStrafeRight), // 0x00040000,
99 STR(PendingRoot), // 0x00080000,
100 STR(Swimming), // 0x00100000, // Appears With Fly Flag Also
101 STR(Ascending), // 0x00200000, // Swim Up Also
102 STR(Descending), // 0x00400000, // Swim Down Also
103 STR(Can_Fly), // 0x00800000, // Can Fly In 3.3?
104 STR(Flying), // 0x01000000, // Actual Flying Mode
105 STR(Spline_Elevation), // 0x02000000, // Used For Flight Paths
106 STR(Waterwalking), // 0x04000000, // Prevent Unit From Falling Through Water
107 STR(Safe_Fall), // 0x08000000, // Active Rogue Safe Fall Spell (Passive)
108 STR(Hover), // 0x10000000
109 STR(Local_Dirty), // 0x20000000
110 STR(None31), // 0x40000000
111 STR(None32), // 0x80000000
112 };
113
115 {
116 STR(NoStrafe),
117 STR(NoJump),
118 STR(FullSpeedTurning),
119 STR(FullSpeedPitching),
120 STR(Allow_Pitching),
121 STR(Unk6),
122 STR(Unk7),
123 STR(Unk8),
124 STR(Unk9),
125 STR(Unk10),
126 STR(Unk11),
127 STR(Unk12),
128 STR(Unk13),
129 STR(Interpolated_Movement),
130 STR(Interpolated_Turning),
131 STR(Interpolated_Pitching),
132 };
133
134 char const* g_SplineFlag_names[32] =
135 {
136 STR(AnimBit1), // 0x00000001,
137 STR(AnimBit2), // 0x00000002,
138 STR(AnimBit3), // 0x00000004,
139 STR(Unknown0), // 0x00000008,
140 STR(FallingSlow), // 0x00000010,
141 STR(Done), // 0x00000020,
142 STR(Falling), // 0x00000040, // Not Compartible With Trajectory Movement
143 STR(No_Spline), // 0x00000080,
144 STR(Unknown2), // 0x00000100,
145 STR(Flying), // 0x00000200, // Smooth Movement(Catmullrom Interpolation Mode), Flying Animation
146 STR(OrientationFixed), // 0x00000400, // Model Orientation Fixed
147 STR(Catmullrom), // 0x00000800, // Used Catmullrom Interpolation Mode
148 STR(Cyclic), // 0x00001000, // Movement By Cycled Spline
149 STR(Enter_Cycle), // 0x00002000, // Everytime Appears With Cyclic Flag In Monster Move Packet
150 STR(Frozen), // 0x00004000,
151 STR(TransportEnter), // 0x00008000
152 STR(TransportExit), // 0x00010000
153 STR(Unknown3), // 0x00020000,
154 STR(Unknown4), // 0x00040000,
155 STR(OrientationInversed), // 0x00080000, // Appears With Runmode Flag, Nodes ), // 1, Handles Orientation
156 STR(SmoothGroundPath), // 0x00100000,
157 STR(Walkmode), // 0x00200000,
158 STR(UncompressedPath), // 0x00400000,
159 STR(Unknown6), // 0x00800000,
160 STR(Animation), // 0x01000000, // Animationid (0...3), Uint32 Time, Not Compartible With Trajectory And Fall Movement
161 STR(Parabolic), // 0x02000000, // Not Compartible With Fall Movement
162 STR(Final_Point), // 0x04000000,
163 STR(Final_Target), // 0x08000000,
164 STR(Final_Angle), // 0x10000000,
165 STR(Unknown7), // 0x20000000,
166 STR(Unknown8), // 0x40000000,
167 STR(Unknown9), // 0x80000000,
168 };
169
170 template<class Flags, int N>
171 void print_flags(Flags t, char const* (&names)[N], std::string& str)
172 {
173 for (int i = 0; i < N; ++i)
174 {
175 if ((t & Flags(1 << i)) && names[i] != NULL)
176 str.append(" ").append(names[i]);
177 }
178 }
179
180 std::string MoveSplineFlag::ToString() const
181 {
182 std::string str;
184 return str;
185 }
186
188 {
189 std::string str;
191 return str;
192 }
193
195 {
196 std::string str;
198 return str;
199 }
200}
std::uint32_t uint32
Definition Define.h:77
#define STR(x)
std::string ToString() const
double 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
UInt32Counter splineIdGen
float terminalSafefallVelocity
std::string MovementFlags_ToString(uint32 flags)
const float terminal_length
float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity=0.0f)
std::string MovementFlagsExtra_ToString(uint32 flags)
float terminalVelocity
Velocity bounds that makes fall speed limited.
char const * g_SplineFlag_names[32]
const float terminal_fallTime
counter< uint32, 0xFFFFFFFF > UInt32Counter
char const * g_MovementFlagExtra_names[]