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.

272 lines
5.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "weapon_csbase.h"
  8. #include "fx_cs_shared.h"
  9. #if defined( CLIENT_DLL )
  10. #define CWeaponXM1014 C_WeaponXM1014
  11. #include "c_cs_player.h"
  12. #else
  13. #include "cs_player.h"
  14. #include "te_shotgun_shot.h"
  15. #endif
  16. // NOTE: This has to be the last file included!
  17. #include "tier0/memdbgon.h"
  18. class CWeaponXM1014 : public CWeaponCSBase
  19. {
  20. public:
  21. DECLARE_CLASS( CWeaponXM1014, CWeaponCSBase );
  22. DECLARE_NETWORKCLASS();
  23. DECLARE_PREDICTABLE();
  24. CWeaponXM1014( void );
  25. virtual void PrimaryAttack( void );
  26. virtual bool Reload( void );
  27. virtual void WeaponIdle( void );
  28. virtual CSWeaponID GetCSWeaponID( void ) const { return WEAPON_XM1014; }
  29. virtual int GetShotgunReloadState( void ) { return m_reloadState; }
  30. private:
  31. CWeaponXM1014( const CWeaponXM1014 & );
  32. float m_flPumpTime;
  33. CNetworkVar( int, m_reloadState ); // special reload state for shotgun
  34. };
  35. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponXM1014, DT_WeaponXM1014 )
  36. BEGIN_NETWORK_TABLE( CWeaponXM1014, DT_WeaponXM1014 )
  37. #ifdef CLIENT_DLL
  38. RecvPropInt( RECVINFO( m_reloadState ) )
  39. #else
  40. SendPropInt( SENDINFO( m_reloadState ), 2, SPROP_UNSIGNED )
  41. #endif
  42. END_NETWORK_TABLE()
  43. #if defined(CLIENT_DLL)
  44. BEGIN_PREDICTION_DATA( CWeaponXM1014 )
  45. DEFINE_PRED_FIELD( m_reloadState, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
  46. END_PREDICTION_DATA()
  47. #endif
  48. LINK_ENTITY_TO_CLASS_ALIASED( weapon_xm1014, WeaponXM1014 );
  49. // PRECACHE_REGISTER( weapon_xm1014 );
  50. CWeaponXM1014::CWeaponXM1014( void )
  51. {
  52. m_flPumpTime = 0;
  53. m_reloadState = 0;
  54. }
  55. void CWeaponXM1014::PrimaryAttack( void )
  56. {
  57. CCSPlayer *pPlayer = GetPlayerOwner();
  58. if ( !pPlayer )
  59. return;
  60. const CCSWeaponInfo& weaponInfo = GetCSWpnData();
  61. float flCycleTime = GetCycleTime();
  62. // don't fire underwater
  63. if ( pPlayer->GetWaterLevel() == WL_Eyes )
  64. {
  65. PlayEmptySound();
  66. m_flNextPrimaryAttack = gpGlobals->curtime + 0.15f;
  67. return;
  68. }
  69. if ( m_iClip1 <= 0 )
  70. {
  71. Reload();
  72. if ( m_iClip1 == 0 )
  73. {
  74. PlayEmptySound();
  75. m_flNextPrimaryAttack = gpGlobals->curtime + 0.25f;
  76. }
  77. return;
  78. }
  79. SendWeaponAnim( ACT_VM_PRIMARYATTACK );
  80. //pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
  81. //pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
  82. pPlayer->DoMuzzleFlash();
  83. // player "shoot" animation
  84. pPlayer->SetAnimation( PLAYER_ATTACK1 );
  85. uint16 nItemDefIndex = 0;
  86. // Dispatch the FX right away with full accuracy.
  87. float flCurAttack = CalculateNextAttackTime( flCycleTime );
  88. FX_FireBullets(
  89. pPlayer->entindex(),
  90. nItemDefIndex,
  91. pPlayer->Weapon_ShootPosition(),
  92. pPlayer->GetFinalAimAngle(),
  93. GetCSWeaponID(),
  94. Primary_Mode,
  95. CBaseEntity::GetPredictionRandomSeed( SERVER_PLATTIME_RNG ) & 255, // wrap it for network traffic so it's the same between client and server
  96. GetInaccuracy(),
  97. GetSpread(), // flSpread
  98. GetAccuracyFishtail(),
  99. flCurAttack,
  100. SINGLE,
  101. m_flRecoilIndex );
  102. // are we firing the last round in the clip?
  103. if ( m_iClip1 == 1 )
  104. {
  105. SetWeaponIdleTime( gpGlobals->curtime + 0.25f );
  106. }
  107. else
  108. {
  109. m_flPumpTime = gpGlobals->curtime + 0.5f;
  110. SetWeaponIdleTime( gpGlobals->curtime + 2.5f );
  111. }
  112. m_reloadState = 0;
  113. // update accuracy
  114. m_fAccuracyPenalty += weaponInfo.GetInaccuracyFire( GetEconItemView(), Primary_Mode );
  115. // table driven recoil
  116. Recoil( Primary_Mode );
  117. ++pPlayer->m_iShotsFired;
  118. m_flRecoilIndex += 1.0f;
  119. --m_iClip1;
  120. }
  121. bool CWeaponXM1014::Reload( void )
  122. {
  123. CCSPlayer *pPlayer = GetPlayerOwner();
  124. if ( !pPlayer )
  125. return false;
  126. if ( GetReserveAmmoCount( AMMO_POSITION_PRIMARY ) <= 0 || m_iClip1 == GetMaxClip1() )
  127. return true;
  128. // don't reload until recoil is done
  129. if ( m_flNextPrimaryAttack > gpGlobals->curtime )
  130. return true;
  131. //MIKETODO: shotgun reloading (wait until we get content)
  132. // check to see if we're ready to reload
  133. if ( m_reloadState == 0 )
  134. {
  135. pPlayer->SetAnimation( PLAYER_RELOAD );
  136. SendWeaponAnim( ACT_SHOTGUN_RELOAD_START );
  137. m_reloadState = 1;
  138. pPlayer->m_flNextAttack = gpGlobals->curtime + 0.5f;
  139. SetWeaponIdleTime( gpGlobals->curtime + 0.5f );
  140. m_flNextPrimaryAttack = gpGlobals->curtime + 0.5f;
  141. m_flNextSecondaryAttack = gpGlobals->curtime + 0.5f;
  142. #ifdef GAME_DLL
  143. pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD_START );
  144. #endif
  145. return true;
  146. }
  147. else if ( m_reloadState == 1 )
  148. {
  149. if ( m_flTimeWeaponIdle > gpGlobals->curtime )
  150. return true;
  151. // was waiting for gun to move to side
  152. m_reloadState = 2;
  153. SendWeaponAnim( ACT_VM_RELOAD );
  154. SetWeaponIdleTime( gpGlobals->curtime + 0.5f );
  155. #ifdef GAME_DLL
  156. // [mlowrance] Only play the looping anim
  157. pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD_LOOP );
  158. #endif
  159. }
  160. else
  161. {
  162. // Add them to the clip
  163. m_iClip1 += 1;
  164. #ifdef GAME_DLL
  165. SendActivityEvents();
  166. #endif
  167. GiveReserveAmmo( AMMO_POSITION_PRIMARY, -1, true );
  168. m_reloadState = 1;
  169. }
  170. return true;
  171. }
  172. void CWeaponXM1014::WeaponIdle( void )
  173. {
  174. CCSPlayer *pPlayer = GetPlayerOwner();
  175. if ( !pPlayer )
  176. return;
  177. if ( m_flPumpTime && m_flPumpTime < gpGlobals->curtime )
  178. {
  179. // play pumping sound
  180. m_flPumpTime = 0;
  181. }
  182. if ( m_flTimeWeaponIdle < gpGlobals->curtime )
  183. {
  184. if ( m_iClip1 == 0 && m_reloadState == 0 && GetReserveAmmoCount( AMMO_POSITION_PRIMARY ) )
  185. {
  186. Reload();
  187. }
  188. else if ( m_reloadState != 0 )
  189. {
  190. if ( m_iClip1 != GetMaxClip1() && GetReserveAmmoCount( AMMO_POSITION_PRIMARY ) )
  191. {
  192. Reload();
  193. }
  194. else
  195. {
  196. // reload debounce has timed out
  197. //MIKETODO: shotgun anims
  198. SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH );
  199. #if defined( GAME_DLL )
  200. // [mlowrance] play the finish for 3rd person
  201. pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD_END );
  202. #endif
  203. // play cocking sound
  204. m_reloadState = 0;
  205. SetWeaponIdleTime( gpGlobals->curtime + 1.5f );
  206. }
  207. }
  208. else
  209. {
  210. SendWeaponAnim( ACT_VM_IDLE );
  211. }
  212. }
  213. }