summaryrefslogtreecommitdiff
path: root/game/server/cstrike/bot/cs_bot_event_weapon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game/server/cstrike/bot/cs_bot_event_weapon.cpp')
-rw-r--r--game/server/cstrike/bot/cs_bot_event_weapon.cpp167
1 files changed, 167 insertions, 0 deletions
diff --git a/game/server/cstrike/bot/cs_bot_event_weapon.cpp b/game/server/cstrike/bot/cs_bot_event_weapon.cpp
new file mode 100644
index 0000000..90f8b9f
--- /dev/null
+++ b/game/server/cstrike/bot/cs_bot_event_weapon.cpp
@@ -0,0 +1,167 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+// Author: Michael S. Booth ([email protected]), 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
+}
+
+
+