const char* CCSPlayerAnimState::GetWeaponSuffix() { VPROF( "CCSPlayerAnimState::GetWeaponSuffix" ); // Figure out the weapon suffix. CWeaponCSBase *pWeapon = m_pHelpers->CSAnim_GetActiveWeapon(); if ( !pWeapon ) return 0; const char *pSuffix = pWeapon->GetCSWpnData().m_szAnimExtension; #ifdef CS_SHIELD_ENABLED if ( m_pOuter->HasShield() == true ) { if ( m_pOuter->IsShieldDrawn() == true ) pSuffix = "shield"; else pSuffix = "shield_undeployed"; } #endif return pSuffix; }
int CCSPlayerAnimState::CalcReloadLayerSequence( PlayerAnimEvent_t event ) { if ( m_delayedFire != PLAYERANIMEVENT_COUNT ) return -1; const char *weaponSuffix = GetWeaponSuffix(); if ( !weaponSuffix ) return -1; CWeaponCSBase *pWeapon = m_pHelpers->CSAnim_GetActiveWeapon(); if ( !pWeapon ) return -1; const char *prefix = ""; switch ( GetCurrentMainSequenceActivity() ) { case ACT_PLAYER_RUN_FIRE: case ACT_RUN: prefix = "run"; break; case ACT_PLAYER_WALK_FIRE: case ACT_WALK: prefix = "walk"; break; case ACT_PLAYER_CROUCH_FIRE: case ACT_CROUCHIDLE: prefix = "crouch_idle"; break; case ACT_PLAYER_CROUCH_WALK_FIRE: case ACT_RUN_CROUCH: prefix = "crouch_walk"; break; default: case ACT_PLAYER_IDLE_FIRE: prefix = "idle"; break; } const char *reloadSuffix = ""; switch ( event ) { case PLAYERANIMEVENT_RELOAD_START: reloadSuffix = "_start"; break; case PLAYERANIMEVENT_RELOAD_LOOP: reloadSuffix = "_loop"; break; case PLAYERANIMEVENT_RELOAD_END: reloadSuffix = "_end"; break; } // First, look for <prefix>_reload_<weapon name><_start|_loop|_end>. char szName[512]; Q_snprintf( szName, sizeof( szName ), "%s_reload_%s%s", prefix, weaponSuffix, reloadSuffix ); int iReloadSequence = m_pOuter->LookupSequence( szName ); if ( iReloadSequence != -1 ) return iReloadSequence; // Next, look for reload_<weapon name><_start|_loop|_end>. Q_snprintf( szName, sizeof( szName ), "reload_%s%s", weaponSuffix, reloadSuffix ); iReloadSequence = m_pOuter->LookupSequence( szName ); if ( iReloadSequence != -1 ) return iReloadSequence; // Ok, look for generic categories.. pistol, shotgun, rifle, etc. if ( pWeapon->GetCSWpnData().m_WeaponType == WEAPONTYPE_PISTOL ) { Q_snprintf( szName, sizeof( szName ), "reload_pistol" ); iReloadSequence = m_pOuter->LookupSequence( szName ); if ( iReloadSequence != -1 ) return iReloadSequence; } // Fall back to reload_m4. iReloadSequence = CalcSequenceIndex( "reload_m4" ); if ( iReloadSequence > 0 ) return iReloadSequence; return -1; }
void CCSPlayerAnimState::DoAnimationEvent( PlayerAnimEvent_t event, int nData ) { Assert( event != PLAYERANIMEVENT_THROW_GRENADE ); MDLCACHE_CRITICAL_SECTION(); switch ( event ) { case PLAYERANIMEVENT_FIRE_GUN_PRIMARY: case PLAYERANIMEVENT_FIRE_GUN_SECONDARY: // Regardless of what we're doing in the fire layer, restart it. m_flFireCycle = 0; m_iFireSequence = CalcFireLayerSequence( event ); m_bFiring = m_iFireSequence != -1; // If we are interrupting a (shotgun) reload, cancel the reload, and fire next frame. if ( m_bFiring && m_bReloading ) { m_bReloading = false; m_iReloadSequence = -1; m_delayedFire = event; m_bFiring = false; m_iFireSequence = -1; CAnimationLayer *pLayer = m_pOuter->GetAnimOverlay( RELOADSEQUENCE_LAYER ); if ( pLayer ) { pLayer->m_flWeight = 0.0f; pLayer->m_nOrder = 15; } } #ifdef CLIENT_DLL if ( m_bFiring && !m_bReloading ) { if ( m_pPlayer ) { m_pPlayer->ProcessMuzzleFlashEvent(); } } #endif break; case PLAYERANIMEVENT_JUMP: // Play the jump animation. m_bJumping = true; m_bFirstJumpFrame = true; m_flJumpStartTime = gpGlobals->curtime; break; case PLAYERANIMEVENT_RELOAD: { // ignore normal reload events for shotguns - they get sent to trigger sounds etc only CWeaponCSBase *pWeapon = m_pHelpers->CSAnim_GetActiveWeapon(); if ( pWeapon && pWeapon->GetCSWpnData().m_WeaponType != WEAPONTYPE_SHOTGUN ) { m_iReloadSequence = CalcReloadLayerSequence( event ); if ( m_iReloadSequence != -1 ) { m_bReloading = true; m_flReloadCycle = 0; } else { m_bReloading = false; } } } break; case PLAYERANIMEVENT_RELOAD_START: case PLAYERANIMEVENT_RELOAD_LOOP: // Set the hold time for _start and _loop anims, then fall through to the _end case m_flReloadHoldEndTime = gpGlobals->curtime + 0.75f; case PLAYERANIMEVENT_RELOAD_END: { // ignore shotgun reload events for non-shotguns CWeaponCSBase *pWeapon = m_pHelpers->CSAnim_GetActiveWeapon(); if ( pWeapon && pWeapon->GetCSWpnData().m_WeaponType != WEAPONTYPE_SHOTGUN ) { m_flReloadHoldEndTime = 0.0f; // clear this out in case we set it in _START or _LOOP above } else { m_iReloadSequence = CalcReloadLayerSequence( event ); if ( m_iReloadSequence != -1 ) { m_bReloading = true; m_flReloadCycle = 0; } else { m_bReloading = false; } } } break; default: Assert( !"CCSPlayerAnimState::DoAnimationEvent" ); } }