Counter Strike : Global Offensive Source Code
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.

186 lines
4.3 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "weapon_csbasegun.h"
  8. #include "cs_gamerules.h"
  9. #if defined( CLIENT_DLL )
  10. #define CWeaponTaser C_WeaponTaser
  11. #define CWeaponPartyPopper C_WeaponPartyPopper
  12. #include "c_cs_player.h"
  13. #else
  14. #include "cs_player.h"
  15. #endif
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include <tier0/memdbgon.h>
  18. #define TASER_BIRTHDAY_PARTICLES "weapon_confetti"
  19. #define TASER_BIRTHDAY_SOUND "Weapon_PartyHorn.Single"
  20. class CWeaponTaser : public CWeaponCSBaseGun
  21. {
  22. public:
  23. DECLARE_CLASS( CWeaponTaser, CWeaponCSBaseGun );
  24. DECLARE_NETWORKCLASS();
  25. DECLARE_PREDICTABLE();
  26. CWeaponTaser();
  27. virtual void Precache();
  28. virtual void PrimaryAttack( void );
  29. virtual const char* GetMuzzleFlashEffectName_1stPerson( void );
  30. virtual const char* GetMuzzleFlashEffectName_3rdPerson( void );
  31. #if defined( GAME_DLL )
  32. virtual bool Holster( CBaseCombatWeapon *pSwitchingTo );
  33. virtual void ItemPostFrame();
  34. #endif
  35. virtual CSWeaponID GetCSWeaponID( void ) const { return WEAPON_TASER; }
  36. private:
  37. CWeaponTaser( const CWeaponTaser& );
  38. float m_fFireTime;
  39. };
  40. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponTaser, DT_WeaponTaser )
  41. BEGIN_NETWORK_TABLE( CWeaponTaser, DT_WeaponTaser )
  42. END_NETWORK_TABLE()
  43. BEGIN_PREDICTION_DATA( CWeaponTaser )
  44. END_PREDICTION_DATA()
  45. LINK_ENTITY_TO_CLASS_ALIASED( weapon_taser, WeaponTaser );
  46. // PRECACHE_REGISTER( weapon_taser );
  47. CWeaponTaser::CWeaponTaser() :
  48. m_fFireTime(0.0f)
  49. {
  50. }
  51. void CWeaponTaser::Precache()
  52. {
  53. BaseClass::Precache();
  54. PrecacheParticleSystem( TASER_BIRTHDAY_PARTICLES );
  55. PrecacheScriptSound( TASER_BIRTHDAY_SOUND );
  56. }
  57. void CWeaponTaser::PrimaryAttack( void )
  58. {
  59. if ( !CSBaseGunFire( GetCycleTime(), Primary_Mode ) )
  60. return;
  61. m_fFireTime = gpGlobals->curtime;
  62. if ( CSGameRules() && CSGameRules()->IsCSGOBirthday() )
  63. {
  64. //CPASAttenuationFilter filter( this, params.soundlevel );
  65. //EmitSound( filter, entindex(), TASER_BIRTHDAY_SOUND, &GetLocalOrigin(), 0.0f );
  66. CPASAttenuationFilter filter( this );
  67. filter.UsePredictionRules();
  68. EmitSound( filter, entindex(), TASER_BIRTHDAY_SOUND );
  69. }
  70. }
  71. const char* CWeaponTaser::GetMuzzleFlashEffectName_1stPerson( void )
  72. {
  73. if ( CSGameRules() && CSGameRules()->IsCSGOBirthday() )
  74. {
  75. return TASER_BIRTHDAY_PARTICLES;
  76. }
  77. else
  78. {
  79. return GetCSWpnData().GetMuzzleFlashEffectName_1stPerson( GetEconItemView() );
  80. }
  81. }
  82. const char* CWeaponTaser::GetMuzzleFlashEffectName_3rdPerson( void )
  83. {
  84. if ( CSGameRules() && CSGameRules()->IsCSGOBirthday() )
  85. {
  86. return TASER_BIRTHDAY_PARTICLES;
  87. }
  88. else
  89. {
  90. return GetCSWpnData().GetMuzzleFlashEffectName_3rdPerson( GetEconItemView() );
  91. }
  92. }
  93. #if defined( GAME_DLL )
  94. bool CWeaponTaser::Holster( CBaseCombatWeapon *pSwitchingTo )
  95. {
  96. if ( HasAmmo() == false )
  97. {
  98. // just drop it if it's out of ammo and we're trying to switch away
  99. GetPlayerOwner()->CSWeaponDrop( this );
  100. }
  101. return BaseClass::Holster(pSwitchingTo);
  102. }
  103. void CWeaponTaser::ItemPostFrame()
  104. {
  105. const float kTaserDropDelay = 0.5f;
  106. BaseClass::ItemPostFrame();
  107. if ( HasAmmo() == false && gpGlobals->curtime >= m_fFireTime + kTaserDropDelay )
  108. {
  109. GetPlayerOwner()->Weapon_Drop( this, NULL, NULL );
  110. #ifndef CLIENT_DLL
  111. //pPlayer->RemoveWeaponOnPlayer( this );
  112. UTIL_Remove(this);
  113. #endif
  114. }
  115. }
  116. #endif
  117. /*
  118. class CWeaponPartyPopper : public CWeaponTaser
  119. {
  120. public:
  121. DECLARE_CLASS( CWeaponPartyPopper, CWeaponTaser );
  122. DECLARE_NETWORKCLASS();
  123. DECLARE_PREDICTABLE();
  124. //CWeaponPartyPopper();
  125. //virtual void PrimaryAttack( void );
  126. //virtual CSWeaponID GetCSWeaponID( void ) const { return WEAPON_TASER; }
  127. private:
  128. //CWeaponPartyPopper( const CWeaponPartyPopper& );
  129. };
  130. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponPartyPopper, DT_WeaponPartyPopper )
  131. BEGIN_NETWORK_TABLE( CWeaponPartyPopper, DT_WeaponPartyPopper )
  132. END_NETWORK_TABLE()
  133. BEGIN_PREDICTION_DATA( CWeaponPartyPopper )
  134. END_PREDICTION_DATA()
  135. LINK_ENTITY_TO_CLASS_ALIASED( weapon_partypopper, WeaponPartyPopper );
  136. void CWeaponPartyPopper::PrimaryAttack( void )
  137. {
  138. BaseClass::PrimaryAttack();
  139. if ( CSGameRules() && CSGameRules()->IsCSGOBirthday() )
  140. {
  141. CPASAttenuationFilter filter( this );
  142. filter.UsePredictionRules();
  143. EmitSound( filter, entindex(), TASER_BIRTHDAY_SOUND );
  144. //EmitSound( filter, entindex(), "Weapon_MAC10.Single" );
  145. }
  146. }
  147. */