Debian Codegraph @

code/cgame/cg_players.c

raw
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 // cg_players.c -- handle the media and animation for player entities
24 #include "cg_local.h"
25
26 char *cg_customSoundNames[MAX_CUSTOM_SOUNDS] = {
27 "*death1.wav",
28 "*death2.wav",
29 "*death3.wav",
30 "*jump1.wav",
31 "*pain25_1.wav",
32 "*pain50_1.wav",
33 "*pain75_1.wav",
34 "*pain100_1.wav",
35 "*falling1.wav",
36 "*gasp.wav",
37 "*drown.wav",
38 "*fall1.wav",
39 "*taunt.wav"
40 };
41
42
43 /*
44 ================
45 CG_CustomSound
46
47 ================
48 */
49 sfxHandle_t CG_CustomSound( int clientNum, const char *soundName ) {
50 clientInfo_t *ci;
51 int i;
52
53 if ( soundName[0] != '*' ) {
54 return trap_S_RegisterSound( soundName, qfalse );
55 }
56
57 if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) {
58 clientNum = 0;
59 }
60 ci = &cgs.clientinfo[ clientNum ];
61
62 for ( i = 0 ; i < MAX_CUSTOM_SOUNDS && cg_customSoundNames[i] ; i++ ) {
63 if ( !strcmp( soundName, cg_customSoundNames[i] ) ) {
64 return ci->sounds[i];
65 }
66 }
67
68 CG_Error( "Unknown custom sound: %s", soundName );
69 return 0;
70 }
71
72
73
74 /*
75 =============================================================================
76
77 CLIENT INFO
78
79 =============================================================================
80 */
81
82 /*
83 ======================
84 CG_ParseAnimationFile
85
86 Read a configuration file containing animation coutns and rates
87 models/players/visor/animation.cfg, etc
88 ======================
89 */
90 static qboolean CG_ParseAnimationFile( const char *filename, clientInfo_t *ci ) {
91 char *text_p, *prev;
92 int len;
93 int i;
94 char *token;
95 float fps;
96 int skip;
97 char text[20000];
98 fileHandle_t f;
99 animation_t *animations;
100
101 animations = ci->animations;
102
103 // load the file
104 len = trap_FS_FOpenFile( filename, &f, FS_READ );
105 if ( len <= 0 ) {
106 return qfalse;
107 }
108 if ( len >= sizeof( text ) - 1 ) {
109 CG_Printf( "File %s too long\n", filename );
110 trap_FS_FCloseFile( f );
111 return qfalse;
112 }
113 trap_FS_Read( text, len, f );
114 text[len] = 0;
115 trap_FS_FCloseFile( f );
116
117 // parse the text
118 text_p = text;
119 skip = 0; // quite the compiler warning
120
121 ci->footsteps = FOOTSTEP_NORMAL;
122 VectorClear( ci->headOffset );
123 ci->gender = GENDER_MALE;
124 ci->fixedlegs = qfalse;
125 ci->fixedtorso = qfalse;
126
127 // read optional parameters
128 while ( 1 ) {
129 prev = text_p; // so we can unget
130 token = COM_Parse( &text_p );
131 if ( !token ) {
132 break;
133 }
134 if ( !Q_stricmp( token, "footsteps" ) ) {
135 token = COM_Parse( &text_p );
136 if ( !token ) {
137 break;
138 }
139 if ( !Q_stricmp( token, "default" ) || !Q_stricmp( token, "normal" ) ) {
140 ci->footsteps = FOOTSTEP_NORMAL;
141 } else if ( !Q_stricmp( token, "boot" ) ) {
142 ci->footsteps = FOOTSTEP_BOOT;
143 } else if ( !Q_stricmp( token, "flesh" ) ) {
144 ci->footsteps = FOOTSTEP_FLESH;
145 } else if ( !Q_stricmp( token, "mech" ) ) {
146 ci->footsteps = FOOTSTEP_MECH;
147 } else if ( !Q_stricmp( token, "energy" ) ) {
148 ci->footsteps = FOOTSTEP_ENERGY;
149 } else {
150 CG_Printf( "Bad footsteps parm in %s: %s\n", filename, token );
151 }
152 continue;
153 } else if ( !Q_stricmp( token, "headoffset" ) ) {
154 for ( i = 0 ; i < 3 ; i++ ) {
155 token = COM_Parse( &text_p );
156 if ( !token ) {
157 break;
158 }
159 ci->headOffset[i] = atof( token );
160 }
161 continue;
162 } else if ( !Q_stricmp( token, "sex" ) ) {
163 token = COM_Parse( &text_p );
164 if ( !token ) {
165 break;
166 }
167 if ( token[0] == 'f' || token[0] == 'F' ) {
168 ci->gender = GENDER_FEMALE;
169 } else if ( token[0] == 'n' || token[0] == 'N' ) {
170 ci->gender = GENDER_NEUTER;
171 } else {
172 ci->gender = GENDER_MALE;
173 }
174 continue;
175 } else if ( !Q_stricmp( token, "fixedlegs" ) ) {
176 ci->fixedlegs = qtrue;
177 continue;
178 } else if ( !Q_stricmp( token, "fixedtorso" ) ) {
179 ci->fixedtorso = qtrue;
180 continue;
181 }
182
183 // if it is a number, start parsing animations
184 if ( token[0] >= '0' && token[0] <= '9' ) {
185 text_p = prev; // unget the token
186 break;
187 }
188 Com_Printf( "unknown token '%s' is %s\n", token, filename );
189 }
190
191 // read information for each frame
192 for ( i = 0 ; i < MAX_ANIMATIONS ; i++ ) {
193
194 token = COM_Parse( &text_p );
195 if ( !*token ) {
196 if( i >= TORSO_GETFLAG && i <= TORSO_NEGATIVE ) {
197 animations[i].firstFrame = animations[TORSO_GESTURE].firstFrame;
198 animations[i].frameLerp = animations[TORSO_GESTURE].frameLerp;
199 animations[i].initialLerp = animations[TORSO_GESTURE].initialLerp;
200 animations[i].loopFrames = animations[TORSO_GESTURE].loopFrames;
201 animations[i].numFrames = animations[TORSO_GESTURE].numFrames;
202 animations[i].reversed = qfalse;
203 animations[i].flipflop = qfalse;
204 continue;
205 }
206 break;
207 }
208 animations[i].firstFrame = atoi( token );
209 // leg only frames are adjusted to not count the upper body only frames
210 if ( i == LEGS_WALKCR ) {
211 skip = animations[LEGS_WALKCR].firstFrame - animations[TORSO_GESTURE].firstFrame;
212 }
213 if ( i >= LEGS_WALKCR && i<TORSO_GETFLAG) {
214 animations[i].firstFrame -= skip;
215 }
216
217 token = COM_Parse( &text_p );
218 if ( !*token ) {
219 break;
220 }
221 animations[i].numFrames = atoi( token );
222
223 animations[i].reversed = qfalse;
224 animations[i].flipflop = qfalse;
225 // if numFrames is negative the animation is reversed
226 if (animations[i].numFrames < 0) {
227 animations[i].numFrames = -animations[i].numFrames;
228 animations[i].reversed = qtrue;
229 }
230
231 token = COM_Parse( &text_p );
232 if ( !*token ) {
233 break;
234 }
235 animations[i].loopFrames = atoi( token );
236
237 token = COM_Parse( &text_p );
238 if ( !*token ) {
239 break;
240 }
241 fps = atof( token );
242 if ( fps == 0 ) {
243 fps = 1;
244 }
245 animations[i].frameLerp = 1000 / fps;
246 animations[i].initialLerp = 1000 / fps;
247 }
248
249 if ( i != MAX_ANIMATIONS ) {
250 CG_Printf( "Error parsing animation file: %s\n", filename );
251 return qfalse;
252 }
253
254 // crouch backward animation
255 memcpy(&animations[LEGS_BACKCR], &animations[LEGS_WALKCR], sizeof(animation_t));
256 animations[LEGS_BACKCR].reversed = qtrue;
257 // walk backward animation
258 memcpy(&animations[LEGS_BACKWALK], &animations[LEGS_WALK], sizeof(animation_t));
259 animations[LEGS_BACKWALK].reversed = qtrue;
260 // flag moving fast
261 animations[FLAG_RUN].firstFrame = 0;
262 animations[FLAG_RUN].numFrames = 16;
263 animations[FLAG_RUN].loopFrames = 16;
264 animations[FLAG_RUN].frameLerp = 1000 / 15;
265 animations[FLAG_RUN].initialLerp = 1000 / 15;
266 animations[FLAG_RUN].reversed = qfalse;
267 // flag not moving or moving slowly
268 animations[FLAG_STAND].firstFrame = 16;
269 animations[FLAG_STAND].numFrames = 5;
270 animations[FLAG_STAND].loopFrames = 0;
271 animations[FLAG_STAND].frameLerp = 1000 / 20;
272 animations[FLAG_STAND].initialLerp = 1000 / 20;
273 animations[FLAG_STAND].reversed = qfalse;
274 // flag speeding up
275 animations[FLAG_STAND2RUN].firstFrame = 16;
276 animations[FLAG_STAND2RUN].numFrames = 5;
277 animations[FLAG_STAND2RUN].loopFrames = 1;
278 animations[FLAG_STAND2RUN].frameLerp = 1000 / 15;
279 animations[FLAG_STAND2RUN].initialLerp = 1000 / 15;
280 animations[FLAG_STAND2RUN].reversed = qtrue;
281 //
282 // new anims changes
283 //
284 animations[TORSO_GETFLAG].flipflop = qtrue;
285 animations[TORSO_GUARDBASE].flipflop = qtrue;
286 animations[TORSO_PATROL].flipflop = qtrue;
287 animations[TORSO_AFFIRMATIVE].flipflop = qtrue;
288 animations[TORSO_NEGATIVE].flipflop = qtrue;
289 //
290 return qtrue;
291 }
292
293 /*
294 ==========================
295 CG_FileExists
296 ==========================
297 */
298 static qboolean CG_FileExists(const char *filename) {
299 int len;
300
301 len = trap_FS_FOpenFile( filename, NULL, FS_READ );
302 if (len>0) {
303 return qtrue;
304 }
305 return qfalse;
306 }
307
308 /*
309 ==========================
310 CG_FindClientModelFile
311 ==========================
312 */
313 static qboolean CG_FindClientModelFile( char *filename, int length, clientInfo_t *ci, const char *teamName, const char *modelName, const char *skinName, const char *base, const char *ext ) {
314 char *team, *charactersFolder;
315 int i;
316
317 if ( cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) {
318 switch ( ci->team ) {
319 case TEAM_BLUE: {
320 team = "blue";
321 break;
322 }
323 default: {
324 team = "red";
325 break;
326 }
327 }
328 }
329 else {
330 team = "default";
331 }
332 charactersFolder = "";
333 while(1) {
334 for ( i = 0; i < 2; i++ ) {
335 if ( i == 0 && teamName && *teamName ) {
336 // "models/players/characters/sergei/stroggs/lower_lily_red.skin"
337 Com_sprintf( filename, length, "models/players/%s%s/%s%s_%s_%s.%s", charactersFolder, modelName, teamName, base, skinName, team, ext );
338 }
339 else {
340 // "models/players/characters/sergei/lower_lily_red.skin"
341 Com_sprintf( filename, length, "models/players/%s%s/%s_%s_%s.%s", charactersFolder, modelName, base, skinName, team, ext );
342 }
343 if ( CG_FileExists( filename ) ) {
344 return qtrue;
345 }
346 if ( cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) {
347 if ( i == 0 && teamName && *teamName ) {
348 // "models/players/characters/sergei/stroggs/lower_red.skin"
349 Com_sprintf( filename, length, "models/players/%s%s/%s%s_%s.%s", charactersFolder, modelName, teamName, base, team, ext );
350 }
351 else {
352 // "models/players/characters/sergei/lower_red.skin"
353 Com_sprintf( filename, length, "models/players/%s%s/%s_%s.%s", charactersFolder, modelName, base, team, ext );
354 }
355 }
356 else {
357 if ( i == 0 && teamName && *teamName ) {
358 // "models/players/characters/sergei/stroggs/lower_lily.skin"
359 Com_sprintf( filename, length, "models/players/%s%s/%s%s_%s.%s", charactersFolder, modelName, teamName, base, skinName, ext );
360 }
361 else {
362 // "models/players/characters/sergei/lower_lily.skin"
363 Com_sprintf( filename, length, "models/players/%s%s/%s_%s.%s", charactersFolder, modelName, base, skinName, ext );
364 }
365 }
366 if ( CG_FileExists( filename ) ) {
367 return qtrue;
368 }
369 if ( !teamName || !*teamName ) {
370 break;
371 }
372 }
373 // if tried the heads folder first
374 if ( charactersFolder[0] ) {
375 break;
376 }
377 charactersFolder = "characters/";
378 }
379
380 return qfalse;
381 }
382
383 /*
384 ==========================
385 CG_FindClientHeadFile
386 ==========================
387 */
388 static qboolean CG_FindClientHeadFile( char *filename, int length, clientInfo_t *ci, const char *teamName, const char *headModelName, const char *headSkinName, const char *base, const char *ext ) {
389 char *team, *headsFolder;
390 int i;
391
392 if ( cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) {
393 switch ( ci->team ) {
394 case TEAM_BLUE: {
395 team = "blue";
396 break;
397 }
398 default: {
399 team = "red";
400 break;
401 }
402 }
403 }
404 else {
405 team = "default";
406 }
407
408 if ( headModelName[0] == '*' ) {
409 headsFolder = "heads/";
410 headModelName++;
411 }
412 else {
413 headsFolder = "";
414 }
415 while(1) {
416 for ( i = 0; i < 2; i++ ) {
417 if ( i == 0 && teamName && *teamName ) {
418 Com_sprintf( filename, length, "models/players/%s%s/%s/%s%s_%s.%s", headsFolder, headModelName, headSkinName, teamName, base, team, ext );
419 }
420 else {
421 Com_sprintf( filename, length, "models/players/%s%s/%s/%s_%s.%s", headsFolder, headModelName, headSkinName, base, team, ext );
422 }
423 if ( CG_FileExists( filename ) ) {
424 return qtrue;
425 }
426 if ( cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) {
427 if ( i == 0 && teamName && *teamName ) {
428 Com_sprintf( filename, length, "models/players/%s%s/%s%s_%s.%s", headsFolder, headModelName, teamName, base, team, ext );
429 }
430 else {
431 Com_sprintf( filename, length, "models/players/%s%s/%s_%s.%s", headsFolder, headModelName, base, team, ext );
432 }
433 }
434 else {
435 if ( i == 0 && teamName && *teamName ) {
436 Com_sprintf( filename, length, "models/players/%s%s/%s%s_%s.%s", headsFolder, headModelName, teamName, base, headSkinName, ext );
437 }
438 else {
439 Com_sprintf( filename, length, "models/players/%s%s/%s_%s.%s", headsFolder, headModelName, base, headSkinName, ext );
440 }
441 }
442 if ( CG_FileExists( filename ) ) {
443 return qtrue;
444 }
445 if ( !teamName || !*teamName ) {
446 break;
447 }
448 }
449 // if tried the heads folder first
450 if ( headsFolder[0] ) {
451 break;
452 }
453 headsFolder = "heads/";
454 }
455
456 return qfalse;
457 }
458
459 /*
460 ==========================
461 CG_RegisterClientSkin
462 ==========================
463 */
464 static qboolean CG_RegisterClientSkin( clientInfo_t *ci, const char *teamName, const char *modelName, const char *skinName, const char *headModelName, const char *headSkinName ) {
465 char filename[MAX_QPATH];
466
467 /*
468 Com_sprintf( filename, sizeof( filename ), "models/players/%s/%slower_%s.skin", modelName, teamName, skinName );
469 ci->legsSkin = trap_R_RegisterSkin( filename );
470 if (!ci->legsSkin) {
471 Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/%slower_%s.skin", modelName, teamName, skinName );
472 ci->legsSkin = trap_R_RegisterSkin( filename );
473 if (!ci->legsSkin) {
474 Com_Printf( "Leg skin load failure: %s\n", filename );
475 }
476 }
477
478
479 Com_sprintf( filename, sizeof( filename ), "models/players/%s/%supper_%s.skin", modelName, teamName, skinName );
480 ci->torsoSkin = trap_R_RegisterSkin( filename );
481 if (!ci->torsoSkin) {
482 Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/%supper_%s.skin", modelName, teamName, skinName );
483 ci->torsoSkin = trap_R_RegisterSkin( filename );
484 if (!ci->torsoSkin) {
485 Com_Printf( "Torso skin load failure: %s\n", filename );
486 }
487 }
488 */
489 if ( CG_FindClientModelFile( filename, sizeof(filename), ci, teamName, modelName, skinName, "lower", "skin" ) ) {
490 ci->legsSkin = trap_R_RegisterSkin( filename );
491 }
492 if (!ci->legsSkin) {
493 Com_Printf( "Leg skin load failure: %s\n", filename );
494 }
495
496 if ( CG_FindClientModelFile( filename, sizeof(filename), ci, teamName, modelName, skinName, "upper", "skin" ) ) {
497 ci->torsoSkin = trap_R_RegisterSkin( filename );
498 }
499 if (!ci->torsoSkin) {
500 Com_Printf( "Torso skin load failure: %s\n", filename );
501 }
502
503 if ( CG_FindClientHeadFile( filename, sizeof(filename), ci, teamName, headModelName, headSkinName, "head", "skin" ) ) {
504 ci->headSkin = trap_R_RegisterSkin( filename );
505 }
506 if (!ci->headSkin) {
507 Com_Printf( "Head skin load failure: %s\n", filename );
508 }
509
510 // if any skins failed to load
511 if ( !ci->legsSkin || !ci->torsoSkin || !ci->headSkin ) {
512 return qfalse;
513 }
514 return qtrue;
515 }
516
517 /*
518 ==========================
519 CG_RegisterClientModelname
520 ==========================
521 */
522 static qboolean CG_RegisterClientModelname( clientInfo_t *ci, const char *modelName, const char *skinName, const char *headModelName, const char *headSkinName, const char *teamName ) {
523 char filename[MAX_QPATH*2];
524 const char *headName;
525 char newTeamName[MAX_QPATH*2];
526
527 if ( headModelName[0] == '\0' ) {
528 headName = modelName;
529 }
530 else {
531 headName = headModelName;
532 }
533 Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower.md3", modelName );
534 ci->legsModel = trap_R_RegisterModel( filename );
535 if ( !ci->legsModel ) {
536 Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/lower.md3", modelName );
537 ci->legsModel = trap_R_RegisterModel( filename );
538 if ( !ci->legsModel ) {
539 Com_Printf( "Failed to load model file %s\n", filename );
540 return qfalse;
541 }
542 }
543
544 Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper.md3", modelName );
545 ci->torsoModel = trap_R_RegisterModel( filename );
546 if ( !ci->torsoModel ) {
547 Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/upper.md3", modelName );
548 ci->torsoModel = trap_R_RegisterModel( filename );
549 if ( !ci->torsoModel ) {
550 Com_Printf( "Failed to load model file %s\n", filename );
551 return qfalse;
552 }
553 }
554
555 if( headName[0] == '*' ) {
556 Com_sprintf( filename, sizeof( filename ), "models/players/heads/%s/%s.md3", &headModelName[1], &headModelName[1] );
557 }
558 else {
559 Com_sprintf( filename, sizeof( filename ), "models/players/%s/head.md3", headName );
560 }
561 ci->headModel = trap_R_RegisterModel( filename );
562 // if the head model could not be found and we didn't load from the heads folder try to load from there
563 if ( !ci->headModel && headName[0] != '*' ) {
564 Com_sprintf( filename, sizeof( filename ), "models/players/heads/%s/%s.md3", headModelName, headModelName );
565 ci->headModel = trap_R_RegisterModel( filename );
566 }
567 if ( !ci->headModel ) {
568 Com_Printf( "Failed to load model file %s\n", filename );
569 return qfalse;
570 }
571
572 // if any skins failed to load, return failure
573 if ( !CG_RegisterClientSkin( ci, teamName, modelName, skinName, headName, headSkinName ) ) {
574 if ( teamName && *teamName) {
575 Com_Printf( "Failed to load skin file: %s : %s : %s, %s : %s\n", teamName, modelName, skinName, headName, headSkinName );
576 if( ci->team == TEAM_BLUE ) {
577 Com_sprintf(newTeamName, sizeof(newTeamName), "%s/", DEFAULT_BLUETEAM_NAME);
578 }
579 else {
580 Com_sprintf(newTeamName, sizeof(newTeamName), "%s/", DEFAULT_REDTEAM_NAME);
581 }
582 if ( !CG_RegisterClientSkin( ci, newTeamName, modelName, skinName, headName, headSkinName ) ) {
583 Com_Printf( "Failed to load skin file: %s : %s : %s, %s : %s\n", newTeamName, modelName, skinName, headName, headSkinName );
584 return qfalse;
585 }
586 } else {
587 Com_Printf( "Failed to load skin file: %s : %s, %s : %s\n", modelName, skinName, headName, headSkinName );
588 return qfalse;
589 }
590 }
591
592 // load the animations
593 Com_sprintf( filename, sizeof( filename ), "models/players/%s/animation.cfg", modelName );
594 if ( !CG_ParseAnimationFile( filename, ci ) ) {
595 Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/animation.cfg", modelName );
596 if ( !CG_ParseAnimationFile( filename, ci ) ) {
597 Com_Printf( "Failed to load animation file %s\n", filename );
598 return qfalse;
599 }
600 }
601
602 if ( CG_FindClientHeadFile( filename, sizeof(filename), ci, teamName, headName, headSkinName, "icon", "skin" ) ) {
603 ci->modelIcon = trap_R_RegisterShaderNoMip( filename );
604 }
605 else if ( CG_FindClientHeadFile( filename, sizeof(filename), ci, teamName, headName, headSkinName, "icon", "tga" ) ) {
606 ci->modelIcon = trap_R_RegisterShaderNoMip( filename );
607 }
608
609 if ( !ci->modelIcon ) {
610 return qfalse;
611 }
612
613 return qtrue;
614 }
615
616 /*
617 ====================
618 CG_ColorFromString
619 ====================
620 */
621 static void CG_ColorFromString( const char *v, vec3_t color ) {
622 int val;
623
624 VectorClear( color );
625
626 val = atoi( v );
627
628 if ( val < 1 || val > 7 ) {
629 VectorSet( color, 1, 1, 1 );
630 return;
631 }
632
633 if ( val & 1 ) {
634 color[2] = 1.0f;
635 }
636 if ( val & 2 ) {
637 color[1] = 1.0f;
638 }
639 if ( val & 4 ) {
640 color[0] = 1.0f;
641 }
642 }
643
644 /*
645 ===================
646 CG_LoadClientInfo
647
648 Load it now, taking the disk hits.
649 This will usually be deferred to a safe time
650 ===================
651 */
652 static void CG_LoadClientInfo( int clientNum, clientInfo_t *ci ) {
653 const char *dir, *fallback;
654 int i, modelloaded;
655 const char *s;
656 char teamname[MAX_QPATH];
657
658 teamname[0] = 0;
659 #ifdef MISSIONPACK
660 if( cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) {
661 if( ci->team == TEAM_BLUE ) {
662 Q_strncpyz(teamname, cg_blueTeamName.string, sizeof(teamname) );
663 } else {
664 Q_strncpyz(teamname, cg_redTeamName.string, sizeof(teamname) );
665 }
666 }
667 if( teamname[0] ) {
668 strcat( teamname, "/" );
669 }
670 #endif
671 modelloaded = qtrue;
672 if ( !CG_RegisterClientModelname( ci, ci->modelName, ci->skinName, ci->headModelName, ci->headSkinName, teamname ) ) {
673 if ( cg_buildScript.integer ) {
674 CG_Error( "CG_RegisterClientModelname( %s, %s, %s, %s %s ) failed", ci->modelName, ci->skinName, ci->headModelName, ci->headSkinName, teamname );
675 }
676
677 // fall back to default team name
678 if( cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) {
679 // keep skin name
680 if( ci->team == TEAM_BLUE ) {
681 Q_strncpyz(teamname, DEFAULT_BLUETEAM_NAME, sizeof(teamname) );
682 } else {
683 Q_strncpyz(teamname, DEFAULT_REDTEAM_NAME, sizeof(teamname) );
684 }
685 if ( !CG_RegisterClientModelname( ci, DEFAULT_TEAM_MODEL, ci->skinName, DEFAULT_TEAM_HEAD, ci->skinName, teamname ) ) {
686 CG_Error( "DEFAULT_TEAM_MODEL / skin (%s/%s) failed to register", DEFAULT_TEAM_MODEL, ci->skinName );
687 }
688 } else {
689 if ( !CG_RegisterClientModelname( ci, DEFAULT_MODEL, "default", DEFAULT_MODEL, "default", teamname ) ) {
690 CG_Error( "DEFAULT_MODEL (%s) failed to register", DEFAULT_MODEL );
691 }
692 }
693 modelloaded = qfalse;
694 }
695
696 ci->newAnims = qfalse;
697 if ( ci->torsoModel ) {
698 orientation_t tag;
699 // if the torso model has the "tag_flag"
700 if ( trap_R_LerpTag( &tag, ci->torsoModel, 0, 0, 1, "tag_flag" ) ) {
701 ci->newAnims = qtrue;
702 }
703 }
704
705 // sounds
706 dir = ci->modelName;
707 fallback = (cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) ? DEFAULT_TEAM_MODEL : DEFAULT_MODEL;
708
709 for ( i = 0 ; i < MAX_CUSTOM_SOUNDS ; i++ ) {
710 s = cg_customSoundNames[i];
711 if ( !s ) {
712 break;
713 }
714 ci->sounds[i] = 0;
715 // if the model didn't load use the sounds of the default model
716 if (modelloaded) {
717 ci->sounds[i] = trap_S_RegisterSound( va("sound/player/%s/%s", dir, s + 1), qfalse );
718 }
719 if ( !ci->sounds[i] ) {
720 ci->sounds[i] = trap_S_RegisterSound( va("sound/player/%s/%s", fallback, s + 1), qfalse );
721 }
722 }
723
724 ci->deferred = qfalse;
725
726 // reset any existing players and bodies, because they might be in bad
727 // frames for this new model
728 for ( i = 0 ; i < MAX_GENTITIES ; i++ ) {
729 if ( cg_entities[i].currentState.clientNum == clientNum
730 && cg_entities[i].currentState.eType == ET_PLAYER ) {
731 CG_ResetPlayerEntity( &cg_entities[i] );
732 }
733 }
734 }
735
736 /*
737 ======================
738 CG_CopyClientInfoModel
739 ======================
740 */
741 static void CG_CopyClientInfoModel( clientInfo_t *from, clientInfo_t *to ) {
742 VectorCopy( from->headOffset, to->headOffset );
743 to->footsteps = from->footsteps;
744 to->gender = from->gender;
745
746 to->legsModel = from->legsModel;
747 to->legsSkin = from->legsSkin;
748 to->torsoModel = from->torsoModel;
749 to->torsoSkin = from->torsoSkin;
750 to->headModel = from->headModel;
751 to->headSkin = from->headSkin;
752 to->modelIcon = from->modelIcon;
753
754 to->newAnims = from->newAnims;
755
756 memcpy( to->animations, from->animations, sizeof( to->animations ) );
757 memcpy( to->sounds, from->sounds, sizeof( to->sounds ) );
758 }
759
760 /*
761 ======================
762 CG_ScanForExistingClientInfo
763 ======================
764 */
765 static qboolean CG_ScanForExistingClientInfo( clientInfo_t *ci ) {
766 int i;
767 clientInfo_t *match;
768
769 for ( i = 0 ; i < cgs.maxclients ; i++ ) {
770 match = &cgs.clientinfo[ i ];
771 if ( !match->infoValid ) {
772 continue;
773 }
774 if ( match->deferred ) {
775 continue;
776 }
777 if ( !Q_stricmp( ci->modelName, match->modelName )
778 && !Q_stricmp( ci->skinName, match->skinName )
779 && !Q_stricmp( ci->headModelName, match->headModelName )
780 && !Q_stricmp( ci->headSkinName, match->headSkinName )
781 && !Q_stricmp( ci->blueTeam, match->blueTeam )
782 && !Q_stricmp( ci->redTeam, match->redTeam )
783 && (cgs.gametype < GT_TEAM || cgs.ffa_gt==1 || ci->team == match->team) ) {
784 // this clientinfo is identical, so use it's handles
785
786 ci->deferred = qfalse;
787
788 CG_CopyClientInfoModel( match, ci );
789
790 return qtrue;
791 }
792 }
793
794 // nothing matches, so defer the load
795 return qfalse;
796 }
797
798 /*
799 ======================
800 CG_SetDeferredClientInfo
801
802 We aren't going to load it now, so grab some other
803 client's info to use until we have some spare time.
804 ======================
805 */
806 static void CG_SetDeferredClientInfo( int clientNum, clientInfo_t *ci ) {
807 int i;
808 clientInfo_t *match;
809
810 // if someone else is already the same models and skins we
811 // can just load the client info
812 for ( i = 0 ; i < cgs.maxclients ; i++ ) {
813 match = &cgs.clientinfo[ i ];
814 if ( !match->infoValid || match->deferred ) {
815 continue;
816 }
817 if ( Q_stricmp( ci->skinName, match->skinName ) ||
818 Q_stricmp( ci->modelName, match->modelName ) ||
819 // Q_stricmp( ci->headModelName, match->headModelName ) ||
820 // Q_stricmp( ci->headSkinName, match->headSkinName ) ||
821 (cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1 && ci->team != match->team) ) {
822 continue;
823 }
824 // just load the real info cause it uses the same models and skins
825 CG_LoadClientInfo( clientNum, ci );
826 return;
827 }
828
829 // if we are in teamplay, only grab a model if the skin is correct
830 if ( cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) {
831 for ( i = 0 ; i < cgs.maxclients ; i++ ) {
832 match = &cgs.clientinfo[ i ];
833 if ( !match->infoValid || match->deferred ) {
834 continue;
835 }
836 if ( Q_stricmp( ci->skinName, match->skinName ) ||
837 (cgs.gametype >= GT_TEAM && cgs.ffa_gt != 1 && ci->team != match->team) ) {
838 continue;
839 }
840 ci->deferred = qtrue;
841 CG_CopyClientInfoModel( match, ci );
842 return;
843 }
844 // load the full model, because we don't ever want to show
845 // an improper team skin. This will cause a hitch for the first
846 // player, when the second enters. Combat shouldn't be going on
847 // yet, so it shouldn't matter
848 CG_LoadClientInfo( clientNum, ci );
849 return;
850 }
851
852 // find the first valid clientinfo and grab its stuff
853 for ( i = 0 ; i < cgs.maxclients ; i++ ) {
854 match = &cgs.clientinfo[ i ];
855 if ( !match->infoValid ) {
856 continue;
857 }
858
859 ci->deferred = qtrue;
860 CG_CopyClientInfoModel( match, ci );
861 return;
862 }
863
864 // we should never get here...
865 CG_Printf( "CG_SetDeferredClientInfo: no valid clients!\n" );
866
867 CG_LoadClientInfo( clientNum, ci );
868 }
869
870
871 /*
872 ======================
873 CG_NewClientInfo
874 ======================
875 */
876 void CG_NewClientInfo( int clientNum ) {
877 clientInfo_t *ci;
878 clientInfo_t newInfo;
879 const char *configstring;
880 const char *v;
881 char *slash;
882
883 ci = &cgs.clientinfo[clientNum];
884
885 configstring = CG_ConfigString( clientNum + CS_PLAYERS );
886 if ( !configstring[0] ) {
887 memset( ci, 0, sizeof( *ci ) );
888 return; // player just left
889 }
890
891 // build into a temp buffer so the defer checks can use
892 // the old value
893 memset( &newInfo, 0, sizeof( newInfo ) );
894
895 // isolate the player's name
896 v = Info_ValueForKey(configstring, "n");
897 Q_strncpyz( newInfo.name, v, sizeof( newInfo.name ) );
898
899 // colors
900 v = Info_ValueForKey( configstring, "c1" );
901 CG_ColorFromString( v, newInfo.color1 );
902
903 v = Info_ValueForKey( configstring, "c2" );
904 CG_ColorFromString( v, newInfo.color2 );
905
906 // bot skill
907 v = Info_ValueForKey( configstring, "skill" );
908 newInfo.botSkill = atoi( v );
909
910 // handicap
911 v = Info_ValueForKey( configstring, "hc" );
912 newInfo.handicap = atoi( v );
913
914 // wins
915 v = Info_ValueForKey( configstring, "w" );
916 newInfo.wins = atoi( v );
917
918 // losses
919 v = Info_ValueForKey( configstring, "l" );
920 newInfo.losses = atoi( v );
921
922 // team
923 v = Info_ValueForKey( configstring, "t" );
924 newInfo.team = atoi( v );
925
926 // team task
927 v = Info_ValueForKey( configstring, "tt" );
928 newInfo.teamTask = atoi(v);
929
930 // team leader
931 v = Info_ValueForKey( configstring, "tl" );
932 newInfo.teamLeader = atoi(v);
933
934 v = Info_ValueForKey( configstring, "g_redteam" );
935 Q_strncpyz(newInfo.redTeam, v, MAX_TEAMNAME);
936
937 v = Info_ValueForKey( configstring, "g_blueteam" );
938 Q_strncpyz(newInfo.blueTeam, v, MAX_TEAMNAME);
939
940 // model
941 v = Info_ValueForKey( configstring, "model" );
942 if ( cg_forceModel.integer ) {
943 // forcemodel makes everyone use a single model
944 // to prevent load hitches
945 char modelStr[MAX_QPATH];
946 char *skin;
947
948 if( cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) {
949 Q_strncpyz( newInfo.modelName, DEFAULT_TEAM_MODEL, sizeof( newInfo.modelName ) );
950 Q_strncpyz( newInfo.skinName, "default", sizeof( newInfo.skinName ) );
951 } else {
952 trap_Cvar_VariableStringBuffer( "model", modelStr, sizeof( modelStr ) );
953 if ( ( skin = strchr( modelStr, '/' ) ) == NULL) {
954 skin = "default";
955 } else {
956 *skin++ = 0;
957 }
958
959 Q_strncpyz( newInfo.skinName, skin, sizeof( newInfo.skinName ) );
960 Q_strncpyz( newInfo.modelName, modelStr, sizeof( newInfo.modelName ) );
961 }
962
963 if ( cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1 ) {
964 // keep skin name
965 slash = strchr( v, '/' );
966 if ( slash ) {
967 Q_strncpyz( newInfo.skinName, slash + 1, sizeof( newInfo.skinName ) );
968 }
969 }
970 } else {
971 Q_strncpyz( newInfo.modelName, v, sizeof( newInfo.modelName ) );
972
973 slash = strchr( newInfo.modelName, '/' );
974 if ( !slash ) {
975 // modelName didn not include a skin name
976 Q_strncpyz( newInfo.skinName, "default", sizeof( newInfo.skinName ) );
977 } else {
978 Q_strncpyz( newInfo.skinName, slash + 1, sizeof( newInfo.skinName ) );
979 // truncate modelName
980 *slash = 0;
981 }
982 }
983
984 // head model
985 v = Info_ValueForKey( configstring, "hmodel" );
986 if ( cg_forceModel.integer ) {
987 // forcemodel makes everyone use a single model
988 // to prevent load hitches
989 char modelStr[MAX_QPATH];
990 char *skin;
991
992 if( cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) {
993 Q_strncpyz( newInfo.headModelName, DEFAULT_TEAM_MODEL, sizeof( newInfo.headModelName ) );
994 Q_strncpyz( newInfo.headSkinName, "default", sizeof( newInfo.headSkinName ) );
995 } else {
996 trap_Cvar_VariableStringBuffer( "headmodel", modelStr, sizeof( modelStr ) );
997 if ( ( skin = strchr( modelStr, '/' ) ) == NULL) {
998 skin = "default";
999 } else {
1000 *skin++ = 0;
1001 }
1002
1003 Q_strncpyz( newInfo.headSkinName, skin, sizeof( newInfo.headSkinName ) );
1004 Q_strncpyz( newInfo.headModelName, modelStr, sizeof( newInfo.headModelName ) );
1005 }
1006
1007 if ( cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) {
1008 // keep skin name
1009 slash = strchr( v, '/' );
1010 if ( slash ) {
1011 Q_strncpyz( newInfo.headSkinName, slash + 1, sizeof( newInfo.headSkinName ) );
1012 }
1013 }
1014 } else {
1015 Q_strncpyz( newInfo.headModelName, v, sizeof( newInfo.headModelName ) );
1016
1017 slash = strchr( newInfo.headModelName, '/' );
1018 if ( !slash ) {
1019 // modelName didn not include a skin name
1020 Q_strncpyz( newInfo.headSkinName, "default", sizeof( newInfo.headSkinName ) );
1021 } else {
1022 Q_strncpyz( newInfo.headSkinName, slash + 1, sizeof( newInfo.headSkinName ) );
1023 // truncate modelName
1024 *slash = 0;
1025 }
1026 }
1027
1028 // scan for an existing clientinfo that matches this modelname
1029 // so we can avoid loading checks if possible
1030 if ( !CG_ScanForExistingClientInfo( &newInfo ) ) {
1031 qboolean forceDefer;
1032
1033 forceDefer = trap_MemoryRemaining() < 4000000;
1034
1035 // if we are defering loads, just have it pick the first valid
1036 if ( forceDefer || (cg_deferPlayers.integer && !cg_buildScript.integer && !cg.loading ) ) {
1037 // keep whatever they had if it won't violate team skins
1038 CG_SetDeferredClientInfo( clientNum, &newInfo );
1039 // if we are low on memory, leave them with this model
1040 if ( forceDefer ) {
1041 CG_Printf( "Memory is low. Using deferred model.\n" );
1042 newInfo.deferred = qfalse;
1043 }
1044 } else {
1045 CG_LoadClientInfo( clientNum, &newInfo );
1046 }
1047 }
1048
1049 // replace whatever was there with the new one
1050 newInfo.infoValid = qtrue;
1051 *ci = newInfo;
1052 }
1053
1054
1055
1056 /*
1057 ======================
1058 CG_LoadDeferredPlayers
1059
1060 Called each frame when a player is dead
1061 and the scoreboard is up
1062 so deferred players can be loaded
1063 ======================
1064 */
1065 void CG_LoadDeferredPlayers( void ) {
1066 int i;
1067 clientInfo_t *ci;
1068
1069 // scan for a deferred player to load
1070 for ( i = 0, ci = cgs.clientinfo ; i < cgs.maxclients ; i++, ci++ ) {
1071 if ( ci->infoValid && ci->deferred ) {
1072 // if we are low on memory, leave it deferred
1073 if ( trap_MemoryRemaining() < 4000000 ) {
1074 CG_Printf( "Memory is low. Using deferred model.\n" );
1075 ci->deferred = qfalse;
1076 continue;
1077 }
1078 CG_LoadClientInfo( i, ci );
1079 // break;
1080 }
1081 }
1082 }
1083
1084 /*
1085 =============================================================================
1086
1087 PLAYER ANIMATION
1088
1089 =============================================================================
1090 */
1091
1092
1093 /*
1094 ===============
1095 CG_SetLerpFrameAnimation
1096
1097 may include ANIM_TOGGLEBIT
1098 ===============
1099 */
1100 static void CG_SetLerpFrameAnimation( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation ) {
1101 animation_t *anim;
1102
1103 lf->animationNumber = newAnimation;
1104 newAnimation &= ~ANIM_TOGGLEBIT;
1105
1106 if ( newAnimation < 0 || newAnimation >= MAX_TOTALANIMATIONS ) {
1107 CG_Error( "Bad animation number: %i", newAnimation );
1108 }
1109
1110 anim = &ci->animations[ newAnimation ];
1111
1112 lf->animation = anim;
1113 lf->animationTime = lf->frameTime + anim->initialLerp;
1114
1115 if ( cg_debugAnim.integer ) {
1116 CG_Printf( "Anim: %i\n", newAnimation );
1117 }
1118 }
1119
1120 /*
1121 ===============
1122 CG_RunLerpFrame
1123
1124 Sets cg.snap, cg.oldFrame, and cg.backlerp
1125 cg.time should be between oldFrameTime and frameTime after exit
1126 ===============
1127 */
1128 static void CG_RunLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, float speedScale ) {
1129 int f, numFrames;
1130 animation_t *anim;
1131
1132 // debugging tool to get no animations
1133 if ( cg_animSpeed.integer == 0 ) {
1134 lf->oldFrame = lf->frame = lf->backlerp = 0;
1135 return;
1136 }
1137
1138 // see if the animation sequence is switching
1139 if ( newAnimation != lf->animationNumber || !lf->animation ) {
1140 CG_SetLerpFrameAnimation( ci, lf, newAnimation );
1141 }
1142
1143 // if we have passed the current frame, move it to
1144 // oldFrame and calculate a new frame
1145 if ( cg.time >= lf->frameTime ) {
1146 lf->oldFrame = lf->frame;
1147 lf->oldFrameTime = lf->frameTime;
1148
1149 // get the next frame based on the animation
1150 anim = lf->animation;
1151 if ( !anim->frameLerp ) {
1152 return; // shouldn't happen
1153 }
1154 if ( cg.time < lf->animationTime ) {
1155 lf->frameTime = lf->animationTime; // initial lerp
1156 } else {
1157 lf->frameTime = lf->oldFrameTime + anim->frameLerp;
1158 }
1159 f = ( lf->frameTime - lf->animationTime ) / anim->frameLerp;
1160 f *= speedScale; // adjust for haste, etc
1161
1162 numFrames = anim->numFrames;
1163 if (anim->flipflop) {
1164 numFrames *= 2;
1165 }
1166 if ( f >= numFrames ) {
1167 f -= numFrames;
1168 if ( anim->loopFrames ) {
1169 f %= anim->loopFrames;
1170 f += anim->numFrames - anim->loopFrames;
1171 } else {
1172 f = numFrames - 1;
1173 // the animation is stuck at the end, so it
1174 // can immediately transition to another sequence
1175 lf->frameTime = cg.time;
1176 }
1177 }
1178 if ( anim->reversed ) {
1179 lf->frame = anim->firstFrame + anim->numFrames - 1 - f;
1180 }
1181 else if (anim->flipflop && f>=anim->numFrames) {
1182 lf->frame = anim->firstFrame + anim->numFrames - 1 - (f%anim->numFrames);
1183 }
1184 else {
1185 lf->frame = anim->firstFrame + f;
1186 }
1187 if ( cg.time > lf->frameTime ) {
1188 lf->frameTime = cg.time;
1189 if ( cg_debugAnim.integer ) {
1190 CG_Printf( "Clamp lf->frameTime\n");
1191 }
1192 }
1193 }
1194
1195 if ( lf->frameTime > cg.time + 200 ) {
1196 lf->frameTime = cg.time;
1197 }
1198
1199 if ( lf->oldFrameTime > cg.time ) {
1200 lf->oldFrameTime = cg.time;
1201 }
1202 // calculate current lerp value
1203 if ( lf->frameTime == lf->oldFrameTime ) {
1204 lf->backlerp = 0;
1205 } else {
1206 lf->backlerp = 1.0 - (float)( cg.time - lf->oldFrameTime ) / ( lf->frameTime - lf->oldFrameTime );
1207 }
1208 }
1209
1210
1211 /*
1212 ===============
1213 CG_ClearLerpFrame
1214 ===============
1215 */
1216 static void CG_ClearLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int animationNumber ) {
1217 lf->frameTime = lf->oldFrameTime = cg.time;
1218 CG_SetLerpFrameAnimation( ci, lf, animationNumber );
1219 lf->oldFrame = lf->frame = lf->animation->firstFrame;
1220 }
1221
1222
1223 /*
1224 ===============
1225 CG_PlayerAnimation
1226 ===============
1227 */
1228 static void CG_PlayerAnimation( centity_t *cent, int *legsOld, int *legs, float *legsBackLerp,
1229 int *torsoOld, int *torso, float *torsoBackLerp ) {
1230 clientInfo_t *ci;
1231 int clientNum;
1232 float speedScale;
1233
1234 clientNum = cent->currentState.clientNum;
1235
1236 if ( cg_noPlayerAnims.integer ) {
1237 *legsOld = *legs = *torsoOld = *torso = 0;
1238 return;
1239 }
1240
1241 if ( cent->currentState.powerups & ( 1 << PW_HASTE ) ) {
1242 speedScale = 1.5;
1243 } else {
1244 speedScale = 1;
1245 }
1246
1247 ci = &cgs.clientinfo[ clientNum ];
1248
1249 // do the shuffle turn frames locally
1250 if ( cent->pe.legs.yawing && ( cent->currentState.legsAnim & ~ANIM_TOGGLEBIT ) == LEGS_IDLE ) {
1251 CG_RunLerpFrame( ci, &cent->pe.legs, LEGS_TURN, speedScale );
1252 } else {
1253 CG_RunLerpFrame( ci, &cent->pe.legs, cent->currentState.legsAnim, speedScale );
1254 }
1255
1256 *legsOld = cent->pe.legs.oldFrame;
1257 *legs = cent->pe.legs.frame;
1258 *legsBackLerp = cent->pe.legs.backlerp;
1259
1260 CG_RunLerpFrame( ci, &cent->pe.torso, cent->currentState.torsoAnim, speedScale );
1261
1262 *torsoOld = cent->pe.torso.oldFrame;
1263 *torso = cent->pe.torso.frame;
1264 *torsoBackLerp = cent->pe.torso.backlerp;
1265 }
1266
1267 /*
1268 =============================================================================
1269
1270 PLAYER ANGLES
1271
1272 =============================================================================
1273 */
1274
1275 /*
1276 ==================
1277 CG_SwingAngles
1278 ==================
1279 */
1280 static void CG_SwingAngles( float destination, float swingTolerance, float clampTolerance,
1281 float speed, float *angle, qboolean *swinging ) {
1282 float swing;
1283 float move;
1284 float scale;
1285
1286 if ( !*swinging ) {
1287 // see if a swing should be started
1288 swing = AngleSubtract( *angle, destination );
1289 if ( swing > swingTolerance || swing < -swingTolerance ) {
1290 *swinging = qtrue;
1291 }
1292 }
1293
1294 if ( !*swinging ) {
1295 return;
1296 }
1297
1298 // modify the speed depending on the delta
1299 // so it doesn't seem so linear
1300 swing = AngleSubtract( destination, *angle );
1301 scale = fabs( swing );
1302 if ( scale < swingTolerance * 0.5 ) {
1303 scale = 0.5;
1304 } else if ( scale < swingTolerance ) {
1305 scale = 1.0;
1306 } else {
1307 scale = 2.0;
1308 }
1309
1310 // swing towards the destination angle
1311 if ( swing >= 0 ) {
1312 move = cg.frametime * scale * speed;
1313 if ( move >= swing ) {
1314 move = swing;
1315 *swinging = qfalse;
1316 }
1317 *angle = AngleMod( *angle + move );
1318 } else if ( swing < 0 ) {
1319 move = cg.frametime * scale * -speed;
1320 if ( move <= swing ) {
1321 move = swing;
1322 *swinging = qfalse;
1323 }
1324 *angle = AngleMod( *angle + move );
1325 }
1326
1327 // clamp to no more than tolerance
1328 swing = AngleSubtract( destination, *angle );
1329 if ( swing > clampTolerance ) {
1330 *angle = AngleMod( destination - (clampTolerance - 1) );
1331 } else if ( swing < -clampTolerance ) {
1332 *angle = AngleMod( destination + (clampTolerance - 1) );
1333 }
1334 }
1335
1336 /*
1337 =================
1338 CG_AddPainTwitch
1339 =================
1340 */
1341 static void CG_AddPainTwitch( centity_t *cent, vec3_t torsoAngles ) {
1342 int t;
1343 float f;
1344
1345 t = cg.time - cent->pe.painTime;
1346 if ( t >= PAIN_TWITCH_TIME ) {
1347 return;
1348 }
1349
1350 f = 1.0 - (float)t / PAIN_TWITCH_TIME;
1351
1352 if ( cent->pe.painDirection ) {
1353 torsoAngles[ROLL] += 20 * f;
1354 } else {
1355 torsoAngles[ROLL] -= 20 * f;
1356 }
1357 }
1358
1359
1360 /*
1361 ===============
1362 CG_PlayerAngles
1363
1364 Handles seperate torso motion
1365
1366 legs pivot based on direction of movement
1367
1368 head always looks exactly at cent->lerpAngles
1369
1370 if motion < 20 degrees, show in head only
1371 if < 45 degrees, also show in torso
1372 ===============
1373 */
1374 static void CG_PlayerAngles( centity_t *cent, vec3_t legs[3], vec3_t torso[3], vec3_t head[3] ) {
1375 vec3_t legsAngles, torsoAngles, headAngles;
1376 float dest;
1377 static int movementOffsets[8] = { 0, 22, 45, -22, 0, 22, -45, -22 };
1378 vec3_t velocity;
1379 float speed;
1380 int dir, clientNum;
1381 clientInfo_t *ci;
1382
1383 VectorCopy( cent->lerpAngles, headAngles );
1384 headAngles[YAW] = AngleMod( headAngles[YAW] );
1385 VectorClear( legsAngles );
1386 VectorClear( torsoAngles );
1387
1388 // --------- yaw -------------
1389
1390 // allow yaw to drift a bit
1391 if ( ( cent->currentState.legsAnim & ~ANIM_TOGGLEBIT ) != LEGS_IDLE
1392 || ((cent->currentState.torsoAnim & ~ANIM_TOGGLEBIT) != TORSO_STAND
1393 && (cent->currentState.torsoAnim & ~ANIM_TOGGLEBIT) != TORSO_STAND2)) {
1394 // if not standing still, always point all in the same direction
1395 cent->pe.torso.yawing = qtrue; // always center
1396 cent->pe.torso.pitching = qtrue; // always center
1397 cent->pe.legs.yawing = qtrue; // always center
1398 }
1399
1400 // adjust legs for movement dir
1401 if ( cent->currentState.eFlags & EF_DEAD ) {
1402 // don't let dead bodies twitch
1403 dir = 0;
1404 } else {
1405 dir = cent->currentState.angles2[YAW];
1406 if ( dir < 0 || dir > 7 ) {
1407 CG_Error( "Bad player movement angle" );
1408 }
1409 }
1410 legsAngles[YAW] = headAngles[YAW] + movementOffsets[ dir ];
1411 torsoAngles[YAW] = headAngles[YAW] + 0.25 * movementOffsets[ dir ];
1412
1413 // torso
1414 CG_SwingAngles( torsoAngles[YAW], 25, 90, cg_swingSpeed.value, &cent->pe.torso.yawAngle, &cent->pe.torso.yawing );
1415 CG_SwingAngles( legsAngles[YAW], 40, 90, cg_swingSpeed.value, &cent->pe.legs.yawAngle, &cent->pe.legs.yawing );
1416
1417 torsoAngles[YAW] = cent->pe.torso.yawAngle;
1418 legsAngles[YAW] = cent->pe.legs.yawAngle;
1419
1420
1421 // --------- pitch -------------
1422
1423 // only show a fraction of the pitch angle in the torso
1424 if ( headAngles[PITCH] > 180 ) {
1425 dest = (-360 + headAngles[PITCH]) * 0.75f;
1426 } else {
1427 dest = headAngles[PITCH] * 0.75f;
1428 }
1429 CG_SwingAngles( dest, 15, 30, 0.1f, &cent->pe.torso.pitchAngle, &cent->pe.torso.pitching );
1430 torsoAngles[PITCH] = cent->pe.torso.pitchAngle;
1431
1432 //
1433 clientNum = cent->currentState.clientNum;
1434 if ( clientNum >= 0 && clientNum < MAX_CLIENTS ) {
1435 ci = &cgs.clientinfo[ clientNum ];
1436 if ( ci->fixedtorso ) {
1437 torsoAngles[PITCH] = 0.0f;
1438 }
1439 }
1440
1441 // --------- roll -------------
1442
1443
1444 // lean towards the direction of travel
1445 VectorCopy( cent->currentState.pos.trDelta, velocity );
1446 speed = VectorNormalize( velocity );
1447 if ( speed ) {
1448 vec3_t axis[3];
1449 float side;
1450
1451 speed *= 0.05f;
1452
1453 AnglesToAxis( legsAngles, axis );
1454 side = speed * DotProduct( velocity, axis[1] );
1455 legsAngles[ROLL] -= side;
1456
1457 side = speed * DotProduct( velocity, axis[0] );
1458 legsAngles[PITCH] += side;
1459 }
1460
1461 //
1462 clientNum = cent->currentState.clientNum;
1463 if ( clientNum >= 0 && clientNum < MAX_CLIENTS ) {
1464 ci = &cgs.clientinfo[ clientNum ];
1465 if ( ci->fixedlegs ) {
1466 legsAngles[YAW] = torsoAngles[YAW];
1467 legsAngles[PITCH] = 0.0f;
1468 legsAngles[ROLL] = 0.0f;
1469 }
1470 }
1471
1472 // pain twitch
1473 CG_AddPainTwitch( cent, torsoAngles );
1474
1475 // pull the angles back out of the hierarchial chain
1476 AnglesSubtract( headAngles, torsoAngles, headAngles );
1477 AnglesSubtract( torsoAngles, legsAngles, torsoAngles );
1478 AnglesToAxis( legsAngles, legs );
1479 AnglesToAxis( torsoAngles, torso );
1480 AnglesToAxis( headAngles, head );
1481 }
1482
1483
1484 //==========================================================================
1485
1486 /*
1487 ===============
1488 CG_HasteTrail
1489 ===============
1490 */
1491 static void CG_HasteTrail( centity_t *cent ) {
1492 localEntity_t *smoke;
1493 vec3_t origin;
1494 int anim;
1495
1496 if ( cent->trailTime > cg.time ) {
1497 return;
1498 }
1499 anim = cent->pe.legs.animationNumber & ~ANIM_TOGGLEBIT;
1500 if ( anim != LEGS_RUN && anim != LEGS_BACK ) {
1501 return;
1502 }
1503
1504 cent->trailTime += 100;
1505 if ( cent->trailTime < cg.time ) {
1506 cent->trailTime = cg.time;
1507 }
1508
1509 VectorCopy( cent->lerpOrigin, origin );
1510 origin[2] -= 16;
1511
1512 smoke = CG_SmokePuff( origin, vec3_origin,
1513 8,
1514 1, 1, 1, 1,
1515 500,
1516 cg.time,
1517 0,
1518 0,
1519 cgs.media.hastePuffShader );
1520
1521 // use the optimized local entity add
1522 smoke->leType = LE_SCALE_FADE;
1523 }
1524
1525 /*
1526 ===============
1527 CG_BreathPuffs
1528 ===============
1529 */
1530 static void CG_BreathPuffs( centity_t *cent, refEntity_t *head) {
1531 clientInfo_t *ci;
1532 vec3_t up, origin;
1533 int contents;
1534
1535 ci = &cgs.clientinfo[ cent->currentState.number ];
1536
1537 if (!cg_enableBreath.integer) {
1538 return;
1539 }
1540 if ( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson) {
1541 return;
1542 }
1543 if ( cent->currentState.eFlags & EF_DEAD ) {
1544 return;
1545 }
1546 contents = CG_PointContents( head->origin, 0 );
1547 if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
1548 return;
1549 }
1550 if ( ci->breathPuffTime > cg.time ) {
1551 return;
1552 }
1553
1554 VectorSet( up, 0, 0, 8 );
1555 VectorMA(head->origin, 8, head->axis[0], origin);
1556 VectorMA(origin, -4, head->axis[2], origin);
1557 CG_SmokePuff( origin, up, 16, 1, 1, 1, 0.66f, 1500, cg.time, cg.time + 400, LEF_PUFF_DONT_SCALE, cgs.media.shotgunSmokePuffShader );
1558 ci->breathPuffTime = cg.time + 2000;
1559 }
1560
1561 /*
1562 ===============
1563 CG_DustTrail
1564 ===============
1565 */
1566 static void CG_DustTrail( centity_t *cent ) {
1567 int anim;
1568 localEntity_t *dust;
1569 vec3_t end, vel;
1570 trace_t tr;
1571
1572 if (!cg_enableDust.integer)
1573 return;
1574
1575 if ( cent->dustTrailTime > cg.time ) {
1576 return;
1577 }
1578
1579 anim = cent->pe.legs.animationNumber & ~ANIM_TOGGLEBIT;
1580 if ( anim != LEGS_LANDB && anim != LEGS_LAND ) {
1581 return;
1582 }
1583
1584 cent->dustTrailTime += 40;
1585 if ( cent->dustTrailTime < cg.time ) {
1586 cent->dustTrailTime = cg.time;
1587 }
1588
1589 VectorCopy(cent->currentState.pos.trBase, end);
1590 end[2] -= 64;
1591 CG_Trace( &tr, cent->currentState.pos.trBase, NULL, NULL, end, cent->currentState.number, MASK_PLAYERSOLID );
1592
1593 if ( !(tr.surfaceFlags & SURF_DUST) )
1594 return;
1595
1596 VectorCopy( cent->currentState.pos.trBase, end );
1597 end[2] -= 16;
1598
1599 VectorSet(vel, 0, 0, -30);
1600 dust = CG_SmokePuff( end, vel,
1601 24,
1602 .8f, .8f, 0.7f, 0.33f,
1603 500,
1604 cg.time,
1605 0,
1606 0,
1607 cgs.media.dustPuffShader );
1608 }
1609
1610 /*
1611 ===============
1612 CG_TrailItem
1613 ===============
1614 */
1615 static void CG_TrailItem( centity_t *cent, qhandle_t hModel ) {
1616 refEntity_t ent;
1617 vec3_t angles;
1618 vec3_t axis[3];
1619
1620 VectorCopy( cent->lerpAngles, angles );
1621 angles[PITCH] = 0;
1622 angles[ROLL] = 0;
1623 AnglesToAxis( angles, axis );
1624
1625 memset( &ent, 0, sizeof( ent ) );
1626 VectorMA( cent->lerpOrigin, -16, axis[0], ent.origin );
1627 ent.origin[2] += 16;
1628 angles[YAW] += 90;
1629 AnglesToAxis( angles, ent.axis );
1630
1631 ent.hModel = hModel;
1632 trap_R_AddRefEntityToScene( &ent );
1633 }
1634
1635
1636 /*
1637 ===============
1638 CG_PlayerFlag
1639 ===============
1640 */
1641 static void CG_PlayerFlag( centity_t *cent, qhandle_t hSkin, refEntity_t *torso ) {
1642 clientInfo_t *ci;
1643 refEntity_t pole;
1644 refEntity_t flag;
1645 vec3_t angles, dir;
1646 int legsAnim, flagAnim, updateangles;
1647 float angle, d;
1648
1649 // show the flag pole model
1650 memset( &pole, 0, sizeof(pole) );
1651 pole.hModel = cgs.media.flagPoleModel;
1652 VectorCopy( torso->lightingOrigin, pole.lightingOrigin );
1653 pole.shadowPlane = torso->shadowPlane;
1654 pole.renderfx = torso->renderfx;
1655 CG_PositionEntityOnTag( &pole, torso, torso->hModel, "tag_flag" );
1656 trap_R_AddRefEntityToScene( &pole );
1657
1658 // show the flag model
1659 memset( &flag, 0, sizeof(flag) );
1660 flag.hModel = cgs.media.flagFlapModel;
1661 flag.customSkin = hSkin;
1662 VectorCopy( torso->lightingOrigin, flag.lightingOrigin );
1663 flag.shadowPlane = torso->shadowPlane;
1664 flag.renderfx = torso->renderfx;
1665
1666 VectorClear(angles);
1667
1668 updateangles = qfalse;
1669 legsAnim = cent->currentState.legsAnim & ~ANIM_TOGGLEBIT;
1670 if( legsAnim == LEGS_IDLE || legsAnim == LEGS_IDLECR ) {
1671 flagAnim = FLAG_STAND;
1672 } else if ( legsAnim == LEGS_WALK || legsAnim == LEGS_WALKCR ) {
1673 flagAnim = FLAG_STAND;
1674 updateangles = qtrue;
1675 } else {
1676 flagAnim = FLAG_RUN;
1677 updateangles = qtrue;
1678 }
1679
1680 if ( updateangles ) {
1681
1682 VectorCopy( cent->currentState.pos.trDelta, dir );
1683 // add gravity
1684 dir[2] += 100;
1685 VectorNormalize( dir );
1686 d = DotProduct(pole.axis[2], dir);
1687 // if there is anough movement orthogonal to the flag pole
1688 if (fabs(d) < 0.9) {
1689 //
1690 d = DotProduct(pole.axis[0], dir);
1691 if (d > 1.0f) {
1692 d = 1.0f;
1693 }
1694 else if (d < -1.0f) {
1695 d = -1.0f;
1696 }
1697 angle = acos(d);
1698
1699 d = DotProduct(pole.axis[1], dir);
1700 if (d < 0) {
1701 angles[YAW] = 360 - angle * 180 / M_PI;
1702 }
1703 else {
1704 angles[YAW] = angle * 180 / M_PI;
1705 }
1706 if (angles[YAW] < 0)
1707 angles[YAW] += 360;
1708 if (angles[YAW] > 360)
1709 angles[YAW] -= 360;
1710
1711 //vectoangles( cent->currentState.pos.trDelta, tmpangles );
1712 //angles[YAW] = tmpangles[YAW] + 45 - cent->pe.torso.yawAngle;
1713 // change the yaw angle
1714 CG_SwingAngles( angles[YAW], 25, 90, 0.15f, &cent->pe.flag.yawAngle, &cent->pe.flag.yawing );
1715 }
1716
1717 /*
1718 d = DotProduct(pole.axis[2], dir);
1719 angle = Q_acos(d);
1720
1721 d = DotProduct(pole.axis[1], dir);
1722 if (d < 0) {
1723 angle = 360 - angle * 180 / M_PI;
1724 }
1725 else {
1726 angle = angle * 180 / M_PI;
1727 }
1728 if (angle > 340 && angle < 20) {
1729 flagAnim = FLAG_RUNUP;
1730 }
1731 if (angle > 160 && angle < 200) {
1732 flagAnim = FLAG_RUNDOWN;
1733 }
1734 */
1735 }
1736
1737 // set the yaw angle
1738 angles[YAW] = cent->pe.flag.yawAngle;
1739 // lerp the flag animation frames
1740 ci = &cgs.clientinfo[ cent->currentState.clientNum ];
1741 CG_RunLerpFrame( ci, &cent->pe.flag, flagAnim, 1 );
1742 flag.oldframe = cent->pe.flag.oldFrame;
1743 flag.frame = cent->pe.flag.frame;
1744 flag.backlerp = cent->pe.flag.backlerp;
1745
1746 AnglesToAxis( angles, flag.axis );
1747 CG_PositionRotatedEntityOnTag( &flag, &pole, pole.hModel, "tag_flag" );
1748
1749 trap_R_AddRefEntityToScene( &flag );
1750 }
1751
1752 /*
1753 ===============
1754 CG_PlayerTokens
1755 ===============
1756 */
1757 static void CG_PlayerTokens( centity_t *cent, int renderfx ) {
1758 int tokens, i, j;
1759 float angle;
1760 refEntity_t ent;
1761 vec3_t dir, origin;
1762 skulltrail_t *trail;
1763 trail = &cg.skulltrails[cent->currentState.number];
1764 tokens = cent->currentState.generic1;
1765 if ( !tokens ) {
1766 trail->numpositions = 0;
1767 return;
1768 }
1769
1770 if ( tokens > MAX_SKULLTRAIL ) {
1771 tokens = MAX_SKULLTRAIL;
1772 }
1773
1774 // add skulls if there are more than last time
1775 for (i = 0; i < tokens - trail->numpositions; i++) {
1776 for (j = trail->numpositions; j > 0; j--) {
1777 VectorCopy(trail->positions[j-1], trail->positions[j]);
1778 }
1779 VectorCopy(cent->lerpOrigin, trail->positions[0]);
1780 }
1781 trail->numpositions = tokens;
1782
1783 // move all the skulls along the trail
1784 VectorCopy(cent->lerpOrigin, origin);
1785 for (i = 0; i < trail->numpositions; i++) {
1786 VectorSubtract(trail->positions[i], origin, dir);
1787 if (VectorNormalize(dir) > 30) {
1788 VectorMA(origin, 30, dir, trail->positions[i]);
1789 }
1790 VectorCopy(trail->positions[i], origin);
1791 }
1792
1793 memset( &ent, 0, sizeof( ent ) );
1794 if( cgs.clientinfo[ cent->currentState.clientNum ].team == TEAM_BLUE ) {
1795 ent.hModel = cgs.media.redCubeModel;
1796 } else {
1797 ent.hModel = cgs.media.blueCubeModel;
1798 }
1799 ent.renderfx = renderfx;
1800
1801 VectorCopy(cent->lerpOrigin, origin);
1802 for (i = 0; i < trail->numpositions; i++) {
1803 VectorSubtract(origin, trail->positions[i], ent.axis[0]);
1804 ent.axis[0][2] = 0;
1805 VectorNormalize(ent.axis[0]);
1806 VectorSet(ent.axis[2], 0, 0, 1);
1807 CrossProduct(ent.axis[0], ent.axis[2], ent.axis[1]);
1808
1809 VectorCopy(trail->positions[i], ent.origin);
1810 angle = (((cg.time + 500 * MAX_SKULLTRAIL - 500 * i) / 16) & 255) * (M_PI * 2) / 255;
1811 ent.origin[2] += sin(angle) * 10;
1812 trap_R_AddRefEntityToScene( &ent );
1813 VectorCopy(trail->positions[i], origin);
1814 }
1815 }
1816
1817
1818 /*
1819 ===============
1820 CG_PlayerPowerups
1821 ===============
1822 */
1823 static void CG_PlayerPowerups( centity_t *cent, refEntity_t *torso ) {
1824 int powerups;
1825 clientInfo_t *ci;
1826
1827 powerups = cent->currentState.powerups;
1828 if ( !powerups ) {
1829 return;
1830 }
1831
1832 // quad gives a dlight
1833 if ( powerups & ( 1 << PW_QUAD ) ) {
1834 trap_R_AddLightToScene( cent->lerpOrigin, 200 + (rand()&31), 0.2f, 0.2f, 1 );
1835 }
1836
1837 // flight plays a looped sound
1838 if ( powerups & ( 1 << PW_FLIGHT ) ) {
1839 trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flightSound );
1840 }
1841
1842 ci = &cgs.clientinfo[ cent->currentState.clientNum ];
1843 // redflag
1844 if ( powerups & ( 1 << PW_REDFLAG ) ) {
1845 if (ci->newAnims) {
1846 CG_PlayerFlag( cent, cgs.media.redFlagFlapSkin, torso );
1847 }
1848 else {
1849 CG_TrailItem( cent, cgs.media.redFlagModel );
1850 }
1851 trap_R_AddLightToScene( cent->lerpOrigin, 200 + (rand()&31), 1.0, 0.2f, 0.2f );
1852 }
1853
1854 // blueflag
1855 if ( powerups & ( 1 << PW_BLUEFLAG ) ) {
1856 if (ci->newAnims){
1857 CG_PlayerFlag( cent, cgs.media.blueFlagFlapSkin, torso );
1858 }
1859 else {
1860 CG_TrailItem( cent, cgs.media.blueFlagModel );
1861 }
1862 trap_R_AddLightToScene( cent->lerpOrigin, 200 + (rand()&31), 0.2f, 0.2f, 1.0 );
1863 }
1864
1865 // neutralflag
1866 if ( powerups & ( 1 << PW_NEUTRALFLAG ) ) {
1867 if (ci->newAnims) {
1868 CG_PlayerFlag( cent, cgs.media.neutralFlagFlapSkin, torso );
1869 }
1870 else {
1871 CG_TrailItem( cent, cgs.media.neutralFlagModel );
1872 }
1873 trap_R_AddLightToScene( cent->lerpOrigin, 200 + (rand()&31), 1.0, 1.0, 1.0 );
1874 }
1875
1876 // haste leaves smoke trails
1877 if ( powerups & ( 1 << PW_HASTE ) ) {
1878 CG_HasteTrail( cent );
1879 }
1880 }
1881
1882
1883 /*
1884 ===============
1885 CG_PlayerFloatSprite
1886
1887 Float a sprite over the player's head
1888 ===============
1889 */
1890 static void CG_PlayerFloatSprite( centity_t *cent, qhandle_t shader ) {
1891 int rf;
1892 refEntity_t ent;
1893
1894 if ( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson ) {
1895 rf = RF_THIRD_PERSON; // only show in mirrors
1896 } else {
1897 rf = 0;
1898 }
1899
1900 memset( &ent, 0, sizeof( ent ) );
1901 VectorCopy( cent->lerpOrigin, ent.origin );
1902 ent.origin[2] += 48;
1903 ent.reType = RT_SPRITE;
1904 ent.customShader = shader;
1905 ent.radius = 10;
1906 ent.renderfx = rf;
1907 ent.shaderRGBA[0] = 255;
1908 ent.shaderRGBA[1] = 255;
1909 ent.shaderRGBA[2] = 255;
1910 ent.shaderRGBA[3] = 255;
1911 trap_R_AddRefEntityToScene( &ent );
1912 }
1913
1914
1915
1916 /*
1917 ===============
1918 CG_PlayerSprites
1919
1920 Float sprites over the player's head
1921 ===============
1922 */
1923 static void CG_PlayerSprites( centity_t *cent ) {
1924 int team;
1925
1926 if ( cent->currentState.eFlags & EF_CONNECTION ) {
1927 CG_PlayerFloatSprite( cent, cgs.media.connectionShader );
1928 return;
1929 }
1930
1931 if ( cent->currentState.eFlags & EF_TALK ) {
1932 CG_PlayerFloatSprite( cent, cgs.media.balloonShader );
1933 return;
1934 }
1935
1936 if ( cent->currentState.eFlags & EF_AWARD_IMPRESSIVE ) {
1937 CG_PlayerFloatSprite( cent, cgs.media.medalImpressive );
1938 return;
1939 }
1940
1941 if ( cent->currentState.eFlags & EF_AWARD_EXCELLENT ) {
1942 CG_PlayerFloatSprite( cent, cgs.media.medalExcellent );
1943 return;
1944 }
1945
1946 if ( cent->currentState.eFlags & EF_AWARD_GAUNTLET ) {
1947 CG_PlayerFloatSprite( cent, cgs.media.medalGauntlet );
1948 return;
1949 }
1950
1951 if ( cent->currentState.eFlags & EF_AWARD_DEFEND ) {
1952 CG_PlayerFloatSprite( cent, cgs.media.medalDefend );
1953 return;
1954 }
1955
1956 if ( cent->currentState.eFlags & EF_AWARD_ASSIST ) {
1957 CG_PlayerFloatSprite( cent, cgs.media.medalAssist );
1958 return;
1959 }
1960
1961 if ( cent->currentState.eFlags & EF_AWARD_CAP ) {
1962 CG_PlayerFloatSprite( cent, cgs.media.medalCapture );
1963 return;
1964 }
1965
1966 team = cgs.clientinfo[ cent->currentState.clientNum ].team;
1967 if ( !(cent->currentState.eFlags & EF_DEAD) &&
1968 cg.snap->ps.persistant[PERS_TEAM] == team &&
1969 cgs.gametype >= GT_TEAM && cgs.ffa_gt!=1) {
1970 if (cg_drawFriend.integer) {
1971 CG_PlayerFloatSprite( cent, cgs.media.friendShader );
1972 }
1973 return;
1974 }
1975 }
1976
1977 /*
1978 ===============
1979 CG_PlayerShadow
1980
1981 Returns the Z component of the surface being shadowed
1982
1983 should it return a full plane instead of a Z?
1984 ===============
1985 */
1986 #define SHADOW_DISTANCE 128
1987 static qboolean CG_PlayerShadow( centity_t *cent, float *shadowPlane ) {
1988 vec3_t end, mins = {-15, -15, 0}, maxs = {15, 15, 2};
1989 trace_t trace;
1990 float alpha;
1991
1992 *shadowPlane = 0;
1993
1994 if ( cg_shadows.integer == 0 ) {
1995 return qfalse;
1996 }
1997
1998 // no shadows when invisible
1999 if ( cent->currentState.powerups & ( 1 << PW_INVIS ) ) {
2000 return qfalse;
2001 }
2002
2003 // send a trace down from the player to the ground
2004 VectorCopy( cent->lerpOrigin, end );
2005 end[2] -= SHADOW_DISTANCE;
2006
2007 trap_CM_BoxTrace( &trace, cent->lerpOrigin, end, mins, maxs, 0, MASK_PLAYERSOLID );
2008
2009 // no shadow if too high
2010 if ( trace.fraction == 1.0 || trace.startsolid || trace.allsolid ) {
2011 return qfalse;
2012 }
2013
2014 *shadowPlane = trace.endpos[2] + 1;
2015
2016 if ( cg_shadows.integer != 1 ) { // no mark for stencil or projection shadows
2017 return qtrue;
2018 }
2019
2020 // fade the shadow out with height
2021 alpha = 1.0 - trace.fraction;
2022
2023 // bk0101022 - hack / FPE - bogus planes?
2024 //assert( DotProduct( trace.plane.normal, trace.plane.normal ) != 0.0f )
2025
2026 // add the mark as a temporary, so it goes directly to the renderer
2027 // without taking a spot in the cg_marks array
2028 CG_ImpactMark( cgs.media.shadowMarkShader, trace.endpos, trace.plane.normal,
2029 cent->pe.legs.yawAngle, alpha,alpha,alpha,1, qfalse, 24, qtrue );
2030
2031 return qtrue;
2032 }
2033
2034
2035 /*
2036 ===============
2037 CG_PlayerSplash
2038
2039 Draw a mark at the water surface
2040 ===============
2041 */
2042 static void CG_PlayerSplash( centity_t *cent ) {
2043 vec3_t start, end;
2044 trace_t trace;
2045 int contents;
2046 polyVert_t verts[4];
2047
2048 if ( !cg_shadows.integer ) {
2049 return;
2050 }
2051
2052 VectorCopy( cent->lerpOrigin, end );
2053 end[2] -= 24;
2054
2055 // if the feet aren't in liquid, don't make a mark
2056 // this won't handle moving water brushes, but they wouldn't draw right anyway...
2057 contents = CG_PointContents( end, 0 );
2058 if ( !( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) ) {
2059 return;
2060 }
2061
2062 VectorCopy( cent->lerpOrigin, start );
2063 start[2] += 32;
2064
2065 // if the head isn't out of liquid, don't make a mark
2066 contents = CG_PointContents( start, 0 );
2067 if ( contents & ( CONTENTS_SOLID | CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
2068 return;
2069 }
2070
2071 // trace down to find the surface
2072 trap_CM_BoxTrace( &trace, start, end, NULL, NULL, 0, ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) );
2073
2074 if ( trace.fraction == 1.0 ) {
2075 return;
2076 }
2077
2078 // create a mark polygon
2079 VectorCopy( trace.endpos, verts[0].xyz );
2080 verts[0].xyz[0] -= 32;
2081 verts[0].xyz[1] -= 32;
2082 verts[0].st[0] = 0;
2083 verts[0].st[1] = 0;
2084 verts[0].modulate[0] = 255;
2085 verts[0].modulate[1] = 255;
2086 verts[0].modulate[2] = 255;
2087 verts[0].modulate[3] = 255;
2088
2089 VectorCopy( trace.endpos, verts[1].xyz );
2090 verts[1].xyz[0] -= 32;
2091 verts[1].xyz[1] += 32;
2092 verts[1].st[0] = 0;
2093 verts[1].st[1] = 1;
2094 verts[1].modulate[0] = 255;
2095 verts[1].modulate[1] = 255;
2096 verts[1].modulate[2] = 255;
2097 verts[1].modulate[3] = 255;
2098
2099 VectorCopy( trace.endpos, verts[2].xyz );
2100 verts[2].xyz[0] += 32;
2101 verts[2].xyz[1] += 32;
2102 verts[2].st[0] = 1;
2103 verts[2].st[1] = 1;
2104 verts[2].modulate[0] = 255;
2105 verts[2].modulate[1] = 255;
2106 verts[2].modulate[2] = 255;
2107 verts[2].modulate[3] = 255;
2108
2109 VectorCopy( trace.endpos, verts[3].xyz );
2110 verts[3].xyz[0] += 32;
2111 verts[3].xyz[1] -= 32;
2112 verts[3].st[0] = 1;
2113 verts[3].st[1] = 0;
2114 verts[3].modulate[0] = 255;
2115 verts[3].modulate[1] = 255;
2116 verts[3].modulate[2] = 255;
2117 verts[3].modulate[3] = 255;
2118
2119 trap_R_AddPolyToScene( cgs.media.wakeMarkShader, 4, verts );
2120 }
2121
2122
2123
2124 /*
2125 ===============
2126 CG_AddRefEntityWithPowerups
2127
2128 Adds a piece with modifications or duplications for powerups
2129 Also called by CG_Missile for quad rockets, but nobody can tell...
2130 ===============
2131 */
2132 void CG_AddRefEntityWithPowerups( refEntity_t *ent, entityState_t *state, int team, qboolean isMissile ) {
2133
2134 if ( state->powerups & ( 1 << PW_INVIS ) ) {
2135 if( (cgs.dmflags & DF_INVIS) == 0) {
2136 ent->customShader = cgs.media.invisShader;
2137 trap_R_AddRefEntityToScene( ent );
2138 }
2139 } else {
2140 /*
2141 if ( state->eFlags & EF_KAMIKAZE ) {
2142 if (team == TEAM_BLUE)
2143 ent->customShader = cgs.media.blueKamikazeShader;
2144 else
2145 ent->customShader = cgs.media.redKamikazeShader;
2146 trap_R_AddRefEntityToScene( ent );
2147 }
2148 else {*/
2149 trap_R_AddRefEntityToScene( ent );
2150 //}
2151 if(!isMissile && (cgs.dmflags & DF_PLAYER_OVERLAY) && !(state->eFlags & EF_DEAD) ) {
2152 switch(team) {
2153 case TEAM_RED:
2154 ent->customShader = cgs.media.redOverlay;
2155 trap_R_AddRefEntityToScene( ent );
2156 break;
2157 case TEAM_BLUE:
2158 ent->customShader = cgs.media.blueOverlay;
2159 trap_R_AddRefEntityToScene( ent );
2160 break;
2161 default:
2162 ent->customShader = cgs.media.neutralOverlay;
2163 trap_R_AddRefEntityToScene( ent );
2164 }
2165 }
2166
2167 if ( state->powerups & ( 1 << PW_QUAD ) )
2168 {
2169 if (team == TEAM_RED)
2170 ent->customShader = cgs.media.redQuadShader;
2171 else
2172 ent->customShader = cgs.media.quadShader;
2173 trap_R_AddRefEntityToScene( ent );
2174 }
2175 if ( state->powerups & ( 1 << PW_REGEN ) ) {
2176 if ( ( ( cg.time / 100 ) % 10 ) == 1 ) {
2177 ent->customShader = cgs.media.regenShader;
2178 trap_R_AddRefEntityToScene( ent );
2179 }
2180 }
2181 if ( state->powerups & ( 1 << PW_BATTLESUIT ) ) {
2182 ent->customShader = cgs.media.battleSuitShader;
2183 trap_R_AddRefEntityToScene( ent );
2184 }
2185 }
2186 }
2187
2188
2189
2190 /*
2191 =================
2192 CG_LightVerts
2193 =================
2194 */
2195 int CG_LightVerts( vec3_t normal, int numVerts, polyVert_t *verts )
2196 {
2197 int i, j;
2198 float incoming;
2199 vec3_t ambientLight;
2200 vec3_t lightDir;
2201 vec3_t directedLight;
2202
2203 trap_R_LightForPoint( verts[0].xyz, ambientLight, directedLight, lightDir );
2204
2205 for (i = 0; i < numVerts; i++) {
2206 incoming = DotProduct (normal, lightDir);
2207 if ( incoming <= 0 ) {
2208 verts[i].modulate[0] = ambientLight[0];
2209 verts[i].modulate[1] = ambientLight[1];
2210 verts[i].modulate[2] = ambientLight[2];
2211 verts[i].modulate[3] = 255;
2212 continue;
2213 }
2214 j = ( ambientLight[0] + incoming * directedLight[0] );
2215 if ( j > 255 ) {
2216 j = 255;
2217 }
2218 verts[i].modulate[0] = j;
2219
2220 j = ( ambientLight[1] + incoming * directedLight[1] );
2221 if ( j > 255 ) {
2222 j = 255;
2223 }
2224 verts[i].modulate[1] = j;
2225
2226 j = ( ambientLight[2] + incoming * directedLight[2] );
2227 if ( j > 255 ) {
2228 j = 255;
2229 }
2230 verts[i].modulate[2] = j;
2231
2232 verts[i].modulate[3] = 255;
2233 }
2234 return qtrue;
2235 }
2236
2237 /*
2238 ===============
2239 CG_Player
2240 ===============
2241 */
2242 void CG_Player( centity_t *cent ) {
2243 clientInfo_t *ci;
2244 refEntity_t legs;
2245 refEntity_t torso;
2246 refEntity_t head;
2247 int clientNum;
2248 int renderfx;
2249 qboolean shadow;
2250 float shadowPlane;
2251 refEntity_t skull;
2252 refEntity_t powerup;
2253 int t;
2254 float c;
2255 float angle;
2256 vec3_t dir, angles;
2257
2258 // the client number is stored in clientNum. It can't be derived
2259 // from the entity number, because a single client may have
2260 // multiple corpses on the level using the same clientinfo
2261 clientNum = cent->currentState.clientNum;
2262 if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) {
2263 CG_Error( "Bad clientNum on player entity");
2264 }
2265 ci = &cgs.clientinfo[ clientNum ];
2266
2267 // it is possible to see corpses from disconnected players that may
2268 // not have valid clientinfo
2269 if ( !ci->infoValid ) {
2270 return;
2271 }
2272
2273 // get the player model information
2274 renderfx = 0;
2275 if ( cent->currentState.number == cg.snap->ps.clientNum) {
2276 if (!cg.renderingThirdPerson) {
2277 renderfx = RF_THIRD_PERSON; // only draw in mirrors
2278 } else {
2279 if (cg_cameraMode.integer) {
2280 return;
2281 }
2282 }
2283 }
2284
2285
2286 memset( &legs, 0, sizeof(legs) );
2287 memset( &torso, 0, sizeof(torso) );
2288 memset( &head, 0, sizeof(head) );
2289
2290 // get the rotation information
2291 CG_PlayerAngles( cent, legs.axis, torso.axis, head.axis );
2292
2293 // get the animation state (after rotation, to allow feet shuffle)
2294 CG_PlayerAnimation( cent, &legs.oldframe, &legs.frame, &legs.backlerp,
2295 &torso.oldframe, &torso.frame, &torso.backlerp );
2296
2297 // add the talk baloon or disconnect icon
2298 CG_PlayerSprites( cent );
2299
2300 // add the shadow
2301 shadow = CG_PlayerShadow( cent, &shadowPlane );
2302
2303 // add a water splash if partially in and out of water
2304 CG_PlayerSplash( cent );
2305
2306 if ( cg_shadows.integer == 3 && shadow ) {
2307 renderfx |= RF_SHADOW_PLANE;
2308 }
2309 renderfx |= RF_LIGHTING_ORIGIN; // use the same origin for all
2310 if( cgs.gametype == GT_HARVESTER ) {
2311 CG_PlayerTokens( cent, renderfx );
2312 }
2313 //
2314 // add the legs
2315 //
2316 legs.hModel = ci->legsModel;
2317 legs.customSkin = ci->legsSkin;
2318
2319 VectorCopy( cent->lerpOrigin, legs.origin );
2320
2321 VectorCopy( cent->lerpOrigin, legs.lightingOrigin );
2322 legs.shadowPlane = shadowPlane;
2323 legs.renderfx = renderfx;
2324 VectorCopy (legs.origin, legs.oldorigin); // don't positionally lerp at all
2325
2326 CG_AddRefEntityWithPowerups( &legs, &cent->currentState, ci->team, qfalse );
2327
2328 // if the model failed, allow the default nullmodel to be displayed
2329 if (!legs.hModel) {
2330 return;
2331 }
2332
2333 //
2334 // add the torso
2335 //
2336 torso.hModel = ci->torsoModel;
2337 if (!torso.hModel) {
2338 return;
2339 }
2340
2341 torso.customSkin = ci->torsoSkin;
2342
2343 VectorCopy( cent->lerpOrigin, torso.lightingOrigin );
2344
2345 CG_PositionRotatedEntityOnTag( &torso, &legs, ci->legsModel, "tag_torso");
2346
2347 torso.shadowPlane = shadowPlane;
2348 torso.renderfx = renderfx;
2349
2350 CG_AddRefEntityWithPowerups( &torso, &cent->currentState, ci->team, qfalse );
2351
2352 if ( cent->currentState.eFlags & EF_KAMIKAZE ) {
2353
2354 memset( &skull, 0, sizeof(skull) );
2355
2356 VectorCopy( cent->lerpOrigin, skull.lightingOrigin );
2357 skull.shadowPlane = shadowPlane;
2358 skull.renderfx = renderfx;
2359
2360 if ( cent->currentState.eFlags & EF_DEAD ) {
2361 // one skull bobbing above the dead body
2362 angle = ((cg.time / 7) & 255) * (M_PI * 2) / 255;
2363 if (angle > M_PI * 2)
2364 angle -= (float)M_PI * 2;
2365 dir[0] = sin(angle) * 20;
2366 dir[1] = cos(angle) * 20;
2367 angle = ((cg.time / 4) & 255) * (M_PI * 2) / 255;
2368 dir[2] = 15 + sin(angle) * 8;
2369 VectorAdd(torso.origin, dir, skull.origin);
2370
2371 dir[2] = 0;
2372 VectorCopy(dir, skull.axis[1]);
2373 VectorNormalize(skull.axis[1]);
2374 VectorSet(skull.axis[2], 0, 0, 1);
2375 CrossProduct(skull.axis[1], skull.axis[2], skull.axis[0]);
2376
2377 skull.hModel = cgs.media.kamikazeHeadModel;
2378 trap_R_AddRefEntityToScene( &skull );
2379 skull.hModel = cgs.media.kamikazeHeadTrail;
2380 trap_R_AddRefEntityToScene( &skull );
2381 }
2382 else {
2383 // three skulls spinning around the player
2384 angle = ((cg.time / 4) & 255) * (M_PI * 2) / 255;
2385 dir[0] = cos(angle) * 20;
2386 dir[1] = sin(angle) * 20;
2387 dir[2] = cos(angle) * 20;
2388 VectorAdd(torso.origin, dir, skull.origin);
2389
2390 angles[0] = sin(angle) * 30;
2391 angles[1] = (angle * 180 / M_PI) + 90;
2392 if (angles[1] > 360)
2393 angles[1] -= 360;
2394 angles[2] = 0;
2395 AnglesToAxis( angles, skull.axis );
2396
2397 /*
2398 dir[2] = 0;
2399 VectorInverse(dir);
2400 VectorCopy(dir, skull.axis[1]);
2401 VectorNormalize(skull.axis[1]);
2402 VectorSet(skull.axis[2], 0, 0, 1);
2403 CrossProduct(skull.axis[1], skull.axis[2], skull.axis[0]);
2404 */
2405
2406 skull.hModel = cgs.media.kamikazeHeadModel;
2407 trap_R_AddRefEntityToScene( &skull );
2408 // flip the trail because this skull is spinning in the other direction
2409 VectorInverse(skull.axis[1]);
2410 skull.hModel = cgs.media.kamikazeHeadTrail;
2411 trap_R_AddRefEntityToScene( &skull );
2412
2413 angle = ((cg.time / 4) & 255) * (M_PI * 2) / 255 + M_PI;
2414 if (angle > M_PI * 2)
2415 angle -= (float)M_PI * 2;
2416 dir[0] = sin(angle) * 20;
2417 dir[1] = cos(angle) * 20;
2418 dir[2] = cos(angle) * 20;
2419 VectorAdd(torso.origin, dir, skull.origin);
2420
2421 angles[0] = cos(angle - 0.5 * M_PI) * 30;
2422 angles[1] = 360 - (angle * 180 / M_PI);
2423 if (angles[1] > 360)
2424 angles[1] -= 360;
2425 angles[2] = 0;
2426 AnglesToAxis( angles, skull.axis );
2427
2428 /*
2429 dir[2] = 0;
2430 VectorCopy(dir, skull.axis[1]);
2431 VectorNormalize(skull.axis[1]);
2432 VectorSet(skull.axis[2], 0, 0, 1);
2433 CrossProduct(skull.axis[1], skull.axis[2], skull.axis[0]);
2434 */
2435
2436 skull.hModel = cgs.media.kamikazeHeadModel;
2437 trap_R_AddRefEntityToScene( &skull );
2438 skull.hModel = cgs.media.kamikazeHeadTrail;
2439 trap_R_AddRefEntityToScene( &skull );
2440
2441 angle = ((cg.time / 3) & 255) * (M_PI * 2) / 255 + 0.5 * M_PI;
2442 if (angle > M_PI * 2)
2443 angle -= (float)M_PI * 2;
2444 dir[0] = sin(angle) * 20;
2445 dir[1] = cos(angle) * 20;
2446 dir[2] = 0;
2447 VectorAdd(torso.origin, dir, skull.origin);
2448
2449 VectorCopy(dir, skull.axis[1]);
2450 VectorNormalize(skull.axis[1]);
2451 VectorSet(skull.axis[2], 0, 0, 1);
2452 CrossProduct(skull.axis[1], skull.axis[2], skull.axis[0]);
2453
2454 skull.hModel = cgs.media.kamikazeHeadModel;
2455 trap_R_AddRefEntityToScene( &skull );
2456 skull.hModel = cgs.media.kamikazeHeadTrail;
2457 trap_R_AddRefEntityToScene( &skull );
2458 }
2459 }
2460
2461 if ( cent->currentState.powerups & ( 1 << PW_GUARD ) ) {
2462 memcpy(&powerup, &torso, sizeof(torso));
2463 powerup.hModel = cgs.media.guardPowerupModel;
2464 powerup.frame = 0;
2465 powerup.oldframe = 0;
2466 powerup.customSkin = 0;
2467 trap_R_AddRefEntityToScene( &powerup );
2468 }
2469 if ( cent->currentState.powerups & ( 1 << PW_SCOUT ) ) {
2470 memcpy(&powerup, &torso, sizeof(torso));
2471 powerup.hModel = cgs.media.scoutPowerupModel;
2472 powerup.frame = 0;
2473 powerup.oldframe = 0;
2474 powerup.customSkin = 0;
2475 trap_R_AddRefEntityToScene( &powerup );
2476 }
2477 if ( cent->currentState.powerups & ( 1 << PW_DOUBLER ) ) {
2478 memcpy(&powerup, &torso, sizeof(torso));
2479 powerup.hModel = cgs.media.doublerPowerupModel;
2480 powerup.frame = 0;
2481 powerup.oldframe = 0;
2482 powerup.customSkin = 0;
2483 trap_R_AddRefEntityToScene( &powerup );
2484 }
2485 if ( cent->currentState.powerups & ( 1 << PW_AMMOREGEN ) ) {
2486 memcpy(&powerup, &torso, sizeof(torso));
2487 powerup.hModel = cgs.media.ammoRegenPowerupModel;
2488 powerup.frame = 0;
2489 powerup.oldframe = 0;
2490 powerup.customSkin = 0;
2491 trap_R_AddRefEntityToScene( &powerup );
2492 }
2493 if ( cent->currentState.powerups & ( 1 << PW_INVULNERABILITY ) ) {
2494 if ( !ci->invulnerabilityStartTime ) {
2495 ci->invulnerabilityStartTime = cg.time;
2496 }
2497 ci->invulnerabilityStopTime = cg.time;
2498 }
2499 else {
2500 ci->invulnerabilityStartTime = 0;
2501 }
2502 if ( (cent->currentState.powerups & ( 1 << PW_INVULNERABILITY ) ) ||
2503 cg.time - ci->invulnerabilityStopTime < 250 ) {
2504
2505 memcpy(&powerup, &torso, sizeof(torso));
2506 powerup.hModel = cgs.media.invulnerabilityPowerupModel;
2507 powerup.customSkin = 0;
2508 // always draw
2509 powerup.renderfx &= ~RF_THIRD_PERSON;
2510 VectorCopy(cent->lerpOrigin, powerup.origin);
2511
2512 if ( cg.time - ci->invulnerabilityStartTime < 250 ) {
2513 c = (float) (cg.time - ci->invulnerabilityStartTime) / 250;
2514 }
2515 else if (cg.time - ci->invulnerabilityStopTime < 250 ) {
2516 c = (float) (250 - (cg.time - ci->invulnerabilityStopTime)) / 250;
2517 }
2518 else {
2519 c = 1;
2520 }
2521 VectorSet( powerup.axis[0], c, 0, 0 );
2522 VectorSet( powerup.axis[1], 0, c, 0 );
2523 VectorSet( powerup.axis[2], 0, 0, c );
2524 trap_R_AddRefEntityToScene( &powerup );
2525 }
2526
2527 t = cg.time - ci->medkitUsageTime;
2528 if ( ci->medkitUsageTime && t < 500 ) {
2529 memcpy(&powerup, &torso, sizeof(torso));
2530 powerup.hModel = cgs.media.medkitUsageModel;
2531 powerup.customSkin = 0;
2532 // always draw
2533 powerup.renderfx &= ~RF_THIRD_PERSON;
2534 VectorClear(angles);
2535 AnglesToAxis(angles, powerup.axis);
2536 VectorCopy(cent->lerpOrigin, powerup.origin);
2537 powerup.origin[2] += -24 + (float) t * 80 / 500;
2538 if ( t > 400 ) {
2539 c = (float) (t - 1000) * 0xff / 100;
2540 powerup.shaderRGBA[0] = 0xff - c;
2541 powerup.shaderRGBA[1] = 0xff - c;
2542 powerup.shaderRGBA[2] = 0xff - c;
2543 powerup.shaderRGBA[3] = 0xff - c;
2544 }
2545 else {
2546 powerup.shaderRGBA[0] = 0xff;
2547 powerup.shaderRGBA[1] = 0xff;
2548 powerup.shaderRGBA[2] = 0xff;
2549 powerup.shaderRGBA[3] = 0xff;
2550 }
2551 trap_R_AddRefEntityToScene( &powerup );
2552 }
2553
2554 //
2555 // add the head
2556 //
2557 head.hModel = ci->headModel;
2558 if (!head.hModel) {
2559 return;
2560 }
2561 head.customSkin = ci->headSkin;
2562
2563 VectorCopy( cent->lerpOrigin, head.lightingOrigin );
2564
2565 CG_PositionRotatedEntityOnTag( &head, &torso, ci->torsoModel, "tag_head");
2566
2567 head.shadowPlane = shadowPlane;
2568 head.renderfx = renderfx;
2569
2570 CG_AddRefEntityWithPowerups( &head, &cent->currentState, ci->team, qfalse );
2571
2572 CG_BreathPuffs(cent, &head);
2573
2574 CG_DustTrail(cent);
2575
2576 //
2577 // add the gun / barrel / flash
2578 //
2579 CG_AddPlayerWeapon( &torso, NULL, cent, ci->team );
2580
2581 // add powerups floating behind the player
2582 CG_PlayerPowerups( cent, &torso );
2583 }
2584
2585
2586 //=====================================================================
2587
2588 /*
2589 ===============
2590 CG_ResetPlayerEntity
2591
2592 A player just came into view or teleported, so reset all animation info
2593 ===============
2594 */
2595 void CG_ResetPlayerEntity( centity_t *cent ) {
2596 cent->errorTime = -99999; // guarantee no error decay added
2597 cent->extrapolated = qfalse;
2598
2599 CG_ClearLerpFrame( &cgs.clientinfo[ cent->currentState.clientNum ], &cent->pe.legs, cent->currentState.legsAnim );
2600 CG_ClearLerpFrame( &cgs.clientinfo[ cent->currentState.clientNum ], &cent->pe.torso, cent->currentState.torsoAnim );
2601
2602 BG_EvaluateTrajectory( &cent->currentState.pos, cg.time, cent->lerpOrigin );
2603 BG_EvaluateTrajectory( &cent->currentState.apos, cg.time, cent->lerpAngles );
2604
2605 VectorCopy( cent->lerpOrigin, cent->rawOrigin );
2606 VectorCopy( cent->lerpAngles, cent->rawAngles );
2607
2608 memset( &cent->pe.legs, 0, sizeof( cent->pe.legs ) );
2609 cent->pe.legs.yawAngle = cent->rawAngles[YAW];
2610 cent->pe.legs.yawing = qfalse;
2611 cent->pe.legs.pitchAngle = 0;
2612 cent->pe.legs.pitching = qfalse;
2613
2614 memset( &cent->pe.torso, 0, sizeof( cent->pe.legs ) );
2615 cent->pe.torso.yawAngle = cent->rawAngles[YAW];
2616 cent->pe.torso.yawing = qfalse;
2617 cent->pe.torso.pitchAngle = cent->rawAngles[PITCH];
2618 cent->pe.torso.pitching = qfalse;
2619
2620 if ( cg_debugPosition.integer ) {
2621 CG_Printf("%i ResetPlayerEntity yaw=%i\n", cent->currentState.number, cent->pe.torso.yawAngle );
2622 }
2623 }
2624