// ui_player.c #define CG_PLAYERS_CPP #include "ui_local.h" #include "ui_playerinfo.h" #include "..\game\weapons.h" #define UI_TIMER_GESTURE 2300 #define UI_TIMER_JUMP 1000 #define UI_TIMER_LAND 130 #define UI_TIMER_WEAPON_SWITCH 300 #define UI_TIMER_ATTACK 500 #define UI_TIMER_MUZZLE_FLASH 20 #define UI_TIMER_WEAPON_DELAY 250 #define JUMP_HEIGHT 56 #define SWINGSPEED 0.3f #define SPIN_SPEED 0.9f #define COAST_TIME 1000 static int dp_realtime; static float jumpHeight; qboolean G_ParseString( char **data, char **s ) { *s = COM_ParseExt( data, qfalse ); if ( s[0] == 0 ) { // gi.Printf( "unexpected EOF\n" ); return qtrue; } return qfalse; } qboolean G_ParseInt( char **data, int *i ) { char *token; token = COM_ParseExt( data, qfalse ); if ( token[0] == 0 ) { // gi.Printf( "unexpected EOF\n" ); return qtrue; } *i = atoi( token ); return qfalse; } qboolean G_ParseFloat( char **data, float *f ) { char *token; token = COM_ParseExt( data, qfalse ); if ( token[0] == 0 ) { // gi.Printf( "unexpected EOF\n" ); return qtrue; } *f = atof( token ); return qfalse; } /* =============== UI_PlayerInfo_SetWeapon =============== */ static void UI_PlayerInfo_SetWeapon( playerInfo_t *pi, weapon_t weaponNum ) { // gitem_t * item; char path[MAX_QPATH]; pi->currentWeapon = weaponNum; if ( weaponNum == WP_NONE ) { pi->weaponModel = 0; pi->flashModel = 0; return; } /* for ( item = bg_itemlist + 1; item->classname ; item++ ) { if ( item->giType != IT_WEAPON ) { continue; } if ( item->giTag == weaponNum ) { break; } } if ( !item->classname ) { return; } */ strcpy( path, weaponData[weaponNum].weaponMdl ); COM_StripExtension( path, path ); strcat( path, "_w.md3" ); pi->weaponModel = ui.R_RegisterModel( path ); strcpy( path, weaponData[weaponNum].weaponMdl ); COM_StripExtension( path, path ); strcat( path, "_flash.md3" ); pi->flashModel = ui.R_RegisterModel( path ); } /* =============== UI_ForceLegsAnim =============== */ static void UI_ForceLegsAnim( playerInfo_t *pi, int anim ) { pi->legsAnim = ( ( pi->legsAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; if ( anim == BOTH_JUMP1 ) { pi->legsAnimationTimer = UI_TIMER_JUMP; } } /* =============== UI_SetLegsAnim =============== */ static void UI_SetLegsAnim( playerInfo_t *pi, int anim ) { if ( pi->pendingLegsAnim ) { anim = pi->pendingLegsAnim; pi->pendingLegsAnim = 0; } UI_ForceLegsAnim( pi, anim ); } /* =============== UI_ForceTorsoAnim =============== */ static void UI_ForceTorsoAnim( playerInfo_t *pi, int anim ) { pi->torsoAnim = ( ( pi->torsoAnim & ANIM_TOGGLEBIT ) ^ ANIM_TOGGLEBIT ) | anim; if ( anim == BOTH_GESTURE1 ) { pi->torsoAnimationTimer = UI_TIMER_GESTURE; } if ( anim == BOTH_ATTACK1 || anim == BOTH_ATTACK2 ) { pi->torsoAnimationTimer = UI_TIMER_ATTACK; } } /* =============== UI_SetTorsoAnim =============== */ static void UI_SetTorsoAnim( playerInfo_t *pi, int anim ) { if ( pi->pendingTorsoAnim ) { anim = pi->pendingTorsoAnim; pi->pendingTorsoAnim = 0; } UI_ForceTorsoAnim( pi, anim ); } /* =============== UI_TorsoSequencing =============== */ static void UI_TorsoSequencing( playerInfo_t *pi ) { int currentAnim; currentAnim = pi->torsoAnim & ~ANIM_TOGGLEBIT; if ( pi->weapon != pi->currentWeapon ) { if ( currentAnim != TORSO_DROPWEAP1 ) { pi->torsoAnimationTimer = UI_TIMER_WEAPON_SWITCH; UI_ForceTorsoAnim( pi, TORSO_DROPWEAP1 ); } } if ( pi->torsoAnimationTimer > 0 ) { return; } if( currentAnim == BOTH_GESTURE1 ) { UI_SetTorsoAnim( pi, BOTH_STAND1 ); return; } if( currentAnim == BOTH_ATTACK1 || currentAnim == BOTH_ATTACK2 ) { UI_SetTorsoAnim( pi, BOTH_STAND1 ); return; } if ( currentAnim == TORSO_DROPWEAP1 ) { UI_PlayerInfo_SetWeapon( pi, pi->weapon ); pi->torsoAnimationTimer = UI_TIMER_WEAPON_SWITCH; UI_ForceTorsoAnim( pi, TORSO_RAISEWEAP1 ); return; } if ( currentAnim == TORSO_RAISEWEAP1 ) { UI_SetTorsoAnim( pi, BOTH_STAND1 ); return; } } /* =============== UI_LegsSequencing =============== */ static void UI_LegsSequencing( playerInfo_t *pi ) { int currentAnim; currentAnim = pi->legsAnim & ~ANIM_TOGGLEBIT; if ( pi->legsAnimationTimer > 0 ) { if ( currentAnim == BOTH_JUMP1 ) { jumpHeight = JUMP_HEIGHT * sin( M_PI * ( UI_TIMER_JUMP - pi->legsAnimationTimer ) / UI_TIMER_JUMP ); } return; } if ( currentAnim == BOTH_JUMP1 ) { UI_ForceLegsAnim( pi, BOTH_LAND1 ); UI_ForceTorsoAnim( pi, BOTH_STAND1 ); pi->legsAnimationTimer = UI_TIMER_LAND; jumpHeight = 0; return; } if ( currentAnim == BOTH_LAND1 ) { UI_SetLegsAnim( pi, BOTH_STAND1 ); return; } } /* ====================== UI_PositionEntityOnTag ====================== */ static void UI_PositionEntityOnTag( refEntity_t *entity, const refEntity_t *parent, clipHandle_t parentModel, char *tagName ) { int i; orientation_t lerped; // lerp the tag ui.R_LerpTag( &lerped, parentModel, parent->oldframe, parent->frame, 1.0 - parent->backlerp, tagName ); // FIXME: allow origin offsets along tag? VectorCopy( parent->origin, entity->origin ); for ( i = 0 ; i < 3 ; i++ ) { VectorMA( entity->origin, lerped.origin[i], parent->axis[i], entity->origin ); } // cast away const because of compiler problems MatrixMultiply( lerped.axis, ((refEntity_t*)parent)->axis, entity->axis ); entity->backlerp = parent->backlerp; } /* ====================== UI_PositionRotatedEntityOnTag ====================== */ static void UI_PositionRotatedEntityOnTag( refEntity_t *entity, const refEntity_t *parent, qhandle_t parentModel, char *tagName ) { int i; orientation_t lerped; vec3_t tempAxis[3]; // lerp the tag ui.R_LerpTag( &lerped, parentModel, parent->oldframe, parent->frame, 1.0 - parent->backlerp, tagName ); // FIXME: allow origin offsets along tag? VectorCopy( parent->origin, entity->origin ); for ( i = 0 ; i < 3 ; i++ ) { VectorMA( entity->origin, lerped.origin[i], parent->axis[i], entity->origin ); } // cast away const because of compiler problems MatrixMultiply( entity->axis, ((refEntity_t *)parent)->axis, tempAxis ); MatrixMultiply( lerped.axis, tempAxis, entity->axis ); } /* =============== UI_SetLerpFrameAnimation =============== */ static void UI_SetLerpFrameAnimation( playerInfo_t *ci, lerpFrame_t *lf, int newAnimation ) { animation_t *anim; lf->animationNumber = newAnimation; newAnimation &= ~ANIM_TOGGLEBIT; if ( newAnimation < 0 || newAnimation >= MAX_ANIMATIONS ) { ui.Error( ERR_FATAL, "Bad animation number: %i", newAnimation ); } anim = &ci->animations[ newAnimation ]; lf->animation = anim; lf->animationTime = lf->frameTime + anim->initialLerp; } /* =============== UI_RunLerpFrame =============== */ static void UI_RunLerpFrame( playerInfo_t *ci, lerpFrame_t *lf, int newAnimation ) { int f; animation_t *anim; // see if the animation sequence is switching if ( newAnimation != lf->animationNumber || !lf->animation ) { UI_SetLerpFrameAnimation( ci, lf, newAnimation ); } // if we have passed the current frame, move it to // oldFrame and calculate a new frame if ( dp_realtime >= lf->frameTime ) { lf->oldFrame = lf->frame; lf->oldFrameTime = lf->frameTime; // get the next frame based on the animation anim = lf->animation; if ( dp_realtime < lf->animationTime ) { lf->frameTime = lf->animationTime; // initial lerp } else { lf->frameTime = lf->oldFrameTime + fabs(anim->frameLerp); } f = ( lf->frameTime - lf->animationTime ) / fabs(anim->frameLerp); if ( f >= anim->numFrames ) {//Reached the end of the anim f -= anim->numFrames; if ( anim->loopFrames != -1 ) //Before 0 meant no loop { // f = anim->loopFrames;//Frame to loop back to if(anim->numFrames - anim->loopFrames == 0) { f %= anim->numFrames; } else { f %= (anim->numFrames - anim->loopFrames); } f += anim->loopFrames; } else { f = anim->numFrames - 1; // the animation is stuck at the end, so it // can immediately transition to another sequence lf->frameTime = dp_realtime; } } if ( anim->frameLerp < 0 ) { lf->frame = anim->firstFrame + anim->numFrames - 1 - f; } else { lf->frame = anim->firstFrame +f; } if ( dp_realtime > lf->frameTime ) { lf->frameTime = dp_realtime; } } if ( lf->frameTime > dp_realtime + 200 ) { lf->frameTime = dp_realtime; } if ( lf->oldFrameTime > dp_realtime ) { lf->oldFrameTime = dp_realtime; } // calculate current lerp value if ( lf->frameTime == lf->oldFrameTime ) { lf->backlerp = 0; } else { lf->backlerp = 1.0 - (float)( dp_realtime - lf->oldFrameTime ) / ( lf->frameTime - lf->oldFrameTime ); } } /* =============== UI_PlayerAnimation =============== */ static void UI_PlayerAnimation( playerInfo_t *pi, int *legsOld, int *legs, float *legsBackLerp, int *torsoOld, int *torso, float *torsoBackLerp ) { // legs animation pi->legsAnimationTimer -= uis.frametime; if ( pi->legsAnimationTimer < 0 ) { pi->legsAnimationTimer = 0; } UI_LegsSequencing( pi ); if ( pi->legs.yawing && ( pi->legsAnim & ~ANIM_TOGGLEBIT ) == BOTH_STAND1 ) { UI_RunLerpFrame( pi, &pi->legs, LEGS_TURN1 ); } else { UI_RunLerpFrame( pi, &pi->legs, pi->legsAnim ); } *legsOld = pi->legs.oldFrame; *legs = pi->legs.frame; *legsBackLerp = pi->legs.backlerp; // torso animation pi->torsoAnimationTimer -= uis.frametime; if ( pi->torsoAnimationTimer < 0 ) { pi->torsoAnimationTimer = 0; } UI_TorsoSequencing( pi ); UI_RunLerpFrame( pi, &pi->torso, pi->torsoAnim ); *torsoOld = pi->torso.oldFrame; *torso = pi->torso.frame; *torsoBackLerp = pi->torso.backlerp; } /* ================== UI_SwingAngles ================== */ static void UI_SwingAngles( float destination, float swingTolerance, float clampTolerance, float speed, float *angle, qboolean *swinging ) { float swing; float move; float scale; if ( !*swinging ) { // see if a swing should be started swing = AngleSubtract( *angle, destination ); if ( swing > swingTolerance || swing < -swingTolerance ) { *swinging = qtrue; } } if ( !*swinging ) { return; } // modify the speed depending on the delta // so it doesn't seem so linear swing = AngleSubtract( destination, *angle ); scale = fabs( swing ); if ( scale < swingTolerance * 0.5 ) { scale = 0.5; } else if ( scale < swingTolerance ) { scale = 1.0; } else { scale = 2.0; } // swing towards the destination angle if ( swing >= 0 ) { move = uis.frametime * scale * speed; if ( move >= swing ) { move = swing; *swinging = qfalse; } *angle = AngleMod( *angle + move ); } else if ( swing < 0 ) { move = uis.frametime * scale * -speed; if ( move <= swing ) { move = swing; *swinging = qfalse; } *angle = AngleMod( *angle + move ); } // clamp to no more than tolerance swing = AngleSubtract( destination, *angle ); if ( swing > clampTolerance ) { *angle = AngleMod( destination - (clampTolerance - 1) ); } else if ( swing < -clampTolerance ) { *angle = AngleMod( destination + (clampTolerance - 1) ); } } /* ====================== UI_MovedirAdjustment ====================== */ static float UI_MovedirAdjustment( playerInfo_t *pi ) { vec3_t relativeAngles; vec3_t moveVector; VectorSubtract( pi->viewAngles, pi->moveAngles, relativeAngles ); AngleVectors( relativeAngles, moveVector, NULL, NULL ); if ( Q_fabs( moveVector[0] ) < 0.01 ) { moveVector[0] = 0.0; } if ( Q_fabs( moveVector[1] ) < 0.01 ) { moveVector[1] = 0.0; } if ( moveVector[1] == 0 && moveVector[0] > 0 ) { return 0; } if ( moveVector[1] < 0 && moveVector[0] > 0 ) { return 22; } if ( moveVector[1] < 0 && moveVector[0] == 0 ) { return 45; } if ( moveVector[1] < 0 && moveVector[0] < 0 ) { return -22; } if ( moveVector[1] == 0 && moveVector[0] < 0 ) { return 0; } if ( moveVector[1] > 0 && moveVector[0] < 0 ) { return 22; } if ( moveVector[1] > 0 && moveVector[0] == 0 ) { return -45; } return -22; } /* =============== UI_PlayerAngles =============== */ static void UI_PlayerAngles( playerInfo_t *pi, vec3_t legs[3], vec3_t torso[3], vec3_t head[3] ) { vec3_t legsAngles, torsoAngles, headAngles; float dest; float adjust; VectorCopy( pi->viewAngles, headAngles ); headAngles[YAW] = AngleMod( headAngles[YAW] ); VectorClear( legsAngles ); VectorClear( torsoAngles ); // --------- yaw ------------- // allow yaw to drift a bit if ( ( pi->legsAnim & ~ANIM_TOGGLEBIT ) != BOTH_STAND1 || ( pi->torsoAnim & ~ANIM_TOGGLEBIT ) != BOTH_STAND1 ) { // if not standing still, always point all in the same direction pi->torso.yawing = qtrue; // always center pi->torso.pitching = qtrue; // always center pi->legs.yawing = qtrue; // always center } // adjust legs for movement dir adjust = UI_MovedirAdjustment( pi ); legsAngles[YAW] = headAngles[YAW] + adjust; torsoAngles[YAW] = headAngles[YAW] + 0.25 * adjust; // torso UI_SwingAngles( torsoAngles[YAW], 25, 90, SWINGSPEED, &pi->torso.yawAngle, &pi->torso.yawing ); UI_SwingAngles( legsAngles[YAW], 40, 90, SWINGSPEED, &pi->legs.yawAngle, &pi->legs.yawing ); torsoAngles[YAW] = pi->torso.yawAngle; legsAngles[YAW] = pi->legs.yawAngle; // --------- pitch ------------- // only show a fraction of the pitch angle in the torso if ( headAngles[PITCH] > 180 ) { dest = (-360 + headAngles[PITCH]) * 0.75; } else { dest = headAngles[PITCH] * 0.75; } UI_SwingAngles( dest, 15, 30, 0.1f, &pi->torso.pitchAngle, &pi->torso.pitching ); torsoAngles[PITCH] = pi->torso.pitchAngle; // pull the angles back out of the hierarchial chain AnglesSubtract( headAngles, torsoAngles, headAngles ); AnglesSubtract( torsoAngles, legsAngles, torsoAngles ); AnglesToAxis( legsAngles, legs ); AnglesToAxis( torsoAngles, torso ); if (pi->looking) { //find the mouse and look at it! if (uis.cursorx > pi->looking) { headAngles[YAW] = -45; } } AnglesToAxis( headAngles, head ); } /* =============== UI_PlayerFloatSprite =============== */ static void UI_PlayerFloatSprite( playerInfo_t *pi, vec3_t origin, qhandle_t shader ) { refEntity_t ent; memset( &ent, 0, sizeof( ent ) ); VectorCopy( origin, ent.origin ); ent.origin[2] += 48; ent.reType = RT_SPRITE; ent.customShader = shader; ent.radius = 10; ent.renderfx = 0; ui.R_AddRefEntityToScene( &ent ); } /* =============== UI_DrawPlayer =============== */ void UI_DrawPlayer( float x, float y, float w, float h, playerInfo_t *pi, int time ) { refdef_t refdef; refEntity_t legs; refEntity_t torso; refEntity_t head; refEntity_t gun; refEntity_t flash; vec3_t origin; int renderfx; vec3_t mins = {-16, -16, -24}; vec3_t maxs = {16, 16, 32}; float len; float xx; // if ( !pi->legsModel || !pi->torsoModel || !pi->headModel || !pi->animations[0].numFrames ) { // return; // } if (!pi->animations[0].numFrames ) { return; } dp_realtime = time; if ( pi->pendingWeapon != -1 && dp_realtime > pi->weaponTimer ) { pi->weapon = pi->pendingWeapon; pi->lastWeapon = pi->pendingWeapon; pi->pendingWeapon = (weapon_t) -1; pi->weaponTimer = 0; } UI_AdjustFrom640( &x, &y, &w, &h ); y -= jumpHeight; memset( &refdef, 0, sizeof( refdef ) ); memset( &legs, 0, sizeof(legs) ); memset( &torso, 0, sizeof(torso) ); memset( &head, 0, sizeof(head) ); refdef.rdflags = RDF_NOWORLDMODEL; AxisClear( refdef.viewaxis ); refdef.x = x; refdef.y = y; refdef.width = w; refdef.height = h; refdef.fov_x = (int)((float)refdef.width / 640.0f * 90.0f); xx = refdef.width / tan( refdef.fov_x / 360 * M_PI ); refdef.fov_y = atan2( refdef.height, xx ); refdef.fov_y *= (float)( 360.0f / M_PI ); // calculate distance so the player nearly fills the box len = 0.7 * ( maxs[2] - mins[2] ); origin[0] = len / tan( DEG2RAD(refdef.fov_x) * 0.5 ); origin[1] = 0.5 * ( mins[1] + maxs[1] ); origin[2] = -0.5 * ( mins[2] + maxs[2] ); refdef.time = dp_realtime; ui.R_ClearScene(); // get the rotation information UI_PlayerAngles( pi, legs.axis, torso.axis, head.axis ); // get the animation state (after rotation, to allow feet shuffle) UI_PlayerAnimation( pi, &legs.oldframe, &legs.frame, &legs.backlerp, &torso.oldframe, &torso.frame, &torso.backlerp ); renderfx = RF_LIGHTING_ORIGIN | RF_NOSHADOW; // // add the legs // legs.hModel = pi->legsModel; legs.customSkin = pi->legsSkin; VectorCopy( origin, legs.origin ); VectorCopy( origin, legs.lightingOrigin ); legs.renderfx = renderfx; VectorCopy (legs.origin, legs.oldorigin); ui.R_AddRefEntityToScene( &legs ); if (!legs.hModel) { return; } // // add the torso // torso.hModel = pi->torsoModel; if (!torso.hModel) { return; } torso.customSkin = pi->torsoSkin; VectorCopy( origin, torso.lightingOrigin ); UI_PositionRotatedEntityOnTag( &torso, &legs, pi->legsModel, "tag_torso"); torso.renderfx = renderfx; ui.R_AddRefEntityToScene( &torso ); // // add the head // head.hModel = pi->headModel; if (head.hModel) { head.customSkin = pi->headSkin; VectorCopy( origin, head.lightingOrigin ); UI_PositionRotatedEntityOnTag( &head, &torso, pi->torsoModel, "tag_head"); head.renderfx = renderfx; ui.R_AddRefEntityToScene( &head ); } // // add the gun // if ( pi->currentWeapon != WP_NONE ) { memset( &gun, 0, sizeof(gun) ); gun.hModel = pi->weaponModel; VectorCopy( origin, gun.lightingOrigin ); UI_PositionEntityOnTag( &gun, &torso, pi->torsoModel, "tag_weapon"); gun.renderfx = renderfx; ui.R_AddRefEntityToScene( &gun ); } // // add muzzle flash // if ( dp_realtime <= pi->muzzleFlashTime ) { if ( pi->flashModel ) { memset( &flash, 0, sizeof(flash) ); flash.hModel = pi->flashModel; VectorCopy( origin, flash.lightingOrigin ); UI_PositionEntityOnTag( &flash, &gun, pi->weaponModel, "tag_flash"); flash.renderfx = renderfx; ui.R_AddRefEntityToScene( &flash ); } // make a dlight for the flash if ( pi->flashDlightColor[0] || pi->flashDlightColor[1] || pi->flashDlightColor[2] ) { ui.R_AddLightToScene( flash.origin, 200 + (rand()&31), pi->flashDlightColor[0], pi->flashDlightColor[1], pi->flashDlightColor[2] ); } } // // add the chat icon // if ( pi->chat ) { UI_PlayerFloatSprite( pi, origin, ui.R_RegisterShader( "sprites/balloon3" ) ); } // // add an accent light // origin[0] -= 100; // + = behind, - = in front origin[1] += 100; // + = left, - = right origin[2] += 100; // + = above, - = below ui.R_AddLightToScene( origin, 500, 1.0, 1.0, 1.0 ); origin[0] -= 100; origin[1] -= 100; origin[2] -= 100; ui.R_AddLightToScene( origin, 500, 1.0, 0.0, 0.0 ); ui.R_RenderScene( &refdef ); } /* ========================== UI_RegisterClientSkin ========================== */ static qboolean UI_RegisterClientSkin( playerInfo_t *pi, const char *modelName, const char *skinName, const char *headmodelName, const char *headskinName ) { char filename[MAX_QPATH]; Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower_%s.skin", modelName, skinName ); pi->legsSkin = ui.R_RegisterSkin( filename ); Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper_%s.skin", modelName, skinName ); pi->torsoSkin = ui.R_RegisterSkin( filename); if (Q_stricmp(headmodelName,"NONE")) // A head was specified { Com_sprintf( filename, sizeof( filename ), "models/players/%s/head_%s.skin", headmodelName, headskinName ); pi->headSkin = ui.R_RegisterSkin( filename); if (pi->headSkin<0) { pi->headSkin = -pi->headSkin; //has talking frames } if ( !pi->legsSkin || !pi->torsoSkin || !pi->headSkin ) { return qfalse; } } return qtrue; } /* ====================== UI_ParseAnimationFile Read a configuration file containing animation counts and rates ====================== */ static qboolean UI_ParseAnimationFile( const char *filename, animation_t *animations ) { char *text_p; int len; int i; char *token; float fps; int skip; char text[20000]; fileHandle_t f; int animNum; memset( animations, 0, sizeof( animation_t ) * MAX_ANIMATIONS ); // load the file len = ui.FS_FOpenFile( filename, &f, FS_READ ); if ( len <= 0 ) { return qfalse; } if ( len >= ( sizeof( text ) - 1 ) ) { Com_Printf( "File %s too long\n", filename ); return qfalse; } ui.FS_Read( text, len, f ); text[len] = 0; ui.FS_FCloseFile( f ); // parse the text text_p = text; skip = 0; // quite the compiler warning //initialize anim array so that from 0 to MAX_ANIMATIONS, set default values of 0 1 0 100 for(i = 0; i < MAX_ANIMATIONS; i++) { animations[i].firstFrame = 0; animations[i].numFrames = 1; animations[i].loopFrames = -1; animations[i].frameLerp = 100; animations[i].initialLerp = 100; } // read information for each frame while(1) { token = COM_Parse( &text_p ); if ( !token || !token[0]) { break; } animNum = GetIDForString(animTable, token); if(animNum == -1) { continue; } token = COM_Parse( &text_p ); if ( !token ) { break; } animations[animNum].firstFrame = atoi( token ); token = COM_Parse( &text_p ); if ( !token ) { break; } animations[animNum].numFrames = atoi( token ); token = COM_Parse( &text_p ); if ( !token ) { break; } animations[animNum].loopFrames = atoi( token ); token = COM_Parse( &text_p ); if ( !token ) { break; } fps = atof( token ); if ( fps == 0 ) { fps = 1;//Don't allow divide by zero error } if ( fps < 0 ) {//backwards animations[animNum].frameLerp = floor(1000.0f / fps); } else { animations[animNum].frameLerp = ceil(1000.0f / fps); } animations[animNum].initialLerp = ceil(1000.0f / fabs(fps)); } // if ( i != MAX_ANIMATIONS ) { // Com_Printf( S_COLOR_RED"Error parsing animation file: %s", filename ); // return qfalse; // } return qtrue; } /* ========================== UI_RegisterClientModelname ========================== */ qboolean UI_RegisterClientModelname( playerInfo_t *pi, const char *modelSkinName, const char* headmodelSkinName ) { char modelName[MAX_QPATH]; char skinName[MAX_QPATH]; char headmodelName[MAX_QPATH]; char headskinName[MAX_QPATH]; char filename[MAX_QPATH]; char *slash; pi->legsModel = 0; pi->torsoModel = 0; pi->headModel = 0; if ( !modelSkinName[0] ) { return qfalse; } Q_strncpyz( modelName, modelSkinName, sizeof( modelName ) ); slash = strchr( modelName, '/' ); if ( !slash ) { // modelName did not include a skin name Q_strncpyz( skinName, "default", sizeof( skinName ) ); } else { Q_strncpyz( skinName, slash + 1, sizeof( skinName ) ); // truncate modelName *slash = 0; } Com_sprintf( filename, sizeof( filename ), "models/players/%s/lower.mdr", modelName ); pi->legsModel = ui.R_RegisterModel( filename ); if ( !pi->legsModel ) { Com_Printf( "Failed to load model file %s\n", filename ); return qfalse; } Com_sprintf( filename, sizeof( filename ), "models/players/%s/upper.mdr", modelName ); pi->torsoModel = ui.R_RegisterModel( filename ); if ( !pi->torsoModel ) { Com_Printf( "Failed to load model file %s\n", filename ); return qfalse; } Q_strncpyz( headmodelName, headmodelSkinName, sizeof( headmodelName ) ); if (Q_stricmp(headmodelName,"NONE")) // A head was specified { slash = strchr( headmodelName, '/' ); if ( !slash ) { // modelName did not include a skin name Q_strncpyz( headskinName, "default", sizeof( headskinName ) ); } else { Q_strncpyz( headskinName, slash + 1, sizeof( headskinName ) ); // truncate modelName *slash = 0; } Com_sprintf( filename, sizeof( filename ), "models/players/%s/head.md3", headmodelName ); pi->headModel = ui.R_RegisterModel( filename ); if ( !pi->headModel ) { Com_Printf( "Failed to load model file %s\n", filename ); return qfalse; } } // if any skins failed to load, fall back to default if ( !UI_RegisterClientSkin( pi, modelName, skinName, headmodelName, headskinName ) ) { if ( !UI_RegisterClientSkin( pi, modelName, "default", headmodelName, "default" ) ) { Com_Printf( "Failed to load skin file: %s : %s\n", modelName, skinName ); return qfalse; } } // load the animations Com_sprintf( filename, sizeof( filename ), "models/players/%s/animation.cfg", modelName ); if ( !UI_ParseAnimationFile( filename, pi->animations ) ) { Com_Printf( "Failed to load animation file %s\n", filename ); return qfalse; } return qtrue; } /* =============== UI_PlayerInfo_SetModel =============== */ void UI_PlayerInfo_SetModel( playerInfo_t *pi, const char *model, const char* headmodel ) { memset( pi, 0, sizeof(*pi) ); UI_RegisterClientModelname( pi, model, headmodel ); pi->weapon = WP_PHASER; pi->currentWeapon = pi->weapon; pi->lastWeapon = pi->weapon; pi->pendingWeapon = (weapon_t) -1; pi->weaponTimer = 0; pi->chat = qfalse; UI_PlayerInfo_SetWeapon( pi, pi->weapon ); } /* =============== UI_PlayerInfo_SetInfo =============== */ void UI_PlayerInfo_SetInfo( playerInfo_t *pi, int legsAnim, int torsoAnim, vec3_t viewAngles, vec3_t moveAngles, weapon_t weaponNumber, qboolean chat ) { int currentAnim; weapon_t weaponNum; pi->chat = chat; // view angles VectorCopy( viewAngles, pi->viewAngles ); // move angles VectorCopy( moveAngles, pi->moveAngles ); // weapon if ( weaponNumber == -1 ) { pi->pendingWeapon = (weapon_t) -1; pi->weaponTimer = 0; } else if ( weaponNumber != WP_NONE ) { pi->pendingWeapon = weaponNumber; pi->weaponTimer = dp_realtime + UI_TIMER_WEAPON_DELAY; } weaponNum = pi->lastWeapon; pi->weapon = weaponNum; if ( torsoAnim == BOTH_DEATH1 || legsAnim == BOTH_DEATH1 ) { torsoAnim = legsAnim = BOTH_DEATH1; pi->weapon = pi->currentWeapon = WP_NONE; UI_PlayerInfo_SetWeapon( pi, pi->weapon ); jumpHeight = 0; pi->pendingLegsAnim = 0; UI_ForceLegsAnim( pi, legsAnim ); pi->pendingTorsoAnim = 0; UI_ForceTorsoAnim( pi, torsoAnim ); return; } // leg animation currentAnim = pi->legsAnim & ~ANIM_TOGGLEBIT; if ( legsAnim != BOTH_JUMP1 && ( currentAnim == BOTH_JUMP1 || currentAnim == BOTH_LAND1 ) ) { pi->pendingLegsAnim = legsAnim; } else if ( legsAnim != currentAnim ) { jumpHeight = 0; pi->pendingLegsAnim = 0; UI_ForceLegsAnim( pi, legsAnim ); } // torso animation if ( torsoAnim == BOTH_STAND1 || torsoAnim == BOTH_STAND2 ) { if ( weaponNum == WP_NONE || weaponNum == WP_PHASER ) { torsoAnim = BOTH_STAND1; } else { torsoAnim = BOTH_STAND2; } } if ( torsoAnim == BOTH_ATTACK1 || torsoAnim == BOTH_ATTACK2 ) { if ( weaponNum == WP_NONE || weaponNum == WP_PHASER ) { torsoAnim = BOTH_ATTACK1; } else { torsoAnim = BOTH_ATTACK2; } pi->muzzleFlashTime = dp_realtime + UI_TIMER_MUZZLE_FLASH; } currentAnim = pi->torsoAnim & ~ANIM_TOGGLEBIT; if ( weaponNum != pi->currentWeapon || currentAnim == TORSO_RAISEWEAP1 || currentAnim == TORSO_DROPWEAP1) { pi->pendingTorsoAnim = torsoAnim; } else if ( ( currentAnim == BOTH_GESTURE1 || currentAnim == BOTH_ATTACK1 ) && ( torsoAnim != currentAnim ) ) { pi->pendingTorsoAnim = torsoAnim; } else if ( torsoAnim != currentAnim ) { pi->pendingTorsoAnim = 0; UI_ForceTorsoAnim( pi, torsoAnim ); } }