Team Fortress 2 Source Code as on 22/4/2020
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.

203 lines
5.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "weapon_dodsniper.h"
  8. #include "dod_shareddefs.h"
  9. #ifndef CLIENT_DLL
  10. #include "te_effect_dispatch.h"
  11. #include "effect_dispatch_data.h"
  12. #endif
  13. #if defined( CLIENT_DLL )
  14. #define CWeaponGarand C_WeaponGarand
  15. #include "c_dod_player.h"
  16. #endif
  17. class CWeaponGarand : public CDODSniperWeapon
  18. {
  19. public:
  20. DECLARE_CLASS( CWeaponGarand, CDODSniperWeapon );
  21. DECLARE_NETWORKCLASS();
  22. DECLARE_PREDICTABLE();
  23. DECLARE_ACTTABLE();
  24. CWeaponGarand() {}
  25. virtual void Spawn( void );
  26. virtual DODWeaponID GetWeaponID( void ) const { return WEAPON_GARAND; }
  27. // weapon id for stats purposes
  28. virtual DODWeaponID GetStatsWeaponID( void )
  29. {
  30. if ( IsFullyZoomed() )
  31. return WEAPON_GARAND_ZOOMED;
  32. else
  33. return WEAPON_GARAND;
  34. }
  35. virtual Activity GetIdleActivity( void );
  36. virtual Activity GetPrimaryAttackActivity( void );
  37. virtual Activity GetDrawActivity( void );
  38. virtual void PrimaryAttack( void );
  39. virtual bool Reload( void );
  40. virtual float GetZoomedFOV( void ) { return 55; }
  41. virtual bool HideViewModelWhenZoomed( void ) { return false; }
  42. virtual bool ShouldZoomOutBetweenShots( void ) { return false; }
  43. virtual bool ShouldRezoomAfterReload( void ) { return true; }
  44. virtual float GetRecoil( void ) { return 4.0f; }
  45. private:
  46. CWeaponGarand( const CWeaponGarand & );
  47. };
  48. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponGarand, DT_WeaponGarand )
  49. BEGIN_NETWORK_TABLE( CWeaponGarand, DT_WeaponGarand )
  50. END_NETWORK_TABLE()
  51. BEGIN_PREDICTION_DATA( CWeaponGarand )
  52. END_PREDICTION_DATA()
  53. LINK_ENTITY_TO_CLASS( weapon_garand, CWeaponGarand );
  54. PRECACHE_WEAPON_REGISTER( weapon_garand );
  55. void CWeaponGarand::Spawn( void )
  56. {
  57. m_iAltFireHint = HINT_USE_IRON_SIGHTS;
  58. BaseClass::Spawn();
  59. }
  60. acttable_t CWeaponGarand::m_acttable[] =
  61. {
  62. { ACT_DOD_STAND_AIM, ACT_DOD_STAND_AIM_RIFLE, false },
  63. { ACT_DOD_CROUCH_AIM, ACT_DOD_CROUCH_AIM_RIFLE, false },
  64. { ACT_DOD_CROUCHWALK_AIM, ACT_DOD_CROUCHWALK_AIM_RIFLE, false },
  65. { ACT_DOD_WALK_AIM, ACT_DOD_WALK_AIM_RIFLE, false },
  66. { ACT_DOD_RUN_AIM, ACT_DOD_RUN_AIM_RIFLE, false },
  67. { ACT_PRONE_IDLE, ACT_DOD_PRONE_AIM_RIFLE, false },
  68. { ACT_PRONE_FORWARD, ACT_DOD_PRONEWALK_IDLE_RIFLE, false },
  69. { ACT_DOD_STAND_IDLE, ACT_DOD_STAND_IDLE_RIFLE, false },
  70. { ACT_DOD_CROUCH_IDLE, ACT_DOD_CROUCH_IDLE_RIFLE, false },
  71. { ACT_DOD_CROUCHWALK_IDLE, ACT_DOD_CROUCHWALK_IDLE_RIFLE, false },
  72. { ACT_DOD_WALK_IDLE, ACT_DOD_WALK_IDLE_RIFLE, false },
  73. { ACT_DOD_RUN_IDLE, ACT_DOD_RUN_IDLE_RIFLE, false },
  74. { ACT_SPRINT, ACT_DOD_SPRINT_IDLE_RIFLE, false },
  75. // Zoomed Aim
  76. { ACT_DOD_IDLE_ZOOMED, ACT_DOD_STAND_ZOOM_RIFLE, false },
  77. { ACT_DOD_CROUCH_ZOOMED, ACT_DOD_CROUCH_ZOOM_RIFLE, false },
  78. { ACT_DOD_CROUCHWALK_ZOOMED, ACT_DOD_CROUCHWALK_ZOOM_RIFLE, false },
  79. { ACT_DOD_WALK_ZOOMED, ACT_DOD_WALK_ZOOM_RIFLE, false },
  80. { ACT_DOD_PRONE_ZOOMED, ACT_DOD_PRONE_ZOOM_RIFLE, false },
  81. { ACT_DOD_PRONE_FORWARD_ZOOMED, ACT_DOD_PRONE_ZOOM_FORWARD_RIFLE, false },
  82. // Attack ( prone? deployed? )
  83. { ACT_RANGE_ATTACK1, ACT_DOD_PRIMARYATTACK_RIFLE, false },
  84. { ACT_DOD_PRIMARYATTACK_CROUCH, ACT_DOD_PRIMARYATTACK_RIFLE, false },
  85. { ACT_DOD_PRIMARYATTACK_PRONE, ACT_DOD_PRIMARYATTACK_PRONE_RIFLE, false },
  86. { ACT_RELOAD, ACT_DOD_RELOAD_RIFLE, false },
  87. { ACT_DOD_RELOAD_CROUCH, ACT_DOD_RELOAD_CROUCH_RIFLE, false },
  88. { ACT_DOD_RELOAD_PRONE, ACT_DOD_RELOAD_PRONE_RIFLE, false },
  89. // Hand Signals
  90. { ACT_DOD_HS_IDLE, ACT_DOD_HS_IDLE_K98, false },
  91. { ACT_DOD_HS_CROUCH, ACT_DOD_HS_CROUCH_K98, false },
  92. };
  93. IMPLEMENT_ACTTABLE( CWeaponGarand );
  94. Activity CWeaponGarand::GetIdleActivity( void )
  95. {
  96. Activity actIdle;
  97. if( m_iClip1 <= 0 )
  98. actIdle = ACT_VM_IDLE_EMPTY;
  99. else
  100. actIdle = ACT_VM_IDLE;
  101. return actIdle;
  102. }
  103. Activity CWeaponGarand::GetPrimaryAttackActivity( void )
  104. {
  105. Activity actPrim;
  106. if ( IsFullyZoomed() )
  107. actPrim = ACT_VM_PRIMARYATTACK_DEPLOYED;
  108. else if( m_iClip1 <= 0 )
  109. actPrim = ACT_VM_PRIMARYATTACK_EMPTY;
  110. else
  111. actPrim = ACT_VM_PRIMARYATTACK;
  112. return actPrim;
  113. }
  114. Activity CWeaponGarand::GetDrawActivity( void )
  115. {
  116. Activity actDraw;
  117. if( m_iClip1 <= 0 )
  118. actDraw = ACT_VM_DRAW_EMPTY;
  119. else
  120. actDraw = ACT_VM_DRAW;
  121. return actDraw;
  122. }
  123. void CWeaponGarand::PrimaryAttack( void )
  124. {
  125. int clip = m_iClip1;
  126. BaseClass::PrimaryAttack();
  127. // If we just fired our last bullet
  128. if( clip != m_iClip1 && m_iClip1 == 0 )
  129. {
  130. // clip "DING!"
  131. WeaponSound( SPECIAL1 );
  132. #ifndef CLIENT_DLL
  133. CEffectData data;
  134. data.m_nHitBox = EJECTBRASS_GARANDCLIP;
  135. GetPlayerOwner()->GetAttachment( 2, data.m_vOrigin, data.m_vAngles );
  136. // shoot it up in the air
  137. data.m_vAngles.x = -90;
  138. data.m_vAngles.y = 0;
  139. data.m_vAngles.z = 0;
  140. DispatchEffect( "DOD_EjectBrass", data );
  141. #endif
  142. }
  143. }
  144. bool CWeaponGarand::Reload( void )
  145. {
  146. if( m_iClip1 > 0 )
  147. {
  148. #ifdef CLIENT_DLL
  149. CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
  150. Assert( pPlayer );
  151. pPlayer->HintMessage( HINT_GARAND_RELOAD, true );
  152. #endif
  153. return false;
  154. }
  155. return BaseClass::Reload();
  156. }