Debian Codegraph @

code/cgame/cg_players.c

raw symbols SCIP
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 counts 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[0] ) {
132 break;
133 }
134 if ( !Q_stricmp( token, "footsteps" ) ) {
135 token = COM_Parse( &text_p );
136 if ( !token[0] ) {
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[0] ) {
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[0] ) {
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' in %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[0] ) {
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[0] ) {
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[0] ) {
233 break;
234 }
235 animations[i].loopFrames = atoi( token );
236
237 token = COM_Parse( &text_p );
238 if ( !token[0] ) {
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 ) {
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/james/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/james/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 ) {
347 if ( i == 0 && teamName && *teamName ) {
348 // "models/players/characters/james/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/james/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/james/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/james/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 ) {
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 ) {
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];
524 const char *headName;
525 char newTeamName[MAX_QPATH];
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) {
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) {
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) ? 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 || ci->team == match->team) ) {
784 // this clientinfo is identical, so use its 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 && 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 ) {
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 && 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 newInfo.c1RGBA[0] = 255 * newInfo.color1[0];
904 newInfo.c1RGBA[1] = 255 * newInfo.color1[1];
905 newInfo.c1RGBA[2] = 255 * newInfo.color1[2];
906 newInfo.c1RGBA[3] = 255;
907
908 v = Info_ValueForKey( configstring, "c2" );
909 CG_ColorFromString( v, newInfo.color2 );
910
911 newInfo.c2RGBA[0] = 255 * newInfo.color2[0];
912 newInfo.c2RGBA[1] = 255 * newInfo.color2[1];
913 newInfo.c2RGBA[2] = 255 * newInfo.color2[2];
914 newInfo.c2RGBA[3] = 255;
915
916 // bot skill
917 v = Info_ValueForKey( configstring, "skill" );
918 newInfo.botSkill = atoi( v );
919
920 // handicap
921 v = Info_ValueForKey( configstring, "hc" );
922 newInfo.handicap = atoi( v );
923
924 // wins
925 v = Info_ValueForKey( configstring, "w" );
926 newInfo.wins = atoi( v );
927
928 // losses
929 v = Info_ValueForKey( configstring, "l" );
930 newInfo.losses = atoi( v );
931
932 // team
933 v = Info_ValueForKey( configstring, "t" );
934 newInfo.team = atoi( v );
935
936 // team task
937 v = Info_ValueForKey( configstring, "tt" );
938 newInfo.teamTask = atoi(v);
939
940 // team leader
941 v = Info_ValueForKey( configstring, "tl" );
942 newInfo.teamLeader = atoi(v);
943
944 v = Info_ValueForKey( configstring, "g_redteam" );
945 Q_strncpyz(newInfo.redTeam, v, MAX_TEAMNAME);
946
947 v = Info_ValueForKey( configstring, "g_blueteam" );
948 Q_strncpyz(newInfo.blueTeam, v, MAX_TEAMNAME);
949
950 // model
951 v = Info_ValueForKey( configstring, "model" );
952 if ( cg_forceModel.integer ) {
953 // forcemodel makes everyone use a single model
954 // to prevent load hitches
955 char modelStr[MAX_QPATH];
956 char *skin;
957
958 if( cgs.gametype >= GT_TEAM ) {
959 Q_strncpyz( newInfo.modelName, DEFAULT_TEAM_MODEL, sizeof( newInfo.modelName ) );
960 Q_strncpyz( newInfo.skinName, "default", sizeof( newInfo.skinName ) );
961 } else {
962 trap_Cvar_VariableStringBuffer( "model", modelStr, sizeof( modelStr ) );
963 if ( ( skin = strchr( modelStr, '/' ) ) == NULL) {
964 skin = "default";
965 } else {
966 *skin++ = 0;
967 }
968
969 Q_strncpyz( newInfo.skinName, skin, sizeof( newInfo.skinName ) );
970 Q_strncpyz( newInfo.modelName, modelStr, sizeof( newInfo.modelName ) );
971 }
972
973 if ( cgs.gametype >= GT_TEAM ) {
974 // keep skin name
975 slash = strchr( v, '/' );
976 if ( slash ) {
977 Q_strncpyz( newInfo.skinName, slash + 1, sizeof( newInfo.skinName ) );
978 }
979 }
980 } else {
981 Q_strncpyz( newInfo.modelName, v, sizeof( newInfo.modelName ) );
982
983 slash = strchr( newInfo.modelName, '/' );
984 if ( !slash ) {
985 // modelName didn not include a skin name
986 Q_strncpyz( newInfo.skinName, "default", sizeof( newInfo.skinName ) );
987 } else {
988 Q_strncpyz( newInfo.skinName, slash + 1, sizeof( newInfo.skinName ) );
989 // truncate modelName
990 *slash = 0;
991 }
992 }
993
994 // head model
995 v = Info_ValueForKey( configstring, "hmodel" );
996 if ( cg_forceModel.integer ) {
997 // forcemodel makes everyone use a single model
998 // to prevent load hitches
999 char modelStr[MAX_QPATH];
1000 char *skin;
1001
1002 if( cgs.gametype >= GT_TEAM ) {
1003 Q_strncpyz( newInfo.headModelName, DEFAULT_TEAM_HEAD, sizeof( newInfo.headModelName ) );
1004 Q_strncpyz( newInfo.headSkinName, "default", sizeof( newInfo.headSkinName ) );
1005 } else {
1006 trap_Cvar_VariableStringBuffer( "headmodel", modelStr, sizeof( modelStr ) );
1007 if ( ( skin = strchr( modelStr, '/' ) ) == NULL) {
1008 skin = "default";
1009 } else {
1010 *skin++ = 0;
1011 }
1012
1013 Q_strncpyz( newInfo.headSkinName, skin, sizeof( newInfo.headSkinName ) );
1014 Q_strncpyz( newInfo.headModelName, modelStr, sizeof( newInfo.headModelName ) );
1015 }
1016
1017 if ( cgs.gametype >= GT_TEAM ) {
1018 // keep skin name
1019 slash = strchr( v, '/' );
1020 if ( slash ) {
1021 Q_strncpyz( newInfo.headSkinName, slash + 1, sizeof( newInfo.headSkinName ) );
1022 }
1023 }
1024 } else {
1025 Q_strncpyz( newInfo.headModelName, v, sizeof( newInfo.headModelName ) );
1026
1027 slash = strchr( newInfo.headModelName, '/' );
1028 if ( !slash ) {
1029 // modelName didn not include a skin name
1030 Q_strncpyz( newInfo.headSkinName, "default", sizeof( newInfo.headSkinName ) );
1031 } else {
1032 Q_strncpyz( newInfo.headSkinName, slash + 1, sizeof( newInfo.headSkinName ) );
1033 // truncate modelName
1034 *slash = 0;
1035 }
1036 }
1037
1038 // scan for an existing clientinfo that matches this modelname
1039 // so we can avoid loading checks if possible
1040 if ( !CG_ScanForExistingClientInfo( &newInfo ) ) {
1041 qboolean forceDefer;
1042
1043 forceDefer = trap_MemoryRemaining() < 4000000;
1044
1045 // if we are defering loads, just have it pick the first valid
1046 if ( forceDefer || (cg_deferPlayers.integer && !cg_buildScript.integer && !cg.loading ) ) {
1047 // keep whatever they had if it won't violate team skins
1048 CG_SetDeferredClientInfo( clientNum, &newInfo );
1049 // if we are low on memory, leave them with this model
1050 if ( forceDefer ) {
1051 CG_Printf( "Memory is low. Using deferred model.\n" );
1052 newInfo.deferred = qfalse;
1053 }
1054 } else {
1055 CG_LoadClientInfo( clientNum, &newInfo );
1056 }
1057 }
1058
1059 // replace whatever was there with the new one
1060 newInfo.infoValid = qtrue;
1061 *ci = newInfo;
1062 }
1063
1064
1065
1066 /*
1067 ======================
1068 CG_LoadDeferredPlayers
1069
1070 Called each frame when a player is dead
1071 and the scoreboard is up
1072 so deferred players can be loaded
1073 ======================
1074 */
1075 void CG_LoadDeferredPlayers( void ) {
1076 int i;
1077 clientInfo_t *ci;
1078
1079 // scan for a deferred player to load
1080 for ( i = 0, ci = cgs.clientinfo ; i < cgs.maxclients ; i++, ci++ ) {
1081 if ( ci->infoValid && ci->deferred ) {
1082 // if we are low on memory, leave it deferred
1083 if ( trap_MemoryRemaining() < 4000000 ) {
1084 CG_Printf( "Memory is low. Using deferred model.\n" );
1085 ci->deferred = qfalse;
1086 continue;
1087 }
1088 CG_LoadClientInfo( i, ci );
1089 // break;
1090 }
1091 }
1092 }
1093
1094 /*
1095 =============================================================================
1096
1097 PLAYER ANIMATION
1098
1099 =============================================================================
1100 */
1101
1102
1103 /*
1104 ===============
1105 CG_SetLerpFrameAnimation
1106
1107 may include ANIM_TOGGLEBIT
1108 ===============
1109 */
1110 static void CG_SetLerpFrameAnimation( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation ) {
1111 animation_t *anim;
1112
1113 lf->animationNumber = newAnimation;
1114 newAnimation &= ~ANIM_TOGGLEBIT;
1115
1116 if ( newAnimation < 0 || newAnimation >= MAX_TOTALANIMATIONS ) {
1117 CG_Error( "Bad animation number: %i", newAnimation );
1118 }
1119
1120 anim = &ci->animations[ newAnimation ];
1121
1122 lf->animation = anim;
1123 lf->animationTime = lf->frameTime + anim->initialLerp;
1124
1125 if ( cg_debugAnim.integer ) {
1126 CG_Printf( "Anim: %i\n", newAnimation );
1127 }
1128 }
1129
1130 /*
1131 ===============
1132 CG_RunLerpFrame
1133
1134 Sets cg.snap, cg.oldFrame, and cg.backlerp
1135 cg.time should be between oldFrameTime and frameTime after exit
1136 ===============
1137 */
1138 static void CG_RunLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int newAnimation, float speedScale ) {
1139 int f, numFrames;
1140 animation_t *anim;
1141
1142 // debugging tool to get no animations
1143 if ( cg_animSpeed.integer == 0 ) {
1144 lf->oldFrame = lf->frame = lf->backlerp = 0;
1145 return;
1146 }
1147
1148 // see if the animation sequence is switching
1149 if ( newAnimation != lf->animationNumber || !lf->animation ) {
1150 CG_SetLerpFrameAnimation( ci, lf, newAnimation );
1151 }
1152
1153 // if we have passed the current frame, move it to
1154 // oldFrame and calculate a new frame
1155 if ( cg.time >= lf->frameTime ) {
1156 lf->oldFrame = lf->frame;
1157 lf->oldFrameTime = lf->frameTime;
1158
1159 // get the next frame based on the animation
1160 anim = lf->animation;
1161 if ( !anim->frameLerp ) {
1162 return; // shouldn't happen
1163 }
1164 if ( cg.time < lf->animationTime ) {
1165 lf->frameTime = lf->animationTime; // initial lerp
1166 } else {
1167 lf->frameTime = lf->oldFrameTime + anim->frameLerp;
1168 }
1169 f = ( lf->frameTime - lf->animationTime ) / anim->frameLerp;
1170 f *= speedScale; // adjust for haste, etc
1171
1172 numFrames = anim->numFrames;
1173 if (anim->flipflop) {
1174 numFrames *= 2;
1175 }
1176 if ( f >= numFrames ) {
1177 f -= numFrames;
1178 if ( anim->loopFrames ) {
1179 f %= anim->loopFrames;
1180 f += anim->numFrames - anim->loopFrames;
1181 } else {
1182 f = numFrames - 1;
1183 // the animation is stuck at the end, so it
1184 // can immediately transition to another sequence
1185 lf->frameTime = cg.time;
1186 }
1187 }
1188 if ( anim->reversed ) {
1189 lf->frame = anim->firstFrame + anim->numFrames - 1 - f;
1190 }
1191 else if (anim->flipflop && f>=anim->numFrames) {
1192 lf->frame = anim->firstFrame + anim->numFrames - 1 - (f%anim->numFrames);
1193 }
1194 else {
1195 lf->frame = anim->firstFrame + f;
1196 }
1197 if ( cg.time > lf->frameTime ) {
1198 lf->frameTime = cg.time;
1199 if ( cg_debugAnim.integer ) {
1200 CG_Printf( "Clamp lf->frameTime\n");
1201 }
1202 }
1203 }
1204
1205 if ( lf->frameTime > cg.time + 200 ) {
1206 lf->frameTime = cg.time;
1207 }
1208
1209 if ( lf->oldFrameTime > cg.time ) {
1210 lf->oldFrameTime = cg.time;
1211 }
1212 // calculate current lerp value
1213 if ( lf->frameTime == lf->oldFrameTime ) {
1214 lf->backlerp = 0;
1215 } else {
1216 lf->backlerp = 1.0 - (float)( cg.time - lf->oldFrameTime ) / ( lf->frameTime - lf->oldFrameTime );
1217 }
1218 }
1219
1220
1221 /*
1222 ===============
1223 CG_ClearLerpFrame
1224 ===============
1225 */
1226 static void CG_ClearLerpFrame( clientInfo_t *ci, lerpFrame_t *lf, int animationNumber ) {
1227 lf->frameTime = lf->oldFrameTime = cg.time;
1228 CG_SetLerpFrameAnimation( ci, lf, animationNumber );
1229 lf->oldFrame = lf->frame = lf->animation->firstFrame;
1230 }
1231
1232
1233 /*
1234 ===============
1235 CG_PlayerAnimation
1236 ===============
1237 */
1238 static void CG_PlayerAnimation( centity_t *cent, int *legsOld, int *legs, float *legsBackLerp,
1239 int *torsoOld, int *torso, float *torsoBackLerp ) {
1240 clientInfo_t *ci;
1241 int clientNum;
1242 float speedScale;
1243
1244 clientNum = cent->currentState.clientNum;
1245
1246 if ( cg_noPlayerAnims.integer ) {
1247 *legsOld = *legs = *torsoOld = *torso = 0;
1248 return;
1249 }
1250
1251 if ( cent->currentState.powerups & ( 1 << PW_HASTE ) ) {
1252 speedScale = 1.5;
1253 } else {
1254 speedScale = 1;
1255 }
1256
1257 ci = &cgs.clientinfo[ clientNum ];
1258
1259 // do the shuffle turn frames locally
1260 if ( cent->pe.legs.yawing && ( cent->currentState.legsAnim & ~ANIM_TOGGLEBIT ) == LEGS_IDLE ) {
1261 CG_RunLerpFrame( ci, &cent->pe.legs, LEGS_TURN, speedScale );
1262 } else {
1263 CG_RunLerpFrame( ci, &cent->pe.legs, cent->currentState.legsAnim, speedScale );
1264 }
1265
1266 *legsOld = cent->pe.legs.oldFrame;
1267 *legs = cent->pe.legs.frame;
1268 *legsBackLerp = cent->pe.legs.backlerp;
1269
1270 CG_RunLerpFrame( ci, &cent->pe.torso, cent->currentState.torsoAnim, speedScale );
1271
1272 *torsoOld = cent->pe.torso.oldFrame;
1273 *torso = cent->pe.torso.frame;
1274 *torsoBackLerp = cent->pe.torso.backlerp;
1275 }
1276
1277 /*
1278 =============================================================================
1279
1280 PLAYER ANGLES
1281
1282 =============================================================================
1283 */
1284
1285 /*
1286 ==================
1287 CG_SwingAngles
1288 ==================
1289 */
1290 static void CG_SwingAngles( float destination, float swingTolerance, float clampTolerance,
1291 float speed, float *angle, qboolean *swinging ) {
1292 float swing;
1293 float move;
1294 float scale;
1295
1296 if ( !*swinging ) {
1297 // see if a swing should be started
1298 swing = AngleSubtract( *angle, destination );
1299 if ( swing > swingTolerance || swing < -swingTolerance ) {
1300 *swinging = qtrue;
1301 }
1302 }
1303
1304 if ( !*swinging ) {
1305 return;
1306 }
1307
1308 // modify the speed depending on the delta
1309 // so it doesn't seem so linear
1310 swing = AngleSubtract( destination, *angle );
1311 scale = fabs( swing );
1312 if ( scale < swingTolerance * 0.5 ) {
1313 scale = 0.5;
1314 } else if ( scale < swingTolerance ) {
1315 scale = 1.0;
1316 } else {
1317 scale = 2.0;
1318 }
1319
1320 // swing towards the destination angle
1321 if ( swing >= 0 ) {
1322 move = cg.frametime * scale * speed;
1323 if ( move >= swing ) {
1324 move = swing;
1325 *swinging = qfalse;
1326 }
1327 *angle = AngleMod( *angle + move );
1328 } else if ( swing < 0 ) {
1329 move = cg.frametime * scale * -speed;
1330 if ( move <= swing ) {
1331 move = swing;
1332 *swinging = qfalse;
1333 }
1334 *angle = AngleMod( *angle + move );
1335 }
1336
1337 // clamp to no more than tolerance
1338 swing = AngleSubtract( destination, *angle );
1339 if ( swing > clampTolerance ) {
1340 *angle = AngleMod( destination - (clampTolerance - 1) );
1341 } else if ( swing < -clampTolerance ) {
1342 *angle = AngleMod( destination + (clampTolerance - 1) );
1343 }
1344 }
1345
1346 /*
1347 =================
1348 CG_AddPainTwitch
1349 =================
1350 */
1351 static void CG_AddPainTwitch( centity_t *cent, vec3_t torsoAngles ) {
1352 int t;
1353 float f;
1354
1355 t = cg.time - cent->pe.painTime;
1356 if ( t >= PAIN_TWITCH_TIME ) {
1357 return;
1358 }
1359
1360 f = 1.0 - (float)t / PAIN_TWITCH_TIME;
1361
1362 if ( cent->pe.painDirection ) {
1363 torsoAngles[ROLL] += 20 * f;
1364 } else {
1365 torsoAngles[ROLL] -= 20 * f;
1366 }
1367 }
1368
1369
1370 /*
1371 ===============
1372 CG_PlayerAngles
1373
1374 Handles separate torso motion
1375
1376 legs pivot based on direction of movement
1377
1378 head always looks exactly at cent->lerpAngles
1379
1380 if motion < 20 degrees, show in head only
1381 if < 45 degrees, also show in torso
1382 ===============
1383 */
1384 static void CG_PlayerAngles( centity_t *cent, vec3_t legs[3], vec3_t torso[3], vec3_t head[3] ) {
1385 vec3_t legsAngles, torsoAngles, headAngles;
1386 float dest;
1387 static int movementOffsets[8] = { 0, 22, 45, -22, 0, 22, -45, -22 };
1388 vec3_t velocity;
1389 float speed;
1390 int dir, clientNum;
1391 clientInfo_t *ci;
1392
1393 VectorCopy( cent->lerpAngles, headAngles );
1394 headAngles[YAW] = AngleMod( headAngles[YAW] );
1395 VectorClear( legsAngles );
1396 VectorClear( torsoAngles );
1397
1398 // --------- yaw -------------
1399
1400 // allow yaw to drift a bit
1401 if ( ( cent->currentState.legsAnim & ~ANIM_TOGGLEBIT ) != LEGS_IDLE
1402 || ((cent->currentState.torsoAnim & ~ANIM_TOGGLEBIT) != TORSO_STAND
1403 && (cent->currentState.torsoAnim & ~ANIM_TOGGLEBIT) != TORSO_STAND2)) {
1404 // if not standing still, always point all in the same direction
1405 cent->pe.torso.yawing = qtrue; // always center
1406 cent->pe.torso.pitching = qtrue; // always center
1407 cent->pe.legs.yawing = qtrue; // always center
1408 }
1409
1410 // adjust legs for movement dir
1411 if ( cent->currentState.eFlags & EF_DEAD ) {
1412 // don't let dead bodies twitch
1413 dir = 0;
1414 } else {
1415 dir = cent->currentState.angles2[YAW];
1416 if ( dir < 0 || dir > 7 ) {
1417 CG_Error( "Bad player movement angle" );
1418 }
1419 }
1420 legsAngles[YAW] = headAngles[YAW] + movementOffsets[ dir ];
1421 torsoAngles[YAW] = headAngles[YAW] + 0.25 * movementOffsets[ dir ];
1422
1423 // torso
1424 CG_SwingAngles( torsoAngles[YAW], 25, 90, cg_swingSpeed.value, &cent->pe.torso.yawAngle, &cent->pe.torso.yawing );
1425 CG_SwingAngles( legsAngles[YAW], 40, 90, cg_swingSpeed.value, &cent->pe.legs.yawAngle, &cent->pe.legs.yawing );
1426
1427 torsoAngles[YAW] = cent->pe.torso.yawAngle;
1428 legsAngles[YAW] = cent->pe.legs.yawAngle;
1429
1430
1431 // --------- pitch -------------
1432
1433 // only show a fraction of the pitch angle in the torso
1434 if ( headAngles[PITCH] > 180 ) {
1435 dest = (-360 + headAngles[PITCH]) * 0.75f;
1436 } else {
1437 dest = headAngles[PITCH] * 0.75f;
1438 }
1439 CG_SwingAngles( dest, 15, 30, 0.1f, &cent->pe.torso.pitchAngle, &cent->pe.torso.pitching );
1440 torsoAngles[PITCH] = cent->pe.torso.pitchAngle;
1441
1442 //
1443 clientNum = cent->currentState.clientNum;
1444 if ( clientNum >= 0 && clientNum < MAX_CLIENTS ) {
1445 ci = &cgs.clientinfo[ clientNum ];
1446 if ( ci->fixedtorso ) {
1447 torsoAngles[PITCH] = 0.0f;
1448 }
1449 }
1450
1451 // --------- roll -------------
1452
1453
1454 // lean towards the direction of travel
1455 VectorCopy( cent->currentState.pos.trDelta, velocity );
1456 speed = VectorNormalize( velocity );
1457 if ( speed ) {
1458 vec3_t axis[3];
1459 float side;
1460
1461 speed *= 0.05f;
1462
1463 AnglesToAxis( legsAngles, axis );
1464 side = speed * DotProduct( velocity, axis[1] );
1465 legsAngles[ROLL] -= side;
1466
1467 side = speed * DotProduct( velocity, axis[0] );
1468 legsAngles[PITCH] += side;
1469 }
1470
1471 //
1472 clientNum = cent->currentState.clientNum;
1473 if ( clientNum >= 0 && clientNum < MAX_CLIENTS ) {
1474 ci = &cgs.clientinfo[ clientNum ];
1475 if ( ci->fixedlegs ) {
1476 legsAngles[YAW] = torsoAngles[YAW];
1477 legsAngles[PITCH] = 0.0f;
1478 legsAngles[ROLL] = 0.0f;
1479 }
1480 }
1481
1482 // pain twitch
1483 CG_AddPainTwitch( cent, torsoAngles );
1484
1485 // pull the angles back out of the hierarchial chain
1486 AnglesSubtract( headAngles, torsoAngles, headAngles );
1487 AnglesSubtract( torsoAngles, legsAngles, torsoAngles );
1488 AnglesToAxis( legsAngles, legs );
1489 AnglesToAxis( torsoAngles, torso );
1490 AnglesToAxis( headAngles, head );
1491 }
1492
1493
1494 //==========================================================================
1495
1496 /*
1497 ===============
1498 CG_HasteTrail
1499 ===============
1500 */
1501 static void CG_HasteTrail( centity_t *cent ) {
1502 localEntity_t *smoke;
1503 vec3_t origin;
1504 int anim;
1505
1506 if ( cent->trailTime > cg.time ) {
1507 return;
1508 }
1509 anim = cent->pe.legs.animationNumber & ~ANIM_TOGGLEBIT;
1510 if ( anim != LEGS_RUN && anim != LEGS_BACK ) {
1511 return;
1512 }
1513
1514 cent->trailTime += 100;
1515 if ( cent->trailTime < cg.time ) {
1516 cent->trailTime = cg.time;
1517 }
1518
1519 VectorCopy( cent->lerpOrigin, origin );
1520 origin[2] -= 16;
1521
1522 smoke = CG_SmokePuff( origin, vec3_origin,
1523 8,
1524 1, 1, 1, 1,
1525 500,
1526 cg.time,
1527 0,
1528 0,
1529 cgs.media.hastePuffShader );
1530
1531 // use the optimized local entity add
1532 smoke->leType = LE_SCALE_FADE;
1533 }
1534
1535 #ifdef MISSIONPACK
1536 /*
1537 ===============
1538 CG_BreathPuffs
1539 ===============
1540 */
1541 static void CG_BreathPuffs( centity_t *cent, refEntity_t *head) {
1542 clientInfo_t *ci;
1543 vec3_t up, origin;
1544 int contents;
1545
1546 ci = &cgs.clientinfo[ cent->currentState.number ];
1547
1548 if (!cg_enableBreath.integer) {
1549 return;
1550 }
1551 if ( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson) {
1552 return;
1553 }
1554 if ( cent->currentState.eFlags & EF_DEAD ) {
1555 return;
1556 }
1557 contents = CG_PointContents( head->origin, 0 );
1558 if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
1559 return;
1560 }
1561 if ( ci->breathPuffTime > cg.time ) {
1562 return;
1563 }
1564
1565 VectorSet( up, 0, 0, 8 );
1566 VectorMA(head->origin, 8, head->axis[0], origin);
1567 VectorMA(origin, -4, head->axis[2], origin);
1568 CG_SmokePuff( origin, up, 16, 1, 1, 1, 0.66f, 1500, cg.time, cg.time + 400, LEF_PUFF_DONT_SCALE, cgs.media.shotgunSmokePuffShader );
1569 ci->breathPuffTime = cg.time + 2000;
1570 }
1571
1572 /*
1573 ===============
1574 CG_DustTrail
1575 ===============
1576 */
1577 static void CG_DustTrail( centity_t *cent ) {
1578 int anim;
1579 vec3_t end, vel;
1580 trace_t tr;
1581
1582 if (!cg_enableDust.integer)
1583 return;
1584
1585 if ( cent->dustTrailTime > cg.time ) {
1586 return;
1587 }
1588
1589 anim = cent->pe.legs.animationNumber & ~ANIM_TOGGLEBIT;
1590 if ( anim != LEGS_LANDB && anim != LEGS_LAND ) {
1591 return;
1592 }
1593
1594 cent->dustTrailTime += 40;
1595 if ( cent->dustTrailTime < cg.time ) {
1596 cent->dustTrailTime = cg.time;
1597 }
1598
1599 VectorCopy(cent->currentState.pos.trBase, end);
1600 end[2] -= 64;
1601 CG_Trace( &tr, cent->currentState.pos.trBase, NULL, NULL, end, cent->currentState.number, MASK_PLAYERSOLID );
1602
1603 if ( !(tr.surfaceFlags & SURF_DUST) )
1604 return;
1605
1606 VectorCopy( cent->currentState.pos.trBase, end );
1607 end[2] -= 16;
1608
1609 VectorSet(vel, 0, 0, -30);
1610 CG_SmokePuff( end, vel,
1611 24,
1612 .8f, .8f, 0.7f, 0.33f,
1613 500,
1614 cg.time,
1615 0,
1616 0,
1617 cgs.media.dustPuffShader );
1618 }
1619
1620 #endif
1621
1622 /*
1623 ===============
1624 CG_TrailItem
1625 ===============
1626 */
1627 static void CG_TrailItem( centity_t *cent, qhandle_t hModel ) {
1628 refEntity_t ent;
1629 vec3_t angles;
1630 vec3_t axis[3];
1631
1632 VectorCopy( cent->lerpAngles, angles );
1633 angles[PITCH] = 0;
1634 angles[ROLL] = 0;
1635 AnglesToAxis( angles, axis );
1636
1637 memset( &ent, 0, sizeof( ent ) );
1638 VectorMA( cent->lerpOrigin, -16, axis[0], ent.origin );
1639 ent.origin[2] += 16;
1640 angles[YAW] += 90;
1641 AnglesToAxis( angles, ent.axis );
1642
1643 ent.hModel = hModel;
1644 trap_R_AddRefEntityToScene( &ent );
1645 }
1646
1647
1648 /*
1649 ===============
1650 CG_PlayerFlag
1651 ===============
1652 */
1653 static void CG_PlayerFlag( centity_t *cent, qhandle_t hSkin, refEntity_t *torso ) {
1654 clientInfo_t *ci;
1655 refEntity_t pole;
1656 refEntity_t flag;
1657 vec3_t angles, dir;
1658 int legsAnim, flagAnim, updateangles;
1659 float angle, d;
1660
1661 // show the flag pole model
1662 memset( &pole, 0, sizeof(pole) );
1663 pole.hModel = cgs.media.flagPoleModel;
1664 VectorCopy( torso->lightingOrigin, pole.lightingOrigin );
1665 pole.shadowPlane = torso->shadowPlane;
1666 pole.renderfx = torso->renderfx;
1667 CG_PositionEntityOnTag( &pole, torso, torso->hModel, "tag_flag" );
1668 trap_R_AddRefEntityToScene( &pole );
1669
1670 // show the flag model
1671 memset( &flag, 0, sizeof(flag) );
1672 flag.hModel = cgs.media.flagFlapModel;
1673 flag.customSkin = hSkin;
1674 VectorCopy( torso->lightingOrigin, flag.lightingOrigin );
1675 flag.shadowPlane = torso->shadowPlane;
1676 flag.renderfx = torso->renderfx;
1677
1678 VectorClear(angles);
1679
1680 updateangles = qfalse;
1681 legsAnim = cent->currentState.legsAnim & ~ANIM_TOGGLEBIT;
1682 if( legsAnim == LEGS_IDLE || legsAnim == LEGS_IDLECR ) {
1683 flagAnim = FLAG_STAND;
1684 } else if ( legsAnim == LEGS_WALK || legsAnim == LEGS_WALKCR ) {
1685 flagAnim = FLAG_STAND;
1686 updateangles = qtrue;
1687 } else {
1688 flagAnim = FLAG_RUN;
1689 updateangles = qtrue;
1690 }
1691
1692 if ( updateangles ) {
1693
1694 VectorCopy( cent->currentState.pos.trDelta, dir );
1695 // add gravity
1696 dir[2] += 100;
1697 VectorNormalize( dir );
1698 d = DotProduct(pole.axis[2], dir);
1699 // if there is enough movement orthogonal to the flag pole
1700 if (fabs(d) < 0.9) {
1701 //
1702 d = DotProduct(pole.axis[0], dir);
1703 if (d > 1.0f) {
1704 d = 1.0f;
1705 }
1706 else if (d < -1.0f) {
1707 d = -1.0f;
1708 }
1709 angle = acos(d);
1710
1711 d = DotProduct(pole.axis[1], dir);
1712 if (d < 0) {
1713 angles[YAW] = 360 - angle * 180 / M_PI;
1714 }
1715 else {
1716 angles[YAW] = angle * 180 / M_PI;
1717 }
1718 if (angles[YAW] < 0)
1719 angles[YAW] += 360;
1720 if (angles[YAW] > 360)
1721 angles[YAW] -= 360;
1722
1723 //vectoangles( cent->currentState.pos.trDelta, tmpangles );
1724 //angles[YAW] = tmpangles[YAW] + 45 - cent->pe.torso.yawAngle;
1725 // change the yaw angle
1726 CG_SwingAngles( angles[YAW], 25, 90, 0.15f, &cent->pe.flag.yawAngle, &cent->pe.flag.yawing );
1727 }
1728
1729 /*
1730 d = DotProduct(pole.axis[2], dir);
1731 angle = Q_acos(d);
1732
1733 d = DotProduct(pole.axis[1], dir);
1734 if (d < 0) {
1735 angle = 360 - angle * 180 / M_PI;
1736 }
1737 else {
1738 angle = angle * 180 / M_PI;
1739 }
1740 if (angle > 340 && angle < 20) {
1741 flagAnim = FLAG_RUNUP;
1742 }
1743 if (angle > 160 && angle < 200) {
1744 flagAnim = FLAG_RUNDOWN;
1745 }
1746 */
1747 }
1748
1749 // set the yaw angle
1750 angles[YAW] = cent->pe.flag.yawAngle;
1751 // lerp the flag animation frames
1752 ci = &cgs.clientinfo[ cent->currentState.clientNum ];
1753 CG_RunLerpFrame( ci, &cent->pe.flag, flagAnim, 1 );
1754 flag.oldframe = cent->pe.flag.oldFrame;
1755 flag.frame = cent->pe.flag.frame;
1756 flag.backlerp = cent->pe.flag.backlerp;
1757
1758 AnglesToAxis( angles, flag.axis );
1759 CG_PositionRotatedEntityOnTag( &flag, &pole, pole.hModel, "tag_flag" );
1760
1761 trap_R_AddRefEntityToScene( &flag );
1762 }
1763
1764
1765 #ifdef MISSIONPACK
1766 /*
1767 ===============
1768 CG_PlayerTokens
1769 ===============
1770 */
1771 static void CG_PlayerTokens( centity_t *cent, int renderfx ) {
1772 int tokens, i, j;
1773 float angle;
1774 refEntity_t ent;
1775 vec3_t dir, origin;
1776 skulltrail_t *trail;
1777 if ( cent->currentState.number >= MAX_CLIENTS ) {
1778 return;
1779 }
1780 trail = &cg.skulltrails[cent->currentState.number];
1781 tokens = cent->currentState.generic1;
1782 if ( !tokens ) {
1783 trail->numpositions = 0;
1784 return;
1785 }
1786
1787 if ( tokens > MAX_SKULLTRAIL ) {
1788 tokens = MAX_SKULLTRAIL;
1789 }
1790
1791 // add skulls if there are more than last time
1792 for (i = 0; i < tokens - trail->numpositions; i++) {
1793 for (j = trail->numpositions; j > 0; j--) {
1794 VectorCopy(trail->positions[j-1], trail->positions[j]);
1795 }
1796 VectorCopy(cent->lerpOrigin, trail->positions[0]);
1797 }
1798 trail->numpositions = tokens;
1799
1800 // move all the skulls along the trail
1801 VectorCopy(cent->lerpOrigin, origin);
1802 for (i = 0; i < trail->numpositions; i++) {
1803 VectorSubtract(trail->positions[i], origin, dir);
1804 if (VectorNormalize(dir) > 30) {
1805 VectorMA(origin, 30, dir, trail->positions[i]);
1806 }
1807 VectorCopy(trail->positions[i], origin);
1808 }
1809
1810 memset( &ent, 0, sizeof( ent ) );
1811 if( cgs.clientinfo[ cent->currentState.clientNum ].team == TEAM_BLUE ) {
1812 ent.hModel = cgs.media.redCubeModel;
1813 } else {
1814 ent.hModel = cgs.media.blueCubeModel;
1815 }
1816 ent.renderfx = renderfx;
1817
1818 VectorCopy(cent->lerpOrigin, origin);
1819 for (i = 0; i < trail->numpositions; i++) {
1820 VectorSubtract(origin, trail->positions[i], ent.axis[0]);
1821 ent.axis[0][2] = 0;
1822 VectorNormalize(ent.axis[0]);
1823 VectorSet(ent.axis[2], 0, 0, 1);
1824 CrossProduct(ent.axis[0], ent.axis[2], ent.axis[1]);
1825
1826 VectorCopy(trail->positions[i], ent.origin);
1827 angle = (((cg.time + 500 * MAX_SKULLTRAIL - 500 * i) / 16) & 255) * (M_PI * 2) / 255;
1828 ent.origin[2] += sin(angle) * 10;
1829 trap_R_AddRefEntityToScene( &ent );
1830 VectorCopy(trail->positions[i], origin);
1831 }
1832 }
1833 #endif
1834
1835
1836 /*
1837 ===============
1838 CG_PlayerPowerups
1839 ===============
1840 */
1841 static void CG_PlayerPowerups( centity_t *cent, refEntity_t *torso ) {
1842 int powerups;
1843 clientInfo_t *ci;
1844
1845 powerups = cent->currentState.powerups;
1846 if ( !powerups ) {
1847 return;
1848 }
1849
1850 // quad gives a dlight
1851 if ( powerups & ( 1 << PW_QUAD ) ) {
1852 trap_R_AddLightToScene( cent->lerpOrigin, 200 + (rand()&31), 0.2f, 0.2f, 1 );
1853 }
1854
1855 // flight plays a looped sound
1856 if ( powerups & ( 1 << PW_FLIGHT ) ) {
1857 trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.flightSound );
1858 }
1859
1860 ci = &cgs.clientinfo[ cent->currentState.clientNum ];
1861 // redflag
1862 if ( powerups & ( 1 << PW_REDFLAG ) ) {
1863 if (ci->newAnims) {
1864 CG_PlayerFlag( cent, cgs.media.redFlagFlapSkin, torso );
1865 }
1866 else {
1867 CG_TrailItem( cent, cgs.media.redFlagModel );
1868 }
1869 trap_R_AddLightToScene( cent->lerpOrigin, 200 + (rand()&31), 1.0, 0.2f, 0.2f );
1870 }
1871
1872 // blueflag
1873 if ( powerups & ( 1 << PW_BLUEFLAG ) ) {
1874 if (ci->newAnims){
1875 CG_PlayerFlag( cent, cgs.media.blueFlagFlapSkin, torso );
1876 }
1877 else {
1878 CG_TrailItem( cent, cgs.media.blueFlagModel );
1879 }
1880 trap_R_AddLightToScene( cent->lerpOrigin, 200 + (rand()&31), 0.2f, 0.2f, 1.0 );
1881 }
1882
1883 // neutralflag
1884 if ( powerups & ( 1 << PW_NEUTRALFLAG ) ) {
1885 if (ci->newAnims) {
1886 CG_PlayerFlag( cent, cgs.media.neutralFlagFlapSkin, torso );
1887 }
1888 else {
1889 CG_TrailItem( cent, cgs.media.neutralFlagModel );
1890 }
1891 trap_R_AddLightToScene( cent->lerpOrigin, 200 + (rand()&31), 1.0, 1.0, 1.0 );
1892 }
1893
1894 // haste leaves smoke trails
1895 if ( powerups & ( 1 << PW_HASTE ) ) {
1896 CG_HasteTrail( cent );
1897 }
1898 }
1899
1900
1901 /*
1902 ===============
1903 CG_PlayerFloatSprite
1904
1905 Float a sprite over the player's head
1906 ===============
1907 */
1908 static void CG_PlayerFloatSprite( centity_t *cent, qhandle_t shader ) {
1909 int rf;
1910 refEntity_t ent;
1911
1912 if ( cent->currentState.number == cg.snap->ps.clientNum && !cg.renderingThirdPerson ) {
1913 rf = RF_THIRD_PERSON; // only show in mirrors
1914 } else {
1915 rf = 0;
1916 }
1917
1918 memset( &ent, 0, sizeof( ent ) );
1919 VectorCopy( cent->lerpOrigin, ent.origin );
1920 ent.origin[2] += 48;
1921 ent.reType = RT_SPRITE;
1922 ent.customShader = shader;
1923 ent.radius = 10;
1924 ent.renderfx = rf;
1925 ent.shaderRGBA[0] = 255;
1926 ent.shaderRGBA[1] = 255;
1927 ent.shaderRGBA[2] = 255;
1928 ent.shaderRGBA[3] = 255;
1929 trap_R_AddRefEntityToScene( &ent );
1930 }
1931
1932
1933
1934 /*
1935 ===============
1936 CG_PlayerSprites
1937
1938 Float sprites over the player's head
1939 ===============
1940 */
1941 static void CG_PlayerSprites( centity_t *cent ) {
1942 int team;
1943
1944 if ( cent->currentState.eFlags & EF_CONNECTION ) {
1945 CG_PlayerFloatSprite( cent, cgs.media.connectionShader );
1946 return;
1947 }
1948
1949 if ( cent->currentState.eFlags & EF_TALK ) {
1950 CG_PlayerFloatSprite( cent, cgs.media.balloonShader );
1951 return;
1952 }
1953
1954 if ( cent->currentState.eFlags & EF_AWARD_IMPRESSIVE ) {
1955 CG_PlayerFloatSprite( cent, cgs.media.medalImpressive );
1956 return;
1957 }
1958
1959 if ( cent->currentState.eFlags & EF_AWARD_EXCELLENT ) {
1960 CG_PlayerFloatSprite( cent, cgs.media.medalExcellent );
1961 return;
1962 }
1963
1964 if ( cent->currentState.eFlags & EF_AWARD_GAUNTLET ) {
1965 CG_PlayerFloatSprite( cent, cgs.media.medalGauntlet );
1966 return;
1967 }
1968
1969 if ( cent->currentState.eFlags & EF_AWARD_DEFEND ) {
1970 CG_PlayerFloatSprite( cent, cgs.media.medalDefend );
1971 return;
1972 }
1973
1974 if ( cent->currentState.eFlags & EF_AWARD_ASSIST ) {
1975 CG_PlayerFloatSprite( cent, cgs.media.medalAssist );
1976 return;
1977 }
1978
1979 if ( cent->currentState.eFlags & EF_AWARD_CAP ) {
1980 CG_PlayerFloatSprite( cent, cgs.media.medalCapture );
1981 return;
1982 }
1983
1984 team = cgs.clientinfo[ cent->currentState.clientNum ].team;
1985 if ( !(cent->currentState.eFlags & EF_DEAD) &&
1986 cg.snap->ps.persistant[PERS_TEAM] == team &&
1987 cgs.gametype >= GT_TEAM) {
1988 if (cg_drawFriend.integer) {
1989 CG_PlayerFloatSprite( cent, cgs.media.friendShader );
1990 }
1991 return;
1992 }
1993 }
1994
1995 /*
1996 ===============
1997 CG_PlayerShadow
1998
1999 Returns the Z component of the surface being shadowed
2000
2001 should it return a full plane instead of a Z?
2002 ===============
2003 */
2004 #define SHADOW_DISTANCE 128
2005 static qboolean CG_PlayerShadow( centity_t *cent, float *shadowPlane ) {
2006 vec3_t end, mins = {-15, -15, 0}, maxs = {15, 15, 2};
2007 trace_t trace;
2008 float alpha;
2009
2010 *shadowPlane = 0;
2011
2012 if ( cg_shadows.integer == 0 ) {
2013 return qfalse;
2014 }
2015
2016 // no shadows when invisible
2017 if ( cent->currentState.powerups & ( 1 << PW_INVIS ) ) {
2018 return qfalse;
2019 }
2020
2021 // send a trace down from the player to the ground
2022 VectorCopy( cent->lerpOrigin, end );
2023 end[2] -= SHADOW_DISTANCE;
2024
2025 trap_CM_BoxTrace( &trace, cent->lerpOrigin, end, mins, maxs, 0, MASK_PLAYERSOLID );
2026
2027 // no shadow if too high
2028 if ( trace.fraction == 1.0 || trace.startsolid || trace.allsolid ) {
2029 return qfalse;
2030 }
2031
2032 *shadowPlane = trace.endpos[2] + 1;
2033
2034 if ( cg_shadows.integer != 1 ) { // no mark for stencil or projection shadows
2035 return qtrue;
2036 }
2037
2038 // fade the shadow out with height
2039 alpha = 1.0 - trace.fraction;
2040
2041 // hack / FPE - bogus planes?
2042 //assert( DotProduct( trace.plane.normal, trace.plane.normal ) != 0.0f )
2043
2044 // add the mark as a temporary, so it goes directly to the renderer
2045 // without taking a spot in the cg_marks array
2046 CG_ImpactMark( cgs.media.shadowMarkShader, trace.endpos, trace.plane.normal,
2047 cent->pe.legs.yawAngle, alpha,alpha,alpha,1, qfalse, 24, qtrue );
2048
2049 return qtrue;
2050 }
2051
2052
2053 /*
2054 ===============
2055 CG_PlayerSplash
2056
2057 Draw a mark at the water surface
2058 ===============
2059 */
2060 static void CG_PlayerSplash( centity_t *cent ) {
2061 vec3_t start, end;
2062 trace_t trace;
2063 int contents;
2064 polyVert_t verts[4];
2065
2066 if ( !cg_shadows.integer ) {
2067 return;
2068 }
2069
2070 VectorCopy( cent->lerpOrigin, end );
2071 end[2] -= 24;
2072
2073 // if the feet aren't in liquid, don't make a mark
2074 // this won't handle moving water brushes, but they wouldn't draw right anyway...
2075 contents = CG_PointContents( end, 0 );
2076 if ( !( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) ) {
2077 return;
2078 }
2079
2080 VectorCopy( cent->lerpOrigin, start );
2081 start[2] += 32;
2082
2083 // if the head isn't out of liquid, don't make a mark
2084 contents = CG_PointContents( start, 0 );
2085 if ( contents & ( CONTENTS_SOLID | CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
2086 return;
2087 }
2088
2089 // trace down to find the surface
2090 trap_CM_BoxTrace( &trace, start, end, NULL, NULL, 0, ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) );
2091
2092 if ( trace.fraction == 1.0 ) {
2093 return;
2094 }
2095
2096 // create a mark polygon
2097 VectorCopy( trace.endpos, verts[0].xyz );
2098 verts[0].xyz[0] -= 32;
2099 verts[0].xyz[1] -= 32;
2100 verts[0].st[0] = 0;
2101 verts[0].st[1] = 0;
2102 verts[0].modulate[0] = 255;
2103 verts[0].modulate[1] = 255;
2104 verts[0].modulate[2] = 255;
2105 verts[0].modulate[3] = 255;
2106
2107 VectorCopy( trace.endpos, verts[1].xyz );
2108 verts[1].xyz[0] -= 32;
2109 verts[1].xyz[1] += 32;
2110 verts[1].st[0] = 0;
2111 verts[1].st[1] = 1;
2112 verts[1].modulate[0] = 255;
2113 verts[1].modulate[1] = 255;
2114 verts[1].modulate[2] = 255;
2115 verts[1].modulate[3] = 255;
2116
2117 VectorCopy( trace.endpos, verts[2].xyz );
2118 verts[2].xyz[0] += 32;
2119 verts[2].xyz[1] += 32;
2120 verts[2].st[0] = 1;
2121 verts[2].st[1] = 1;
2122 verts[2].modulate[0] = 255;
2123 verts[2].modulate[1] = 255;
2124 verts[2].modulate[2] = 255;
2125 verts[2].modulate[3] = 255;
2126
2127 VectorCopy( trace.endpos, verts[3].xyz );
2128 verts[3].xyz[0] += 32;
2129 verts[3].xyz[1] -= 32;
2130 verts[3].st[0] = 1;
2131 verts[3].st[1] = 0;
2132 verts[3].modulate[0] = 255;
2133 verts[3].modulate[1] = 255;
2134 verts[3].modulate[2] = 255;
2135 verts[3].modulate[3] = 255;
2136
2137 trap_R_AddPolyToScene( cgs.media.wakeMarkShader, 4, verts );
2138 }
2139
2140
2141
2142 /*
2143 ===============
2144 CG_AddRefEntityWithPowerups
2145
2146 Adds a piece with modifications or duplications for powerups
2147 Also called by CG_Missile for quad rockets, but nobody can tell...
2148 ===============
2149 */
2150 void CG_AddRefEntityWithPowerups( refEntity_t *ent, entityState_t *state, int team ) {
2151
2152 if ( state->powerups & ( 1 << PW_INVIS ) ) {
2153 ent->customShader = cgs.media.invisShader;
2154 trap_R_AddRefEntityToScene( ent );
2155 } else {
2156 /*
2157 if ( state->eFlags & EF_KAMIKAZE ) {
2158 if (team == TEAM_BLUE)
2159 ent->customShader = cgs.media.blueKamikazeShader;
2160 else
2161 ent->customShader = cgs.media.redKamikazeShader;
2162 trap_R_AddRefEntityToScene( ent );
2163 }
2164 else {*/
2165 trap_R_AddRefEntityToScene( ent );
2166 //}
2167
2168 if ( state->powerups & ( 1 << PW_QUAD ) )
2169 {
2170 if (team == TEAM_RED)
2171 ent->customShader = cgs.media.redQuadShader;
2172 else
2173 ent->customShader = cgs.media.quadShader;
2174 trap_R_AddRefEntityToScene( ent );
2175 }
2176 if ( state->powerups & ( 1 << PW_REGEN ) ) {
2177 if ( ( ( cg.time / 100 ) % 10 ) == 1 ) {
2178 ent->customShader = cgs.media.regenShader;
2179 trap_R_AddRefEntityToScene( ent );
2180 }
2181 }
2182 if ( state->powerups & ( 1 << PW_BATTLESUIT ) ) {
2183 ent->customShader = cgs.media.battleSuitShader;
2184 trap_R_AddRefEntityToScene( ent );
2185 }
2186 }
2187 }
2188
2189 /*
2190 =================
2191 CG_LightVerts
2192 =================
2193 */
2194 int CG_LightVerts( vec3_t normal, int numVerts, polyVert_t *verts )
2195 {
2196 int i, j;
2197 float incoming;
2198 vec3_t ambientLight;
2199 vec3_t lightDir;
2200 vec3_t directedLight;
2201
2202 trap_R_LightForPoint( verts[0].xyz, ambientLight, directedLight, lightDir );
2203
2204 for (i = 0; i < numVerts; i++) {
2205 incoming = DotProduct (normal, lightDir);
2206 if ( incoming <= 0 ) {
2207 verts[i].modulate[0] = ambientLight[0];
2208 verts[i].modulate[1] = ambientLight[1];
2209 verts[i].modulate[2] = ambientLight[2];
2210 verts[i].modulate[3] = 255;
2211 continue;
2212 }
2213 j = ( ambientLight[0] + incoming * directedLight[0] );
2214 if ( j > 255 ) {
2215 j = 255;
2216 }
2217 verts[i].modulate[0] = j;
2218
2219 j = ( ambientLight[1] + incoming * directedLight[1] );
2220 if ( j > 255 ) {
2221 j = 255;
2222 }
2223 verts[i].modulate[1] = j;
2224
2225 j = ( ambientLight[2] + incoming * directedLight[2] );
2226 if ( j > 255 ) {
2227 j = 255;
2228 }
2229 verts[i].modulate[2] = j;
2230
2231 verts[i].modulate[3] = 255;
2232 }
2233 return qtrue;
2234 }
2235
2236 /*
2237 ===============
2238 CG_Player
2239 ===============
2240 */
2241 void CG_Player( centity_t *cent ) {
2242 clientInfo_t *ci;
2243 refEntity_t legs;
2244 refEntity_t torso;
2245 refEntity_t head;
2246 int clientNum;
2247 int renderfx;
2248 qboolean shadow;
2249 float shadowPlane;
2250 #ifdef MISSIONPACK
2251 refEntity_t skull;
2252 refEntity_t powerup;
2253 int t;
2254 float c;
2255 float angle;
2256 vec3_t dir, angles;
2257 #endif
2258
2259 // the client number is stored in clientNum. It can't be derived
2260 // from the entity number, because a single client may have
2261 // multiple corpses on the level using the same clientinfo
2262 clientNum = cent->currentState.clientNum;
2263 if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) {
2264 CG_Error( "Bad clientNum on player entity");
2265 }
2266 ci = &cgs.clientinfo[ clientNum ];
2267
2268 // it is possible to see corpses from disconnected players that may
2269 // not have valid clientinfo
2270 if ( !ci->infoValid ) {
2271 return;
2272 }
2273
2274 // get the player model information
2275 renderfx = 0;
2276 if ( cent->currentState.number == cg.snap->ps.clientNum) {
2277 if (!cg.renderingThirdPerson) {
2278 renderfx = RF_THIRD_PERSON; // only draw in mirrors
2279 } else {
2280 if (cg_cameraMode.integer) {
2281 return;
2282 }
2283 }
2284 }
2285
2286
2287 memset( &legs, 0, sizeof(legs) );
2288 memset( &torso, 0, sizeof(torso) );
2289 memset( &head, 0, sizeof(head) );
2290
2291 // get the rotation information
2292 CG_PlayerAngles( cent, legs.axis, torso.axis, head.axis );
2293
2294 // get the animation state (after rotation, to allow feet shuffle)
2295 CG_PlayerAnimation( cent, &legs.oldframe, &legs.frame, &legs.backlerp,
2296 &torso.oldframe, &torso.frame, &torso.backlerp );
2297
2298 // add the talk baloon or disconnect icon
2299 CG_PlayerSprites( cent );
2300
2301 // add the shadow
2302 shadow = CG_PlayerShadow( cent, &shadowPlane );
2303
2304 // add a water splash if partially in and out of water
2305 CG_PlayerSplash( cent );
2306
2307 if ( cg_shadows.integer == 3 && shadow ) {
2308 renderfx |= RF_SHADOW_PLANE;
2309 }
2310 renderfx |= RF_LIGHTING_ORIGIN; // use the same origin for all
2311 #ifdef MISSIONPACK
2312 if( cgs.gametype == GT_HARVESTER ) {
2313 CG_PlayerTokens( cent, renderfx );
2314 }
2315 #endif
2316 //
2317 // add the legs
2318 //
2319 legs.hModel = ci->legsModel;
2320 legs.customSkin = ci->legsSkin;
2321
2322 VectorCopy( cent->lerpOrigin, legs.origin );
2323
2324 VectorCopy( cent->lerpOrigin, legs.lightingOrigin );
2325 legs.shadowPlane = shadowPlane;
2326 legs.renderfx = renderfx;
2327 VectorCopy (legs.origin, legs.oldorigin); // don't positionally lerp at all
2328
2329 CG_AddRefEntityWithPowerups( &legs, &cent->currentState, ci->team );
2330
2331 // if the model failed, allow the default nullmodel to be displayed
2332 if (!legs.hModel) {
2333 return;
2334 }
2335
2336 //
2337 // add the torso
2338 //
2339 torso.hModel = ci->torsoModel;
2340 if (!torso.hModel) {
2341 return;
2342 }
2343
2344 torso.customSkin = ci->torsoSkin;
2345
2346 VectorCopy( cent->lerpOrigin, torso.lightingOrigin );
2347
2348 CG_PositionRotatedEntityOnTag( &torso, &legs, ci->legsModel, "tag_torso");
2349
2350 torso.shadowPlane = shadowPlane;
2351 torso.renderfx = renderfx;
2352
2353 CG_AddRefEntityWithPowerups( &torso, &cent->currentState, ci->team );
2354
2355 #ifdef MISSIONPACK
2356 if ( cent->currentState.eFlags & EF_KAMIKAZE ) {
2357
2358 memset( &skull, 0, sizeof(skull) );
2359
2360 VectorCopy( cent->lerpOrigin, skull.lightingOrigin );
2361 skull.shadowPlane = shadowPlane;
2362 skull.renderfx = renderfx;
2363
2364 if ( cent->currentState.eFlags & EF_DEAD ) {
2365 // one skull bobbing above the dead body
2366 angle = ((cg.time / 7) & 255) * (M_PI * 2) / 255;
2367 if (angle > M_PI * 2)
2368 angle -= (float)M_PI * 2;
2369 dir[0] = sin(angle) * 20;
2370 dir[1] = cos(angle) * 20;
2371 angle = ((cg.time / 4) & 255) * (M_PI * 2) / 255;
2372 dir[2] = 15 + sin(angle) * 8;
2373 VectorAdd(torso.origin, dir, skull.origin);
2374
2375 dir[2] = 0;
2376 VectorCopy(dir, skull.axis[1]);
2377 VectorNormalize(skull.axis[1]);
2378 VectorSet(skull.axis[2], 0, 0, 1);
2379 CrossProduct(skull.axis[1], skull.axis[2], skull.axis[0]);
2380
2381 skull.hModel = cgs.media.kamikazeHeadModel;
2382 trap_R_AddRefEntityToScene( &skull );
2383 skull.hModel = cgs.media.kamikazeHeadTrail;
2384 trap_R_AddRefEntityToScene( &skull );
2385 }
2386 else {
2387 // three skulls spinning around the player
2388 angle = ((cg.time / 4) & 255) * (M_PI * 2) / 255;
2389 dir[0] = cos(angle) * 20;
2390 dir[1] = sin(angle) * 20;
2391 dir[2] = cos(angle) * 20;
2392 VectorAdd(torso.origin, dir, skull.origin);
2393
2394 angles[0] = sin(angle) * 30;
2395 angles[1] = (angle * 180 / M_PI) + 90;
2396 if (angles[1] > 360)
2397 angles[1] -= 360;
2398 angles[2] = 0;
2399 AnglesToAxis( angles, skull.axis );
2400
2401 /*
2402 dir[2] = 0;
2403 VectorInverse(dir);
2404 VectorCopy(dir, skull.axis[1]);
2405 VectorNormalize(skull.axis[1]);
2406 VectorSet(skull.axis[2], 0, 0, 1);
2407 CrossProduct(skull.axis[1], skull.axis[2], skull.axis[0]);
2408 */
2409
2410 skull.hModel = cgs.media.kamikazeHeadModel;
2411 trap_R_AddRefEntityToScene( &skull );
2412 // flip the trail because this skull is spinning in the other direction
2413 VectorInverse(skull.axis[1]);
2414 skull.hModel = cgs.media.kamikazeHeadTrail;
2415 trap_R_AddRefEntityToScene( &skull );
2416
2417 angle = ((cg.time / 4) & 255) * (M_PI * 2) / 255 + M_PI;
2418 if (angle > M_PI * 2)
2419 angle -= (float)M_PI * 2;
2420 dir[0] = sin(angle) * 20;
2421 dir[1] = cos(angle) * 20;
2422 dir[2] = cos(angle) * 20;
2423 VectorAdd(torso.origin, dir, skull.origin);
2424
2425 angles[0] = cos(angle - 0.5 * M_PI) * 30;
2426 angles[1] = 360 - (angle * 180 / M_PI);
2427 if (angles[1] > 360)
2428 angles[1] -= 360;
2429 angles[2] = 0;
2430 AnglesToAxis( angles, skull.axis );
2431
2432 /*
2433 dir[2] = 0;
2434 VectorCopy(dir, skull.axis[1]);
2435 VectorNormalize(skull.axis[1]);
2436 VectorSet(skull.axis[2], 0, 0, 1);
2437 CrossProduct(skull.axis[1], skull.axis[2], skull.axis[0]);
2438 */
2439
2440 skull.hModel = cgs.media.kamikazeHeadModel;
2441 trap_R_AddRefEntityToScene( &skull );
2442 skull.hModel = cgs.media.kamikazeHeadTrail;
2443 trap_R_AddRefEntityToScene( &skull );
2444
2445 angle = ((cg.time / 3) & 255) * (M_PI * 2) / 255 + 0.5 * M_PI;
2446 if (angle > M_PI * 2)
2447 angle -= (float)M_PI * 2;
2448 dir[0] = sin(angle) * 20;
2449 dir[1] = cos(angle) * 20;
2450 dir[2] = 0;
2451 VectorAdd(torso.origin, dir, skull.origin);
2452
2453 VectorCopy(dir, skull.axis[1]);
2454 VectorNormalize(skull.axis[1]);
2455 VectorSet(skull.axis[2], 0, 0, 1);
2456 CrossProduct(skull.axis[1], skull.axis[2], skull.axis[0]);
2457
2458 skull.hModel = cgs.media.kamikazeHeadModel;
2459 trap_R_AddRefEntityToScene( &skull );
2460 skull.hModel = cgs.media.kamikazeHeadTrail;
2461 trap_R_AddRefEntityToScene( &skull );
2462 }
2463 }
2464
2465 if ( cent->currentState.powerups & ( 1 << PW_GUARD ) ) {
2466 memcpy(&powerup, &torso, sizeof(torso));
2467 powerup.hModel = cgs.media.guardPowerupModel;
2468 powerup.frame = 0;
2469 powerup.oldframe = 0;
2470 powerup.customSkin = 0;
2471 trap_R_AddRefEntityToScene( &powerup );
2472 }
2473 if ( cent->currentState.powerups & ( 1 << PW_SCOUT ) ) {
2474 memcpy(&powerup, &torso, sizeof(torso));
2475 powerup.hModel = cgs.media.scoutPowerupModel;
2476 powerup.frame = 0;
2477 powerup.oldframe = 0;
2478 powerup.customSkin = 0;
2479 trap_R_AddRefEntityToScene( &powerup );
2480 }
2481 if ( cent->currentState.powerups & ( 1 << PW_DOUBLER ) ) {
2482 memcpy(&powerup, &torso, sizeof(torso));
2483 powerup.hModel = cgs.media.doublerPowerupModel;
2484 powerup.frame = 0;
2485 powerup.oldframe = 0;
2486 powerup.customSkin = 0;
2487 trap_R_AddRefEntityToScene( &powerup );
2488 }
2489 if ( cent->currentState.powerups & ( 1 << PW_AMMOREGEN ) ) {
2490 memcpy(&powerup, &torso, sizeof(torso));
2491 powerup.hModel = cgs.media.ammoRegenPowerupModel;
2492 powerup.frame = 0;
2493 powerup.oldframe = 0;
2494 powerup.customSkin = 0;
2495 trap_R_AddRefEntityToScene( &powerup );
2496 }
2497 if ( cent->currentState.powerups & ( 1 << PW_INVULNERABILITY ) ) {
2498 if ( !ci->invulnerabilityStartTime ) {
2499 ci->invulnerabilityStartTime = cg.time;
2500 }
2501 ci->invulnerabilityStopTime = cg.time;
2502 }
2503 else {
2504 ci->invulnerabilityStartTime = 0;
2505 }
2506 if ( (cent->currentState.powerups & ( 1 << PW_INVULNERABILITY ) ) ||
2507 cg.time - ci->invulnerabilityStopTime < 250 ) {
2508
2509 memcpy(&powerup, &torso, sizeof(torso));
2510 powerup.hModel = cgs.media.invulnerabilityPowerupModel;
2511 powerup.frame = 0;
2512 powerup.oldframe = 0;
2513 powerup.customSkin = 0;
2514 // always draw
2515 powerup.renderfx &= ~RF_THIRD_PERSON;
2516 VectorCopy(cent->lerpOrigin, powerup.origin);
2517
2518 if ( cg.time - ci->invulnerabilityStartTime < 250 ) {
2519 c = (float) (cg.time - ci->invulnerabilityStartTime) / 250;
2520 }
2521 else if (cg.time - ci->invulnerabilityStopTime < 250 ) {
2522 c = (float) (250 - (cg.time - ci->invulnerabilityStopTime)) / 250;
2523 }
2524 else {
2525 c = 1;
2526 }
2527 VectorSet( powerup.axis[0], c, 0, 0 );
2528 VectorSet( powerup.axis[1], 0, c, 0 );
2529 VectorSet( powerup.axis[2], 0, 0, c );
2530 trap_R_AddRefEntityToScene( &powerup );
2531 }
2532
2533 t = cg.time - ci->medkitUsageTime;
2534 if ( ci->medkitUsageTime && t < 500 ) {
2535 memcpy(&powerup, &torso, sizeof(torso));
2536 powerup.hModel = cgs.media.medkitUsageModel;
2537 powerup.frame = 0;
2538 powerup.oldframe = 0;
2539 powerup.customSkin = 0;
2540 // always draw
2541 powerup.renderfx &= ~RF_THIRD_PERSON;
2542 VectorClear(angles);
2543 AnglesToAxis(angles, powerup.axis);
2544 VectorCopy(cent->lerpOrigin, powerup.origin);
2545 powerup.origin[2] += -24 + (float) t * 80 / 500;
2546 if ( t > 400 ) {
2547 c = (float) (t - 1000) * 0xff / 100;
2548 powerup.shaderRGBA[0] = 0xff - c;
2549 powerup.shaderRGBA[1] = 0xff - c;
2550 powerup.shaderRGBA[2] = 0xff - c;
2551 powerup.shaderRGBA[3] = 0xff - c;
2552 }
2553 else {
2554 powerup.shaderRGBA[0] = 0xff;
2555 powerup.shaderRGBA[1] = 0xff;
2556 powerup.shaderRGBA[2] = 0xff;
2557 powerup.shaderRGBA[3] = 0xff;
2558 }
2559 trap_R_AddRefEntityToScene( &powerup );
2560 }
2561 #endif // MISSIONPACK
2562
2563 //
2564 // add the head
2565 //
2566 head.hModel = ci->headModel;
2567 if (!head.hModel) {
2568 return;
2569 }
2570 head.customSkin = ci->headSkin;
2571
2572 VectorCopy( cent->lerpOrigin, head.lightingOrigin );
2573
2574 CG_PositionRotatedEntityOnTag( &head, &torso, ci->torsoModel, "tag_head");
2575
2576 head.shadowPlane = shadowPlane;
2577 head.renderfx = renderfx;
2578
2579 CG_AddRefEntityWithPowerups( &head, &cent->currentState, ci->team );
2580
2581 #ifdef MISSIONPACK
2582 CG_BreathPuffs(cent, &head);
2583
2584 CG_DustTrail(cent);
2585 #endif
2586
2587 //
2588 // add the gun / barrel / flash
2589 //
2590 CG_AddPlayerWeapon( &torso, NULL, cent, ci->team );
2591
2592 // add powerups floating behind the player
2593 CG_PlayerPowerups( cent, &torso );
2594 }
2595
2596
2597 //=====================================================================
2598
2599 /*
2600 ===============
2601 CG_ResetPlayerEntity
2602
2603 A player just came into view or teleported, so reset all animation info
2604 ===============
2605 */
2606 void CG_ResetPlayerEntity( centity_t *cent ) {
2607 cent->errorTime = -99999; // guarantee no error decay added
2608 cent->extrapolated = qfalse;
2609
2610 CG_ClearLerpFrame( &cgs.clientinfo[ cent->currentState.clientNum ], &cent->pe.legs, cent->currentState.legsAnim );
2611 CG_ClearLerpFrame( &cgs.clientinfo[ cent->currentState.clientNum ], &cent->pe.torso, cent->currentState.torsoAnim );
2612
2613 BG_EvaluateTrajectory( &cent->currentState.pos, cg.time, cent->lerpOrigin );
2614 BG_EvaluateTrajectory( &cent->currentState.apos, cg.time, cent->lerpAngles );
2615
2616 VectorCopy( cent->lerpOrigin, cent->rawOrigin );
2617 VectorCopy( cent->lerpAngles, cent->rawAngles );
2618
2619 memset( &cent->pe.legs, 0, sizeof( cent->pe.legs ) );
2620 cent->pe.legs.yawAngle = cent->rawAngles[YAW];
2621 cent->pe.legs.yawing = qfalse;
2622 cent->pe.legs.pitchAngle = 0;
2623 cent->pe.legs.pitching = qfalse;
2624
2625 memset( &cent->pe.torso, 0, sizeof( cent->pe.torso ) );
2626 cent->pe.torso.yawAngle = cent->rawAngles[YAW];
2627 cent->pe.torso.yawing = qfalse;
2628 cent->pe.torso.pitchAngle = cent->rawAngles[PITCH];
2629 cent->pe.torso.pitching = qfalse;
2630
2631 if ( cg_debugPosition.integer ) {
2632 CG_Printf("%i ResetPlayerEntity yaw=%f\n", cent->currentState.number, cent->pe.torso.yawAngle );
2633 }
2634 }
2635