| 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 |
// ui_players.c |
| 24 |
|
| 25 |
#include "ui_local.h" |
| 26 |
|
| 27 |
|
| 28 |
#define UI_TIMER_GESTURE 2300 |
| 29 |
#define UI_TIMER_JUMP 1000 |
| 30 |
#define UI_TIMER_LAND 130 |
| 31 |
#define UI_TIMER_WEAPON_SWITCH 300 |
| 32 |
#define UI_TIMER_ATTACK 500 |
| 33 |
#define UI_TIMER_MUZZLE_FLASH 20 |
| 34 |
#define UI_TIMER_WEAPON_DELAY 250 |
| 35 |
|
| 36 |
#define JUMP_HEIGHT 56 |
| 37 |
|
| 38 |
#define SWINGSPEED 0.3f |
| 39 |
|
| 40 |
#define SPIN_SPEED 0.9f |
| 41 |
#define COAST_TIME 1000 |
| 42 |
|
| 43 |
|
| 44 |
static int dp_realtime; |
| 45 |
static float jumpHeight; |
| 46 |
sfxHandle_t weaponChangeSound; |
| 47 |
|
| 48 |
|
| 49 |
/* |
| 50 |
=============== |
| 51 |
UI_PlayerInfo_SetWeapon |
| 52 |
=============== |
| 53 |
*/ |
| 54 |
static void UI_PlayerInfo_SetWeapon( playerInfo_t *pi, weapon_t weaponNum ) { |
| 55 |
gitem_t * item; |
| 56 |
char path[MAX_QPATH]; |
| 57 |
|
| 58 |
pi->currentWeapon = weaponNum; |
| 59 |
tryagain: |
| 60 |
pi->realWeapon = weaponNum; |
| 61 |
pi->weaponModel = 0; |
| 62 |
pi->barrelModel = 0; |
| 63 |
pi->flashModel = 0; |
| 64 |
|
| 65 |
if ( weaponNum == WP_NONE ) { |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
for ( item = bg_itemlist + 1; item->classname ; item++ ) { |
| 70 |
if ( item->giType != IT_WEAPON ) { |
| 71 |
continue; |
| 72 |
} |
| 73 |
if ( item->giTag == weaponNum ) { |
| 74 |
break; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
if ( item->classname ) { |
| 79 |
pi->weaponModel = trap_R_RegisterModel( item->world_model[0] ); |
| 80 |
} |
| 81 |
|
| 82 |
if( pi->weaponModel == 0 ) { |
| 83 |
if( weaponNum == WP_MACHINEGUN ) { |
| 84 |
weaponNum = WP_NONE; |
| 85 |
goto tryagain; |
| 86 |
} |
| 87 |
weaponNum = WP_MACHINEGUN; |
| 88 |
goto tryagain; |
| 89 |
} |
| 90 |
|
| 91 |
if ( weaponNum == WP_MACHINEGUN || weaponNum == WP_GAUNTLET || weaponNum == WP_BFG ) { |
| •92 |
COM_StripExtension(item->world_model[0], path, sizeof(path)); |
| 93 |
strcat( path, "_barrel.md3" ); |
| 94 |
pi->barrelModel = trap_R_RegisterModel( path ); |
| 95 |
} |
| 96 |
|
| •97 |
COM_StripExtension(item->world_model[0], path, sizeof(path)); |
| 98 |
strcat( path, "_flash.md3" ); |
| 99 |
pi->flashModel = trap_R_RegisterModel( path ); |
| 100 |
|
| 101 |
switch( weaponNum ) { |
| 102 |
case WP_GAUNTLET: |
| 103 |
MAKERGB( pi->flashDlightColor, 0.6f, 0.6f, 1 ); |
| 104 |
break; |
| 105 |
|
| 106 |
case WP_MACHINEGUN: |
| 107 |
MAKERGB( pi->flashDlightColor, 1, 1, 0 ); |
| 108 |
break; |
| 109 |
|
| 110 |
case WP_SHOTGUN: |
| 111 |
MAKERGB( pi->flashDlightColor, 1, 1, 0 ); |
| 112 |
break; |
| 113 |
|
| 114 |
case WP_GRENADE_LAUNCHER: |
| 115 |
MAKERGB( pi->flashDlightColor, 1, 0.7f, 0.5f ); |
| 116 |
break; |
| 117 |
|
| 118 |
case WP_ROCKET_LAUNCHER: |
| 119 |
MAKERGB( pi->flashDlightColor, 1, 0.75f, 0 ); |
| 120 |
break; |
| 121 |
|
| 122 |
case WP_LIGHTNING: |
| 123 |
MAKERGB( pi->flashDlightColor, 0.6f, 0.6f, 1 ); |
| 124 |
break; |
| 125 |
|
| 126 |
case WP_RAILGUN: |
| 127 |
MAKERGB( pi->flashDlightColor, 1, 0.5f, 0 ); |
| 128 |
break; |
| 129 |
|
| 130 |
case WP_PLASMAGUN: |
| 131 |
MAKERGB( pi->flashDlightColor, 0.6f, 0.6f, 1 ); |
| 132 |
break; |
| 133 |
|
| 134 |
case WP_BFG: |
| 135 |
MAKERGB( pi->flashDlightColor, 1, 0.7f, 1 ); |
| 136 |
break; |
| 137 |
|
| 138 |
case WP_GRAPPLING_HOOK: |
| 139 |
MAKERGB( pi->flashDlightColor, 0.6f, 0.6f, 1 ); |
| 140 |
break; |
| 141 |
|
| 142 |
default: |
| 143 |
MAKERGB( pi->flashDlightColor, 1, 1, 1 ); |
| 144 |
break; |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
/* |
| 150 |
=============== |
| 151 |
UI_ForceLegsAnim |
| 152 |
=============== |
| 153 |
*/ |
| 154 |
static void UI_ForceLegsAnim( playerInfo_t *pi, int anim ) { |
| 155 |
pi->legsAnim = ( ( pi->legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; |
| 156 |
|
| 157 |
if ( anim == LEGS_JUMP ) { |
| 158 |
pi->legsAnimationTimer = UI_TIMER_JUMP; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
/* |
| 164 |
=============== |
| 165 |
UI_SetLegsAnim |
| 166 |
=============== |
| 167 |
*/ |
| 168 |
static void UI_SetLegsAnim( playerInfo_t *pi, int anim ) { |
| 169 |
if ( pi->pendingLegsAnim ) { |
| 170 |
anim = pi->pendingLegsAnim; |
| 171 |
pi->pendingLegsAnim = 0; |
| 172 |
} |
| 173 |
UI_ForceLegsAnim( pi, anim ); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
/* |
| 178 |
=============== |
| 179 |
UI_ForceTorsoAnim |
| 180 |
=============== |
| 181 |
*/ |
| 182 |
static void UI_ForceTorsoAnim( playerInfo_t *pi, int anim ) { |
| 183 |
pi->torsoAnim = ( ( pi->torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; |
| 184 |
|
| 185 |
if ( anim == TORSO_GESTURE ) { |
| 186 |
pi->torsoAnimationTimer = UI_TIMER_GESTURE; |
| 187 |
} |
| 188 |
|
| 189 |
if ( anim == TORSO_ATTACK || anim == TORSO_ATTACK2 ) { |
| 190 |
pi->torsoAnimationTimer = UI_TIMER_ATTACK; |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
/* |
| 196 |
=============== |
| 197 |
UI_SetTorsoAnim |
| 198 |
=============== |
| 199 |
*/ |
| 200 |
static void UI_SetTorsoAnim( playerInfo_t *pi, int anim ) { |
| 201 |
if ( pi->pendingTorsoAnim ) { |
| 202 |
anim = pi->pendingTorsoAnim; |
| 203 |
pi->pendingTorsoAnim = 0; |
| 204 |
} |
| 205 |
|
| 206 |
UI_ForceTorsoAnim( pi, anim ); |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
/* |
| 211 |
=============== |
| 212 |
UI_TorsoSequencing |
| 213 |
=============== |
| 214 |
*/ |
| 215 |
static void UI_TorsoSequencing( playerInfo_t *pi ) { |
| 216 |
int currentAnim; |
| 217 |
|
| 218 |
currentAnim = pi->torsoAnim & ~ANIM_TOGGLEBIT; |
| 219 |
|
| 220 |
if ( pi->weapon != pi->currentWeapon ) { |
| 221 |
if ( currentAnim != TORSO_DROP ) { |
| 222 |
pi->torsoAnimationTimer = UI_TIMER_WEAPON_SWITCH; |
| 223 |
UI_ForceTorsoAnim( pi, TORSO_DROP ); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
if ( pi->torsoAnimationTimer > 0 ) { |
| 228 |
return; |
| 229 |
} |
| 230 |
|
| 231 |
if( currentAnim == TORSO_GESTURE ) { |
| 232 |
UI_SetTorsoAnim( pi, TORSO_STAND ); |
| 233 |
return; |
| 234 |
} |
| 235 |
|
| 236 |
if( currentAnim == TORSO_ATTACK || currentAnim == TORSO_ATTACK2 ) { |
| 237 |
UI_SetTorsoAnim( pi, TORSO_STAND ); |
| 238 |
return; |
| 239 |
} |
| 240 |
|
| 241 |
if ( currentAnim == TORSO_DROP ) { |
| 242 |
UI_PlayerInfo_SetWeapon( pi, pi->weapon ); |
| 243 |
pi->torsoAnimationTimer = UI_TIMER_WEAPON_SWITCH; |
| 244 |
UI_ForceTorsoAnim( pi, TORSO_RAISE ); |
| 245 |
return; |
| 246 |
} |
| 247 |
|
| 248 |
if ( currentAnim == TORSO_RAISE ) { |
| 249 |
UI_SetTorsoAnim( pi, TORSO_STAND ); |
| 250 |
return; |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
/* |
| 256 |
=============== |
| 257 |
UI_LegsSequencing |
| 258 |
=============== |
| 259 |
*/ |
| 260 |
static void UI_LegsSequencing( playerInfo_t *pi ) { |
| 261 |
int currentAnim; |
| 262 |
|
| 263 |
currentAnim = pi->legsAnim & ~ANIM_TOGGLEBIT; |
| 264 |
|
| 265 |
if ( pi->legsAnimationTimer > 0 ) { |
| 266 |
if ( currentAnim == LEGS_JUMP ) { |
| 267 |
jumpHeight = JUMP_HEIGHT * sin( M_PI * ( UI_TIMER_JUMP - pi->legsAnimationTimer ) / UI_TIMER_JUMP ); |
| 268 |
} |
| 269 |
return; |
| 270 |
} |
| 271 |
|
| 272 |
if ( currentAnim == LEGS_JUMP ) { |
| 273 |
UI_ForceLegsAnim( pi, LEGS_LAND ); |
| 274 |
pi->legsAnimationTimer = UI_TIMER_LAND; |
| 275 |
jumpHeight = 0; |
| 276 |
return; |
| 277 |
} |
| 278 |
|
| 279 |
if ( currentAnim == LEGS_LAND ) { |
| 280 |
UI_SetLegsAnim( pi, LEGS_IDLE ); |
| 281 |
return; |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
/* |
| 287 |
====================== |
| 288 |
UI_PositionEntityOnTag |
| 289 |
====================== |
| 290 |
*/ |
| 291 |
static void UI_PositionEntityOnTag( refEntity_t *entity, const refEntity_t *parent, |
| 292 |
clipHandle_t parentModel, char *tagName ) { |
| 293 |
int i; |
| 294 |
orientation_t lerped; |
| 295 |
|
| 296 |
// lerp the tag |
| 297 |
trap_CM_LerpTag( &lerped, parentModel, parent->oldframe, parent->frame, |
| 298 |
1.0 - parent->backlerp, tagName ); |
| 299 |
|
| 300 |
// FIXME: allow origin offsets along tag? |
| 301 |
VectorCopy( parent->origin, entity->origin ); |
| 302 |
for ( i = 0 ; i < 3 ; i++ ) { |
| 303 |
VectorMA( entity->origin, lerped.origin[i], parent->axis[i], entity->origin ); |
| 304 |
} |
| 305 |
|
| 306 |
// cast away const because of compiler problems |
| 307 |
MatrixMultiply( lerped.axis, ((refEntity_t*)parent)->axis, entity->axis ); |
| 308 |
entity->backlerp = parent->backlerp; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
/* |
| 313 |
====================== |
| 314 |
UI_PositionRotatedEntityOnTag |
| 315 |
====================== |
| 316 |
*/ |
| 317 |
static void UI_PositionRotatedEntityOnTag( refEntity_t *entity, const refEntity_t *parent, |
| 318 |
clipHandle_t parentModel, char *tagName ) { |
| 319 |
int i; |
| 320 |
orientation_t lerped; |
| 321 |
vec3_t tempAxis[3]; |
| 322 |
|
| 323 |
// lerp the tag |
| 324 |
trap_CM_LerpTag( &lerped, parentModel, parent->oldframe, parent->frame, |
| 325 |
1.0 - parent->backlerp, tagName ); |
| 326 |
|
| 327 |
// FIXME: allow origin offsets along tag? |
| 328 |
VectorCopy( parent->origin, entity->origin ); |
| 329 |
for ( i = 0 ; i < 3 ; i++ ) { |
| 330 |
VectorMA( entity->origin, lerped.origin[i], parent->axis[i], entity->origin ); |
| 331 |
} |
| 332 |
|
| 333 |
// cast away const because of compiler problems |
| 334 |
MatrixMultiply( entity->axis, ((refEntity_t *)parent)->axis, tempAxis ); |
| 335 |
MatrixMultiply( lerped.axis, tempAxis, entity->axis ); |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
/* |
| 340 |
=============== |
| 341 |
UI_SetLerpFrameAnimation |
| 342 |
=============== |
| 343 |
*/ |
| 344 |
static void UI_SetLerpFrameAnimation( playerInfo_t *ci, lerpFrame_t *lf, int newAnimation ) { |
| 345 |
animation_t *anim; |
| 346 |
|
| 347 |
lf->animationNumber = newAnimation; |
| 348 |
newAnimation &= ~ANIM_TOGGLEBIT; |
| 349 |
|
| 350 |
if ( newAnimation < 0 || newAnimation >= MAX_ANIMATIONS ) { |
| 351 |
trap_Error( va("Bad animation number: %i", newAnimation) ); |
| 352 |
} |
| 353 |
|
| 354 |
anim = &ci->animations[ newAnimation ]; |
| 355 |
|
| 356 |
lf->animation = anim; |
| 357 |
lf->animationTime = lf->frameTime + anim->initialLerp; |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
/* |
| 362 |
=============== |
| 363 |
UI_RunLerpFrame |
| 364 |
=============== |
| 365 |
*/ |
| 366 |
static void UI_RunLerpFrame( playerInfo_t *ci, lerpFrame_t *lf, int newAnimation ) { |
| 367 |
int f; |
| 368 |
animation_t *anim; |
| 369 |
|
| 370 |
// see if the animation sequence is switching |
| 371 |
if ( newAnimation != lf->animationNumber || !lf->animation ) { |
| 372 |
UI_SetLerpFrameAnimation( ci, lf, newAnimation ); |
| 373 |
} |
| 374 |
|
| 375 |
// if we have passed the current frame, move it to |
| 376 |
// oldFrame and calculate a new frame |
| 377 |
if ( dp_realtime >= lf->frameTime ) { |
| 378 |
lf->oldFrame = lf->frame; |
| 379 |
lf->oldFrameTime = lf->frameTime; |
| 380 |
|
| 381 |
// get the next frame based on the animation |
| 382 |
anim = lf->animation; |
| 383 |
if ( dp_realtime < lf->animationTime ) { |
| 384 |
lf->frameTime = lf->animationTime; // initial lerp |
| 385 |
} else { |
| 386 |
lf->frameTime = lf->oldFrameTime + anim->frameLerp; |
| 387 |
} |
| 388 |
f = ( lf->frameTime - lf->animationTime ) / anim->frameLerp; |
| 389 |
if ( f >= anim->numFrames ) { |
| 390 |
f -= anim->numFrames; |
| 391 |
if ( anim->loopFrames ) { |
| 392 |
f %= anim->loopFrames; |
| 393 |
f += anim->numFrames - anim->loopFrames; |
| 394 |
} else { |
| 395 |
f = anim->numFrames - 1; |
| 396 |
// the animation is stuck at the end, so it |
| 397 |
// can immediately transition to another sequence |
| 398 |
lf->frameTime = dp_realtime; |
| 399 |
} |
| 400 |
} |
| 401 |
lf->frame = anim->firstFrame + f; |
| 402 |
if ( dp_realtime > lf->frameTime ) { |
| 403 |
lf->frameTime = dp_realtime; |
| 404 |
} |
| 405 |
} |
| 406 |
|
| 407 |
if ( lf->frameTime > dp_realtime + 200 ) { |
| 408 |
lf->frameTime = dp_realtime; |
| 409 |
} |
| 410 |
|
| 411 |
if ( lf->oldFrameTime > dp_realtime ) { |
| 412 |
lf->oldFrameTime = dp_realtime; |
| 413 |
} |
| 414 |
// calculate current lerp value |
| 415 |
if ( lf->frameTime == lf->oldFrameTime ) { |
| 416 |
lf->backlerp = 0; |
| 417 |
} else { |
| 418 |
lf->backlerp = 1.0 - (float)( dp_realtime - lf->oldFrameTime ) / ( lf->frameTime - lf->oldFrameTime ); |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
/* |
| 424 |
=============== |
| 425 |
UI_PlayerAnimation |
| 426 |
=============== |
| 427 |
*/ |
| 428 |
static void UI_PlayerAnimation( playerInfo_t *pi, int *legsOld, int *legs, float *legsBackLerp, |
| 429 |
int *torsoOld, int *torso, float *torsoBackLerp ) { |
| 430 |
|
| 431 |
// legs animation |
| 432 |
pi->legsAnimationTimer -= uiInfo.uiDC.frameTime; |
| 433 |
if ( pi->legsAnimationTimer < 0 ) { |
| 434 |
pi->legsAnimationTimer = 0; |
| 435 |
} |
| 436 |
|
| 437 |
UI_LegsSequencing( pi ); |
| 438 |
|
| 439 |
if ( pi->legs.yawing && ( pi->legsAnim & ~ANIM_TOGGLEBIT ) == LEGS_IDLE ) { |
| 440 |
UI_RunLerpFrame( pi, &pi->legs, LEGS_TURN ); |
| 441 |
} else { |
| 442 |
UI_RunLerpFrame( pi, &pi->legs, pi->legsAnim ); |
| 443 |
} |
| 444 |
*legsOld = pi->legs.oldFrame; |
| 445 |
*legs = pi->legs.frame; |
| 446 |
*legsBackLerp = pi->legs.backlerp; |
| 447 |
|
| 448 |
// torso animation |
| 449 |
pi->torsoAnimationTimer -= uiInfo.uiDC.frameTime; |
| 450 |
if ( pi->torsoAnimationTimer < 0 ) { |
| 451 |
pi->torsoAnimationTimer = 0; |
| 452 |
} |
| 453 |
|
| 454 |
UI_TorsoSequencing( pi ); |
| 455 |
|
| 456 |
UI_RunLerpFrame( pi, &pi->torso, pi->torsoAnim ); |
| 457 |
*torsoOld = pi->torso.oldFrame; |
| 458 |
*torso = pi->torso.frame; |
| 459 |
*torsoBackLerp = pi->torso.backlerp; |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
/* |
| 464 |
================== |
| 465 |
UI_SwingAngles |
| 466 |
================== |
| 467 |
*/ |
| 468 |
static void UI_SwingAngles( float destination, float swingTolerance, float clampTolerance, |
| 469 |
float speed, float *angle, qboolean *swinging ) { |
| 470 |
float swing; |
| 471 |
float move; |
| 472 |
float scale; |
| 473 |
|
| 474 |
if ( !*swinging ) { |
| 475 |
// see if a swing should be started |
| 476 |
swing = AngleSubtract( *angle, destination ); |
| 477 |
if ( swing > swingTolerance || swing < -swingTolerance ) { |
| 478 |
*swinging = qtrue; |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
if ( !*swinging ) { |
| 483 |
return; |
| 484 |
} |
| 485 |
|
| 486 |
// modify the speed depending on the delta |
| 487 |
// so it doesn't seem so linear |
| 488 |
swing = AngleSubtract( destination, *angle ); |
| 489 |
scale = fabs( swing ); |
| 490 |
if ( scale < swingTolerance * 0.5 ) { |
| 491 |
scale = 0.5; |
| 492 |
} else if ( scale < swingTolerance ) { |
| 493 |
scale = 1.0; |
| 494 |
} else { |
| 495 |
scale = 2.0; |
| 496 |
} |
| 497 |
|
| 498 |
// swing towards the destination angle |
| 499 |
if ( swing >= 0 ) { |
| 500 |
move = uiInfo.uiDC.frameTime * scale * speed; |
| 501 |
if ( move >= swing ) { |
| 502 |
move = swing; |
| 503 |
*swinging = qfalse; |
| 504 |
} |
| 505 |
*angle = AngleMod( *angle + move ); |
| 506 |
} else if ( swing < 0 ) { |
| 507 |
move = uiInfo.uiDC.frameTime * scale * -speed; |
| 508 |
if ( move <= swing ) { |
| 509 |
move = swing; |
| 510 |
*swinging = qfalse; |
| 511 |
} |
| 512 |
*angle = AngleMod( *angle + move ); |
| 513 |
} |
| 514 |
|
| 515 |
// clamp to no more than tolerance |
| 516 |
swing = AngleSubtract( destination, *angle ); |
| 517 |
if ( swing > clampTolerance ) { |
| 518 |
*angle = AngleMod( destination - (clampTolerance - 1) ); |
| 519 |
} else if ( swing < -clampTolerance ) { |
| 520 |
*angle = AngleMod( destination + (clampTolerance - 1) ); |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
/* |
| 526 |
====================== |
| 527 |
UI_MovedirAdjustment |
| 528 |
====================== |
| 529 |
*/ |
| 530 |
static float UI_MovedirAdjustment( playerInfo_t *pi ) { |
| 531 |
vec3_t relativeAngles; |
| 532 |
vec3_t moveVector; |
| 533 |
|
| 534 |
VectorSubtract( pi->viewAngles, pi->moveAngles, relativeAngles ); |
| 535 |
AngleVectors( relativeAngles, moveVector, NULL, NULL ); |
| 536 |
if ( Q_fabs( moveVector[0] ) < 0.01 ) { |
| 537 |
moveVector[0] = 0.0; |
| 538 |
} |
| 539 |
if ( Q_fabs( moveVector[1] ) < 0.01 ) { |
| 540 |
moveVector[1] = 0.0; |
| 541 |
} |
| 542 |
|
| 543 |
if ( moveVector[1] == 0 && moveVector[0] > 0 ) { |
| 544 |
return 0; |
| 545 |
} |
| 546 |
if ( moveVector[1] < 0 && moveVector[0] > 0 ) { |
| 547 |
return 22; |
| 548 |
} |
| 549 |
if ( moveVector[1] < 0 && moveVector[0] == 0 ) { |
| 550 |
return 45; |
| 551 |
} |
| 552 |
if ( moveVector[1] < 0 && moveVector[0] < 0 ) { |
| 553 |
return -22; |
| 554 |
} |
| 555 |
if ( moveVector[1] == 0 && moveVector[0] < 0 ) { |
| 556 |
return 0; |
| 557 |
} |
| 558 |
if ( moveVector[1] > 0 && moveVector[0] < 0 ) { |
| 559 |
return 22; |
| 560 |
} |
| 561 |
if ( moveVector[1] > 0 && moveVector[0] == 0 ) { |
| 562 |
return -45; |
| 563 |
} |
| 564 |
|
| 565 |
return -22; |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
/* |
| 570 |
=============== |
| 571 |
UI_PlayerAngles |
| 572 |
=============== |
| 573 |
*/ |
| 574 |
static void UI_PlayerAngles( playerInfo_t *pi, vec3_t legs[3], vec3_t torso[3], vec3_t head[3] ) { |
| 575 |
vec3_t legsAngles, torsoAngles, headAngles; |
| 576 |
float dest; |
| 577 |
float adjust; |
| 578 |
|
| 579 |
VectorCopy( pi->viewAngles, headAngles ); |
| 580 |
headAngles[YAW] = AngleMod( headAngles[YAW] ); |
| 581 |
VectorClear( legsAngles ); |
| 582 |
VectorClear( torsoAngles ); |
| 583 |
|
| 584 |
// --------- yaw ------------- |
| 585 |
|
| 586 |
// allow yaw to drift a bit |
| 587 |
if ( ( pi->legsAnim & ~ANIM_TOGGLEBIT ) != LEGS_IDLE |
| 588 |
|| ( pi->torsoAnim & ~ANIM_TOGGLEBIT ) != TORSO_STAND ) { |
| 589 |
// if not standing still, always point all in the same direction |
| 590 |
pi->torso.yawing = qtrue; // always center |
| 591 |
pi->torso.pitching = qtrue; // always center |
| 592 |
pi->legs.yawing = qtrue; // always center |
| 593 |
} |
| 594 |
|
| 595 |
// adjust legs for movement dir |
| 596 |
adjust = UI_MovedirAdjustment( pi ); |
| 597 |
legsAngles[YAW] = headAngles[YAW] + adjust; |
| 598 |
torsoAngles[YAW] = headAngles[YAW] + 0.25 * adjust; |
| 599 |
|
| 600 |
|
| 601 |
// torso |
| 602 |
UI_SwingAngles( torsoAngles[YAW], 25, 90, SWINGSPEED, &pi->torso.yawAngle, &pi->torso.yawing ); |
| 603 |
UI_SwingAngles( legsAngles[YAW], 40, 90, SWINGSPEED, &pi->legs.yawAngle, &pi->legs.yawing ); |
| 604 |
|
| 605 |
torsoAngles[YAW] = pi->torso.yawAngle; |
| 606 |
legsAngles[YAW] = pi->legs.yawAngle; |
| 607 |
|
| 608 |
// --------- pitch ------------- |
| 609 |
|
| 610 |
// only show a fraction of the pitch angle in the torso |
| 611 |
if ( headAngles[PITCH] > 180 ) { |
| 612 |
dest = (-360 + headAngles[PITCH]) * 0.75; |
| 613 |
} else { |
| 614 |
dest = headAngles[PITCH] * 0.75; |
| 615 |
} |
| 616 |
UI_SwingAngles( dest, 15, 30, 0.1f, &pi->torso.pitchAngle, &pi->torso.pitching ); |
| 617 |
torsoAngles[PITCH] = pi->torso.pitchAngle; |
| 618 |
|
| 619 |
// pull the angles back out of the hierarchial chain |
| 620 |
AnglesSubtract( headAngles, torsoAngles, headAngles ); |
| 621 |
AnglesSubtract( torsoAngles, legsAngles, torsoAngles ); |
| 622 |
AnglesToAxis( legsAngles, legs ); |
| 623 |
AnglesToAxis( torsoAngles, torso ); |
| 624 |
AnglesToAxis( headAngles, head ); |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
/* |
| 629 |
=============== |
| 630 |
UI_PlayerFloatSprite |
| 631 |
=============== |
| 632 |
*/ |
| 633 |
static void UI_PlayerFloatSprite( playerInfo_t *pi, vec3_t origin, qhandle_t shader ) { |
| 634 |
refEntity_t ent; |
| 635 |
|
| 636 |
memset( &ent, 0, sizeof( ent ) ); |
| 637 |
VectorCopy( origin, ent.origin ); |
| 638 |
ent.origin[2] += 48; |
| 639 |
ent.reType = RT_SPRITE; |
| 640 |
ent.customShader = shader; |
| 641 |
ent.radius = 10; |
| 642 |
ent.renderfx = 0; |
| 643 |
trap_R_AddRefEntityToScene( &ent ); |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
/* |
| 648 |
====================== |
| 649 |
UI_MachinegunSpinAngle |
| 650 |
====================== |
| 651 |
*/ |
| 652 |
float UI_MachinegunSpinAngle( playerInfo_t *pi ) { |
| 653 |
int delta; |
| 654 |
float angle; |
| 655 |
float speed; |
| 656 |
int torsoAnim; |
| 657 |
|
| 658 |
delta = dp_realtime - pi->barrelTime; |
| 659 |
if ( pi->barrelSpinning ) { |
| 660 |
angle = pi->barrelAngle + delta * SPIN_SPEED; |
| 661 |
} else { |
| 662 |
if ( delta > COAST_TIME ) { |
| 663 |
delta = COAST_TIME; |
| 664 |
} |
| 665 |
|
| 666 |
speed = 0.5 * ( SPIN_SPEED + (float)( COAST_TIME - delta ) / COAST_TIME ); |
| 667 |
angle = pi->barrelAngle + delta * speed; |
| 668 |
} |
| 669 |
|
| 670 |
torsoAnim = pi->torsoAnim & ~ANIM_TOGGLEBIT; |
| 671 |
if( torsoAnim == TORSO_ATTACK2 ) { |
| 672 |
torsoAnim = TORSO_ATTACK; |
| 673 |
} |
| 674 |
if ( pi->barrelSpinning == !(torsoAnim == TORSO_ATTACK) ) { |
| 675 |
pi->barrelTime = dp_realtime; |
| 676 |
pi->barrelAngle = AngleMod( angle ); |
| 677 |
pi->barrelSpinning = !!(torsoAnim == TORSO_ATTACK); |
| 678 |
} |
| 679 |
|
| 680 |
return angle; |
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
/* |
| 685 |
=============== |
| 686 |
UI_DrawPlayer |
| 687 |
=============== |
| 688 |
*/ |
| 689 |
void UI_DrawPlayer( float x, float y, float w, float h, playerInfo_t *pi, int time ) { |
| 690 |
refdef_t refdef; |
| 691 |
refEntity_t legs; |
| 692 |
refEntity_t torso; |
| 693 |
refEntity_t head; |
| 694 |
refEntity_t gun; |
| 695 |
refEntity_t barrel; |
| 696 |
refEntity_t flash; |
| 697 |
vec3_t origin; |
| 698 |
int renderfx; |
| 699 |
vec3_t mins = {-16, -16, -24}; |
| 700 |
vec3_t maxs = {16, 16, 32}; |
| 701 |
float len; |
| 702 |
float xx; |
| 703 |
|
| 704 |
if ( !pi->legsModel || !pi->torsoModel || !pi->headModel || !pi->animations[0].numFrames ) { |
| 705 |
return; |
| 706 |
} |
| 707 |
|
| 708 |
// this allows the ui to cache the player model on the main menu |
| 709 |
if (w == 0 || h == 0) { |
| 710 |
return; |
| 711 |
} |
| 712 |
|
| 713 |
dp_realtime = time; |
| 714 |
|
| 715 |
if ( pi->pendingWeapon != -1 && dp_realtime > pi->weaponTimer ) { |
| 716 |
pi->weapon = pi->pendingWeapon; |
| 717 |
pi->lastWeapon = pi->pendingWeapon; |
| 718 |
pi->pendingWeapon = -1; |
| 719 |
pi->weaponTimer = 0; |
| 720 |
if( pi->currentWeapon != pi->weapon ) { |
| 721 |
trap_S_StartLocalSound( weaponChangeSound, CHAN_LOCAL ); |
| 722 |
} |
| 723 |
} |
| 724 |
|
| 725 |
UI_AdjustFrom640( &x, &y, &w, &h ); |
| 726 |
|
| 727 |
y -= jumpHeight; |
| 728 |
|
| 729 |
memset( &refdef, 0, sizeof( refdef ) ); |
| 730 |
memset( &legs, 0, sizeof(legs) ); |
| 731 |
memset( &torso, 0, sizeof(torso) ); |
| 732 |
memset( &head, 0, sizeof(head) ); |
| 733 |
|
| 734 |
refdef.rdflags = RDF_NOWORLDMODEL; |
| 735 |
|
| 736 |
AxisClear( refdef.viewaxis ); |
| 737 |
|
| 738 |
refdef.x = x; |
| 739 |
refdef.y = y; |
| 740 |
refdef.width = w; |
| 741 |
refdef.height = h; |
| 742 |
|
| 743 |
refdef.fov_x = (int)((float)refdef.width / 640.0f * 90.0f); |
| 744 |
xx = refdef.width / tan( refdef.fov_x / 360 * M_PI ); |
| 745 |
refdef.fov_y = atan2( refdef.height, xx ); |
| 746 |
refdef.fov_y *= ( 360 / (float)M_PI ); |
| 747 |
|
| 748 |
// calculate distance so the player nearly fills the box |
| 749 |
len = 0.7 * ( maxs[2] - mins[2] ); |
| 750 |
origin[0] = len / tan( DEG2RAD(refdef.fov_x) * 0.5 ); |
| 751 |
origin[1] = 0.5 * ( mins[1] + maxs[1] ); |
| 752 |
origin[2] = -0.5 * ( mins[2] + maxs[2] ); |
| 753 |
|
| 754 |
refdef.time = dp_realtime; |
| 755 |
|
| 756 |
trap_R_ClearScene(); |
| 757 |
|
| 758 |
// get the rotation information |
| 759 |
UI_PlayerAngles( pi, legs.axis, torso.axis, head.axis ); |
| 760 |
|
| 761 |
// get the animation state (after rotation, to allow feet shuffle) |
| 762 |
UI_PlayerAnimation( pi, &legs.oldframe, &legs.frame, &legs.backlerp, |
| 763 |
&torso.oldframe, &torso.frame, &torso.backlerp ); |
| 764 |
|
| 765 |
renderfx = RF_LIGHTING_ORIGIN | RF_NOSHADOW; |
| 766 |
|
| 767 |
// |
| 768 |
// add the legs |
| 769 |
// |
| 770 |
legs.hModel = pi->legsModel; |
| 771 |
legs.customSkin = pi->legsSkin; |
| 772 |
|
| 773 |
VectorCopy( origin, legs.origin ); |
| 774 |
|
| 775 |
VectorCopy( origin, legs.lightingOrigin ); |
| 776 |
legs.renderfx = renderfx; |
| 777 |
VectorCopy (legs.origin, legs.oldorigin); |
| 778 |
|
| 779 |
trap_R_AddRefEntityToScene( &legs ); |
| 780 |
|
| 781 |
if (!legs.hModel) { |
| 782 |
return; |
| 783 |
} |
| 784 |
|
| 785 |
// |
| 786 |
// add the torso |
| 787 |
// |
| 788 |
torso.hModel = pi->torsoModel; |
| 789 |
if (!torso.hModel) { |
| 790 |
return; |
| 791 |
} |
| 792 |
|
| 793 |
torso.customSkin = pi->torsoSkin; |
| 794 |
|
| 795 |
VectorCopy( origin, torso.lightingOrigin ); |
| 796 |
|
| 797 |
UI_PositionRotatedEntityOnTag( &torso, &legs, pi->legsModel, "tag_torso"); |
| 798 |
|
| 799 |
torso.renderfx = renderfx; |
| 800 |
|
| 801 |
trap_R_AddRefEntityToScene( &torso ); |
| 802 |
|
| 803 |
// |
| 804 |
// add the head |
| 805 |
// |
| 806 |
head.hModel = pi->headModel; |
| 807 |
if (!head.hModel) { |
| 808 |
return; |
| 809 |
} |
| 810 |
head.customSkin = pi->headSkin; |
| 811 |
|
| 812 |
VectorCopy( origin, head.lightingOrigin ); |
| 813 |
|
| 814 |
UI_PositionRotatedEntityOnTag( &head, &torso, pi->torsoModel, "tag_head"); |
| 815 |
|
| 816 |
head.renderfx = renderfx; |
| 817 |
|
| 818 |
trap_R_AddRefEntityToScene( &head ); |
| 819 |
|
| 820 |
// |
| 821 |
// add the gun |
| 822 |
// |
| 823 |
if ( pi->currentWeapon != WP_NONE ) { |
| 824 |
memset( &gun, 0, sizeof(gun) ); |
| 825 |
gun.hModel = pi->weaponModel; |
| 826 |
VectorCopy( origin, gun.lightingOrigin ); |
| 827 |
UI_PositionEntityOnTag( &gun, &torso, pi->torsoModel, "tag_weapon"); |
| 828 |
gun.renderfx = renderfx; |
| 829 |
trap_R_AddRefEntityToScene( &gun ); |
| 830 |
} |
| 831 |
|
| 832 |
// |
| 833 |
// add the spinning barrel |
| 834 |
// |
| 835 |
if ( pi->realWeapon == WP_MACHINEGUN || pi->realWeapon == WP_GAUNTLET || pi->realWeapon == WP_BFG ) { |
| 836 |
vec3_t angles; |
| 837 |
|
| 838 |
memset( &barrel, 0, sizeof(barrel) ); |
| 839 |
VectorCopy( origin, barrel.lightingOrigin ); |
| 840 |
barrel.renderfx = renderfx; |
| 841 |
|
| 842 |
barrel.hModel = pi->barrelModel; |
| 843 |
angles[YAW] = 0; |
| 844 |
angles[PITCH] = 0; |
| 845 |
angles[ROLL] = UI_MachinegunSpinAngle( pi ); |
| 846 |
if( pi->realWeapon == WP_GAUNTLET || pi->realWeapon == WP_BFG ) { |
| 847 |
angles[PITCH] = angles[ROLL]; |
| 848 |
angles[ROLL] = 0; |
| 849 |
} |
| 850 |
AnglesToAxis( angles, barrel.axis ); |
| 851 |
|
| 852 |
UI_PositionRotatedEntityOnTag( &barrel, &gun, pi->weaponModel, "tag_barrel"); |
| 853 |
|
| 854 |
trap_R_AddRefEntityToScene( &barrel ); |
| 855 |
} |
| 856 |
|
| 857 |
// |
| 858 |
// add muzzle flash |
| 859 |
// |
| 860 |
if ( dp_realtime <= pi->muzzleFlashTime ) { |
| 861 |
if ( pi->flashModel ) { |
| 862 |
memset( &flash, 0, sizeof(flash) ); |
| 863 |
flash.hModel = pi->flashModel; |
| 864 |
VectorCopy( origin, flash.lightingOrigin ); |
| 865 |
UI_PositionEntityOnTag( &flash, &gun, pi->weaponModel, "tag_flash"); |
| 866 |
flash.renderfx = renderfx; |
| 867 |
trap_R_AddRefEntityToScene( &flash ); |
| 868 |
} |
| 869 |
|
| 870 |
// make a dlight for the flash |
| 871 |
if ( pi->flashDlightColor[0] || pi->flashDlightColor[1] || pi->flashDlightColor[2] ) { |
| 872 |
trap_R_AddLightToScene( flash.origin, 200 + (rand()&31), pi->flashDlightColor[0], |
| 873 |
pi->flashDlightColor[1], pi->flashDlightColor[2] ); |
| 874 |
} |
| 875 |
} |
| 876 |
|
| 877 |
// |
| 878 |
// add the chat icon |
| 879 |
// |
| 880 |
if ( pi->chat ) { |
| 881 |
UI_PlayerFloatSprite( pi, origin, trap_R_RegisterShaderNoMip( "sprites/balloon3" ) ); |
| 882 |
} |
| 883 |
|
| 884 |
// |
| 885 |
// add an accent light |
| 886 |
// |
| 887 |
origin[0] -= 100; // + = behind, - = in front |
| 888 |
origin[1] += 100; // + = left, - = right |
| 889 |
origin[2] += 100; // + = above, - = below |
| 890 |
trap_R_AddLightToScene( origin, 500, 1.0, 1.0, 1.0 ); |
| 891 |
|
| 892 |
origin[0] -= 100; |
| 893 |
origin[1] -= 100; |
| 894 |
origin[2] -= 100; |
| 895 |
trap_R_AddLightToScene( origin, 500, 1.0, 0.0, 0.0 ); |
| 896 |
|
| 897 |
trap_R_RenderScene( &refdef ); |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
/* |
| 903 |
=============== |
| 904 |
UI_DrawPlayerII |
| 905 |
|
| 906 |
A less FOV stretched version for drawing on the main menu |
| 907 |
=============== |
| 908 |
*/ |
| 909 |
void UI_DrawPlayerII( float x, float y, float w, float h, playerInfo_t *pi, int time ) { |
| 910 |
refdef_t refdef; |
| 911 |
refEntity_t legs; |
| 912 |
refEntity_t torso; |
| 913 |
refEntity_t head; |
| 914 |
refEntity_t gun; |
| 915 |
refEntity_t barrel; |
| 916 |
refEntity_t flash; |
| 917 |
vec3_t origin; |
| 918 |
int renderfx; |
| 919 |
vec3_t mins = {-16, -16, -24}; |
| 920 |
vec3_t maxs = {16, 16, 32}; |
| 921 |
float len; |
| 922 |
float xx; |
| 923 |
|
| 924 |
if ( !pi->legsModel || !pi->torsoModel || !pi->headModel || !pi->animations[0].numFrames ) { |
| 925 |
return; |
| 926 |
} |
| 927 |
|
| 928 |
// this allows the ui to cache the player model on the main menu |
| 929 |
if (w == 0 || h == 0) { |
| 930 |
return; |
| 931 |
} |
| 932 |
|
| 933 |
dp_realtime = time; |
| 934 |
|
| 935 |
if ( pi->pendingWeapon != -1 && dp_realtime > pi->weaponTimer ) { |
| 936 |
pi->weapon = pi->pendingWeapon; |
| 937 |
pi->lastWeapon = pi->pendingWeapon; |
| 938 |
pi->pendingWeapon = -1; |
| 939 |
pi->weaponTimer = 0; |
| 940 |
if( pi->currentWeapon != pi->weapon ) { |
| 941 |
trap_S_StartLocalSound( weaponChangeSound, CHAN_LOCAL ); |
| 942 |
} |
| 943 |
} |
| 944 |
|
| 945 |
UI_AdjustFrom640( &x, &y, &w, &h ); |
| 946 |
|
| 947 |
y -= jumpHeight; |
| 948 |
|
| 949 |
memset( &refdef, 0, sizeof( refdef ) ); |
| 950 |
memset( &legs, 0, sizeof(legs) ); |
| 951 |
memset( &torso, 0, sizeof(torso) ); |
| 952 |
memset( &head, 0, sizeof(head) ); |
| 953 |
|
| 954 |
refdef.rdflags = RDF_NOWORLDMODEL; |
| 955 |
|
| 956 |
AxisClear( refdef.viewaxis ); |
| 957 |
|
| 958 |
refdef.x = x; |
| 959 |
refdef.y = y; |
| 960 |
refdef.width = w; |
| 961 |
refdef.height = h; |
| 962 |
|
| 963 |
refdef.fov_x = (int)((float)refdef.width / 640.0f * 30.0f); |
| 964 |
xx = refdef.width / tan( refdef.fov_x / 360 * M_PI ); |
| 965 |
refdef.fov_y = atan2( refdef.height, xx ); |
| 966 |
refdef.fov_y *= ( 360 / (float)M_PI ); |
| 967 |
|
| 968 |
// calculate distance so the player nearly fills the box |
| 969 |
len = 0.7 * ( maxs[2] - mins[2] ); |
| 970 |
origin[0] = len / tan( DEG2RAD(refdef.fov_x) * 0.93 ); |
| 971 |
origin[1] = 1.0 * ( mins[1] + maxs[1] ); |
| 972 |
origin[2] = -2.7 * ( mins[2] + maxs[2] ); |
| 973 |
|
| 974 |
refdef.time = dp_realtime; |
| 975 |
|
| 976 |
trap_R_ClearScene(); |
| 977 |
|
| 978 |
// get the rotation information |
| 979 |
UI_PlayerAngles( pi, legs.axis, torso.axis, head.axis ); |
| 980 |
|
| 981 |
// get the animation state (after rotation, to allow feet shuffle) |
| 982 |
UI_PlayerAnimation( pi, &legs.oldframe, &legs.frame, &legs.backlerp, |
| 983 |
&torso.oldframe, &torso.frame, &torso.backlerp ); |
| 984 |
|
| 985 |
renderfx = RF_LIGHTING_ORIGIN; |
| 986 |
|
| 987 |
// |
| 988 |
// add the legs |
| 989 |
// |
| 990 |
legs.hModel = pi->legsModel; |
| 991 |
legs.customSkin = pi->legsSkin; |
| 992 |
|
| 993 |
VectorCopy( origin, legs.origin ); |
| 994 |
|
| 995 |
VectorCopy( origin, legs.lightingOrigin ); |
| 996 |
legs.renderfx = renderfx; |
| 997 |
VectorCopy (legs.origin, legs.oldorigin); |
| 998 |
|
| 999 |
trap_R_AddRefEntityToScene( &legs ); |
| 1000 |
if (!legs.hModel) { |
| 1001 |
return; |
| 1002 |
} |
| 1003 |
|
| 1004 |
// |
| 1005 |
// add the torso |
| 1006 |
// |
| 1007 |
torso.hModel = pi->torsoModel; |
| 1008 |
if (!torso.hModel) { |
| 1009 |
return; |
| 1010 |
} |
| 1011 |
|
| 1012 |
torso.customSkin = pi->torsoSkin; |
| 1013 |
|
| 1014 |
VectorCopy( origin, torso.lightingOrigin ); |
| 1015 |
|
| 1016 |
UI_PositionRotatedEntityOnTag( &torso, &legs, pi->legsModel, "tag_torso"); |
| 1017 |
|
| 1018 |
torso.renderfx = renderfx; |
| 1019 |
|
| 1020 |
trap_R_AddRefEntityToScene( &torso ); |
| 1021 |
|
| 1022 |
// |
| 1023 |
// add the head |
| 1024 |
// |
| 1025 |
head.hModel = pi->headModel; |
| 1026 |
if (!head.hModel) { |
| 1027 |
return; |
| 1028 |
} |
| 1029 |
head.customSkin = pi->headSkin; |
| 1030 |
|
| 1031 |
VectorCopy( origin, head.lightingOrigin ); |
| 1032 |
|
| 1033 |
UI_PositionRotatedEntityOnTag( &head, &torso, pi->torsoModel, "tag_head"); |
| 1034 |
|
| 1035 |
head.renderfx = renderfx; |
| 1036 |
|
| 1037 |
trap_R_AddRefEntityToScene( &head ); |
| 1038 |
|
| 1039 |
// |
| 1040 |
// add the gun |
| 1041 |
// |
| 1042 |
if ( pi->currentWeapon != WP_NONE ) { |
| 1043 |
memset( &gun, 0, sizeof(gun) ); |
| 1044 |
gun.hModel = pi->weaponModel; |
| 1045 |
VectorCopy( origin, gun.lightingOrigin ); |
| 1046 |
UI_PositionEntityOnTag( &gun, &torso, pi->torsoModel, "tag_weapon"); |
| 1047 |
gun.renderfx = renderfx; |
| 1048 |
trap_R_AddRefEntityToScene( &gun ); |
| 1049 |
} |
| 1050 |
|
| 1051 |
// |
| 1052 |
// add the spinning barrel |
| 1053 |
// |
| 1054 |
if ( pi->realWeapon == WP_MACHINEGUN || pi->realWeapon == WP_GAUNTLET || pi->realWeapon == WP_BFG ) { |
| 1055 |
vec3_t angles; |
| 1056 |
|
| 1057 |
memset( &barrel, 0, sizeof(barrel) ); |
| 1058 |
VectorCopy( origin, barrel.lightingOrigin ); |
| 1059 |
barrel.renderfx = renderfx; |
| 1060 |
|
| 1061 |
barrel.hModel = pi->barrelModel; |
| 1062 |
angles[YAW] = 0; |
| 1063 |
angles[PITCH] = 0; |
| 1064 |
angles[ROLL] = UI_MachinegunSpinAngle( pi ); |
| 1065 |
if( pi->realWeapon == WP_GAUNTLET || pi->realWeapon == WP_BFG ) { |
| 1066 |
angles[PITCH] = angles[ROLL]; |
| 1067 |
angles[ROLL] = 0; |
| 1068 |
} |
| 1069 |
AnglesToAxis( angles, barrel.axis ); |
| 1070 |
|
| 1071 |
UI_PositionRotatedEntityOnTag( &barrel, &gun, pi->weaponModel, "tag_barrel"); |
| 1072 |
|
| 1073 |
trap_R_AddRefEntityToScene( &barrel ); |
| 1074 |
} |
| 1075 |
|
| 1076 |
// |
| 1077 |
// add muzzle flash |
| 1078 |
// |
| 1079 |
if ( dp_realtime <= pi->muzzleFlashTime ) { |
| 1080 |
if ( pi->flashModel ) { |
| 1081 |
memset( &flash, 0, sizeof(flash) ); |
| 1082 |
flash.hModel = pi->flashModel; |
| 1083 |
VectorCopy( origin, flash.lightingOrigin ); |
| 1084 |
UI_PositionEntityOnTag( &flash, &gun, pi->weaponModel, "tag_flash"); |
| 1085 |
flash.renderfx = renderfx; |
| 1086 |
trap_R_AddRefEntityToScene( &flash ); |
| 1087 |
} |
| 1088 |
|
| 1089 |
// make a dlight for the flash |
| 1090 |
if ( pi->flashDlightColor[0] || pi->flashDlightColor[1] || pi->flashDlightColor[2] ) { |
| 1091 |
trap_R_AddLightToScene( flash.origin, 200 + (rand()&31), pi->flashDlightColor[0], |
| 1092 |
pi->flashDlightColor[1], pi->flashDlightColor[2] ); |
| 1093 |
} |
| 1094 |
} |
| 1095 |
|
| 1096 |
// |
| 1097 |
// add the chat icon |
| 1098 |
// |
| 1099 |
if ( pi->chat ) { |
| 1100 |
UI_PlayerFloatSprite( pi, origin, trap_R_RegisterShaderNoMip( "sprites/balloon3" ) ); |
| 1101 |
} |
| 1102 |
|
| 1103 |
// |
| 1104 |
// add an accent light |
| 1105 |
// |
| 1106 |
origin[0] -= 100; // + = behind, - = in front |
| 1107 |
origin[1] += 100; // + = left, - = right |
| 1108 |
origin[2] += 100; // + = above, - = below |
| 1109 |
//trap_R_AddLightToScene( origin, 500, 0.3, 0.2, 0.8 ); |
| 1110 |
|
| 1111 |
origin[0] += 10; // + = behind, - = in front |
| 1112 |
origin[1] += 80; // + = left, - = right |
| 1113 |
origin[2] += 130; // + = above, - = below |
| 1114 |
trap_R_AddLightToScene( origin, 250, 0.54, 0.89, 0.79 ); |
| 1115 |
|
| 1116 |
|
| 1117 |
origin[0] -= 50; // + = behind, - = in front |
| 1118 |
origin[1] -= 90; // + = left, - = right |
| 1119 |
origin[2] -= 69; // + = above, - = below |
| 1120 |
trap_R_AddLightToScene( origin, 350, 0.60, 0.03, 0.22 ); |
| 1121 |
|
| 1122 |
|
| 1123 |
origin[0] -= 100; |
| 1124 |
origin[1] -= 100; |
| 1125 |
origin[2] -= 100; |
| 1126 |
//trap_R_AddLightToScene( origin, 500, 0.8, 0.2, 0.1 ); |
| 1127 |
// UI_ForceLegsAnim( pi, BOTH_POSE ); // leilei - pose hack |
| 1128 |
// UI_ForceTorsoAnim( pi, BOTH_POSE ); |
| 1129 |
|
| 1130 |
trap_R_RenderScene( &refdef ); |
| 1131 |
} |
| 1132 |
|
| 1133 |
|
| 1134 |
/* |
| 1135 |
========================== |
| 1136 |
UI_FileExists |
| 1137 |
========================== |
| 1138 |
*/ |
| 1139 |
static qboolean UI_FileExists(const char *filename) { |
| 1140 |
int len; |
| 1141 |
|
| 1142 |
len = trap_FS_FOpenFile( filename, NULL, FS_READ ); |
| 1143 |
if (len>0) { |
| 1144 |
return qtrue; |
| 1145 |
} |
| 1146 |
return qfalse; |
| 1147 |
} |
| 1148 |
|
| 1149 |
/* |
| 1150 |
========================== |
| 1151 |
UI_FindClientHeadFile |
| 1152 |
========================== |
| 1153 |
*/ |
| 1154 |
static qboolean UI_FindClientHeadFile( char *filename, int length, const char *teamName, const char *headModelName, const char *headSkinName, const char *base, const char *ext ) { |
| 1155 |
char *team, *headsFolder; |
| 1156 |
int i; |
| 1157 |
|
| 1158 |
team = "default"; |
| 1159 |
|
| 1160 |
if ( headModelName[0] == '*' ) { |
| 1161 |
headsFolder = "heads/"; |
| 1162 |
headModelName++; |
| 1163 |
} |
| 1164 |
else { |
| 1165 |
headsFolder = ""; |
| 1166 |
} |
| 1167 |
while(1) { |
| 1168 |
for ( i = 0; i < 2; i++ ) { |
| 1169 |
if ( i == 0 && teamName && *teamName ) { |
| 1170 |
Com_sprintf( filename, length, "models/players/%s%s/%s/%s%s_%s.%s", headsFolder, headModelName, headSkinName, teamName, base, team, ext ); |
| 1171 |
} |
| 1172 |
else { |
| 1173 |
Com_sprintf( filename, length, "models/players/%s%s/%s/%s_%s.%s", headsFolder, headModelName, headSkinName, base, team, ext ); |
| 1174 |
} |
| 1175 |
if ( UI_FileExists( filename ) ) { |
| 1176 |
return qtrue; |
| 1177 |
} |
| 1178 |
if ( i == 0 && teamName && *teamName ) { |
| 1179 |
Com_sprintf( filename, length, "models/players/%s%s/%s%s_%s.%s", headsFolder, headModelName, teamName, base, headSkinName, ext ); |
| 1180 |
} |
| 1181 |
else { |
| 1182 |
Com_sprintf( filename, length, "models/players/%s%s/%s_%s.%s", headsFolder, headModelName, base, headSkinName, ext ); |
| 1183 |
} |
| 1184 |
if ( UI_FileExists( filename ) ) { |
| 1185 |
return qtrue; |
| 1186 |
} |
| 1187 |
if ( !teamName || !*teamName ) { |
| 1188 |
break; |
| 1189 |
} |
| 1190 |
} |
| 1191 |
// if tried the heads folder first |
| 1192 |
if ( headsFolder[0] ) { |
| 1193 |
break; |
| 1194 |
} |
| 1195 |
headsFolder = "heads/"; |
| 1196 |
} |
| 1197 |
|
| 1198 |
return qfalse; |
| 1199 |
} |
| 1200 |
|
| 1201 |
/* |
| 1202 |
========================== |
| 1203 |
UI_RegisterClientSkin |
| 1204 |
========================== |
| 1205 |
*/ |
| 1206 |
static qboolean UI_RegisterClientSkin( playerInfo_t *pi, const char *modelName, const char *skinName, const char *headModelName, const char *headSkinName , const char *teamName) { |
| 1207 |
char filename[MAX_QPATH*2]; |
| 1208 |
|
| 1209 |
if (teamName && *teamName) { |
| 1210 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/%s/lower_%s.skin", modelName, teamName, skinName ); |
| 1211 |
} else { |
| 1212 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower_%s.skin", modelName, skinName ); |
| 1213 |
} |
| 1214 |
pi->legsSkin = trap_R_RegisterSkin( filename ); |
| 1215 |
if (!pi->legsSkin) { |
| 1216 |
if (teamName && *teamName) { |
| 1217 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/%s/lower_%s.skin", modelName, teamName, skinName ); |
| 1218 |
} else { |
| 1219 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/lower_%s.skin", modelName, skinName ); |
| 1220 |
} |
| 1221 |
pi->legsSkin = trap_R_RegisterSkin( filename ); |
| 1222 |
} |
| 1223 |
|
| 1224 |
if (teamName && *teamName) { |
| 1225 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/%s/upper_%s.skin", modelName, teamName, skinName ); |
| 1226 |
} else { |
| 1227 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper_%s.skin", modelName, skinName ); |
| 1228 |
} |
| 1229 |
pi->torsoSkin = trap_R_RegisterSkin( filename ); |
| 1230 |
if (!pi->torsoSkin) { |
| 1231 |
if (teamName && *teamName) { |
| 1232 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/%s/upper_%s.skin", modelName, teamName, skinName ); |
| 1233 |
} else { |
| 1234 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/upper_%s.skin", modelName, skinName ); |
| 1235 |
} |
| 1236 |
pi->torsoSkin = trap_R_RegisterSkin( filename ); |
| 1237 |
} |
| 1238 |
|
| 1239 |
if ( UI_FindClientHeadFile( filename, sizeof(filename), teamName, headModelName, headSkinName, "head", "skin" ) ) { |
| 1240 |
pi->headSkin = trap_R_RegisterSkin( filename ); |
| 1241 |
} |
| 1242 |
|
| 1243 |
if ( !pi->legsSkin || !pi->torsoSkin || !pi->headSkin ) { |
| 1244 |
return qfalse; |
| 1245 |
} |
| 1246 |
|
| 1247 |
return qtrue; |
| 1248 |
} |
| 1249 |
|
| 1250 |
|
| 1251 |
/* |
| 1252 |
====================== |
| 1253 |
UI_ParseAnimationFile |
| 1254 |
====================== |
| 1255 |
*/ |
| 1256 |
static qboolean UI_ParseAnimationFile( const char *filename, animation_t *animations ) { |
| 1257 |
char *text_p, *prev; |
| 1258 |
int len; |
| 1259 |
int i; |
| 1260 |
char *token; |
| 1261 |
float fps; |
| 1262 |
int skip; |
| 1263 |
char text[20000]; |
| 1264 |
fileHandle_t f; |
| 1265 |
|
| 1266 |
memset( animations, 0, sizeof( animation_t ) * MAX_ANIMATIONS ); |
| 1267 |
|
| 1268 |
// load the file |
| 1269 |
len = trap_FS_FOpenFile( filename, &f, FS_READ ); |
| 1270 |
if ( len <= 0 ) { |
| 1271 |
return qfalse; |
| 1272 |
} |
| 1273 |
if ( len >= ( sizeof( text ) - 1 ) ) { |
| 1274 |
Com_Printf( "File %s too long\n", filename ); |
| 1275 |
trap_FS_FCloseFile( f ); |
| 1276 |
return qfalse; |
| 1277 |
} |
| 1278 |
trap_FS_Read( text, len, f ); |
| 1279 |
text[len] = 0; |
| 1280 |
trap_FS_FCloseFile( f ); |
| 1281 |
|
| 1282 |
COM_Compress(text); |
| 1283 |
|
| 1284 |
// parse the text |
| 1285 |
text_p = text; |
| 1286 |
skip = 0; // quite the compiler warning |
| 1287 |
|
| 1288 |
// read optional parameters |
| 1289 |
while ( 1 ) { |
| 1290 |
prev = text_p; // so we can unget |
| 1291 |
token = COM_Parse( &text_p ); |
| 1292 |
if ( !token ) { |
| 1293 |
break; |
| 1294 |
} |
| 1295 |
if ( !Q_stricmp( token, "footsteps" ) ) { |
| 1296 |
token = COM_Parse( &text_p ); |
| 1297 |
if ( !token ) { |
| 1298 |
break; |
| 1299 |
} |
| 1300 |
continue; |
| 1301 |
} else if ( !Q_stricmp( token, "headoffset" ) ) { |
| 1302 |
for ( i = 0 ; i < 3 ; i++ ) { |
| 1303 |
token = COM_Parse( &text_p ); |
| 1304 |
if ( !token ) { |
| 1305 |
break; |
| 1306 |
} |
| 1307 |
} |
| 1308 |
continue; |
| 1309 |
} else if ( !Q_stricmp( token, "sex" ) ) { |
| 1310 |
token = COM_Parse( &text_p ); |
| 1311 |
if ( !token ) { |
| 1312 |
break; |
| 1313 |
} |
| 1314 |
continue; |
| 1315 |
} |
| 1316 |
|
| 1317 |
// if it is a number, start parsing animations |
| 1318 |
if ( token[0] >= '0' && token[0] <= '9' ) { |
| 1319 |
text_p = prev; // unget the token |
| 1320 |
break; |
| 1321 |
} |
| 1322 |
|
| 1323 |
Com_Printf( "unknown token '%s' is %s\n", token, filename ); |
| 1324 |
} |
| 1325 |
|
| 1326 |
// read information for each frame |
| 1327 |
for ( i = 0 ; i < MAX_ANIMATIONS ; i++ ) { |
| 1328 |
|
| 1329 |
token = COM_Parse( &text_p ); |
| 1330 |
if ( !token ) { |
| 1331 |
break; |
| 1332 |
} |
| 1333 |
animations[i].firstFrame = atoi( token ); |
| 1334 |
// leg only frames are adjusted to not count the upper body only frames |
| 1335 |
if ( i == LEGS_WALKCR ) { |
| 1336 |
skip = animations[LEGS_WALKCR].firstFrame - animations[TORSO_GESTURE].firstFrame; |
| 1337 |
} |
| 1338 |
if ( i >= LEGS_WALKCR ) { |
| 1339 |
animations[i].firstFrame -= skip; |
| 1340 |
} |
| 1341 |
|
| 1342 |
token = COM_Parse( &text_p ); |
| 1343 |
if ( !token ) { |
| 1344 |
break; |
| 1345 |
} |
| 1346 |
animations[i].numFrames = atoi( token ); |
| 1347 |
|
| 1348 |
token = COM_Parse( &text_p ); |
| 1349 |
if ( !token ) { |
| 1350 |
break; |
| 1351 |
} |
| 1352 |
animations[i].loopFrames = atoi( token ); |
| 1353 |
|
| 1354 |
token = COM_Parse( &text_p ); |
| 1355 |
if ( !token ) { |
| 1356 |
break; |
| 1357 |
} |
| 1358 |
fps = atof( token ); |
| 1359 |
if ( fps == 0 ) { |
| 1360 |
fps = 1; |
| 1361 |
} |
| 1362 |
animations[i].frameLerp = 1000 / fps; |
| 1363 |
animations[i].initialLerp = 1000 / fps; |
| 1364 |
} |
| 1365 |
|
| 1366 |
if ( i != MAX_ANIMATIONS ) { |
| 1367 |
Com_Printf( "Error parsing animation file: %s\n", filename ); |
| 1368 |
return qfalse; |
| 1369 |
} |
| 1370 |
|
| 1371 |
return qtrue; |
| 1372 |
} |
| 1373 |
|
| 1374 |
/* |
| 1375 |
========================== |
| 1376 |
UI_RegisterClientModelname |
| 1377 |
========================== |
| 1378 |
*/ |
| 1379 |
qboolean UI_RegisterClientModelname( playerInfo_t *pi, const char *modelSkinName, const char *headModelSkinName, const char *teamName ) { |
| 1380 |
char modelName[MAX_QPATH]; |
| 1381 |
char skinName[MAX_QPATH]; |
| 1382 |
char headModelName[MAX_QPATH]; |
| 1383 |
char headSkinName[MAX_QPATH]; |
| 1384 |
char filename[MAX_QPATH]; |
| 1385 |
char *slash; |
| 1386 |
|
| 1387 |
pi->torsoModel = 0; |
| 1388 |
pi->headModel = 0; |
| 1389 |
|
| 1390 |
if ( !modelSkinName[0] ) { |
| 1391 |
return qfalse; |
| 1392 |
} |
| 1393 |
|
| 1394 |
Q_strncpyz( modelName, modelSkinName, sizeof( modelName ) ); |
| 1395 |
|
| 1396 |
slash = strchr( modelName, '/' ); |
| 1397 |
if ( !slash ) { |
| 1398 |
// modelName did not include a skin name |
| 1399 |
Q_strncpyz( skinName, "default", sizeof( skinName ) ); |
| 1400 |
} else { |
| 1401 |
Q_strncpyz( skinName, slash + 1, sizeof( skinName ) ); |
| 1402 |
*slash = '\0'; |
| 1403 |
} |
| 1404 |
|
| 1405 |
Q_strncpyz( headModelName, headModelSkinName, sizeof( headModelName ) ); |
| 1406 |
slash = strchr( headModelName, '/' ); |
| 1407 |
if ( !slash ) { |
| 1408 |
// modelName did not include a skin name |
| 1409 |
Q_strncpyz( headSkinName, "default", sizeof( skinName ) ); |
| 1410 |
} else { |
| 1411 |
Q_strncpyz( headSkinName, slash + 1, sizeof( skinName ) ); |
| 1412 |
*slash = '\0'; |
| 1413 |
} |
| 1414 |
|
| 1415 |
// load cmodels before models so filecache works |
| 1416 |
|
| 1417 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower.md3", modelName ); |
| 1418 |
pi->legsModel = trap_R_RegisterModel( filename ); |
| 1419 |
if ( !pi->legsModel ) { |
| 1420 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/lower.md3", modelName ); |
| 1421 |
pi->legsModel = trap_R_RegisterModel( filename ); |
| 1422 |
if ( !pi->legsModel ) { |
| 1423 |
Com_Printf( "Failed to load model file %s\n", filename ); |
| 1424 |
return qfalse; |
| 1425 |
} |
| 1426 |
} |
| 1427 |
|
| 1428 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper.md3", modelName ); |
| 1429 |
pi->torsoModel = trap_R_RegisterModel( filename ); |
| 1430 |
if ( !pi->torsoModel ) { |
| 1431 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/upper.md3", modelName ); |
| 1432 |
pi->torsoModel = trap_R_RegisterModel( filename ); |
| 1433 |
if ( !pi->torsoModel ) { |
| 1434 |
Com_Printf( "Failed to load model file %s\n", filename ); |
| 1435 |
return qfalse; |
| 1436 |
} |
| 1437 |
} |
| 1438 |
|
| 1439 |
if (headModelName[0] == '*' ) { |
| 1440 |
Com_sprintf( filename, sizeof( filename ), "models/players/heads/%s/%s.md3", &headModelName[1], &headModelName[1] ); |
| 1441 |
} |
| 1442 |
else { |
| 1443 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/head.md3", headModelName ); |
| 1444 |
} |
| 1445 |
pi->headModel = trap_R_RegisterModel( filename ); |
| 1446 |
if ( !pi->headModel && headModelName[0] != '*') { |
| 1447 |
Com_sprintf( filename, sizeof( filename ), "models/players/heads/%s/%s.md3", headModelName, headModelName ); |
| 1448 |
pi->headModel = trap_R_RegisterModel( filename ); |
| 1449 |
} |
| 1450 |
|
| 1451 |
if (!pi->headModel) { |
| 1452 |
Com_Printf( "Failed to load model file %s\n", filename ); |
| 1453 |
return qfalse; |
| 1454 |
} |
| 1455 |
|
| 1456 |
// if any skins failed to load, fall back to default |
| 1457 |
if ( !UI_RegisterClientSkin( pi, modelName, skinName, headModelName, headSkinName, teamName) ) { |
| 1458 |
if ( !UI_RegisterClientSkin( pi, modelName, "default", headModelName, "default", teamName ) ) { |
| 1459 |
Com_Printf( "Failed to load skin file: %s : %s\n", modelName, skinName ); |
| 1460 |
return qfalse; |
| 1461 |
} |
| 1462 |
} |
| 1463 |
|
| 1464 |
// load the animations |
| 1465 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/animation.cfg", modelName ); |
| 1466 |
if ( !UI_ParseAnimationFile( filename, pi->animations ) ) { |
| 1467 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/animation.cfg", modelName ); |
| 1468 |
if ( !UI_ParseAnimationFile( filename, pi->animations ) ) { |
| 1469 |
Com_Printf( "Failed to load animation file %s\n", filename ); |
| 1470 |
return qfalse; |
| 1471 |
} |
| 1472 |
} |
| 1473 |
|
| 1474 |
return qtrue; |
| 1475 |
} |
| 1476 |
|
| 1477 |
|
| 1478 |
/* |
| 1479 |
=============== |
| 1480 |
UI_PlayerInfo_SetModel |
| 1481 |
=============== |
| 1482 |
*/ |
| 1483 |
void UI_PlayerInfo_SetModel( playerInfo_t *pi, const char *model, const char *headmodel, char *teamName ) { |
| 1484 |
memset( pi, 0, sizeof(*pi) ); |
| 1485 |
UI_RegisterClientModelname( pi, model, headmodel, teamName ); |
| 1486 |
pi->weapon = WP_MACHINEGUN; |
| 1487 |
pi->currentWeapon = pi->weapon; |
| 1488 |
pi->lastWeapon = pi->weapon; |
| 1489 |
pi->pendingWeapon = -1; |
| 1490 |
pi->weaponTimer = 0; |
| 1491 |
pi->chat = qfalse; |
| 1492 |
pi->newModel = qtrue; |
| 1493 |
UI_PlayerInfo_SetWeapon( pi, pi->weapon ); |
| 1494 |
} |
| 1495 |
|
| 1496 |
|
| 1497 |
/* |
| 1498 |
=============== |
| 1499 |
UI_PlayerInfo_SetInfo |
| 1500 |
=============== |
| 1501 |
*/ |
| 1502 |
void UI_PlayerInfo_SetInfo( playerInfo_t *pi, int legsAnim, int torsoAnim, vec3_t viewAngles, vec3_t moveAngles, weapon_t weaponNumber, qboolean chat ) { |
| 1503 |
int currentAnim; |
| 1504 |
weapon_t weaponNum; |
| 1505 |
|
| 1506 |
pi->chat = chat; |
| 1507 |
|
| 1508 |
// view angles |
| 1509 |
VectorCopy( viewAngles, pi->viewAngles ); |
| 1510 |
|
| 1511 |
// move angles |
| 1512 |
VectorCopy( moveAngles, pi->moveAngles ); |
| 1513 |
|
| 1514 |
if ( pi->newModel ) { |
| 1515 |
pi->newModel = qfalse; |
| 1516 |
|
| 1517 |
jumpHeight = 0; |
| 1518 |
pi->pendingLegsAnim = 0; |
| 1519 |
UI_ForceLegsAnim( pi, legsAnim ); |
| 1520 |
pi->legs.yawAngle = viewAngles[YAW]; |
| 1521 |
pi->legs.yawing = qfalse; |
| 1522 |
|
| 1523 |
pi->pendingTorsoAnim = 0; |
| 1524 |
UI_ForceTorsoAnim( pi, torsoAnim ); |
| 1525 |
pi->torso.yawAngle = viewAngles[YAW]; |
| 1526 |
pi->torso.yawing = qfalse; |
| 1527 |
|
| 1528 |
if ( weaponNumber != -1 ) { |
| 1529 |
pi->weapon = weaponNumber; |
| 1530 |
pi->currentWeapon = weaponNumber; |
| 1531 |
pi->lastWeapon = weaponNumber; |
| 1532 |
pi->pendingWeapon = -1; |
| 1533 |
pi->weaponTimer = 0; |
| 1534 |
UI_PlayerInfo_SetWeapon( pi, pi->weapon ); |
| 1535 |
} |
| 1536 |
|
| 1537 |
return; |
| 1538 |
} |
| 1539 |
|
| 1540 |
// weapon |
| 1541 |
if ( weaponNumber == -1 ) { |
| 1542 |
pi->pendingWeapon = -1; |
| 1543 |
pi->weaponTimer = 0; |
| 1544 |
} |
| 1545 |
else if ( weaponNumber != WP_NONE ) { |
| 1546 |
pi->pendingWeapon = weaponNumber; |
| 1547 |
pi->weaponTimer = dp_realtime + UI_TIMER_WEAPON_DELAY; |
| 1548 |
} |
| 1549 |
weaponNum = pi->lastWeapon; |
| 1550 |
pi->weapon = weaponNum; |
| 1551 |
|
| 1552 |
if ( torsoAnim == BOTH_DEATH1 || legsAnim == BOTH_DEATH1 ) { |
| 1553 |
torsoAnim = legsAnim = BOTH_DEATH1; |
| 1554 |
pi->weapon = pi->currentWeapon = WP_NONE; |
| 1555 |
UI_PlayerInfo_SetWeapon( pi, pi->weapon ); |
| 1556 |
|
| 1557 |
jumpHeight = 0; |
| 1558 |
pi->pendingLegsAnim = 0; |
| 1559 |
UI_ForceLegsAnim( pi, legsAnim ); |
| 1560 |
|
| 1561 |
pi->pendingTorsoAnim = 0; |
| 1562 |
UI_ForceTorsoAnim( pi, torsoAnim ); |
| 1563 |
|
| 1564 |
return; |
| 1565 |
} |
| 1566 |
|
| 1567 |
// leg animation |
| 1568 |
currentAnim = pi->legsAnim & ~ANIM_TOGGLEBIT; |
| 1569 |
if ( legsAnim != LEGS_JUMP && ( currentAnim == LEGS_JUMP || currentAnim == LEGS_LAND ) ) { |
| 1570 |
pi->pendingLegsAnim = legsAnim; |
| 1571 |
} |
| 1572 |
else if ( legsAnim != currentAnim ) { |
| 1573 |
jumpHeight = 0; |
| 1574 |
pi->pendingLegsAnim = 0; |
| 1575 |
UI_ForceLegsAnim( pi, legsAnim ); |
| 1576 |
} |
| 1577 |
|
| 1578 |
// torso animation |
| 1579 |
if ( torsoAnim == TORSO_STAND || torsoAnim == TORSO_STAND2 ) { |
| 1580 |
if ( weaponNum == WP_NONE || weaponNum == WP_GAUNTLET ) { |
| 1581 |
torsoAnim = TORSO_STAND2; |
| 1582 |
} |
| 1583 |
else { |
| 1584 |
torsoAnim = TORSO_STAND; |
| 1585 |
} |
| 1586 |
} |
| 1587 |
|
| 1588 |
if ( torsoAnim == TORSO_ATTACK || torsoAnim == TORSO_ATTACK2 ) { |
| 1589 |
if ( weaponNum == WP_NONE || weaponNum == WP_GAUNTLET ) { |
| 1590 |
torsoAnim = TORSO_ATTACK2; |
| 1591 |
} |
| 1592 |
else { |
| 1593 |
torsoAnim = TORSO_ATTACK; |
| 1594 |
} |
| 1595 |
pi->muzzleFlashTime = dp_realtime + UI_TIMER_MUZZLE_FLASH; |
| 1596 |
//FIXME play firing sound here |
| 1597 |
} |
| 1598 |
|
| 1599 |
currentAnim = pi->torsoAnim & ~ANIM_TOGGLEBIT; |
| 1600 |
|
| 1601 |
if ( weaponNum != pi->currentWeapon || currentAnim == TORSO_RAISE || currentAnim == TORSO_DROP ) { |
| 1602 |
pi->pendingTorsoAnim = torsoAnim; |
| 1603 |
} |
| 1604 |
else if ( ( currentAnim == TORSO_GESTURE || currentAnim == TORSO_ATTACK ) && ( torsoAnim != currentAnim ) ) { |
| 1605 |
pi->pendingTorsoAnim = torsoAnim; |
| 1606 |
} |
| 1607 |
else if ( torsoAnim != currentAnim ) { |
| 1608 |
pi->pendingTorsoAnim = 0; |
| 1609 |
UI_ForceTorsoAnim( pi, torsoAnim ); |
| 1610 |
} |
| 1611 |
} |