| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#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 |
|
| 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 |
Q_strcat( path, sizeof(path), "_barrel.md3" ); |
| 94 |
pi->barrelModel = trap_R_RegisterModel( path ); |
| 95 |
} |
| 96 |
|
| 97 |
COM_StripExtension( item->world_model[0], path, sizeof(path) ); |
| 98 |
Q_strcat( path, sizeof(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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 297 |
trap_CM_LerpTag( &lerped, parentModel, parent->oldframe, parent->frame, |
| 298 |
1.0 - parent->backlerp, tagName ); |
| 299 |
|
| 300 |
|
| 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 |
|
| 307 |
MatrixMultiply( lerped.axis, ((refEntity_t*)parent)->axis, entity->axis ); |
| 308 |
entity->backlerp = parent->backlerp; |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 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 |
|
| 324 |
trap_CM_LerpTag( &lerped, parentModel, parent->oldframe, parent->frame, |
| 325 |
1.0 - parent->backlerp, tagName ); |
| 326 |
|
| 327 |
|
| 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 |
|
| 334 |
MatrixMultiply( entity->axis, lerped.axis, tempAxis ); |
| 335 |
MatrixMultiply( tempAxis, ((refEntity_t *)parent)->axis, entity->axis ); |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 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 |
|
| 364 |
|
| 365 |
|
| 366 |
static void UI_RunLerpFrame( playerInfo_t *ci, lerpFrame_t *lf, int newAnimation ) { |
| 367 |
int f, numFrames; |
| 368 |
animation_t *anim; |
| 369 |
|
| 370 |
|
| 371 |
if ( newAnimation != lf->animationNumber || !lf->animation ) { |
| 372 |
UI_SetLerpFrameAnimation( ci, lf, newAnimation ); |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
if ( dp_realtime >= lf->frameTime ) { |
| 378 |
lf->oldFrame = lf->frame; |
| 379 |
lf->oldFrameTime = lf->frameTime; |
| 380 |
|
| 381 |
|
| 382 |
anim = lf->animation; |
| 383 |
if ( !anim->frameLerp ) { |
| 384 |
return; |
| 385 |
} |
| 386 |
if ( dp_realtime < lf->animationTime ) { |
| 387 |
lf->frameTime = lf->animationTime; |
| 388 |
} else { |
| 389 |
lf->frameTime = lf->oldFrameTime + anim->frameLerp; |
| 390 |
} |
| 391 |
f = ( lf->frameTime - lf->animationTime ) / anim->frameLerp; |
| 392 |
|
| 393 |
numFrames = anim->numFrames; |
| 394 |
if (anim->flipflop) { |
| 395 |
numFrames *= 2; |
| 396 |
} |
| 397 |
if ( f >= numFrames ) { |
| 398 |
f -= numFrames; |
| 399 |
if ( anim->loopFrames ) { |
| 400 |
f %= anim->loopFrames; |
| 401 |
f += anim->numFrames - anim->loopFrames; |
| 402 |
} else { |
| 403 |
f = numFrames - 1; |
| 404 |
|
| 405 |
|
| 406 |
lf->frameTime = dp_realtime; |
| 407 |
} |
| 408 |
} |
| 409 |
if ( anim->reversed ) { |
| 410 |
lf->frame = anim->firstFrame + anim->numFrames - 1 - f; |
| 411 |
} |
| 412 |
else if (anim->flipflop && f>=anim->numFrames) { |
| 413 |
lf->frame = anim->firstFrame + anim->numFrames - 1 - (f%anim->numFrames); |
| 414 |
} |
| 415 |
else { |
| 416 |
lf->frame = anim->firstFrame + f; |
| 417 |
} |
| 418 |
if ( dp_realtime > lf->frameTime ) { |
| 419 |
lf->frameTime = dp_realtime; |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
if ( lf->frameTime > dp_realtime + 200 ) { |
| 424 |
lf->frameTime = dp_realtime; |
| 425 |
} |
| 426 |
|
| 427 |
if ( lf->oldFrameTime > dp_realtime ) { |
| 428 |
lf->oldFrameTime = dp_realtime; |
| 429 |
} |
| 430 |
|
| 431 |
if ( lf->frameTime == lf->oldFrameTime ) { |
| 432 |
lf->backlerp = 0; |
| 433 |
} else { |
| 434 |
lf->backlerp = 1.0 - (float)( dp_realtime - lf->oldFrameTime ) / ( lf->frameTime - lf->oldFrameTime ); |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
static void UI_PlayerAnimation( playerInfo_t *pi, int *legsOld, int *legs, float *legsBackLerp, |
| 445 |
int *torsoOld, int *torso, float *torsoBackLerp ) { |
| 446 |
|
| 447 |
|
| 448 |
pi->legsAnimationTimer -= uiInfo.uiDC.frameTime; |
| 449 |
if ( pi->legsAnimationTimer < 0 ) { |
| 450 |
pi->legsAnimationTimer = 0; |
| 451 |
} |
| 452 |
|
| 453 |
UI_LegsSequencing( pi ); |
| 454 |
|
| 455 |
if ( pi->legs.yawing && ( pi->legsAnim & ~ANIM_TOGGLEBIT ) == LEGS_IDLE ) { |
| 456 |
UI_RunLerpFrame( pi, &pi->legs, LEGS_TURN ); |
| 457 |
} else { |
| 458 |
UI_RunLerpFrame( pi, &pi->legs, pi->legsAnim ); |
| 459 |
} |
| 460 |
*legsOld = pi->legs.oldFrame; |
| 461 |
*legs = pi->legs.frame; |
| 462 |
*legsBackLerp = pi->legs.backlerp; |
| 463 |
|
| 464 |
|
| 465 |
pi->torsoAnimationTimer -= uiInfo.uiDC.frameTime; |
| 466 |
if ( pi->torsoAnimationTimer < 0 ) { |
| 467 |
pi->torsoAnimationTimer = 0; |
| 468 |
} |
| 469 |
|
| 470 |
UI_TorsoSequencing( pi ); |
| 471 |
|
| 472 |
UI_RunLerpFrame( pi, &pi->torso, pi->torsoAnim ); |
| 473 |
*torsoOld = pi->torso.oldFrame; |
| 474 |
*torso = pi->torso.frame; |
| 475 |
*torsoBackLerp = pi->torso.backlerp; |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
static void UI_SwingAngles( float destination, float swingTolerance, float clampTolerance, |
| 485 |
float speed, float *angle, qboolean *swinging ) { |
| 486 |
float swing; |
| 487 |
float move; |
| 488 |
float scale; |
| 489 |
|
| 490 |
if ( !*swinging ) { |
| 491 |
|
| 492 |
swing = AngleSubtract( *angle, destination ); |
| 493 |
if ( swing > swingTolerance || swing < -swingTolerance ) { |
| 494 |
*swinging = qtrue; |
| 495 |
} |
| 496 |
} |
| 497 |
|
| 498 |
if ( !*swinging ) { |
| 499 |
return; |
| 500 |
} |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
swing = AngleSubtract( destination, *angle ); |
| 505 |
scale = fabs( swing ); |
| 506 |
if ( scale < swingTolerance * 0.5 ) { |
| 507 |
scale = 0.5; |
| 508 |
} else if ( scale < swingTolerance ) { |
| 509 |
scale = 1.0; |
| 510 |
} else { |
| 511 |
scale = 2.0; |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
if ( swing >= 0 ) { |
| 516 |
move = uiInfo.uiDC.frameTime * scale * speed; |
| 517 |
if ( move >= swing ) { |
| 518 |
move = swing; |
| 519 |
*swinging = qfalse; |
| 520 |
} |
| 521 |
*angle = AngleMod( *angle + move ); |
| 522 |
} else if ( swing < 0 ) { |
| 523 |
move = uiInfo.uiDC.frameTime * scale * -speed; |
| 524 |
if ( move <= swing ) { |
| 525 |
move = swing; |
| 526 |
*swinging = qfalse; |
| 527 |
} |
| 528 |
*angle = AngleMod( *angle + move ); |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
swing = AngleSubtract( destination, *angle ); |
| 533 |
if ( swing > clampTolerance ) { |
| 534 |
*angle = AngleMod( destination - (clampTolerance - 1) ); |
| 535 |
} else if ( swing < -clampTolerance ) { |
| 536 |
*angle = AngleMod( destination + (clampTolerance - 1) ); |
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
static float UI_MovedirAdjustment( playerInfo_t *pi ) { |
| 547 |
vec3_t relativeAngles; |
| 548 |
vec3_t moveVector; |
| 549 |
|
| 550 |
VectorSubtract( pi->viewAngles, pi->moveAngles, relativeAngles ); |
| 551 |
AngleVectors( relativeAngles, moveVector, NULL, NULL ); |
| 552 |
if ( Q_fabs( moveVector[0] ) < 0.01 ) { |
| 553 |
moveVector[0] = 0.0; |
| 554 |
} |
| 555 |
if ( Q_fabs( moveVector[1] ) < 0.01 ) { |
| 556 |
moveVector[1] = 0.0; |
| 557 |
} |
| 558 |
|
| 559 |
if ( moveVector[1] == 0 && moveVector[0] > 0 ) { |
| 560 |
return 0; |
| 561 |
} |
| 562 |
if ( moveVector[1] < 0 && moveVector[0] > 0 ) { |
| 563 |
return 22; |
| 564 |
} |
| 565 |
if ( moveVector[1] < 0 && moveVector[0] == 0 ) { |
| 566 |
return 45; |
| 567 |
} |
| 568 |
if ( moveVector[1] < 0 && moveVector[0] < 0 ) { |
| 569 |
return -22; |
| 570 |
} |
| 571 |
if ( moveVector[1] == 0 && moveVector[0] < 0 ) { |
| 572 |
return 0; |
| 573 |
} |
| 574 |
if ( moveVector[1] > 0 && moveVector[0] < 0 ) { |
| 575 |
return 22; |
| 576 |
} |
| 577 |
if ( moveVector[1] > 0 && moveVector[0] == 0 ) { |
| 578 |
return -45; |
| 579 |
} |
| 580 |
|
| 581 |
return -22; |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
static void UI_PlayerAngles( playerInfo_t *pi, vec3_t legs[3], vec3_t torso[3], vec3_t head[3] ) { |
| 591 |
vec3_t legsAngles, torsoAngles, headAngles; |
| 592 |
float dest; |
| 593 |
float adjust; |
| 594 |
|
| 595 |
VectorCopy( pi->viewAngles, headAngles ); |
| 596 |
headAngles[YAW] = AngleMod( headAngles[YAW] ); |
| 597 |
VectorClear( legsAngles ); |
| 598 |
VectorClear( torsoAngles ); |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
if ( ( pi->legsAnim & ~ANIM_TOGGLEBIT ) != LEGS_IDLE |
| 604 |
|| ( pi->torsoAnim & ~ANIM_TOGGLEBIT ) != TORSO_STAND ) { |
| 605 |
|
| 606 |
pi->torso.yawing = qtrue; |
| 607 |
pi->torso.pitching = qtrue; |
| 608 |
pi->legs.yawing = qtrue; |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
adjust = UI_MovedirAdjustment( pi ); |
| 613 |
legsAngles[YAW] = headAngles[YAW] + adjust; |
| 614 |
torsoAngles[YAW] = headAngles[YAW] + 0.25 * adjust; |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
UI_SwingAngles( torsoAngles[YAW], 25, 90, SWINGSPEED, &pi->torso.yawAngle, &pi->torso.yawing ); |
| 619 |
UI_SwingAngles( legsAngles[YAW], 40, 90, SWINGSPEED, &pi->legs.yawAngle, &pi->legs.yawing ); |
| 620 |
|
| 621 |
torsoAngles[YAW] = pi->torso.yawAngle; |
| 622 |
legsAngles[YAW] = pi->legs.yawAngle; |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
if ( headAngles[PITCH] > 180 ) { |
| 628 |
dest = (-360 + headAngles[PITCH]) * 0.75; |
| 629 |
} else { |
| 630 |
dest = headAngles[PITCH] * 0.75; |
| 631 |
} |
| 632 |
UI_SwingAngles( dest, 15, 30, 0.1f, &pi->torso.pitchAngle, &pi->torso.pitching ); |
| 633 |
torsoAngles[PITCH] = pi->torso.pitchAngle; |
| 634 |
|
| 635 |
if ( pi->fixedtorso ) { |
| 636 |
torsoAngles[PITCH] = 0.0f; |
| 637 |
} |
| 638 |
|
| 639 |
if ( pi->fixedlegs ) { |
| 640 |
legsAngles[YAW] = torsoAngles[YAW]; |
| 641 |
legsAngles[PITCH] = 0.0f; |
| 642 |
legsAngles[ROLL] = 0.0f; |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
AnglesSubtract( headAngles, torsoAngles, headAngles ); |
| 647 |
AnglesSubtract( torsoAngles, legsAngles, torsoAngles ); |
| 648 |
AnglesToAxis( legsAngles, legs ); |
| 649 |
AnglesToAxis( torsoAngles, torso ); |
| 650 |
AnglesToAxis( headAngles, head ); |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
static void UI_PlayerFloatSprite( playerInfo_t *pi, vec3_t origin, qhandle_t shader ) { |
| 660 |
refEntity_t ent; |
| 661 |
|
| 662 |
memset( &ent, 0, sizeof( ent ) ); |
| 663 |
VectorCopy( origin, ent.origin ); |
| 664 |
ent.origin[2] += 48; |
| 665 |
ent.reType = RT_SPRITE; |
| 666 |
ent.customShader = shader; |
| 667 |
ent.radius = 10; |
| 668 |
ent.renderfx = 0; |
| 669 |
trap_R_AddRefEntityToScene( &ent ); |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
float UI_MachinegunSpinAngle( playerInfo_t *pi ) { |
| 679 |
int delta; |
| 680 |
float angle; |
| 681 |
float speed; |
| 682 |
int torsoAnim; |
| 683 |
|
| 684 |
delta = dp_realtime - pi->barrelTime; |
| 685 |
if ( pi->barrelSpinning ) { |
| 686 |
angle = pi->barrelAngle + delta * SPIN_SPEED; |
| 687 |
} else { |
| 688 |
if ( delta > COAST_TIME ) { |
| 689 |
delta = COAST_TIME; |
| 690 |
} |
| 691 |
|
| 692 |
speed = 0.5 * ( SPIN_SPEED + (float)( COAST_TIME - delta ) / COAST_TIME ); |
| 693 |
angle = pi->barrelAngle + delta * speed; |
| 694 |
} |
| 695 |
|
| 696 |
torsoAnim = pi->torsoAnim & ~ANIM_TOGGLEBIT; |
| 697 |
if( torsoAnim == TORSO_ATTACK2 ) { |
| 698 |
torsoAnim = TORSO_ATTACK; |
| 699 |
} |
| 700 |
if ( pi->barrelSpinning == !(torsoAnim == TORSO_ATTACK) ) { |
| 701 |
pi->barrelTime = dp_realtime; |
| 702 |
pi->barrelAngle = AngleMod( angle ); |
| 703 |
pi->barrelSpinning = !!(torsoAnim == TORSO_ATTACK); |
| 704 |
} |
| 705 |
|
| 706 |
return angle; |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
void UI_DrawPlayer( float x, float y, float w, float h, playerInfo_t *pi, int time ) { |
| 716 |
refdef_t refdef; |
| 717 |
refEntity_t legs = {0}; |
| 718 |
refEntity_t torso = {0}; |
| 719 |
refEntity_t head = {0}; |
| 720 |
refEntity_t gun = {0}; |
| 721 |
refEntity_t barrel = {0}; |
| 722 |
refEntity_t flash = {0}; |
| 723 |
vec3_t origin; |
| 724 |
int renderfx; |
| 725 |
vec3_t mins = {-16, -16, -24}; |
| 726 |
vec3_t maxs = {16, 16, 32}; |
| 727 |
float len; |
| 728 |
float xx; |
| 729 |
|
| 730 |
if ( !pi->legsModel || !pi->torsoModel || !pi->headModel || !pi->animations[0].numFrames ) { |
| 731 |
return; |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
if (w == 0 || h == 0) { |
| 736 |
return; |
| 737 |
} |
| 738 |
|
| 739 |
dp_realtime = time; |
| 740 |
|
| 741 |
if ( pi->pendingWeapon != WP_NUM_WEAPONS && dp_realtime > pi->weaponTimer ) { |
| 742 |
pi->weapon = pi->pendingWeapon; |
| 743 |
pi->lastWeapon = pi->pendingWeapon; |
| 744 |
pi->pendingWeapon = WP_NUM_WEAPONS; |
| 745 |
pi->weaponTimer = 0; |
| 746 |
if( pi->currentWeapon != pi->weapon ) { |
| 747 |
trap_S_StartLocalSound( weaponChangeSound, CHAN_LOCAL ); |
| 748 |
} |
| 749 |
} |
| 750 |
|
| 751 |
UI_AdjustFrom640( &x, &y, &w, &h ); |
| 752 |
|
| 753 |
y -= jumpHeight; |
| 754 |
|
| 755 |
memset( &refdef, 0, sizeof( refdef ) ); |
| 756 |
memset( &legs, 0, sizeof(legs) ); |
| 757 |
memset( &torso, 0, sizeof(torso) ); |
| 758 |
memset( &head, 0, sizeof(head) ); |
| 759 |
|
| 760 |
refdef.rdflags = RDF_NOWORLDMODEL; |
| 761 |
|
| 762 |
AxisClear( refdef.viewaxis ); |
| 763 |
|
| 764 |
refdef.x = x; |
| 765 |
refdef.y = y; |
| 766 |
refdef.width = w; |
| 767 |
refdef.height = h; |
| 768 |
|
| 769 |
refdef.fov_x = (int)((float)refdef.width / uiInfo.uiDC.xscale / 640.0f * 90.0f); |
| 770 |
xx = refdef.width / uiInfo.uiDC.xscale / tan( refdef.fov_x / 360 * M_PI ); |
| 771 |
refdef.fov_y = atan2( refdef.height / uiInfo.uiDC.yscale, xx ); |
| 772 |
refdef.fov_y *= ( 360 / (float)M_PI ); |
| 773 |
|
| 774 |
|
| 775 |
len = 0.7 * ( maxs[2] - mins[2] ); |
| 776 |
origin[0] = len / tan( DEG2RAD(refdef.fov_x) * 0.5 ); |
| 777 |
origin[1] = 0.5 * ( mins[1] + maxs[1] ); |
| 778 |
origin[2] = -0.5 * ( mins[2] + maxs[2] ); |
| 779 |
|
| 780 |
refdef.time = dp_realtime; |
| 781 |
|
| 782 |
trap_R_ClearScene(); |
| 783 |
|
| 784 |
|
| 785 |
UI_PlayerAngles( pi, legs.axis, torso.axis, head.axis ); |
| 786 |
|
| 787 |
|
| 788 |
UI_PlayerAnimation( pi, &legs.oldframe, &legs.frame, &legs.backlerp, |
| 789 |
&torso.oldframe, &torso.frame, &torso.backlerp ); |
| 790 |
|
| 791 |
renderfx = RF_LIGHTING_ORIGIN | RF_NOSHADOW; |
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
legs.hModel = pi->legsModel; |
| 797 |
legs.customSkin = pi->legsSkin; |
| 798 |
|
| 799 |
VectorCopy( origin, legs.origin ); |
| 800 |
|
| 801 |
VectorCopy( origin, legs.lightingOrigin ); |
| 802 |
legs.renderfx = renderfx; |
| 803 |
VectorCopy (legs.origin, legs.oldorigin); |
| 804 |
|
| 805 |
trap_R_AddRefEntityToScene( &legs ); |
| 806 |
|
| 807 |
if (!legs.hModel) { |
| 808 |
return; |
| 809 |
} |
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
torso.hModel = pi->torsoModel; |
| 815 |
if (!torso.hModel) { |
| 816 |
return; |
| 817 |
} |
| 818 |
|
| 819 |
torso.customSkin = pi->torsoSkin; |
| 820 |
|
| 821 |
VectorCopy( origin, torso.lightingOrigin ); |
| 822 |
|
| 823 |
UI_PositionRotatedEntityOnTag( &torso, &legs, pi->legsModel, "tag_torso"); |
| 824 |
|
| 825 |
torso.renderfx = renderfx; |
| 826 |
|
| 827 |
trap_R_AddRefEntityToScene( &torso ); |
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
head.hModel = pi->headModel; |
| 833 |
if (!head.hModel) { |
| 834 |
return; |
| 835 |
} |
| 836 |
head.customSkin = pi->headSkin; |
| 837 |
|
| 838 |
VectorCopy( origin, head.lightingOrigin ); |
| 839 |
|
| 840 |
UI_PositionRotatedEntityOnTag( &head, &torso, pi->torsoModel, "tag_head"); |
| 841 |
|
| 842 |
head.renderfx = renderfx; |
| 843 |
|
| 844 |
trap_R_AddRefEntityToScene( &head ); |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
if ( pi->currentWeapon != WP_NONE ) { |
| 850 |
memset( &gun, 0, sizeof(gun) ); |
| 851 |
gun.hModel = pi->weaponModel; |
| 852 |
VectorCopy( origin, gun.lightingOrigin ); |
| 853 |
UI_PositionEntityOnTag( &gun, &torso, pi->torsoModel, "tag_weapon"); |
| 854 |
gun.renderfx = renderfx; |
| 855 |
trap_R_AddRefEntityToScene( &gun ); |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
if ( pi->realWeapon == WP_MACHINEGUN || pi->realWeapon == WP_GAUNTLET || pi->realWeapon == WP_BFG ) { |
| 862 |
vec3_t angles; |
| 863 |
|
| 864 |
memset( &barrel, 0, sizeof(barrel) ); |
| 865 |
VectorCopy( origin, barrel.lightingOrigin ); |
| 866 |
barrel.renderfx = renderfx; |
| 867 |
|
| 868 |
barrel.hModel = pi->barrelModel; |
| 869 |
angles[YAW] = 0; |
| 870 |
angles[PITCH] = 0; |
| 871 |
angles[ROLL] = UI_MachinegunSpinAngle( pi ); |
| 872 |
AnglesToAxis( angles, barrel.axis ); |
| 873 |
|
| 874 |
UI_PositionRotatedEntityOnTag( &barrel, &gun, pi->weaponModel, "tag_barrel"); |
| 875 |
|
| 876 |
trap_R_AddRefEntityToScene( &barrel ); |
| 877 |
} |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
if ( dp_realtime <= pi->muzzleFlashTime ) { |
| 883 |
if ( pi->flashModel ) { |
| 884 |
memset( &flash, 0, sizeof(flash) ); |
| 885 |
flash.hModel = pi->flashModel; |
| 886 |
VectorCopy( origin, flash.lightingOrigin ); |
| 887 |
UI_PositionEntityOnTag( &flash, &gun, pi->weaponModel, "tag_flash"); |
| 888 |
flash.renderfx = renderfx; |
| 889 |
trap_R_AddRefEntityToScene( &flash ); |
| 890 |
} |
| 891 |
|
| 892 |
|
| 893 |
if ( pi->flashDlightColor[0] || pi->flashDlightColor[1] || pi->flashDlightColor[2] ) { |
| 894 |
trap_R_AddLightToScene( flash.origin, 200 + (rand()&31), pi->flashDlightColor[0], |
| 895 |
pi->flashDlightColor[1], pi->flashDlightColor[2] ); |
| 896 |
} |
| 897 |
} |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
if ( pi->chat ) { |
| 903 |
UI_PlayerFloatSprite( pi, origin, trap_R_RegisterShaderNoMip( "sprites/balloon3" ) ); |
| 904 |
} |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
origin[0] -= 100; |
| 910 |
origin[1] += 100; |
| 911 |
origin[2] += 100; |
| 912 |
trap_R_AddLightToScene( origin, 500, 1.0, 1.0, 1.0 ); |
| 913 |
|
| 914 |
origin[0] -= 100; |
| 915 |
origin[1] -= 100; |
| 916 |
origin[2] -= 100; |
| 917 |
trap_R_AddLightToScene( origin, 500, 1.0, 0.0, 0.0 ); |
| 918 |
|
| 919 |
trap_R_RenderScene( &refdef ); |
| 920 |
} |
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
static qboolean UI_FileExists(const char *filename) { |
| 928 |
int len; |
| 929 |
|
| 930 |
len = trap_FS_FOpenFile( filename, NULL, FS_READ ); |
| 931 |
if (len>0) { |
| 932 |
return qtrue; |
| 933 |
} |
| 934 |
return qfalse; |
| 935 |
} |
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
static qboolean UI_FindClientHeadFile( char *filename, int length, const char *teamName, const char *headModelName, const char *headSkinName, const char *base, const char *ext ) { |
| 943 |
char *team, *headsFolder; |
| 944 |
int i; |
| 945 |
|
| 946 |
team = "default"; |
| 947 |
|
| 948 |
if ( headModelName[0] == '*' ) { |
| 949 |
headsFolder = "heads/"; |
| 950 |
headModelName++; |
| 951 |
} |
| 952 |
else { |
| 953 |
headsFolder = ""; |
| 954 |
} |
| 955 |
while(1) { |
| 956 |
for ( i = 0; i < 2; i++ ) { |
| 957 |
if ( i == 0 && teamName && *teamName ) { |
| 958 |
Com_sprintf( filename, length, "models/players/%s%s/%s/%s%s_%s.%s", headsFolder, headModelName, headSkinName, teamName, base, team, ext ); |
| 959 |
} |
| 960 |
else { |
| 961 |
Com_sprintf( filename, length, "models/players/%s%s/%s/%s_%s.%s", headsFolder, headModelName, headSkinName, base, team, ext ); |
| 962 |
} |
| 963 |
if ( UI_FileExists( filename ) ) { |
| 964 |
return qtrue; |
| 965 |
} |
| 966 |
if ( i == 0 && teamName && *teamName ) { |
| 967 |
Com_sprintf( filename, length, "models/players/%s%s/%s%s_%s.%s", headsFolder, headModelName, teamName, base, headSkinName, ext ); |
| 968 |
} |
| 969 |
else { |
| 970 |
Com_sprintf( filename, length, "models/players/%s%s/%s_%s.%s", headsFolder, headModelName, base, headSkinName, ext ); |
| 971 |
} |
| 972 |
if ( UI_FileExists( filename ) ) { |
| 973 |
return qtrue; |
| 974 |
} |
| 975 |
if ( !teamName || !*teamName ) { |
| 976 |
break; |
| 977 |
} |
| 978 |
} |
| 979 |
|
| 980 |
if ( headsFolder[0] ) { |
| 981 |
break; |
| 982 |
} |
| 983 |
headsFolder = "heads/"; |
| 984 |
} |
| 985 |
|
| 986 |
return qfalse; |
| 987 |
} |
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
static qboolean UI_RegisterClientSkin( playerInfo_t *pi, const char *modelName, const char *skinName, const char *headModelName, const char *headSkinName , const char *teamName) { |
| 995 |
char filename[MAX_QPATH]; |
| 996 |
|
| 997 |
if (teamName && *teamName) { |
| 998 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/%s/lower_%s.skin", modelName, teamName, skinName ); |
| 999 |
} else { |
| 1000 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower_%s.skin", modelName, skinName ); |
| 1001 |
} |
| 1002 |
pi->legsSkin = trap_R_RegisterSkin( filename ); |
| 1003 |
if (!pi->legsSkin) { |
| 1004 |
if (teamName && *teamName) { |
| 1005 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/%s/lower_%s.skin", modelName, teamName, skinName ); |
| 1006 |
} else { |
| 1007 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/lower_%s.skin", modelName, skinName ); |
| 1008 |
} |
| 1009 |
pi->legsSkin = trap_R_RegisterSkin( filename ); |
| 1010 |
} |
| 1011 |
|
| 1012 |
if (teamName && *teamName) { |
| 1013 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/%s/upper_%s.skin", modelName, teamName, skinName ); |
| 1014 |
} else { |
| 1015 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper_%s.skin", modelName, skinName ); |
| 1016 |
} |
| 1017 |
pi->torsoSkin = trap_R_RegisterSkin( filename ); |
| 1018 |
if (!pi->torsoSkin) { |
| 1019 |
if (teamName && *teamName) { |
| 1020 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/%s/upper_%s.skin", modelName, teamName, skinName ); |
| 1021 |
} else { |
| 1022 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/upper_%s.skin", modelName, skinName ); |
| 1023 |
} |
| 1024 |
pi->torsoSkin = trap_R_RegisterSkin( filename ); |
| 1025 |
} |
| 1026 |
|
| 1027 |
if ( UI_FindClientHeadFile( filename, sizeof(filename), teamName, headModelName, headSkinName, "head", "skin" ) ) { |
| 1028 |
pi->headSkin = trap_R_RegisterSkin( filename ); |
| 1029 |
} |
| 1030 |
|
| 1031 |
if ( !pi->legsSkin || !pi->torsoSkin || !pi->headSkin ) { |
| 1032 |
return qfalse; |
| 1033 |
} |
| 1034 |
|
| 1035 |
return qtrue; |
| 1036 |
} |
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
static qboolean UI_ParseAnimationFile( const char *filename, playerInfo_t *pi ) { |
| 1045 |
char *text_p, *prev; |
| 1046 |
int len; |
| 1047 |
int i; |
| 1048 |
char *token; |
| 1049 |
float fps; |
| 1050 |
int skip; |
| 1051 |
char text[20000]; |
| 1052 |
fileHandle_t f; |
| 1053 |
animation_t *animations; |
| 1054 |
|
| 1055 |
animations = pi->animations; |
| 1056 |
|
| 1057 |
memset( animations, 0, sizeof( animation_t ) * MAX_ANIMATIONS ); |
| 1058 |
|
| 1059 |
pi->fixedlegs = qfalse; |
| 1060 |
pi->fixedtorso = qfalse; |
| 1061 |
|
| 1062 |
|
| 1063 |
len = trap_FS_FOpenFile( filename, &f, FS_READ ); |
| 1064 |
if ( len <= 0 ) { |
| 1065 |
return qfalse; |
| 1066 |
} |
| 1067 |
if ( len >= ( sizeof( text ) - 1 ) ) { |
| 1068 |
Com_Printf( "File %s too long\n", filename ); |
| 1069 |
trap_FS_FCloseFile( f ); |
| 1070 |
return qfalse; |
| 1071 |
} |
| 1072 |
trap_FS_Read( text, len, f ); |
| 1073 |
text[len] = 0; |
| 1074 |
trap_FS_FCloseFile( f ); |
| 1075 |
|
| 1076 |
COM_Compress(text); |
| 1077 |
|
| 1078 |
|
| 1079 |
text_p = text; |
| 1080 |
skip = 0; |
| 1081 |
|
| 1082 |
|
| 1083 |
while ( 1 ) { |
| 1084 |
prev = text_p; |
| 1085 |
token = COM_Parse( &text_p ); |
| 1086 |
if ( !token[0] ) { |
| 1087 |
break; |
| 1088 |
} |
| 1089 |
if ( !Q_stricmp( token, "footsteps" ) ) { |
| 1090 |
token = COM_Parse( &text_p ); |
| 1091 |
if ( !token[0] ) { |
| 1092 |
break; |
| 1093 |
} |
| 1094 |
continue; |
| 1095 |
} else if ( !Q_stricmp( token, "headoffset" ) ) { |
| 1096 |
for ( i = 0 ; i < 3 ; i++ ) { |
| 1097 |
token = COM_Parse( &text_p ); |
| 1098 |
if ( !token[0] ) { |
| 1099 |
break; |
| 1100 |
} |
| 1101 |
} |
| 1102 |
continue; |
| 1103 |
} else if ( !Q_stricmp( token, "sex" ) ) { |
| 1104 |
token = COM_Parse( &text_p ); |
| 1105 |
if ( !token[0] ) { |
| 1106 |
break; |
| 1107 |
} |
| 1108 |
continue; |
| 1109 |
} else if ( !Q_stricmp( token, "fixedlegs" ) ) { |
| 1110 |
pi->fixedlegs = qtrue; |
| 1111 |
continue; |
| 1112 |
} else if ( !Q_stricmp( token, "fixedtorso" ) ) { |
| 1113 |
pi->fixedtorso = qtrue; |
| 1114 |
continue; |
| 1115 |
} |
| 1116 |
|
| 1117 |
|
| 1118 |
if ( token[0] >= '0' && token[0] <= '9' ) { |
| 1119 |
text_p = prev; |
| 1120 |
break; |
| 1121 |
} |
| 1122 |
|
| 1123 |
Com_Printf( "unknown token '%s' in %s\n", token, filename ); |
| 1124 |
} |
| 1125 |
|
| 1126 |
|
| 1127 |
for ( i = 0 ; i < MAX_ANIMATIONS ; i++ ) { |
| 1128 |
|
| 1129 |
token = COM_Parse( &text_p ); |
| 1130 |
if ( !token[0] ) { |
| 1131 |
if( i >= TORSO_GETFLAG && i <= TORSO_NEGATIVE ) { |
| 1132 |
animations[i].firstFrame = animations[TORSO_GESTURE].firstFrame; |
| 1133 |
animations[i].frameLerp = animations[TORSO_GESTURE].frameLerp; |
| 1134 |
animations[i].initialLerp = animations[TORSO_GESTURE].initialLerp; |
| 1135 |
animations[i].loopFrames = animations[TORSO_GESTURE].loopFrames; |
| 1136 |
animations[i].numFrames = animations[TORSO_GESTURE].numFrames; |
| 1137 |
animations[i].reversed = qfalse; |
| 1138 |
animations[i].flipflop = qfalse; |
| 1139 |
continue; |
| 1140 |
} |
| 1141 |
break; |
| 1142 |
} |
| 1143 |
animations[i].firstFrame = atoi( token ); |
| 1144 |
|
| 1145 |
if ( i == LEGS_WALKCR ) { |
| 1146 |
skip = animations[LEGS_WALKCR].firstFrame - animations[TORSO_GESTURE].firstFrame; |
| 1147 |
} |
| 1148 |
if ( i >= LEGS_WALKCR && i<TORSO_GETFLAG) { |
| 1149 |
animations[i].firstFrame -= skip; |
| 1150 |
} |
| 1151 |
|
| 1152 |
token = COM_Parse( &text_p ); |
| 1153 |
if ( !token[0] ) { |
| 1154 |
break; |
| 1155 |
} |
| 1156 |
animations[i].numFrames = atoi( token ); |
| 1157 |
|
| 1158 |
animations[i].reversed = qfalse; |
| 1159 |
animations[i].flipflop = qfalse; |
| 1160 |
|
| 1161 |
if (animations[i].numFrames < 0) { |
| 1162 |
animations[i].numFrames = -animations[i].numFrames; |
| 1163 |
animations[i].reversed = qtrue; |
| 1164 |
} |
| 1165 |
|
| 1166 |
token = COM_Parse( &text_p ); |
| 1167 |
if ( !token[0] ) { |
| 1168 |
break; |
| 1169 |
} |
| 1170 |
animations[i].loopFrames = atoi( token ); |
| 1171 |
|
| 1172 |
token = COM_Parse( &text_p ); |
| 1173 |
if ( !token[0] ) { |
| 1174 |
break; |
| 1175 |
} |
| 1176 |
fps = atof( token ); |
| 1177 |
if ( fps == 0 ) { |
| 1178 |
fps = 1; |
| 1179 |
} |
| 1180 |
animations[i].frameLerp = 1000 / fps; |
| 1181 |
animations[i].initialLerp = 1000 / fps; |
| 1182 |
} |
| 1183 |
|
| 1184 |
if ( i != MAX_ANIMATIONS ) { |
| 1185 |
Com_Printf( "Error parsing animation file: %s\n", filename ); |
| 1186 |
return qfalse; |
| 1187 |
} |
| 1188 |
|
| 1189 |
return qtrue; |
| 1190 |
} |
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
qboolean UI_RegisterClientModelname( playerInfo_t *pi, const char *modelSkinName, const char *headModelSkinName, const char *teamName ) { |
| 1198 |
char modelName[MAX_QPATH]; |
| 1199 |
char skinName[MAX_QPATH]; |
| 1200 |
char headModelName[MAX_QPATH]; |
| 1201 |
char headSkinName[MAX_QPATH]; |
| 1202 |
char filename[MAX_QPATH]; |
| 1203 |
char *slash; |
| 1204 |
|
| 1205 |
pi->torsoModel = 0; |
| 1206 |
pi->headModel = 0; |
| 1207 |
|
| 1208 |
if ( !modelSkinName[0] ) { |
| 1209 |
return qfalse; |
| 1210 |
} |
| 1211 |
|
| 1212 |
Q_strncpyz( modelName, modelSkinName, sizeof( modelName ) ); |
| 1213 |
|
| 1214 |
slash = strchr( modelName, '/' ); |
| 1215 |
if ( !slash ) { |
| 1216 |
|
| 1217 |
Q_strncpyz( skinName, "default", sizeof( skinName ) ); |
| 1218 |
} else { |
| 1219 |
Q_strncpyz( skinName, slash + 1, sizeof( skinName ) ); |
| 1220 |
*slash = '\0'; |
| 1221 |
} |
| 1222 |
|
| 1223 |
Q_strncpyz( headModelName, headModelSkinName, sizeof( headModelName ) ); |
| 1224 |
slash = strchr( headModelName, '/' ); |
| 1225 |
if ( !slash ) { |
| 1226 |
|
| 1227 |
Q_strncpyz( headSkinName, "default", sizeof( skinName ) ); |
| 1228 |
} else { |
| 1229 |
Q_strncpyz( headSkinName, slash + 1, sizeof( skinName ) ); |
| 1230 |
*slash = '\0'; |
| 1231 |
} |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower.md3", modelName ); |
| 1236 |
pi->legsModel = trap_R_RegisterModel( filename ); |
| 1237 |
if ( !pi->legsModel ) { |
| 1238 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/lower.md3", modelName ); |
| 1239 |
pi->legsModel = trap_R_RegisterModel( filename ); |
| 1240 |
if ( !pi->legsModel ) { |
| 1241 |
Com_Printf( "Failed to load model file %s\n", filename ); |
| 1242 |
return qfalse; |
| 1243 |
} |
| 1244 |
} |
| 1245 |
|
| 1246 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper.md3", modelName ); |
| 1247 |
pi->torsoModel = trap_R_RegisterModel( filename ); |
| 1248 |
if ( !pi->torsoModel ) { |
| 1249 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/upper.md3", modelName ); |
| 1250 |
pi->torsoModel = trap_R_RegisterModel( filename ); |
| 1251 |
if ( !pi->torsoModel ) { |
| 1252 |
Com_Printf( "Failed to load model file %s\n", filename ); |
| 1253 |
return qfalse; |
| 1254 |
} |
| 1255 |
} |
| 1256 |
|
| 1257 |
if (headModelName[0] == '*' ) { |
| 1258 |
Com_sprintf( filename, sizeof( filename ), "models/players/heads/%s/%s.md3", &headModelName[1], &headModelName[1] ); |
| 1259 |
} |
| 1260 |
else { |
| 1261 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/head.md3", headModelName ); |
| 1262 |
} |
| 1263 |
pi->headModel = trap_R_RegisterModel( filename ); |
| 1264 |
if ( !pi->headModel && headModelName[0] != '*') { |
| 1265 |
Com_sprintf( filename, sizeof( filename ), "models/players/heads/%s/%s.md3", headModelName, headModelName ); |
| 1266 |
pi->headModel = trap_R_RegisterModel( filename ); |
| 1267 |
} |
| 1268 |
|
| 1269 |
if (!pi->headModel) { |
| 1270 |
Com_Printf( "Failed to load model file %s\n", filename ); |
| 1271 |
return qfalse; |
| 1272 |
} |
| 1273 |
|
| 1274 |
|
| 1275 |
if ( !UI_RegisterClientSkin( pi, modelName, skinName, headModelName, headSkinName, teamName) ) { |
| 1276 |
if ( !UI_RegisterClientSkin( pi, modelName, "default", headModelName, "default", teamName ) ) { |
| 1277 |
Com_Printf( "Failed to load skin file: %s : %s\n", modelName, skinName ); |
| 1278 |
return qfalse; |
| 1279 |
} |
| 1280 |
} |
| 1281 |
|
| 1282 |
|
| 1283 |
Com_sprintf( filename, sizeof( filename ), "models/players/%s/animation.cfg", modelName ); |
| 1284 |
if ( !UI_ParseAnimationFile( filename, pi ) ) { |
| 1285 |
Com_sprintf( filename, sizeof( filename ), "models/players/characters/%s/animation.cfg", modelName ); |
| 1286 |
if ( !UI_ParseAnimationFile( filename, pi ) ) { |
| 1287 |
Com_Printf( "Failed to load animation file %s\n", filename ); |
| 1288 |
return qfalse; |
| 1289 |
} |
| 1290 |
} |
| 1291 |
|
| 1292 |
return qtrue; |
| 1293 |
} |
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
void UI_PlayerInfo_SetModel( playerInfo_t *pi, const char *model, const char *headmodel, char *teamName ) { |
| 1302 |
memset( pi, 0, sizeof(*pi) ); |
| 1303 |
UI_RegisterClientModelname( pi, model, headmodel, teamName ); |
| 1304 |
pi->weapon = WP_MACHINEGUN; |
| 1305 |
pi->currentWeapon = pi->weapon; |
| 1306 |
pi->lastWeapon = pi->weapon; |
| 1307 |
pi->pendingWeapon = WP_NUM_WEAPONS; |
| 1308 |
pi->weaponTimer = 0; |
| 1309 |
pi->chat = qfalse; |
| 1310 |
pi->newModel = qtrue; |
| 1311 |
UI_PlayerInfo_SetWeapon( pi, pi->weapon ); |
| 1312 |
} |
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
void UI_PlayerInfo_SetInfo( playerInfo_t *pi, int legsAnim, int torsoAnim, vec3_t viewAngles, vec3_t moveAngles, weapon_t weaponNumber, qboolean chat ) { |
| 1321 |
int currentAnim; |
| 1322 |
weapon_t weaponNum; |
| 1323 |
|
| 1324 |
pi->chat = chat; |
| 1325 |
|
| 1326 |
|
| 1327 |
VectorCopy( viewAngles, pi->viewAngles ); |
| 1328 |
|
| 1329 |
|
| 1330 |
VectorCopy( moveAngles, pi->moveAngles ); |
| 1331 |
|
| 1332 |
if ( pi->newModel ) { |
| 1333 |
pi->newModel = qfalse; |
| 1334 |
|
| 1335 |
jumpHeight = 0; |
| 1336 |
pi->pendingLegsAnim = 0; |
| 1337 |
UI_ForceLegsAnim( pi, legsAnim ); |
| 1338 |
pi->legs.yawAngle = viewAngles[YAW]; |
| 1339 |
pi->legs.yawing = qfalse; |
| 1340 |
|
| 1341 |
pi->pendingTorsoAnim = 0; |
| 1342 |
UI_ForceTorsoAnim( pi, torsoAnim ); |
| 1343 |
pi->torso.yawAngle = viewAngles[YAW]; |
| 1344 |
pi->torso.yawing = qfalse; |
| 1345 |
|
| 1346 |
if ( weaponNumber != WP_NUM_WEAPONS ) { |
| 1347 |
pi->weapon = weaponNumber; |
| 1348 |
pi->currentWeapon = weaponNumber; |
| 1349 |
pi->lastWeapon = weaponNumber; |
| 1350 |
pi->pendingWeapon = WP_NUM_WEAPONS; |
| 1351 |
pi->weaponTimer = 0; |
| 1352 |
UI_PlayerInfo_SetWeapon( pi, pi->weapon ); |
| 1353 |
} |
| 1354 |
|
| 1355 |
return; |
| 1356 |
} |
| 1357 |
|
| 1358 |
|
| 1359 |
if ( weaponNumber == WP_NUM_WEAPONS ) { |
| 1360 |
pi->pendingWeapon = WP_NUM_WEAPONS; |
| 1361 |
pi->weaponTimer = 0; |
| 1362 |
} |
| 1363 |
else if ( weaponNumber != WP_NONE ) { |
| 1364 |
pi->pendingWeapon = weaponNumber; |
| 1365 |
pi->weaponTimer = dp_realtime + UI_TIMER_WEAPON_DELAY; |
| 1366 |
} |
| 1367 |
weaponNum = pi->lastWeapon; |
| 1368 |
pi->weapon = weaponNum; |
| 1369 |
|
| 1370 |
if ( torsoAnim == BOTH_DEATH1 || legsAnim == BOTH_DEATH1 ) { |
| 1371 |
torsoAnim = legsAnim = BOTH_DEATH1; |
| 1372 |
pi->weapon = pi->currentWeapon = WP_NONE; |
| 1373 |
UI_PlayerInfo_SetWeapon( pi, pi->weapon ); |
| 1374 |
|
| 1375 |
jumpHeight = 0; |
| 1376 |
pi->pendingLegsAnim = 0; |
| 1377 |
UI_ForceLegsAnim( pi, legsAnim ); |
| 1378 |
|
| 1379 |
pi->pendingTorsoAnim = 0; |
| 1380 |
UI_ForceTorsoAnim( pi, torsoAnim ); |
| 1381 |
|
| 1382 |
return; |
| 1383 |
} |
| 1384 |
|
| 1385 |
|
| 1386 |
currentAnim = pi->legsAnim & ~ANIM_TOGGLEBIT; |
| 1387 |
if ( legsAnim != LEGS_JUMP && ( currentAnim == LEGS_JUMP || currentAnim == LEGS_LAND ) ) { |
| 1388 |
pi->pendingLegsAnim = legsAnim; |
| 1389 |
} |
| 1390 |
else if ( legsAnim != currentAnim ) { |
| 1391 |
jumpHeight = 0; |
| 1392 |
pi->pendingLegsAnim = 0; |
| 1393 |
UI_ForceLegsAnim( pi, legsAnim ); |
| 1394 |
} |
| 1395 |
|
| 1396 |
|
| 1397 |
if ( torsoAnim == TORSO_STAND || torsoAnim == TORSO_STAND2 ) { |
| 1398 |
if ( weaponNum == WP_NONE || weaponNum == WP_GAUNTLET ) { |
| 1399 |
torsoAnim = TORSO_STAND2; |
| 1400 |
} |
| 1401 |
else { |
| 1402 |
torsoAnim = TORSO_STAND; |
| 1403 |
} |
| 1404 |
} |
| 1405 |
|
| 1406 |
if ( torsoAnim == TORSO_ATTACK || torsoAnim == TORSO_ATTACK2 ) { |
| 1407 |
if ( weaponNum == WP_NONE || weaponNum == WP_GAUNTLET ) { |
| 1408 |
torsoAnim = TORSO_ATTACK2; |
| 1409 |
} |
| 1410 |
else { |
| 1411 |
torsoAnim = TORSO_ATTACK; |
| 1412 |
} |
| 1413 |
pi->muzzleFlashTime = dp_realtime + UI_TIMER_MUZZLE_FLASH; |
| 1414 |
|
| 1415 |
} |
| 1416 |
|
| 1417 |
currentAnim = pi->torsoAnim & ~ANIM_TOGGLEBIT; |
| 1418 |
|
| 1419 |
if ( weaponNum != pi->currentWeapon || currentAnim == TORSO_RAISE || currentAnim == TORSO_DROP ) { |
| 1420 |
pi->pendingTorsoAnim = torsoAnim; |
| 1421 |
} |
| 1422 |
else if ( ( currentAnim == TORSO_GESTURE || currentAnim == TORSO_ATTACK ) && ( torsoAnim != currentAnim ) ) { |
| 1423 |
pi->pendingTorsoAnim = torsoAnim; |
| 1424 |
} |
| 1425 |
else if ( torsoAnim != currentAnim ) { |
| 1426 |
pi->pendingTorsoAnim = 0; |
| 1427 |
UI_ForceTorsoAnim( pi, torsoAnim ); |
| 1428 |
} |
| 1429 |
} |