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.

201 lines
4.2 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. #if defined( CLIENT_DLL )
  9. #define CWeaponElite C_WeaponElite
  10. #include "c_cs_player.h"
  11. #include "c_te_effect_dispatch.h"
  12. #else
  13. #include "cs_player.h"
  14. #endif
  15. // NOTE: This has to be the last file included!
  16. #include "tier0/memdbgon.h"
  17. class CWeaponElite : public CWeaponCSBaseGun
  18. {
  19. public:
  20. DECLARE_CLASS( CWeaponElite, CWeaponCSBaseGun );
  21. DECLARE_NETWORKCLASS();
  22. DECLARE_PREDICTABLE();
  23. CWeaponElite();
  24. virtual void Spawn();
  25. virtual void Precache();
  26. virtual void PrimaryAttack();
  27. // We overload this so we can translate left/right fire activities
  28. virtual bool SendWeaponAnim( int iActivity );
  29. virtual void WeaponIdle();
  30. virtual CSWeaponID GetCSWeaponID( void ) const { return WEAPON_ELITE; }
  31. virtual bool Deploy( void );
  32. #ifdef CLIENT_DLL
  33. virtual int GetMuzzleAttachmentIndex_1stPerson( C_BaseViewModel *pViewModel );
  34. virtual int GetMuzzleAttachmentIndex_3rdPerson( void );
  35. virtual int GetEjectBrassAttachmentIndex_3rdPerson( void );
  36. #endif
  37. protected:
  38. bool FiringLeft() const;
  39. private:
  40. CWeaponElite( const CWeaponElite & );
  41. bool m_inPrecache;
  42. };
  43. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponElite, DT_WeaponElite )
  44. BEGIN_NETWORK_TABLE( CWeaponElite, DT_WeaponElite )
  45. END_NETWORK_TABLE()
  46. #if defined CLIENT_DLL
  47. BEGIN_PREDICTION_DATA( CWeaponElite )
  48. END_PREDICTION_DATA()
  49. #endif
  50. LINK_ENTITY_TO_CLASS_ALIASED( weapon_elite, WeaponElite );
  51. // PRECACHE_REGISTER( weapon_elite );
  52. CWeaponElite::CWeaponElite()
  53. {
  54. m_inPrecache = false;
  55. }
  56. void CWeaponElite::Spawn( )
  57. {
  58. BaseClass::Spawn();
  59. }
  60. void CWeaponElite::Precache()
  61. {
  62. m_inPrecache = true;
  63. PrecacheModel( "models/weapons/w_pist_elite.mdl" );
  64. PrecacheModel( "models/weapons/w_eq_eholster_elite.mdl" );
  65. PrecacheModel( "models/weapons/w_eq_eholster.mdl" );
  66. PrecacheModel( "models/weapons/w_pist_elite_single.mdl" );
  67. BaseClass::Precache();
  68. PrecacheEffect( "CS_MuzzleFlash" );
  69. m_inPrecache = false;
  70. }
  71. bool CWeaponElite::Deploy( void )
  72. {
  73. m_iState = WEAPON_IS_CARRIED_BY_PLAYER;
  74. return BaseClass::Deploy();
  75. }
  76. bool CWeaponElite::FiringLeft() const
  77. {
  78. // fire left-hand gun with even number of bullets left
  79. return (m_iClip1 & 1) == 0;
  80. }
  81. void CWeaponElite::PrimaryAttack()
  82. {
  83. CSBaseGunFire( GetCycleTime(), FiringLeft() ? Primary_Mode : Secondary_Mode);
  84. }
  85. bool CWeaponElite::SendWeaponAnim( int iActivity )
  86. {
  87. if ( iActivity == ACT_VM_PRIMARYATTACK )
  88. {
  89. if ( FiringLeft() )
  90. {
  91. if ( m_iClip1 > 2 )
  92. iActivity = ACT_VM_PRIMARYATTACK;
  93. else
  94. iActivity = ACT_VM_DRYFIRE_LEFT;
  95. }
  96. else
  97. {
  98. if ( m_iClip1 > 2 )
  99. iActivity = ACT_VM_SECONDARYATTACK;
  100. else
  101. iActivity = ACT_VM_DRYFIRE;
  102. }
  103. }
  104. return BaseClass::SendWeaponAnim( iActivity );
  105. }
  106. void CWeaponElite::WeaponIdle()
  107. {
  108. if (m_flTimeWeaponIdle > gpGlobals->curtime)
  109. return;
  110. // only idle if the slid isn't back
  111. if ( m_iClip1 < 2 )
  112. return;
  113. // NB. If we show one or more empty guns when idling, we'll get visual pops when holstering or drawing weapons
  114. // if ( m_iClip1 == 1 )
  115. // SendWeaponAnim( ACT_VM_IDLE_EMPTY_LEFT );
  116. SendWeaponAnim( ACT_VM_IDLE );
  117. SetWeaponIdleTime( gpGlobals->curtime + GetCSWpnData().GetIdleInterval() );
  118. }
  119. #ifdef CLIENT_DLL
  120. int CWeaponElite::GetMuzzleAttachmentIndex_1stPerson( C_BaseViewModel *pViewModel )
  121. {
  122. if ( FiringLeft() )
  123. return pViewModel->LookupAttachment( "1" );
  124. else
  125. return pViewModel->LookupAttachment( "2" );
  126. }
  127. int CWeaponElite::GetMuzzleAttachmentIndex_3rdPerson( void )
  128. {
  129. CBaseWeaponWorldModel *pWeaponWorldModel = GetWeaponWorldModel();
  130. if ( !pWeaponWorldModel )
  131. return -1;
  132. if ( FiringLeft() )
  133. return pWeaponWorldModel->LookupAttachment( "muzzle_flash2" );
  134. else
  135. return pWeaponWorldModel->LookupAttachment( "muzzle_flash" );
  136. }
  137. int CWeaponElite::GetEjectBrassAttachmentIndex_3rdPerson( void )
  138. {
  139. CBaseWeaponWorldModel *pWeaponWorldModel = GetWeaponWorldModel();
  140. if ( !pWeaponWorldModel )
  141. return -1;
  142. if ( FiringLeft() )
  143. return pWeaponWorldModel->LookupAttachment( "shell_eject2" );
  144. else
  145. return pWeaponWorldModel->LookupAttachment( "shell_eject" );
  146. }
  147. #endif