// Games implementing advanced bot support should override this. const char *CPlayerInfoManager::WeaponIdToAlias(int weaponId) { #if defined( TF_DLL ) return WeaponIdToAlias(weaponId); #elif defined ( CSTRIKE_DLL ) || defined ( DOD_DLL ) || defined ( SDK_DLL ) return WeaponIDToAlias(weaponId); #endif return "MOD_DIDNT_IMPLEMENT_ME"; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- static void CC_ListDeaths( const CCommand &args ) { TF_Gamestats_LevelStats_t *map = CTF_GameStats.m_reportedStats.m_pCurrentGame; if ( !map ) return; for( int i = 0; i < map->m_aPlayerDeaths.Count(); i++ ) { Msg( "%s killed %s with %s at (%d,%d,%d), distance %d\n", g_aClassNames[ map->m_aPlayerDeaths[ i ].iAttackClass ], g_aClassNames[ map->m_aPlayerDeaths[ i ].iTargetClass ], WeaponIdToAlias( map->m_aPlayerDeaths[ i ].iWeapon ), map->m_aPlayerDeaths[ i ].nPosition[ 0 ], map->m_aPlayerDeaths[ i ].nPosition[ 1 ], map->m_aPlayerDeaths[ i ].nPosition[ 2 ], map->m_aPlayerDeaths[ i ].iDistance ); } Msg( "\n---------------------------------\n\n" ); for( int i = 0; i < map->m_aPlayerDamage.Count(); i++ ) { Msg( "%.2f : %s at (%d,%d,%d) caused %d damage to %s with %s at (%d,%d,%d)%s%s\n", map->m_aPlayerDamage[ i ].fTime, g_aClassNames[ map->m_aPlayerDamage[ i ].iAttackClass ], map->m_aPlayerDamage[ i ].nAttackerPosition[ 0 ], map->m_aPlayerDamage[ i ].nAttackerPosition[ 1 ], map->m_aPlayerDamage[ i ].nAttackerPosition[ 2 ], map->m_aPlayerDamage[ i ].iDamage, g_aClassNames[ map->m_aPlayerDamage[ i ].iTargetClass ], WeaponIdToAlias( map->m_aPlayerDamage[ i ].iWeapon ), map->m_aPlayerDamage[ i ].nTargetPosition[ 0 ], map->m_aPlayerDamage[ i ].nTargetPosition[ 1 ], map->m_aPlayerDamage[ i ].nTargetPosition[ 2 ], map->m_aPlayerDamage[ i ].iCrit ? ", CRIT!" : "", map->m_aPlayerDamage[ i ].iKill ? ", KILL" : "" ); } Msg( "\n---------------------------------\n\n" ); Msg( "listed %d deaths\n", map->m_aPlayerDeaths.Count() ); Msg( "listed %d damages\n\n", map->m_aPlayerDamage.Count() ); }
//----------------------------------------------------------------------------- // Purpose: Entity classnames need to be in lower case. Use this whenever // you're spawning a weapon. //----------------------------------------------------------------------------- const char *WeaponIdToClassname( int iWeapon ) { const char *pszWeaponAlias = WeaponIdToAlias( iWeapon ); if ( pszWeaponAlias == NULL ) return NULL; static char szEntName[256]; Q_strcpy( szEntName, pszWeaponAlias ); Q_strlower( szEntName ); return szEntName; }
//----------------------------------------------------------------------------- // Purpose: This runs on both the client and the server. On the server, it // only does the damage calculations. On the client, it does all the effects. //----------------------------------------------------------------------------- void FX_FireBullets( int iPlayer, const Vector &vecOrigin, const QAngle &vecAngles, int iWeapon, int iMode, int iSeed, float flSpread, float flDamage /* = -1.0f */, bool bCritical /* = false*/ ) { // Get the weapon information. const char *pszWeaponAlias = WeaponIdToAlias( iWeapon ); if ( !pszWeaponAlias ) { DevMsg( 1, "FX_FireBullets: weapon alias for ID %i not found\n", iWeapon ); return; } WEAPON_FILE_INFO_HANDLE hWpnInfo = LookupWeaponInfoSlot( pszWeaponAlias ); if ( hWpnInfo == GetInvalidWeaponInfoHandle() ) { DevMsg( 1, "FX_FireBullets: LookupWeaponInfoSlot failed for weapon %s\n", pszWeaponAlias ); return; } CTFWeaponInfo *pWeaponInfo = static_cast<CTFWeaponInfo*>( GetFileWeaponInfoFromHandle( hWpnInfo ) ); if( !pWeaponInfo ) return; bool bDoEffects = false; #ifdef CLIENT_DLL C_TFPlayer *pPlayer = ToTFPlayer( ClientEntityList().GetBaseEntity( iPlayer ) ); #else CTFPlayer *pPlayer = ToTFPlayer( UTIL_PlayerByIndex( iPlayer ) ); #endif if ( !pPlayer ) return; // Client specific. #ifdef CLIENT_DLL bDoEffects = true; // The minigun has custom sound & animation code to deal with its windup/down. if ( !pPlayer->IsLocalPlayer() && iWeapon != TF_WEAPON_MINIGUN ) { // Fire the animation event. if ( pPlayer && !pPlayer->IsDormant() ) { if ( iMode == TF_WEAPON_PRIMARY_MODE ) { pPlayer->m_PlayerAnimState->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); } else { pPlayer->m_PlayerAnimState->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_SECONDARY ); } } //FX_WeaponSound( pPlayer->entindex(), SINGLE, vecOrigin, pWeaponInfo ); } // Server specific. #else // If this is server code, send the effect over to client as temp entity and // dispatch one message for all the bullet impacts and sounds. TE_FireBullets( pPlayer->entindex(), vecOrigin, vecAngles, iWeapon, iMode, iSeed, flSpread, bCritical ); // Let the player remember the usercmd he fired a weapon on. Assists in making decisions about lag compensation. pPlayer->NoteWeaponFired(); #endif // Fire bullets, calculate impacts & effects. StartGroupingSounds(); #if !defined (CLIENT_DLL) // Move other players back to history positions based on local player's lag lagcompensation->StartLagCompensation( pPlayer, pPlayer->GetCurrentCommand() ); #endif // Get the shooting angles. Vector vecShootForward, vecShootRight, vecShootUp; AngleVectors( vecAngles, &vecShootForward, &vecShootRight, &vecShootUp ); // Initialize the static firing information. FireBulletsInfo_t fireInfo; fireInfo.m_vecSrc = vecOrigin; if ( flDamage < 0.0f ) { fireInfo.m_flDamage = pWeaponInfo->GetWeaponData( iMode ).m_nDamage; } else { fireInfo.m_flDamage = static_cast<int>(flDamage); } fireInfo.m_flDistance = pWeaponInfo->GetWeaponData( iMode ).m_flRange; fireInfo.m_iShots = 1; fireInfo.m_vecSpread.Init( flSpread, flSpread, 0.0f ); fireInfo.m_iAmmoType = pWeaponInfo->iAmmoType; // Setup the bullet damage type & roll for crit. int nDamageType = DMG_GENERIC; int nCustomDamageType = TF_DMG_CUSTOM_NONE; CTFWeaponBase *pWeapon = pPlayer->GetActiveTFWeapon(); if ( pWeapon ) { nDamageType = pWeapon->GetDamageType(); if ( pWeapon->IsCurrentAttackACrit() || bCritical ) { nDamageType |= DMG_CRITICAL; } nCustomDamageType = pWeapon->GetCustomDamageType(); } if ( iWeapon != TF_WEAPON_MINIGUN ) { fireInfo.m_iTracerFreq = 2; } // Reset multi-damage structures. ClearMultiDamage(); int nBulletsPerShot = pWeaponInfo->GetWeaponData( iMode ).m_nBulletsPerShot; for ( int iBullet = 0; iBullet < nBulletsPerShot; ++iBullet ) { // Initialize random system with this seed. RandomSeed( iSeed ); // Determine if the first bullet should be perfectly accurate. bool bPerfectAccuracy = false; if ( pWeapon && iBullet == 0 ) { float flFireInterval = gpGlobals->curtime - pWeapon->GetLastFireTime(); if ( nBulletsPerShot == 1 ) bPerfectAccuracy = flFireInterval > 1.25f; else bPerfectAccuracy = flFireInterval > 0.25f; } float x = 0.0f; float y = 0.0f; // tf_use_fixed_weapon_spread calculations go here. if ( !bPerfectAccuracy ) { // Get circular gaussian spread. x = RandomFloat( -0.5, 0.5 ) + RandomFloat( -0.5, 0.5 ); y = RandomFloat( -0.5, 0.5 ) + RandomFloat( -0.5, 0.5 ); } // Initialize the varialbe firing information. fireInfo.m_vecDirShooting = vecShootForward + ( x * flSpread * vecShootRight ) + ( y * flSpread * vecShootUp ); fireInfo.m_vecDirShooting.NormalizeInPlace(); // Fire a bullet. pPlayer->FireBullet( fireInfo, bDoEffects, nDamageType, nCustomDamageType ); // Use new seed for next bullet. ++iSeed; } // Apply damage if any. ApplyMultiDamage(); #if !defined (CLIENT_DLL) lagcompensation->FinishLagCompensation( pPlayer ); #endif EndGroupingSounds(); }