diff options
| author | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
|---|---|---|
| committer | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
| commit | 39ed87570bdb2f86969d4be821c94b722dc71179 (patch) | |
| tree | abc53757f75f40c80278e87650ea92808274aa59 /mp/src/game/shared/sdk/weapon_sdkbase.cpp | |
| download | source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip | |
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/game/shared/sdk/weapon_sdkbase.cpp')
| -rw-r--r-- | mp/src/game/shared/sdk/weapon_sdkbase.cpp | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/mp/src/game/shared/sdk/weapon_sdkbase.cpp b/mp/src/game/shared/sdk/weapon_sdkbase.cpp new file mode 100644 index 00000000..bba6a2a3 --- /dev/null +++ b/mp/src/game/shared/sdk/weapon_sdkbase.cpp @@ -0,0 +1,163 @@ +//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#include "cbase.h"
+#include "in_buttons.h"
+#include "takedamageinfo.h"
+#include "weapon_sdkbase.h"
+#include "ammodef.h"
+
+
+#if defined( CLIENT_DLL )
+
+ #include "c_sdk_player.h"
+
+#else
+
+ #include "sdk_player.h"
+
+#endif
+
+
+// ----------------------------------------------------------------------------- //
+// Global functions.
+// ----------------------------------------------------------------------------- //
+
+//--------------------------------------------------------------------------------------------------------
+static const char * s_WeaponAliasInfo[] =
+{
+ "none", // WEAPON_NONE
+ "mp5", // WEAPON_MP5
+ "shotgun", // WEAPON_SHOTGUN
+ "grenade", // WEAPON_GRENADE
+ NULL, // WEAPON_NONE
+};
+
+//--------------------------------------------------------------------------------------------------------
+//
+// Given an alias, return the associated weapon ID
+//
+int AliasToWeaponID( const char *alias )
+{
+ if (alias)
+ {
+ for( int i=0; s_WeaponAliasInfo[i] != NULL; ++i )
+ if (!Q_stricmp( s_WeaponAliasInfo[i], alias ))
+ return i;
+ }
+
+ return WEAPON_NONE;
+}
+
+//--------------------------------------------------------------------------------------------------------
+//
+// Given a weapon ID, return its alias
+//
+const char *WeaponIDToAlias( int id )
+{
+ if ( (id >= WEAPON_MAX) || (id < 0) )
+ return NULL;
+
+ return s_WeaponAliasInfo[id];
+}
+
+// ----------------------------------------------------------------------------- //
+// CWeaponSDKBase tables.
+// ----------------------------------------------------------------------------- //
+
+IMPLEMENT_NETWORKCLASS_ALIASED( WeaponSDKBase, DT_WeaponSDKBase )
+
+BEGIN_NETWORK_TABLE( CWeaponSDKBase, DT_WeaponSDKBase )
+#ifdef CLIENT_DLL
+
+#else
+ // world weapon models have no animations
+ SendPropExclude( "DT_AnimTimeMustBeFirst", "m_flAnimTime" ),
+ SendPropExclude( "DT_BaseAnimating", "m_nSequence" ),
+#endif
+END_NETWORK_TABLE()
+
+#ifdef CLIENT_DLL
+BEGIN_PREDICTION_DATA( CWeaponSDKBase )
+ DEFINE_PRED_FIELD( m_flTimeWeaponIdle, FIELD_FLOAT, FTYPEDESC_OVERRIDE | FTYPEDESC_NOERRORCHECK ),
+END_PREDICTION_DATA()
+#endif
+
+LINK_ENTITY_TO_CLASS( weapon_sdk_base, CWeaponSDKBase );
+
+
+#ifdef GAME_DLL
+
+ BEGIN_DATADESC( CWeaponSDKBase )
+
+ // New weapon Think and Touch Functions go here..
+
+ END_DATADESC()
+
+#endif
+
+// ----------------------------------------------------------------------------- //
+// CWeaponCSBase implementation.
+// ----------------------------------------------------------------------------- //
+CWeaponSDKBase::CWeaponSDKBase()
+{
+ SetPredictionEligible( true );
+
+ AddSolidFlags( FSOLID_TRIGGER ); // Nothing collides with these but it gets touches.
+}
+
+const CSDKWeaponInfo &CWeaponSDKBase::GetSDKWpnData() const
+{
+ const FileWeaponInfo_t *pWeaponInfo = &GetWpnData();
+ const CSDKWeaponInfo *pSDKInfo;
+
+ #ifdef _DEBUG
+ pSDKInfo = dynamic_cast< const CSDKWeaponInfo* >( pWeaponInfo );
+ Assert( pSDKInfo );
+ #else
+ pSDKInfo = static_cast< const CSDKWeaponInfo* >( pWeaponInfo );
+ #endif
+
+ return *pSDKInfo;
+}
+
+bool CWeaponSDKBase::PlayEmptySound()
+{
+ CPASAttenuationFilter filter( this );
+ filter.UsePredictionRules();
+
+ EmitSound( filter, entindex(), "Default.ClipEmpty_Rifle" );
+
+ return 0;
+}
+
+CSDKPlayer* CWeaponSDKBase::GetPlayerOwner() const
+{
+ return dynamic_cast< CSDKPlayer* >( GetOwner() );
+}
+
+#ifdef GAME_DLL
+
+void CWeaponSDKBase::SendReloadEvents()
+{
+ CSDKPlayer *pPlayer = dynamic_cast< CSDKPlayer* >( GetOwner() );
+ if ( !pPlayer )
+ return;
+
+ // Send a message to any clients that have this entity to play the reload.
+ CPASFilter filter( pPlayer->GetAbsOrigin() );
+ filter.RemoveRecipient( pPlayer );
+
+ UserMessageBegin( filter, "ReloadEffect" );
+ WRITE_SHORT( pPlayer->entindex() );
+ MessageEnd();
+
+ // Make the player play his reload animation.
+ pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD );
+}
+
+#endif
\ No newline at end of file |