forked from haithun/CoD4X17a_testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
g_sv_movement.c
212 lines (137 loc) · 4.31 KB
/
g_sv_movement.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
===========================================================================
Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team
This file is part of CoD4X17a-Server source code.
CoD4X17a-Server source code is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
CoD4X17a-Server source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
===========================================================================
*/
#include "q_math.h"
#include "cvar.h"
#include "q_shared.h"
#include "qcommon_io.h"
#include "entity.h"
#include "player.h"
#include "server.h"
#include "g_sv_shared.h"
#include <math.h>
qboolean extendedMovementControl = 0;
//This function init movement variables with default values
void Pmove_ExtendedInitForClient(client_t *cl){
if(g_speed)
cl->playerMoveSpeed = g_speed->integer;
else
cl->playerMoveSpeed = 190;
if(jump_height)
cl->jumpHeight = jump_height->value;
else
cl->jumpHeight = 39;
if(g_gravity)
cl->gravity = (int)g_gravity->value;
else
cl->gravity = 800;
}
void Pmove_ExtendedResetState( void ){
int i;
client_t *cl;
for(cl = svs.clients, i = 0; i < MAX_CLIENTS; i++){
Pmove_ExtendedInitForClient(cl);
}
extendedMovementControl = qfalse;
}
void Pmove_ExtendedTurnOn( void ){
int i;
client_t *cl;
if(extendedMovementControl){
return;
}
Com_DPrintf("Turning on per player based movement control. Default global cvars are now disabled\n");
for(cl = svs.clients, i = 0; i < MAX_CLIENTS; i++){
Pmove_ExtendedInitForClient(cl);
}
extendedMovementControl = qtrue;
}
__cdecl __optimize3 int Pmove_GetSpeed( playerState_t *ps ) {
if(extendedMovementControl)
return svs.clients[ps->clientNum].playerMoveSpeed;
else
return g_speed->integer;
}
__cdecl __optimize3 int Pmove_GetGravity( playerState_t *ps ) {
int gravity;
if(extendedMovementControl)
gravity = svs.clients[ps->clientNum].gravity;
else
gravity = (int)g_gravity->value;
return gravity;
}
__cdecl __optimize3 float Jump_GetHeight( playerState_t *ps) {
if(extendedMovementControl)
return svs.clients[ps->clientNum].jumpHeight;
else
return jump_height->value;
}
__cdecl __optimize3 void Jump_ClampVelocity(playerState_t* ps, vec3_t vec){
float comp;
float newZVelocity;
if(ps->origin[2] - vec[2] > 0){
float jumpHeight = Jump_GetHeight(ps);
comp = ps->jumpOriginZ + jumpHeight - ps->origin[2];
if(comp >= (float)0.1){
newZVelocity = sqrtf( (comp + comp) * (float)ps->gravity);
if(ps->velocity[2] > newZVelocity ){
ps->velocity[2] = newZVelocity;
}
}else{
ps->velocity[2] = 0;
return;
}
}
}
__cdecl __optimize3 qboolean Jump_IsPlayerAboveMax(playerState_t* ps){
float jumpHeight = Jump_GetHeight(ps);
if(ps->origin[2] >= ps->jumpOriginZ + jumpHeight )
return qtrue;
else
return qfalse;
}
__cdecl __optimize3 qboolean Jump_GetStepHeight(playerState_t* ps, const vec3_t vec1, float* val2){
float jumpHeight = Jump_GetHeight(ps);
if(vec1[2] > ps->jumpOriginZ + jumpHeight)
return qfalse;
*val2 = jump_stepSize->value;
if(vec1[2] + jump_stepSize->value > ps->jumpOriginZ + jumpHeight)
*val2 = ps->jumpOriginZ + jumpHeight - vec1[2];
return qtrue;
}
__cdecl __optimize3 float Jump_CalcHeight( playerState_t* ps ) {
float val;
float newdiv;
float jumpHeight = Jump_GetHeight(ps);
val = jumpHeight;
val = (val + val) * ps->gravity;
if(ps->var_03 & 64 && ps->pm_time <= 1800 ){
if(jump_slowdownEnable->boolean){
if(ps->pm_time > 1699){
newdiv = 2.5;
}else{
newdiv = ps->pm_time * (float)1.5 * (float)0.00058823527 + (float)1.0;
}
}else{
newdiv = 1.0;
}
val = val / newdiv;
}
return val;
}
__cdecl __optimize3 void StuckInClient( gentity_t* gen )
{
}