| 1 |
/* |
| 2 |
=========================================================================== |
| 3 |
Copyright (C) 1999-2005 Id Software, Inc. |
| 4 |
|
| 5 |
This file is part of Quake III Arena source code. |
| 6 |
|
| 7 |
Quake III Arena source code is free software; you can redistribute it |
| 8 |
and/or modify it under the terms of the GNU General Public License as |
| 9 |
published by the Free Software Foundation; either version 2 of the License, |
| 10 |
or (at your option) any later version. |
| 11 |
|
| 12 |
Quake III Arena source code is distributed in the hope that it will be |
| 13 |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with Quake III Arena source code; if not, write to the Free Software |
| 19 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
=========================================================================== |
| 21 |
*/ |
| 22 |
// |
| 23 |
|
| 24 |
#include "g_local.h" |
| 25 |
|
| 26 |
|
| 27 |
/* |
| 28 |
=============== |
| 29 |
G_DamageFeedback |
| 30 |
|
| 31 |
Called just before a snapshot is sent to the given player. |
| 32 |
Totals up all damage and generates both the player_state_t |
| 33 |
damage values to that client for pain blends and kicks, and |
| 34 |
global pain sound events for all clients. |
| 35 |
=============== |
| 36 |
*/ |
| 37 |
void P_DamageFeedback( gentity_t *player ) { |
| 38 |
gclient_t *client; |
| 39 |
float count; |
| 40 |
vec3_t angles; |
| 41 |
|
| 42 |
client = player->client; |
| 43 |
if ( client->ps.pm_type == PM_DEAD ) { |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
// total points of damage shot at the player this frame |
| 48 |
count = client->damage_blood + client->damage_armor; |
| 49 |
if ( count == 0 ) { |
| 50 |
return; // didn't take any damage |
| 51 |
} |
| 52 |
|
| 53 |
if ( count > 255 ) { |
| 54 |
count = 255; |
| 55 |
} |
| 56 |
|
| 57 |
// send the information to the client |
| 58 |
|
| 59 |
// world damage (falling, slime, etc) uses a special code |
| 60 |
// to make the blend blob centered instead of positional |
| 61 |
if ( client->damage_fromWorld ) { |
| 62 |
client->ps.damagePitch = 255; |
| 63 |
client->ps.damageYaw = 255; |
| 64 |
|
| 65 |
client->damage_fromWorld = qfalse; |
| 66 |
} else { |
| 67 |
vectoangles( client->damage_from, angles ); |
| 68 |
client->ps.damagePitch = angles[PITCH]/360.0 * 256; |
| 69 |
client->ps.damageYaw = angles[YAW]/360.0 * 256; |
| 70 |
} |
| 71 |
|
| 72 |
// play an apropriate pain sound |
| 73 |
if ( (level.time > player->pain_debounce_time) && !(player->flags & FL_GODMODE) ) { |
| 74 |
player->pain_debounce_time = level.time + 700; |
| 75 |
G_AddEvent( player, EV_PAIN, player->health ); |
| 76 |
client->ps.damageEvent++; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
client->ps.damageCount = count; |
| 81 |
|
| 82 |
// |
| 83 |
// clear totals |
| 84 |
// |
| 85 |
client->damage_blood = 0; |
| 86 |
client->damage_armor = 0; |
| 87 |
client->damage_knockback = 0; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
/* |
| 93 |
============= |
| 94 |
P_WorldEffects |
| 95 |
|
| 96 |
Check for lava / slime contents and drowning |
| 97 |
============= |
| 98 |
*/ |
| 99 |
void P_WorldEffects( gentity_t *ent ) { |
| 100 |
qboolean envirosuit; |
| 101 |
int waterlevel; |
| 102 |
|
| 103 |
if ( ent->client->noclip ) { |
| 104 |
ent->client->airOutTime = level.time + 12000; // don't need air |
| 105 |
return; |
| 106 |
} |
| 107 |
|
| 108 |
waterlevel = ent->waterlevel; |
| 109 |
|
| 110 |
envirosuit = ent->client->ps.powerups[PW_BATTLESUIT] > level.time; |
| 111 |
|
| 112 |
// |
| 113 |
// check for drowning |
| 114 |
// |
| 115 |
if ( waterlevel == 3 ) { |
| 116 |
// envirosuit give air |
| 117 |
if ( envirosuit ) { |
| 118 |
ent->client->airOutTime = level.time + 10000; |
| 119 |
} |
| 120 |
|
| 121 |
// if out of air, start drowning |
| 122 |
if ( ent->client->airOutTime < level.time) { |
| 123 |
// drown! |
| 124 |
ent->client->airOutTime += 1000; |
| 125 |
if ( ent->health > 0 ) { |
| 126 |
// take more damage the longer underwater |
| 127 |
ent->damage += 2; |
| 128 |
if (ent->damage > 15) |
| 129 |
ent->damage = 15; |
| 130 |
|
| 131 |
// don't play a normal pain sound |
| 132 |
ent->pain_debounce_time = level.time + 200; |
| 133 |
|
| 134 |
G_Damage (ent, NULL, NULL, NULL, NULL, |
| 135 |
ent->damage, DAMAGE_NO_ARMOR, MOD_WATER); |
| 136 |
} |
| 137 |
} |
| 138 |
} else { |
| 139 |
ent->client->airOutTime = level.time + 12000; |
| 140 |
ent->damage = 2; |
| 141 |
} |
| 142 |
|
| 143 |
// |
| 144 |
// check for sizzle damage (move to pmove?) |
| 145 |
// |
| 146 |
if (waterlevel && |
| 147 |
(ent->watertype&(CONTENTS_LAVA|CONTENTS_SLIME)) ) { |
| 148 |
if (ent->health > 0 |
| 149 |
&& ent->pain_debounce_time <= level.time ) { |
| 150 |
|
| 151 |
if ( envirosuit ) { |
| 152 |
G_AddEvent( ent, EV_POWERUP_BATTLESUIT, 0 ); |
| 153 |
} else { |
| 154 |
if (ent->watertype & CONTENTS_LAVA) { |
| 155 |
G_Damage (ent, NULL, NULL, NULL, NULL, |
| 156 |
30*waterlevel, 0, MOD_LAVA); |
| 157 |
} |
| 158 |
|
| 159 |
if (ent->watertype & CONTENTS_SLIME) { |
| 160 |
G_Damage (ent, NULL, NULL, NULL, NULL, |
| 161 |
10*waterlevel, 0, MOD_SLIME); |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
/* |
| 171 |
=============== |
| 172 |
G_SetClientSound |
| 173 |
=============== |
| 174 |
*/ |
| 175 |
void G_SetClientSound( gentity_t *ent ) { |
| 176 |
if( ent->s.eFlags & EF_TICKING ) { |
| 177 |
ent->client->ps.loopSound = G_SoundIndex( "sound/weapons/proxmine/wstbtick.wav"); |
| 178 |
} |
| 179 |
else |
| 180 |
if (ent->waterlevel && (ent->watertype&(CONTENTS_LAVA|CONTENTS_SLIME)) ) { |
| 181 |
ent->client->ps.loopSound = level.snd_fry; |
| 182 |
} else { |
| 183 |
ent->client->ps.loopSound = 0; |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
//============================================================== |
| 190 |
|
| 191 |
/* |
| 192 |
============== |
| 193 |
ClientImpacts |
| 194 |
============== |
| 195 |
*/ |
| 196 |
void ClientImpacts( gentity_t *ent, pmove_t *pm ) { |
| 197 |
int i, j; |
| 198 |
trace_t trace; |
| 199 |
gentity_t *other; |
| 200 |
|
| 201 |
memset( &trace, 0, sizeof( trace ) ); |
| 202 |
for (i=0 ; i<pm->numtouch ; i++) { |
| 203 |
for (j=0 ; j<i ; j++) { |
| 204 |
if (pm->touchents[j] == pm->touchents[i] ) { |
| 205 |
break; |
| 206 |
} |
| 207 |
} |
| 208 |
if (j != i) { |
| 209 |
continue; // duplicated |
| 210 |
} |
| 211 |
other = &g_entities[ pm->touchents[i] ]; |
| 212 |
|
| 213 |
if ( ( ent->r.svFlags & SVF_BOT ) && ( ent->touch ) ) { |
| 214 |
ent->touch( ent, other, &trace ); |
| 215 |
} |
| 216 |
|
| 217 |
if ( !other->touch ) { |
| 218 |
continue; |
| 219 |
} |
| 220 |
|
| 221 |
other->touch( other, ent, &trace ); |
| 222 |
} |
| 223 |
|
| 224 |
} |
| 225 |
|
| 226 |
/* |
| 227 |
============ |
| 228 |
G_TouchTriggers |
| 229 |
|
| 230 |
Find all trigger entities that ent's current position touches. |
| 231 |
Spectators will only interact with teleporters. |
| 232 |
============ |
| 233 |
*/ |
| 234 |
void G_TouchTriggers( gentity_t *ent ) { |
| 235 |
int i, num; |
| 236 |
int touch[MAX_GENTITIES]; |
| 237 |
gentity_t *hit; |
| 238 |
trace_t trace; |
| 239 |
vec3_t mins, maxs; |
| 240 |
static vec3_t range = { 40, 40, 52 }; |
| 241 |
|
| 242 |
if ( !ent->client ) { |
| 243 |
return; |
| 244 |
} |
| 245 |
|
| 246 |
//ELIMINATION LMS |
| 247 |
// dead clients don't activate triggers! The reason our pm_spectators can't do anything |
| 248 |
if ( ent->client->ps.stats[STAT_HEALTH] <= 0 && ent->client->ps.pm_type != PM_SPECTATOR) { |
| 249 |
return; |
| 250 |
} |
| 251 |
|
| 252 |
VectorSubtract( ent->client->ps.origin, range, mins ); |
| 253 |
VectorAdd( ent->client->ps.origin, range, maxs ); |
| 254 |
|
| 255 |
num = trap_EntitiesInBox( mins, maxs, touch, MAX_GENTITIES ); |
| 256 |
|
| 257 |
// can't use ent->absmin, because that has a one unit pad |
| 258 |
VectorAdd( ent->client->ps.origin, ent->r.mins, mins ); |
| 259 |
VectorAdd( ent->client->ps.origin, ent->r.maxs, maxs ); |
| 260 |
|
| 261 |
for ( i=0 ; i<num ; i++ ) { |
| 262 |
hit = &g_entities[touch[i]]; |
| 263 |
|
| 264 |
if ( !hit->touch && !ent->touch ) { |
| 265 |
continue; |
| 266 |
} |
| 267 |
if ( !( hit->r.contents & CONTENTS_TRIGGER ) ) { |
| 268 |
continue; |
| 269 |
} |
| 270 |
|
| 271 |
// ignore most entities if a spectator |
| 272 |
if ( (ent->client->sess.sessionTeam == TEAM_SPECTATOR) || ent->client->ps.pm_type == PM_SPECTATOR ) { |
| 273 |
if ( hit->s.eType != ET_TELEPORT_TRIGGER && |
| 274 |
// this is ugly but adding a new ET_? type will |
| 275 |
// most likely cause network incompatibilities |
| 276 |
//We need to stop eliminated players from opening doors somewhere else /Sago007 20070814 |
| 277 |
hit->touch != Touch_DoorTrigger ) { |
| 278 |
continue; |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
// use seperate code for determining if an item is picked up |
| 283 |
// so you don't have to actually contact its bounding box |
| 284 |
if ( hit->s.eType == ET_ITEM ) { |
| 285 |
if ( !BG_PlayerTouchesItem( &ent->client->ps, &hit->s, level.time ) ) { |
| 286 |
continue; |
| 287 |
} |
| 288 |
} else { |
| 289 |
if ( !trap_EntityContact( mins, maxs, hit ) ) { |
| 290 |
continue; |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
memset( &trace, 0, sizeof(trace) ); |
| 295 |
|
| 296 |
if ( hit->touch ) { |
| 297 |
hit->touch (hit, ent, &trace); |
| 298 |
} |
| 299 |
|
| 300 |
if ( ( ent->r.svFlags & SVF_BOT ) && ( ent->touch ) ) { |
| 301 |
ent->touch( ent, hit, &trace ); |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
// if we didn't touch a jump pad this pmove frame |
| 306 |
if ( ent->client->ps.jumppad_frame != ent->client->ps.pmove_framecount ) { |
| 307 |
ent->client->ps.jumppad_frame = 0; |
| 308 |
ent->client->ps.jumppad_ent = 0; |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
/* |
| 313 |
================= |
| 314 |
SpectatorThink |
| 315 |
================= |
| 316 |
*/ |
| 317 |
void SpectatorThink( gentity_t *ent, usercmd_t *ucmd ) { |
| 318 |
pmove_t pm; |
| 319 |
gclient_t *client; |
| 320 |
|
| 321 |
client = ent->client; |
| 322 |
|
| 323 |
if ( ( g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION) && |
| 324 |
client->sess.spectatorState != SPECTATOR_FOLLOW && |
| 325 |
g_elimination_lockspectator.integer>1 && |
| 326 |
ent->client->sess.sessionTeam != TEAM_SPECTATOR ) { |
| 327 |
Cmd_FollowCycle_f(ent); |
| 328 |
} |
| 329 |
|
| 330 |
if ( client->sess.spectatorState != SPECTATOR_FOLLOW ) { |
| 331 |
client->ps.pm_type = PM_SPECTATOR; |
| 332 |
client->ps.speed = 400; // faster than normal |
| 333 |
|
| 334 |
// set up for pmove |
| 335 |
memset (&pm, 0, sizeof(pm)); |
| 336 |
pm.ps = &client->ps; |
| 337 |
pm.cmd = *ucmd; |
| 338 |
pm.tracemask = MASK_PLAYERSOLID & ~CONTENTS_BODY; // spectators can fly through bodies |
| 339 |
pm.trace = trap_Trace; |
| 340 |
pm.pointcontents = trap_PointContents; |
| 341 |
|
| 342 |
// perform a pmove |
| 343 |
Pmove (&pm); |
| 344 |
// save results of pmove |
| 345 |
VectorCopy( client->ps.origin, ent->s.origin ); |
| 346 |
|
| 347 |
G_TouchTriggers( ent ); |
| 348 |
trap_UnlinkEntity( ent ); |
| 349 |
} |
| 350 |
|
| 351 |
/* Stopped players from going into follow mode in B5, should be fixed in B9 |
| 352 |
if(ent->client->sess.sessionTeam != TEAM_SPECTATOR && g_gametype.integer>=GT_ELIMINATION && g_gametype.integer<=GT_LMS) |
| 353 |
return; |
| 354 |
*/ |
| 355 |
|
| 356 |
client->oldbuttons = client->buttons; |
| 357 |
client->buttons = ucmd->buttons; |
| 358 |
|
| 359 |
//KK-OAX Changed to keep followcycle functional |
| 360 |
// attack button cycles through spectators |
| 361 |
if ( ( client->buttons & BUTTON_ATTACK ) && ! ( client->oldbuttons & BUTTON_ATTACK ) ) { |
| 362 |
Cmd_FollowCycle_f( ent ); |
| 363 |
} |
| 364 |
|
| 365 |
if ( ( client->buttons & BUTTON_USE_HOLDABLE ) && ! ( client->oldbuttons & BUTTON_USE_HOLDABLE ) ) { |
| 366 |
if ( ( g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION) && |
| 367 |
g_elimination_lockspectator.integer>1 && |
| 368 |
ent->client->sess.sessionTeam != TEAM_SPECTATOR ) { |
| 369 |
return; |
| 370 |
} |
| 371 |
StopFollowing(ent); |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
/* |
| 378 |
================= |
| 379 |
ClientInactivityTimer |
| 380 |
|
| 381 |
Returns qfalse if the client is dropped |
| 382 |
================= |
| 383 |
*/ |
| 384 |
qboolean ClientInactivityTimer( gclient_t *client ) { |
| 385 |
if ( ! g_inactivity.integer ) { |
| 386 |
// give everyone some time, so if the operator sets g_inactivity during |
| 387 |
// gameplay, everyone isn't kicked |
| 388 |
client->inactivityTime = level.time + 60 * 1000; |
| 389 |
client->inactivityWarning = qfalse; |
| 390 |
} else if ( client->pers.cmd.forwardmove || |
| 391 |
client->pers.cmd.rightmove || |
| 392 |
client->pers.cmd.upmove || |
| 393 |
(client->pers.cmd.buttons & BUTTON_ATTACK) ) { |
| 394 |
client->inactivityTime = level.time + g_inactivity.integer * 1000; |
| 395 |
client->inactivityWarning = qfalse; |
| 396 |
} else if ( !client->pers.localClient ) { |
| 397 |
if ( level.time > client->inactivityTime ) { |
| 398 |
trap_DropClient( client - level.clients, "Dropped due to inactivity" ); |
| 399 |
return qfalse; |
| 400 |
} |
| 401 |
if ( level.time > client->inactivityTime - 10000 && !client->inactivityWarning ) { |
| 402 |
client->inactivityWarning = qtrue; |
| 403 |
trap_SendServerCommand( client - level.clients, "cp \"Ten seconds until inactivity drop!\n\"" ); |
| 404 |
} |
| 405 |
} |
| 406 |
return qtrue; |
| 407 |
} |
| 408 |
|
| 409 |
/* |
| 410 |
================== |
| 411 |
ClientTimerActions |
| 412 |
|
| 413 |
Actions that happen once a second |
| 414 |
================== |
| 415 |
*/ |
| 416 |
void ClientTimerActions( gentity_t *ent, int msec ) { |
| 417 |
gclient_t *client; |
| 418 |
int maxHealth; |
| 419 |
|
| 420 |
client = ent->client; |
| 421 |
client->timeResidual += msec; |
| 422 |
|
| 423 |
while ( client->timeResidual >= 1000 ) { |
| 424 |
client->timeResidual -= 1000; |
| 425 |
|
| 426 |
//Stop in elimination!!! |
| 427 |
if (client->ps.pm_flags & PMF_ELIMWARMUP) |
| 428 |
continue; |
| 429 |
|
| 430 |
// regenerate |
| 431 |
if( bg_itemlist[client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_GUARD ) { |
| 432 |
maxHealth = client->ps.stats[STAT_MAX_HEALTH] / 2; |
| 433 |
} |
| 434 |
else if ( client->ps.powerups[PW_REGEN] ) { |
| 435 |
maxHealth = client->ps.stats[STAT_MAX_HEALTH]; |
| 436 |
} |
| 437 |
else { |
| 438 |
maxHealth = 0; |
| 439 |
} |
| 440 |
if( maxHealth ) { |
| 441 |
if ( ent->health < maxHealth ) { |
| 442 |
ent->health += 15; |
| 443 |
if ( ent->health > maxHealth * 1.1 ) { |
| 444 |
ent->health = maxHealth * 1.1; |
| 445 |
} |
| 446 |
G_AddEvent( ent, EV_POWERUP_REGEN, 0 ); |
| 447 |
} else if ( ent->health < maxHealth * 2) { |
| 448 |
ent->health += 5; |
| 449 |
if ( ent->health > maxHealth * 2 ) { |
| 450 |
ent->health = maxHealth * 2; |
| 451 |
} |
| 452 |
G_AddEvent( ent, EV_POWERUP_REGEN, 0 ); |
| 453 |
} |
| 454 |
} else { |
| 455 |
// count down health when over max |
| 456 |
if ( ent->health > client->ps.stats[STAT_MAX_HEALTH] ) { |
| 457 |
ent->health--; |
| 458 |
} |
| 459 |
//Start killing players in LMS, if we are in overtime |
| 460 |
if(g_elimination_roundtime.integer&&g_gametype.integer==GT_LMS && TeamHealthCount( -1, TEAM_FREE ) != ent->health &&(level.roundNumber==level.roundNumberStarted)&&(level.time>=level.roundStartTime+1000*g_elimination_roundtime.integer)) { |
| 461 |
ent->damage=5; |
| 462 |
G_Damage (ent, NULL, NULL, NULL, NULL, |
| 463 |
ent->damage, DAMAGE_NO_ARMOR, MOD_UNKNOWN); |
| 464 |
} |
| 465 |
else |
| 466 |
if ( ent->health < client->ps.stats[STAT_MAX_HEALTH] ) { |
| 467 |
ent->health+=g_regen.integer; |
| 468 |
if(ent->health>client->ps.stats[STAT_MAX_HEALTH]) |
| 469 |
ent->health= client->ps.stats[STAT_MAX_HEALTH]; |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
// count down armor when over max |
| 474 |
if ( client->ps.stats[STAT_ARMOR] > client->ps.stats[STAT_MAX_HEALTH] ) { |
| 475 |
client->ps.stats[STAT_ARMOR]--; |
| 476 |
} |
| 477 |
} |
| 478 |
if( bg_itemlist[client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_AMMOREGEN ) { |
| 479 |
int w, max, inc, t, i; |
| 480 |
int weapList[]={WP_MACHINEGUN,WP_SHOTGUN,WP_GRENADE_LAUNCHER,WP_ROCKET_LAUNCHER,WP_LIGHTNING,WP_RAILGUN,WP_PLASMAGUN,WP_BFG,WP_NAILGUN,WP_PROX_LAUNCHER,WP_CHAINGUN}; |
| 481 |
int weapCount = sizeof(weapList) / sizeof(int); |
| 482 |
// |
| 483 |
for (i = 0; i < weapCount; i++) { |
| 484 |
w = weapList[i]; |
| 485 |
|
| 486 |
switch(w) { |
| 487 |
case WP_MACHINEGUN: max = 50; inc = 4; t = 1000; break; |
| 488 |
case WP_SHOTGUN: max = 10; inc = 1; t = 1500; break; |
| 489 |
case WP_GRENADE_LAUNCHER: max = 10; inc = 1; t = 2000; break; |
| 490 |
case WP_ROCKET_LAUNCHER: max = 10; inc = 1; t = 1750; break; |
| 491 |
case WP_LIGHTNING: max = 50; inc = 5; t = 1500; break; |
| 492 |
case WP_RAILGUN: max = 10; inc = 1; t = 1750; break; |
| 493 |
case WP_PLASMAGUN: max = 50; inc = 5; t = 1500; break; |
| 494 |
case WP_BFG: max = 10; inc = 1; t = 4000; break; |
| 495 |
case WP_NAILGUN: max = 10; inc = 1; t = 1250; break; |
| 496 |
case WP_PROX_LAUNCHER: max = 5; inc = 1; t = 2000; break; |
| 497 |
case WP_CHAINGUN: max = 100; inc = 5; t = 1000; break; |
| 498 |
default: max = 0; inc = 0; t = 1000; break; |
| 499 |
} |
| 500 |
client->ammoTimes[w] += msec; |
| 501 |
if ( client->ps.ammo[w] >= max ) { |
| 502 |
client->ammoTimes[w] = 0; |
| 503 |
} |
| 504 |
if ( client->ammoTimes[w] >= t ) { |
| 505 |
while ( client->ammoTimes[w] >= t ) |
| 506 |
client->ammoTimes[w] -= t; |
| 507 |
client->ps.ammo[w] += inc; |
| 508 |
if ( client->ps.ammo[w] > max ) { |
| 509 |
client->ps.ammo[w] = max; |
| 510 |
} |
| 511 |
} |
| 512 |
} |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
/* |
| 517 |
==================== |
| 518 |
ClientIntermissionThink |
| 519 |
==================== |
| 520 |
*/ |
| 521 |
void ClientIntermissionThink( gclient_t *client ) { |
| 522 |
client->ps.eFlags &= ~EF_TALK; |
| 523 |
client->ps.eFlags &= ~EF_FIRING; |
| 524 |
|
| 525 |
// the level will exit when everyone wants to or after timeouts |
| 526 |
|
| 527 |
if( g_entities[client->ps.clientNum].r.svFlags & SVF_BOT ) |
| 528 |
return; //Bots cannot mark themself as ready |
| 529 |
|
| 530 |
// swap and latch button actions |
| 531 |
client->oldbuttons = client->buttons; |
| 532 |
client->buttons = client->pers.cmd.buttons; |
| 533 |
if ( client->buttons & ( BUTTON_ATTACK | BUTTON_USE_HOLDABLE ) & ( client->oldbuttons ^ client->buttons ) ) { |
| 534 |
// this used to be an ^1 but once a player says ready, it should stick |
| 535 |
client->readyToExit = 1; |
| 536 |
} |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
/* |
| 541 |
================ |
| 542 |
ClientEvents |
| 543 |
|
| 544 |
Events will be passed on to the clients for presentation, |
| 545 |
but any server game effects are handled here |
| 546 |
================ |
| 547 |
*/ |
| 548 |
void ClientEvents( gentity_t *ent, int oldEventSequence ) { |
| 549 |
int i, j; |
| 550 |
int event; |
| 551 |
gclient_t *client; |
| 552 |
int damage; |
| 553 |
vec3_t dir; |
| 554 |
vec3_t origin, angles; |
| 555 |
// qboolean fired; |
| 556 |
gitem_t *item; |
| 557 |
gentity_t *drop; |
| 558 |
|
| 559 |
client = ent->client; |
| 560 |
|
| 561 |
if ( oldEventSequence < client->ps.eventSequence - MAX_PS_EVENTS ) { |
| 562 |
oldEventSequence = client->ps.eventSequence - MAX_PS_EVENTS; |
| 563 |
} |
| 564 |
for ( i = oldEventSequence ; i < client->ps.eventSequence ; i++ ) { |
| 565 |
event = client->ps.events[ i & (MAX_PS_EVENTS-1) ]; |
| 566 |
|
| 567 |
switch ( event ) { |
| 568 |
case EV_FALL_MEDIUM: |
| 569 |
case EV_FALL_FAR: |
| 570 |
if ( ent->s.eType != ET_PLAYER ) { |
| 571 |
break; // not in the player model |
| 572 |
} |
| 573 |
if ( g_dmflags.integer & DF_NO_FALLING ) { |
| 574 |
break; |
| 575 |
} |
| 576 |
if ( event == EV_FALL_FAR ) { |
| 577 |
damage = 10; |
| 578 |
} else { |
| 579 |
damage = 5; |
| 580 |
} |
| 581 |
VectorSet (dir, 0, 0, 1); |
| 582 |
ent->pain_debounce_time = level.time + 200; // no normal pain sound |
| 583 |
G_Damage (ent, NULL, NULL, NULL, NULL, damage, 0, MOD_FALLING); |
| 584 |
break; |
| 585 |
|
| 586 |
case EV_FIRE_WEAPON: |
| 587 |
FireWeapon( ent ); |
| 588 |
break; |
| 589 |
|
| 590 |
case EV_USE_ITEM1: // teleporter |
| 591 |
// drop flags in CTF |
| 592 |
item = NULL; |
| 593 |
j = 0; |
| 594 |
|
| 595 |
if ( ent->client->ps.powerups[ PW_REDFLAG ] ) { |
| 596 |
item = BG_FindItemForPowerup( PW_REDFLAG ); |
| 597 |
j = PW_REDFLAG; |
| 598 |
} else if ( ent->client->ps.powerups[ PW_BLUEFLAG ] ) { |
| 599 |
item = BG_FindItemForPowerup( PW_BLUEFLAG ); |
| 600 |
j = PW_BLUEFLAG; |
| 601 |
} else if ( ent->client->ps.powerups[ PW_NEUTRALFLAG ] ) { |
| 602 |
item = BG_FindItemForPowerup( PW_NEUTRALFLAG ); |
| 603 |
j = PW_NEUTRALFLAG; |
| 604 |
} |
| 605 |
|
| 606 |
if ( item ) { |
| 607 |
drop = Drop_Item( ent, item, 0 ); |
| 608 |
// decide how many seconds it has left |
| 609 |
drop->count = ( ent->client->ps.powerups[ j ] - level.time ) / 1000; |
| 610 |
if ( drop->count < 1 ) { |
| 611 |
drop->count = 1; |
| 612 |
} |
| 613 |
|
| 614 |
ent->client->ps.powerups[ j ] = 0; |
| 615 |
} |
| 616 |
|
| 617 |
if ( g_gametype.integer == GT_HARVESTER ) { |
| 618 |
if ( ent->client->ps.generic1 > 0 ) { |
| 619 |
if ( ent->client->sess.sessionTeam == TEAM_RED ) { |
| 620 |
item = BG_FindItem( "Blue Cube" ); |
| 621 |
} else { |
| 622 |
item = BG_FindItem( "Red Cube" ); |
| 623 |
} |
| 624 |
if ( item ) { |
| 625 |
for ( j = 0; j < ent->client->ps.generic1; j++ ) { |
| 626 |
drop = Drop_Item( ent, item, 0 ); |
| 627 |
if ( ent->client->sess.sessionTeam == TEAM_RED ) { |
| 628 |
drop->spawnflags = TEAM_BLUE; |
| 629 |
} else { |
| 630 |
drop->spawnflags = TEAM_RED; |
| 631 |
} |
| 632 |
} |
| 633 |
} |
| 634 |
ent->client->ps.generic1 = 0; |
| 635 |
} |
| 636 |
} |
| 637 |
SelectSpawnPoint( ent->client->ps.origin, origin, angles ); |
| 638 |
TeleportPlayer( ent, origin, angles ); |
| 639 |
break; |
| 640 |
|
| 641 |
case EV_USE_ITEM2: // medkit |
| 642 |
ent->health = ent->client->ps.stats[STAT_MAX_HEALTH] + 25; |
| 643 |
|
| 644 |
break; |
| 645 |
|
| 646 |
case EV_USE_ITEM3: // kamikaze |
| 647 |
// make sure the invulnerability is off |
| 648 |
ent->client->invulnerabilityTime = 0; |
| 649 |
// start the kamikze |
| 650 |
G_StartKamikaze( ent ); |
| 651 |
break; |
| 652 |
|
| 653 |
case EV_USE_ITEM4: // portal |
| 654 |
if( ent->client->portalID ) { |
| 655 |
DropPortalSource( ent ); |
| 656 |
} |
| 657 |
else { |
| 658 |
DropPortalDestination( ent ); |
| 659 |
} |
| 660 |
break; |
| 661 |
case EV_USE_ITEM5: // invulnerability |
| 662 |
ent->client->invulnerabilityTime = level.time + 10000; |
| 663 |
break; |
| 664 |
|
| 665 |
default: |
| 666 |
break; |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
} |
| 671 |
|
| 672 |
/* |
| 673 |
============== |
| 674 |
StuckInOtherClient |
| 675 |
============== |
| 676 |
*/ |
| 677 |
static int StuckInOtherClient(gentity_t *ent) { |
| 678 |
int i; |
| 679 |
gentity_t *ent2; |
| 680 |
|
| 681 |
ent2 = &g_entities[0]; |
| 682 |
for ( i = 0; i < MAX_CLIENTS; i++, ent2++ ) { |
| 683 |
if ( ent2 == ent ) { |
| 684 |
continue; |
| 685 |
} |
| 686 |
if ( !ent2->inuse ) { |
| 687 |
continue; |
| 688 |
} |
| 689 |
if ( !ent2->client ) { |
| 690 |
continue; |
| 691 |
} |
| 692 |
if ( ent2->health <= 0 ) { |
| 693 |
continue; |
| 694 |
} |
| 695 |
// |
| 696 |
if (ent2->r.absmin[0] > ent->r.absmax[0]) |
| 697 |
continue; |
| 698 |
if (ent2->r.absmin[1] > ent->r.absmax[1]) |
| 699 |
continue; |
| 700 |
if (ent2->r.absmin[2] > ent->r.absmax[2]) |
| 701 |
continue; |
| 702 |
if (ent2->r.absmax[0] < ent->r.absmin[0]) |
| 703 |
continue; |
| 704 |
if (ent2->r.absmax[1] < ent->r.absmin[1]) |
| 705 |
continue; |
| 706 |
if (ent2->r.absmax[2] < ent->r.absmin[2]) |
| 707 |
continue; |
| 708 |
return qtrue; |
| 709 |
} |
| 710 |
return qfalse; |
| 711 |
} |
| 712 |
|
| 713 |
void BotTestSolid(vec3_t origin); |
| 714 |
|
| 715 |
/* |
| 716 |
============== |
| 717 |
SendPendingPredictableEvents |
| 718 |
============== |
| 719 |
*/ |
| 720 |
void SendPendingPredictableEvents( playerState_t *ps ) { |
| 721 |
gentity_t *t; |
| 722 |
int event, seq; |
| 723 |
int extEvent, number; |
| 724 |
|
| 725 |
// if there are still events pending |
| 726 |
if ( ps->entityEventSequence < ps->eventSequence ) { |
| 727 |
// create a temporary entity for this event which is sent to everyone |
| 728 |
// except the client who generated the event |
| 729 |
seq = ps->entityEventSequence & (MAX_PS_EVENTS-1); |
| 730 |
event = ps->events[ seq ] | ( ( ps->entityEventSequence & 3 ) << 8 ); |
| 731 |
// set external event to zero before calling BG_PlayerStateToEntityState |
| 732 |
extEvent = ps->externalEvent; |
| 733 |
ps->externalEvent = 0; |
| 734 |
// create temporary entity for event |
| 735 |
t = G_TempEntity( ps->origin, event ); |
| 736 |
number = t->s.number; |
| 737 |
BG_PlayerStateToEntityState( ps, &t->s, qtrue ); |
| 738 |
t->s.number = number; |
| 739 |
t->s.eType = ET_EVENTS + event; |
| 740 |
t->s.eFlags |= EF_PLAYER_EVENT; |
| 741 |
t->s.otherEntityNum = ps->clientNum; |
| 742 |
// send to everyone except the client who generated the event |
| 743 |
t->r.svFlags |= SVF_NOTSINGLECLIENT; |
| 744 |
t->r.singleClient = ps->clientNum; |
| 745 |
// set back external event |
| 746 |
ps->externalEvent = extEvent; |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
/* |
| 751 |
============== |
| 752 |
ClientThink |
| 753 |
|
| 754 |
This will be called once for each client frame, which will |
| 755 |
usually be a couple times for each server frame on fast clients. |
| 756 |
|
| 757 |
If "g_synchronousClients 1" is set, this will be called exactly |
| 758 |
once for each server frame, which makes for smooth demo recording. |
| 759 |
============== |
| 760 |
*/ |
| 761 |
void ClientThink_real( gentity_t *ent ) { |
| 762 |
gclient_t *client; |
| 763 |
pmove_t pm; |
| 764 |
int oldEventSequence; |
| 765 |
int msec; |
| 766 |
usercmd_t *ucmd; |
| 767 |
|
| 768 |
client = ent->client; |
| 769 |
|
| 770 |
// don't think if the client is not yet connected (and thus not yet spawned in) |
| 771 |
if (client->pers.connected != CON_CONNECTED) { |
| 772 |
return; |
| 773 |
} |
| 774 |
// mark the time, so the connection sprite can be removed |
| 775 |
ucmd = &ent->client->pers.cmd; |
| 776 |
|
| 777 |
// sanity check the command time to prevent speedup cheating |
| 778 |
if ( ucmd->serverTime > level.time + 200 ) { |
| 779 |
ucmd->serverTime = level.time + 200; |
| 780 |
// G_Printf("serverTime <<<<<\n" ); |
| 781 |
} |
| 782 |
if ( ucmd->serverTime < level.time - 1000 ) { |
| 783 |
ucmd->serverTime = level.time - 1000; |
| 784 |
// G_Printf("serverTime >>>>>\n" ); |
| 785 |
} |
| 786 |
|
| 787 |
//Here comes the unlagged bit! |
| 788 |
//unlagged - backward reconciliation #4 |
| 789 |
// frameOffset should be about the number of milliseconds into a frame |
| 790 |
// this command packet was received, depending on how fast the server |
| 791 |
// does a G_RunFrame() |
| 792 |
client->frameOffset = trap_Milliseconds() - level.frameStartTime; |
| 793 |
//unlagged - backward reconciliation #4 |
| 794 |
|
| 795 |
|
| 796 |
//unlagged - lag simulation #3 |
| 797 |
// if the client wants to simulate outgoing packet loss |
| 798 |
/* if ( client->pers.plOut ) { |
| 799 |
// see if a random value is below the threshhold |
| 800 |
float thresh = (float)client->pers.plOut / 100.0f; |
| 801 |
if ( random() < thresh ) { |
| 802 |
// do nothing at all if it is - this is a lost command |
| 803 |
return; |
| 804 |
} |
| 805 |
}*/ |
| 806 |
//unlagged - lag simulation #3 |
| 807 |
|
| 808 |
|
| 809 |
//unlagged - true ping |
| 810 |
// save the estimated ping in a queue for averaging later |
| 811 |
|
| 812 |
// we use level.previousTime to account for 50ms lag correction |
| 813 |
// besides, this will turn out numbers more like what players are used to |
| 814 |
client->pers.pingsamples[client->pers.samplehead] = level.previousTime + client->frameOffset - ucmd->serverTime; |
| 815 |
client->pers.samplehead++; |
| 816 |
if ( client->pers.samplehead >= NUM_PING_SAMPLES ) { |
| 817 |
client->pers.samplehead -= NUM_PING_SAMPLES; |
| 818 |
} |
| 819 |
|
| 820 |
// initialize the real ping |
| 821 |
if ( g_truePing.integer ) { |
| 822 |
int i, sum = 0; |
| 823 |
|
| 824 |
// get an average of the samples we saved up |
| 825 |
for ( i = 0; i < NUM_PING_SAMPLES; i++ ) { |
| 826 |
sum += client->pers.pingsamples[i]; |
| 827 |
} |
| 828 |
|
| 829 |
client->pers.realPing = sum / NUM_PING_SAMPLES; |
| 830 |
} |
| 831 |
else { |
| 832 |
// if g_truePing is off, use the normal ping |
| 833 |
client->pers.realPing = client->ps.ping; |
| 834 |
} |
| 835 |
//unlagged - true ping |
| 836 |
|
| 837 |
|
| 838 |
//unlagged - lag simulation #2 |
| 839 |
// keep a queue of past commands |
| 840 |
/* client->pers.cmdqueue[client->pers.cmdhead] = client->pers.cmd; |
| 841 |
client->pers.cmdhead++; |
| 842 |
if ( client->pers.cmdhead >= MAX_LATENT_CMDS ) { |
| 843 |
client->pers.cmdhead -= MAX_LATENT_CMDS; |
| 844 |
} |
| 845 |
|
| 846 |
// if the client wants latency in commands (client-to-server latency) |
| 847 |
if ( client->pers.latentCmds ) { |
| 848 |
// save the actual command time |
| 849 |
int time = ucmd->serverTime; |
| 850 |
|
| 851 |
// find out which index in the queue we want |
| 852 |
int cmdindex = client->pers.cmdhead - client->pers.latentCmds - 1; |
| 853 |
while ( cmdindex < 0 ) { |
| 854 |
cmdindex += MAX_LATENT_CMDS; |
| 855 |
} |
| 856 |
|
| 857 |
// read in the old command |
| 858 |
client->pers.cmd = client->pers.cmdqueue[cmdindex]; |
| 859 |
|
| 860 |
// adjust the real ping to reflect the new latency |
| 861 |
client->pers.realPing += time - ucmd->serverTime; |
| 862 |
}*/ |
| 863 |
//unlagged - lag simulation #2 |
| 864 |
|
| 865 |
|
| 866 |
//unlagged - backward reconciliation #4 |
| 867 |
// save the command time *before* pmove_fixed messes with the serverTime, |
| 868 |
// and *after* lag simulation messes with it :) |
| 869 |
// attackTime will be used for backward reconciliation later (time shift) |
| 870 |
client->attackTime = ucmd->serverTime; |
| 871 |
//unlagged - backward reconciliation #4 |
| 872 |
|
| 873 |
|
| 874 |
//unlagged - smooth clients #1 |
| 875 |
// keep track of this for later - we'll use this to decide whether or not |
| 876 |
// to send extrapolated positions for this client |
| 877 |
client->lastUpdateFrame = level.framenum; |
| 878 |
//unlagged - smooth clients #1 |
| 879 |
|
| 880 |
|
| 881 |
//unlagged - lag simulation #1 |
| 882 |
// if the client is adding latency to received snapshots (server-to-client latency) |
| 883 |
/*if ( client->pers.latentSnaps ) { |
| 884 |
// adjust the real ping |
| 885 |
client->pers.realPing += client->pers.latentSnaps * (1000 / sv_fps.integer); |
| 886 |
// adjust the attack time so backward reconciliation will work |
| 887 |
client->attackTime -= client->pers.latentSnaps * (1000 / sv_fps.integer); |
| 888 |
}*/ |
| 889 |
//unlagged - lag simulation #1 |
| 890 |
|
| 891 |
|
| 892 |
//unlagged - true ping |
| 893 |
// make sure the true ping is over 0 - with cl_timenudge it can be less |
| 894 |
if ( client->pers.realPing < 0 ) { |
| 895 |
client->pers.realPing = 0; |
| 896 |
} |
| 897 |
//unlagged - true ping |
| 898 |
|
| 899 |
msec = ucmd->serverTime - client->ps.commandTime; |
| 900 |
// following others may result in bad times, but we still want |
| 901 |
// to check for follow toggles |
| 902 |
if ( msec < 1 && client->sess.spectatorState != SPECTATOR_FOLLOW ) { |
| 903 |
return; |
| 904 |
} |
| 905 |
if ( msec > 200 ) { |
| 906 |
msec = 200; |
| 907 |
} |
| 908 |
|
| 909 |
if ( pmove_msec.integer < 8 ) { |
| 910 |
trap_Cvar_Set("pmove_msec", "8"); |
| 911 |
} |
| 912 |
else if (pmove_msec.integer > 33) { |
| 913 |
trap_Cvar_Set("pmove_msec", "33"); |
| 914 |
} |
| 915 |
|
| 916 |
if ( pmove_fixed.integer || client->pers.pmoveFixed ) { |
| 917 |
ucmd->serverTime = ((ucmd->serverTime + pmove_msec.integer-1) / pmove_msec.integer) * pmove_msec.integer; |
| 918 |
//if (ucmd->serverTime - client->ps.commandTime <= 0) |
| 919 |
// return; |
| 920 |
} |
| 921 |
|
| 922 |
// |
| 923 |
// check for exiting intermission |
| 924 |
// |
| 925 |
if ( level.intermissiontime ) { |
| 926 |
ClientIntermissionThink( client ); |
| 927 |
return; |
| 928 |
} |
| 929 |
|
| 930 |
// spectators don't do much |
| 931 |
if ( (client->sess.sessionTeam == TEAM_SPECTATOR) || client->isEliminated ) { |
| 932 |
if ( client->sess.spectatorState == SPECTATOR_SCOREBOARD ) { |
| 933 |
return; |
| 934 |
} |
| 935 |
SpectatorThink( ent, ucmd ); |
| 936 |
return; |
| 937 |
} |
| 938 |
|
| 939 |
// check for inactivity timer, but never drop the local client of a non-dedicated server |
| 940 |
if ( !ClientInactivityTimer( client ) ) { |
| 941 |
return; |
| 942 |
} |
| 943 |
|
| 944 |
// clear the rewards if time |
| 945 |
if ( level.time > client->rewardTime ) { |
| 946 |
client->ps.eFlags &= ~(EF_AWARD_IMPRESSIVE | EF_AWARD_EXCELLENT | EF_AWARD_GAUNTLET | EF_AWARD_ASSIST | EF_AWARD_DEFEND | EF_AWARD_CAP ); |
| 947 |
} |
| 948 |
|
| 949 |
if ( client->noclip ) { |
| 950 |
client->ps.pm_type = PM_NOCLIP; |
| 951 |
} else if ( client->ps.stats[STAT_HEALTH] <= 0 ) { |
| 952 |
client->ps.pm_type = PM_DEAD; |
| 953 |
} else { |
| 954 |
client->ps.pm_type = PM_NORMAL; |
| 955 |
} |
| 956 |
|
| 957 |
client->ps.gravity = g_gravity.value*g_gravityModifier.value; |
| 958 |
|
| 959 |
// set speed |
| 960 |
client->ps.speed = g_speed.value; |
| 961 |
|
| 962 |
if( bg_itemlist[client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_SCOUT ) { |
| 963 |
client->ps.speed *= 1.5; |
| 964 |
} |
| 965 |
else |
| 966 |
if ( client->ps.powerups[PW_HASTE] ) { |
| 967 |
client->ps.speed *= 1.3; |
| 968 |
} |
| 969 |
|
| 970 |
// Let go of the hook if we aren't firing |
| 971 |
if ( client->ps.weapon == WP_GRAPPLING_HOOK && |
| 972 |
client->hook && !( ucmd->buttons & BUTTON_ATTACK ) ) { |
| 973 |
Weapon_HookFree(client->hook); |
| 974 |
} |
| 975 |
|
| 976 |
// set up for pmove |
| 977 |
oldEventSequence = client->ps.eventSequence; |
| 978 |
|
| 979 |
memset (&pm, 0, sizeof(pm)); |
| 980 |
|
| 981 |
// check for the hit-scan gauntlet, don't let the action |
| 982 |
// go through as an attack unless it actually hits something |
| 983 |
if ( client->ps.weapon == WP_GAUNTLET && !( ucmd->buttons & BUTTON_TALK ) && |
| 984 |
( ucmd->buttons & BUTTON_ATTACK ) && client->ps.weaponTime <= 0 ) { |
| 985 |
pm.gauntletHit = CheckGauntletAttack( ent ); |
| 986 |
} |
| 987 |
|
| 988 |
if ( ent->flags & FL_FORCE_GESTURE ) { |
| 989 |
ent->flags &= ~FL_FORCE_GESTURE; |
| 990 |
ent->client->pers.cmd.buttons |= BUTTON_GESTURE; |
| 991 |
} |
| 992 |
|
| 993 |
// check for invulnerability expansion before doing the Pmove |
| 994 |
if (client->ps.powerups[PW_INVULNERABILITY] ) { |
| 995 |
if ( !(client->ps.pm_flags & PMF_INVULEXPAND) ) { |
| 996 |
vec3_t mins = { -42, -42, -42 }; |
| 997 |
vec3_t maxs = { 42, 42, 42 }; |
| 998 |
vec3_t oldmins, oldmaxs; |
| 999 |
|
| 1000 |
VectorCopy (ent->r.mins, oldmins); |
| 1001 |
VectorCopy (ent->r.maxs, oldmaxs); |
| 1002 |
// expand |
| 1003 |
VectorCopy (mins, ent->r.mins); |
| 1004 |
VectorCopy (maxs, ent->r.maxs); |
| 1005 |
trap_LinkEntity(ent); |
| 1006 |
// check if this would get anyone stuck in this player |
| 1007 |
if ( !StuckInOtherClient(ent) ) { |
| 1008 |
// set flag so the expanded size will be set in PM_CheckDuck |
| 1009 |
client->ps.pm_flags |= PMF_INVULEXPAND; |
| 1010 |
} |
| 1011 |
// set back |
| 1012 |
VectorCopy (oldmins, ent->r.mins); |
| 1013 |
VectorCopy (oldmaxs, ent->r.maxs); |
| 1014 |
trap_LinkEntity(ent); |
| 1015 |
} |
| 1016 |
} |
| 1017 |
|
| 1018 |
pm.ps = &client->ps; |
| 1019 |
pm.cmd = *ucmd; |
| 1020 |
if ( pm.ps->pm_type == PM_DEAD ) { |
| 1021 |
pm.tracemask = MASK_PLAYERSOLID & ~CONTENTS_BODY; |
| 1022 |
} |
| 1023 |
else if ( ent->r.svFlags & SVF_BOT ) { |
| 1024 |
pm.tracemask = MASK_PLAYERSOLID | CONTENTS_BOTCLIP; |
| 1025 |
} |
| 1026 |
else { |
| 1027 |
pm.tracemask = MASK_PLAYERSOLID; |
| 1028 |
} |
| 1029 |
pm.trace = trap_Trace; |
| 1030 |
pm.pointcontents = trap_PointContents; |
| 1031 |
pm.debugLevel = g_debugMove.integer; |
| 1032 |
pm.noFootsteps = ( g_dmflags.integer & DF_NO_FOOTSTEPS ) > 0; |
| 1033 |
|
| 1034 |
pm.pmove_fixed = pmove_fixed.integer | client->pers.pmoveFixed; |
| 1035 |
pm.pmove_msec = pmove_msec.integer; |
| 1036 |
pm.pmove_float = pmove_float.integer; |
| 1037 |
pm.pmove_flags = g_dmflags.integer; |
| 1038 |
|
| 1039 |
VectorCopy( client->ps.origin, client->oldOrigin ); |
| 1040 |
|
| 1041 |
#ifdef MISSIONPACK |
| 1042 |
if (level.intermissionQueued != 0 && g_singlePlayer.integer) { |
| 1043 |
if ( level.time - level.intermissionQueued >= 1000 ) { |
| 1044 |
pm.cmd.buttons = 0; |
| 1045 |
pm.cmd.forwardmove = 0; |
| 1046 |
pm.cmd.rightmove = 0; |
| 1047 |
pm.cmd.upmove = 0; |
| 1048 |
if ( level.time - level.intermissionQueued >= 2000 && level.time - level.intermissionQueued <= 2500 ) { |
| 1049 |
trap_SendConsoleCommand( EXEC_APPEND, "centerview\n"); |
| 1050 |
} |
| 1051 |
ent->client->ps.pm_type = PM_SPINTERMISSION; |
| 1052 |
} |
| 1053 |
} |
| 1054 |
#endif |
| 1055 |
Pmove (&pm); |
| 1056 |
|
| 1057 |
// save results of pmove |
| 1058 |
if ( ent->client->ps.eventSequence != oldEventSequence ) { |
| 1059 |
ent->eventTime = level.time; |
| 1060 |
} |
| 1061 |
//unlagged - smooth clients #2 |
| 1062 |
// clients no longer do extrapolation if cg_smoothClients is 1, because |
| 1063 |
// skip correction is all handled server-side now |
| 1064 |
// since that's the case, it makes no sense to store the extra info |
| 1065 |
// in the client's snapshot entity, so let's save a little bandwidth |
| 1066 |
/* |
| 1067 |
if (g_smoothClients.integer) { |
| 1068 |
BG_PlayerStateToEntityStateExtraPolate( &ent->client->ps, &ent->s, ent->client->ps.commandTime, qtrue ); |
| 1069 |
} |
| 1070 |
else { |
| 1071 |
*/ |
| 1072 |
BG_PlayerStateToEntityState( &ent->client->ps, &ent->s, qtrue ); |
| 1073 |
// } |
| 1074 |
//unlagged - smooth clients #2 |
| 1075 |
SendPendingPredictableEvents( &ent->client->ps ); |
| 1076 |
|
| 1077 |
if ( !( ent->client->ps.eFlags & EF_FIRING ) ) { |
| 1078 |
client->fireHeld = qfalse; // for grapple |
| 1079 |
} |
| 1080 |
|
| 1081 |
// use the snapped origin for linking so it matches client predicted versions |
| 1082 |
VectorCopy( ent->s.pos.trBase, ent->r.currentOrigin ); |
| 1083 |
|
| 1084 |
VectorCopy (pm.mins, ent->r.mins); |
| 1085 |
VectorCopy (pm.maxs, ent->r.maxs); |
| 1086 |
|
| 1087 |
ent->waterlevel = pm.waterlevel; |
| 1088 |
ent->watertype = pm.watertype; |
| 1089 |
|
| 1090 |
// execute client events |
| 1091 |
ClientEvents( ent, oldEventSequence ); |
| 1092 |
|
| 1093 |
// link entity now, after any personal teleporters have been used |
| 1094 |
trap_LinkEntity (ent); |
| 1095 |
if ( !ent->client->noclip ) { |
| 1096 |
G_TouchTriggers( ent ); |
| 1097 |
} |
| 1098 |
|
| 1099 |
// NOTE: now copy the exact origin over otherwise clients can be snapped into solid |
| 1100 |
VectorCopy( ent->client->ps.origin, ent->r.currentOrigin ); |
| 1101 |
|
| 1102 |
//test for solid areas in the AAS file |
| 1103 |
BotTestAAS(ent->r.currentOrigin); |
| 1104 |
|
| 1105 |
// touch other objects |
| 1106 |
ClientImpacts( ent, &pm ); |
| 1107 |
|
| 1108 |
// save results of triggers and client events |
| 1109 |
if (ent->client->ps.eventSequence != oldEventSequence) { |
| 1110 |
ent->eventTime = level.time; |
| 1111 |
} |
| 1112 |
|
| 1113 |
// swap and latch button actions |
| 1114 |
client->oldbuttons = client->buttons; |
| 1115 |
client->buttons = ucmd->buttons; |
| 1116 |
client->latched_buttons |= client->buttons & ~client->oldbuttons; |
| 1117 |
|
| 1118 |
// check for respawning |
| 1119 |
if ( client->ps.stats[STAT_HEALTH] <= 0 ) { |
| 1120 |
// wait for the attack button to be pressed |
| 1121 |
// forcerespawn is to prevent users from waiting out powerups |
| 1122 |
// In Last man standing, we force a quick respawn, since |
| 1123 |
// the player must be able to loose health |
| 1124 |
// pressing attack or use is the normal respawn method |
| 1125 |
if ( ( level.time > client->respawnTime ) && |
| 1126 |
( ( ( g_forcerespawn.integer > 0 ) && |
| 1127 |
( level.time - client->respawnTime > g_forcerespawn.integer * 1000 ) ) || |
| 1128 |
( ( ( g_gametype.integer == GT_LMS ) || |
| 1129 |
( g_gametype.integer == GT_ELIMINATION ) || |
| 1130 |
( g_gametype.integer == GT_CTF_ELIMINATION ) ) && |
| 1131 |
( level.time - client->respawnTime > 0 ) ) || |
| 1132 |
( ucmd->buttons & ( BUTTON_ATTACK | BUTTON_USE_HOLDABLE ) ) ) ) { |
| 1133 |
|
| 1134 |
ClientRespawn( ent ); |
| 1135 |
} |
| 1136 |
return; |
| 1137 |
} |
| 1138 |
|
| 1139 |
if ( pm.waterlevel <= 1 && pm.ps->groundEntityNum!=ENTITYNUM_NONE && client->lastSentFlyingTime+500>level.time) { |
| 1140 |
if ( ! (pm.ps->pm_flags & PMF_TIME_KNOCKBACK) ) { |
| 1141 |
client->lastSentFlying = -1; |
| 1142 |
} |
| 1143 |
} |
| 1144 |
|
| 1145 |
// perform once-a-second actions |
| 1146 |
ClientTimerActions( ent, msec ); |
| 1147 |
} |
| 1148 |
|
| 1149 |
/* |
| 1150 |
================== |
| 1151 |
ClientThink |
| 1152 |
|
| 1153 |
A new command has arrived from the client |
| 1154 |
================== |
| 1155 |
*/ |
| 1156 |
void ClientThink( int clientNum ) { |
| 1157 |
gentity_t *ent; |
| 1158 |
|
| 1159 |
ent = g_entities + clientNum; |
| 1160 |
trap_GetUsercmd( clientNum, &ent->client->pers.cmd ); |
| 1161 |
|
| 1162 |
//Unlagged: commented out |
| 1163 |
// mark the time we got info, so we can display the |
| 1164 |
// phone jack if they don't get any for a while |
| 1165 |
//ent->client->lastCmdTime = level.time; |
| 1166 |
|
| 1167 |
if ( !(ent->r.svFlags & SVF_BOT) && !g_synchronousClients.integer ) { |
| 1168 |
ClientThink_real( ent ); |
| 1169 |
} |
| 1170 |
} |
| 1171 |
|
| 1172 |
|
| 1173 |
void G_RunClient( gentity_t *ent ) { |
| 1174 |
if ( !(ent->r.svFlags & SVF_BOT) && !g_synchronousClients.integer ) { |
| 1175 |
return; |
| 1176 |
} |
| 1177 |
ent->client->pers.cmd.serverTime = level.time; |
| 1178 |
ClientThink_real( ent ); |
| 1179 |
} |
| 1180 |
|
| 1181 |
|
| 1182 |
/* |
| 1183 |
================== |
| 1184 |
SpectatorClientEndFrame |
| 1185 |
|
| 1186 |
================== |
| 1187 |
*/ |
| 1188 |
void SpectatorClientEndFrame( gentity_t *ent ) { |
| 1189 |
gclient_t *cl; |
| 1190 |
int i, preservedScore[MAX_PERSISTANT]; //for keeping in elimination |
| 1191 |
|
| 1192 |
// if we are doing a chase cam or a remote view, grab the latest info |
| 1193 |
if ( ent->client->sess.spectatorState == SPECTATOR_FOLLOW ) { |
| 1194 |
int clientNum, flags; |
| 1195 |
|
| 1196 |
clientNum = ent->client->sess.spectatorClient; |
| 1197 |
|
| 1198 |
// team follow1 and team follow2 go to whatever clients are playing |
| 1199 |
if ( clientNum == -1 ) { |
| 1200 |
clientNum = level.follow1; |
| 1201 |
} else if ( clientNum == -2 ) { |
| 1202 |
clientNum = level.follow2; |
| 1203 |
} |
| 1204 |
if ( clientNum >= 0 ) { |
| 1205 |
cl = &level.clients[ clientNum ]; |
| 1206 |
if ( cl->pers.connected == CON_CONNECTED && cl->sess.sessionTeam != TEAM_SPECTATOR ) { |
| 1207 |
flags = (cl->ps.eFlags & ~(EF_VOTED | EF_TEAMVOTED)) | (ent->client->ps.eFlags & (EF_VOTED | EF_TEAMVOTED)); |
| 1208 |
//this is here LMS/Elimination goes wrong with player follow |
| 1209 |
if(ent->client->sess.sessionTeam!=TEAM_SPECTATOR){ |
| 1210 |
for(i = 0; i < MAX_PERSISTANT; i++) |
| 1211 |
preservedScore[i] = ent->client->ps.persistant[i]; |
| 1212 |
ent->client->ps = cl->ps; |
| 1213 |
for(i = 0; i < MAX_PERSISTANT; i++) |
| 1214 |
ent->client->ps.persistant[i] = preservedScore[i]; |
| 1215 |
} |
| 1216 |
else |
| 1217 |
ent->client->ps = cl->ps; |
| 1218 |
ent->client->ps.pm_flags |= PMF_FOLLOW; |
| 1219 |
ent->client->ps.eFlags = flags; |
| 1220 |
return; |
| 1221 |
} else { |
| 1222 |
// drop them to free spectators unless they are dedicated camera followers |
| 1223 |
if ( ent->client->sess.spectatorClient >= 0 ) { |
| 1224 |
ent->client->sess.spectatorState = SPECTATOR_FREE; |
| 1225 |
ClientBegin( ent->client - level.clients ); |
| 1226 |
} |
| 1227 |
} |
| 1228 |
} |
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
} |
| 1233 |
|
| 1234 |
if ( ent->client->sess.spectatorState == SPECTATOR_SCOREBOARD ) { |
| 1235 |
ent->client->ps.pm_flags |= PMF_SCOREBOARD; |
| 1236 |
} else { |
| 1237 |
ent->client->ps.pm_flags &= ~PMF_SCOREBOARD; |
| 1238 |
} |
| 1239 |
} |
| 1240 |
|
| 1241 |
/* |
| 1242 |
============== |
| 1243 |
ClientEndFrame |
| 1244 |
|
| 1245 |
Called at the end of each server frame for each connected client |
| 1246 |
A fast client will have multiple ClientThink for each ClientEdFrame, |
| 1247 |
while a slow client may have multiple ClientEndFrame between ClientThink. |
| 1248 |
============== |
| 1249 |
*/ |
| 1250 |
void ClientEndFrame( gentity_t *ent ) { |
| 1251 |
int i; |
| 1252 |
clientPersistant_t *pers; |
| 1253 |
|
| 1254 |
//unlagged - smooth clients #1 |
| 1255 |
int frames; |
| 1256 |
//unlagged - smooth clients #1 |
| 1257 |
|
| 1258 |
if ( (ent->client->sess.sessionTeam == TEAM_SPECTATOR) || ent->client->isEliminated ) { |
| 1259 |
SpectatorClientEndFrame( ent ); |
| 1260 |
return; |
| 1261 |
} |
| 1262 |
|
| 1263 |
pers = &ent->client->pers; |
| 1264 |
|
| 1265 |
// turn off any expired powerups |
| 1266 |
for ( i = 0 ; i < MAX_POWERUPS ; i++ ) { |
| 1267 |
if ( ent->client->ps.powerups[ i ] < level.time ) { |
| 1268 |
ent->client->ps.powerups[ i ] = 0; |
| 1269 |
} |
| 1270 |
} |
| 1271 |
|
| 1272 |
// set powerup for player animation |
| 1273 |
if( bg_itemlist[ent->client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_GUARD ) { |
| 1274 |
ent->client->ps.powerups[PW_GUARD] = level.time; |
| 1275 |
} |
| 1276 |
if( bg_itemlist[ent->client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_SCOUT ) { |
| 1277 |
ent->client->ps.powerups[PW_SCOUT] = level.time; |
| 1278 |
} |
| 1279 |
if( bg_itemlist[ent->client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_DOUBLER ) { |
| 1280 |
ent->client->ps.powerups[PW_DOUBLER] = level.time; |
| 1281 |
} |
| 1282 |
if( bg_itemlist[ent->client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_AMMOREGEN ) { |
| 1283 |
ent->client->ps.powerups[PW_AMMOREGEN] = level.time; |
| 1284 |
} |
| 1285 |
if ( ent->client->invulnerabilityTime > level.time ) { |
| 1286 |
ent->client->ps.powerups[PW_INVULNERABILITY] = level.time; |
| 1287 |
} |
| 1288 |
|
| 1289 |
// save network bandwidth |
| 1290 |
#if 0 |
| 1291 |
if ( !g_synchronousClients->integer && ent->client->ps.pm_type == PM_NORMAL ) { |
| 1292 |
// FIXME: this must change eventually for non-sync demo recording |
| 1293 |
VectorClear( ent->client->ps.viewangles ); |
| 1294 |
} |
| 1295 |
#endif |
| 1296 |
|
| 1297 |
// |
| 1298 |
// If the end of unit layout is displayed, don't give |
| 1299 |
// the player any normal movement attributes |
| 1300 |
// |
| 1301 |
if ( level.intermissiontime ) { |
| 1302 |
return; |
| 1303 |
} |
| 1304 |
|
| 1305 |
// burn from lava, etc |
| 1306 |
P_WorldEffects (ent); |
| 1307 |
|
| 1308 |
// apply all the damage taken this frame |
| 1309 |
P_DamageFeedback (ent); |
| 1310 |
|
| 1311 |
//Unlagged: Commented out |
| 1312 |
// add the EF_CONNECTION flag if we haven't gotten commands recently |
| 1313 |
/*if ( level.time - ent->client->lastCmdTime > 1000 ) { |
| 1314 |
ent->s.eFlags |= EF_CONNECTION; |
| 1315 |
} else { |
| 1316 |
ent->s.eFlags &= ~EF_CONNECTION; |
| 1317 |
}*/ |
| 1318 |
|
| 1319 |
ent->client->ps.stats[STAT_HEALTH] = ent->health; // FIXME: get rid of ent->health... |
| 1320 |
|
| 1321 |
G_SetClientSound (ent); |
| 1322 |
|
| 1323 |
//Unlagged: Always do the else clause |
| 1324 |
// set the latest infor |
| 1325 |
/* if (g_smoothClients.integer) { |
| 1326 |
BG_PlayerStateToEntityStateExtraPolate( &ent->client->ps, &ent->s, ent->client->ps.commandTime, qtrue ); |
| 1327 |
} |
| 1328 |
else { */ |
| 1329 |
BG_PlayerStateToEntityState( &ent->client->ps, &ent->s, qtrue ); |
| 1330 |
// } |
| 1331 |
SendPendingPredictableEvents( &ent->client->ps ); |
| 1332 |
|
| 1333 |
//unlagged - smooth clients #1 |
| 1334 |
// mark as not missing updates initially |
| 1335 |
ent->client->ps.eFlags &= ~EF_CONNECTION; |
| 1336 |
|
| 1337 |
// see how many frames the client has missed |
| 1338 |
frames = level.framenum - ent->client->lastUpdateFrame - 1; |
| 1339 |
|
| 1340 |
// don't extrapolate more than two frames |
| 1341 |
if ( frames > 2 ) { |
| 1342 |
frames = 2; |
| 1343 |
|
| 1344 |
// if they missed more than two in a row, show the phone jack |
| 1345 |
ent->client->ps.eFlags |= EF_CONNECTION; |
| 1346 |
ent->s.eFlags |= EF_CONNECTION; |
| 1347 |
} |
| 1348 |
|
| 1349 |
// did the client miss any frames? |
| 1350 |
if ( frames > 0 && g_smoothClients.integer ) { |
| 1351 |
// yep, missed one or more, so extrapolate the player's movement |
| 1352 |
G_PredictPlayerMove( ent, (float)frames / sv_fps.integer ); |
| 1353 |
// save network bandwidth |
| 1354 |
SnapVector( ent->s.pos.trBase ); |
| 1355 |
} |
| 1356 |
//unlagged - smooth clients #1 |
| 1357 |
|
| 1358 |
//unlagged - backward reconciliation #1 |
| 1359 |
// store the client's position for backward reconciliation later |
| 1360 |
G_StoreHistory( ent ); |
| 1361 |
//unlagged - backward reconciliation #1 |
| 1362 |
|
| 1363 |
// set the bit for the reachability area the client is currently in |
| 1364 |
// i = trap_AAS_PointReachabilityAreaIndex( ent->client->ps.origin ); |
| 1365 |
// ent->client->areabits[i >> 3] |= 1 << (i & 7); |
| 1366 |
} |
| 1367 |
|
| 1368 |
|