You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
3.7 KiB
168 lines
3.7 KiB
5 years ago
|
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||
|
//
|
||
|
// Purpose:
|
||
|
//
|
||
|
// $NoKeywords: $
|
||
|
//=============================================================================//
|
||
|
|
||
|
// Author: Michael S. Booth (mike@turtlerockstudios.com), 2003
|
||
|
|
||
|
#include "cbase.h"
|
||
|
#include "cs_gamerules.h"
|
||
|
#include "KeyValues.h"
|
||
|
|
||
|
#include "cs_bot.h"
|
||
|
|
||
|
// memdbgon must be the last include file in a .cpp file!!!
|
||
|
#include "tier0/memdbgon.h"
|
||
|
|
||
|
//--------------------------------------------------------------------------------------------------------------
|
||
|
void CCSBot::OnWeaponFire( IGameEvent *event )
|
||
|
{
|
||
|
if ( !IsAlive() )
|
||
|
return;
|
||
|
|
||
|
// don't react to our own events
|
||
|
CBasePlayer *player = UTIL_PlayerByUserId( event->GetInt( "userid" ) );
|
||
|
if ( player == this )
|
||
|
return;
|
||
|
|
||
|
// for knife fighting - if our victim is attacking or reloading, rush him
|
||
|
/// @todo Propagate events into active state
|
||
|
if (GetEnemy() == player && IsUsingKnife())
|
||
|
{
|
||
|
ForceRun( 5.0f );
|
||
|
}
|
||
|
|
||
|
const float ShortRange = 1000.0f;
|
||
|
const float NormalRange = 2000.0f;
|
||
|
|
||
|
float range;
|
||
|
|
||
|
/// @todo Check weapon type (knives are pretty quiet)
|
||
|
/// @todo Use actual volume, account for silencers, etc.
|
||
|
CWeaponCSBase *weapon = (CWeaponCSBase *)((player)?player->GetActiveWeapon():NULL);
|
||
|
|
||
|
if (weapon == NULL)
|
||
|
return;
|
||
|
|
||
|
switch( weapon->GetWeaponID() )
|
||
|
{
|
||
|
// silent "firing"
|
||
|
case WEAPON_HEGRENADE:
|
||
|
case WEAPON_SMOKEGRENADE:
|
||
|
case WEAPON_FLASHBANG:
|
||
|
case WEAPON_SHIELDGUN:
|
||
|
case WEAPON_C4:
|
||
|
return;
|
||
|
|
||
|
// quiet
|
||
|
case WEAPON_KNIFE:
|
||
|
case WEAPON_TMP:
|
||
|
range = ShortRange;
|
||
|
break;
|
||
|
|
||
|
// M4A1 - check for silencer
|
||
|
case WEAPON_M4A1:
|
||
|
{
|
||
|
if (weapon->IsSilenced())
|
||
|
{
|
||
|
range = ShortRange;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
range = NormalRange;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
// USP - check for silencer
|
||
|
case WEAPON_USP:
|
||
|
{
|
||
|
if (weapon->IsSilenced())
|
||
|
{
|
||
|
range = ShortRange;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
range = NormalRange;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
// loud
|
||
|
case WEAPON_AWP:
|
||
|
range = 99999.0f;
|
||
|
break;
|
||
|
|
||
|
// normal
|
||
|
default:
|
||
|
range = NormalRange;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
OnAudibleEvent( event, player, range, PRIORITY_HIGH, true ); // weapon_fire
|
||
|
}
|
||
|
|
||
|
|
||
|
//--------------------------------------------------------------------------------------------------------------
|
||
|
void CCSBot::OnWeaponFireOnEmpty( IGameEvent *event )
|
||
|
{
|
||
|
if ( !IsAlive() )
|
||
|
return;
|
||
|
|
||
|
// don't react to our own events
|
||
|
CBasePlayer *player = UTIL_PlayerByUserId( event->GetInt( "userid" ) );
|
||
|
if ( player == this )
|
||
|
return;
|
||
|
|
||
|
// for knife fighting - if our victim is attacking or reloading, rush him
|
||
|
/// @todo Propagate events into active state
|
||
|
if (GetEnemy() == player && IsUsingKnife())
|
||
|
{
|
||
|
ForceRun( 5.0f );
|
||
|
}
|
||
|
|
||
|
OnAudibleEvent( event, player, 1100.0f, PRIORITY_LOW, false ); // weapon_fire_on_empty
|
||
|
}
|
||
|
|
||
|
|
||
|
//--------------------------------------------------------------------------------------------------------------
|
||
|
void CCSBot::OnWeaponReload( IGameEvent *event )
|
||
|
{
|
||
|
if ( !IsAlive() )
|
||
|
return;
|
||
|
|
||
|
// don't react to our own events
|
||
|
CBasePlayer *player = UTIL_PlayerByUserId( event->GetInt( "userid" ) );
|
||
|
if ( player == this )
|
||
|
return;
|
||
|
|
||
|
// for knife fighting - if our victim is attacking or reloading, rush him
|
||
|
/// @todo Propagate events into active state
|
||
|
if (GetEnemy() == player && IsUsingKnife())
|
||
|
{
|
||
|
ForceRun( 5.0f );
|
||
|
}
|
||
|
|
||
|
OnAudibleEvent( event, player, 1100.0f, PRIORITY_LOW, false ); // weapon_reload
|
||
|
}
|
||
|
|
||
|
|
||
|
//--------------------------------------------------------------------------------------------------------------
|
||
|
void CCSBot::OnWeaponZoom( IGameEvent *event )
|
||
|
{
|
||
|
if ( !IsAlive() )
|
||
|
return;
|
||
|
|
||
|
// don't react to our own events
|
||
|
CBasePlayer *player = UTIL_PlayerByUserId( event->GetInt( "userid" ) );
|
||
|
if ( player == this )
|
||
|
return;
|
||
|
|
||
|
OnAudibleEvent( event, player, 1100.0f, PRIORITY_LOW, false ); // weapon_zoom
|
||
|
}
|
||
|
|
||
|
|
||
|
|