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.

232 lines
5.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "util.h"
  8. #include "weapon_tfc_shotgun.h"
  9. #include "decals.h"
  10. #include "in_buttons.h"
  11. #if defined( CLIENT_DLL )
  12. #include "c_tfc_player.h"
  13. #else
  14. #include "tfc_player.h"
  15. #endif
  16. #define RE_SHOTGUN_TIME 2
  17. // ----------------------------------------------------------------------------- //
  18. // CTFCShotgun tables.
  19. // ----------------------------------------------------------------------------- //
  20. IMPLEMENT_NETWORKCLASS_ALIASED( TFCShotgun, DT_WeaponShotgun )
  21. BEGIN_NETWORK_TABLE( CTFCShotgun, DT_WeaponShotgun )
  22. END_NETWORK_TABLE()
  23. BEGIN_PREDICTION_DATA( CTFCShotgun )
  24. END_PREDICTION_DATA()
  25. LINK_ENTITY_TO_CLASS( weapon_shotgun, CTFCShotgun );
  26. PRECACHE_WEAPON_REGISTER( weapon_shotgun );
  27. #ifndef CLIENT_DLL
  28. BEGIN_DATADESC( CTFCShotgun )
  29. END_DATADESC()
  30. #endif
  31. // ----------------------------------------------------------------------------- //
  32. // CTFCShotgun implementation.
  33. // ----------------------------------------------------------------------------- //
  34. CTFCShotgun::CTFCShotgun()
  35. {
  36. m_fReloadTime = 0.25; // Time to insert an individual shell
  37. m_iShellsReloaded = 1; // Number of shells inserted each reload
  38. m_flPumpTime = -1;
  39. m_fInSpecialReload = 0;
  40. m_flNextReload = -1;
  41. }
  42. TFCWeaponID CTFCShotgun::GetWeaponID() const
  43. {
  44. return WEAPON_SHOTGUN;
  45. }
  46. void CTFCShotgun::PrimaryAttack()
  47. {
  48. CTFCPlayer *pOwner = GetPlayerOwner();
  49. if ( !pOwner )
  50. return;
  51. Assert( Clip1() != 0 );
  52. WeaponSound( SINGLE );
  53. SendWeaponAnim( ACT_VM_PRIMARYATTACK );
  54. pOwner->DoAnimationEvent( PLAYERANIMEVENT_FIRE_GUN );
  55. // Shoot!
  56. FireBulletsInfo_t info;
  57. info.m_vecSrc = pOwner->Weapon_ShootPosition();
  58. info.m_vecDirShooting = pOwner->GetAutoaimVector( AUTOAIM_5DEGREES );
  59. info.m_iShots = 6;
  60. info.m_flDistance = 2048;
  61. info.m_iAmmoType = GetPrimaryAmmoType();
  62. info.m_vecSpread = VECTOR_CONE_TF_SHOTGUN;
  63. info.m_iTracerFreq = 0;
  64. info.m_flDamage = 4;
  65. pOwner->FireBullets( info );
  66. m_flTimeWeaponIdle = gpGlobals->curtime + 5.0;
  67. m_fInSpecialReload = 0;
  68. pOwner->m_Shared.RemoveStateFlags( TFSTATE_RELOADING );
  69. // Setup fire delays
  70. m_iClip1 -= 1;
  71. if ( Clip1() != 0 )
  72. m_flPumpTime = gpGlobals->curtime + 0.5;
  73. m_flNextPrimaryAttack = gpGlobals->curtime + 0.5;
  74. }
  75. void CTFCShotgun::SecondaryAttack()
  76. {
  77. return;
  78. }
  79. bool CTFCShotgun::Reload()
  80. {
  81. CTFCPlayer *pOwner = GetPlayerOwner();
  82. if ( !pOwner )
  83. return false;
  84. if ( pOwner->GetAmmoCount( GetPrimaryAmmoType() ) < m_iShellsReloaded || Clip1() == GetMaxClip1() )
  85. {
  86. return false;
  87. }
  88. if (gpGlobals->curtime < m_flNextReload)
  89. {
  90. return false;
  91. }
  92. // don't reload until recoil is done
  93. if (gpGlobals->curtime < m_flNextPrimaryAttack)
  94. {
  95. return false;
  96. }
  97. // check to see if we're ready to reload
  98. if (m_fInSpecialReload == 0)
  99. {
  100. SendWeaponAnim( ACT_VM_PULLBACK ); // (ie: start reload)
  101. pOwner->m_Shared.AddStateFlags( TFSTATE_RELOADING );
  102. m_fInSpecialReload = 1;
  103. m_flTimeWeaponIdle = gpGlobals->curtime + 0.1; // 0.6;
  104. m_flNextPrimaryAttack = gpGlobals->curtime + 0.1; // 1.0;
  105. }
  106. else if (m_fInSpecialReload == 1)
  107. {
  108. if ( m_flTimeWeaponIdle > gpGlobals->curtime )
  109. {
  110. return false;
  111. }
  112. // was waiting for gun to move to side
  113. m_fInSpecialReload = 2;
  114. SendWeaponAnim( ACT_VM_RELOAD );
  115. WeaponSound( RELOAD );
  116. m_flNextReload = gpGlobals->curtime + m_fReloadTime; //0.5;
  117. m_flTimeWeaponIdle = gpGlobals->curtime + m_fReloadTime; //0.5;
  118. }
  119. else
  120. {
  121. // Add them to the clip
  122. m_iClip1 += m_iShellsReloaded;
  123. pOwner->RemoveAmmo( m_iShellsReloaded, GetPrimaryAmmoType() );
  124. m_fInSpecialReload = 1;
  125. pOwner->m_Shared.RemoveStateFlags( TFSTATE_RELOADING );
  126. }
  127. return true;
  128. }
  129. void CTFCShotgun::WeaponIdle()
  130. {
  131. CTFCPlayer *pOwner = GetPlayerOwner();
  132. if ( !pOwner )
  133. return;
  134. // After firing, pump the shotgun.
  135. if ( m_flPumpTime != -1 && gpGlobals->curtime >= m_flPumpTime )
  136. {
  137. SendWeaponAnim( ACT_VM_PULLBACK_HIGH );
  138. WeaponSound( SPECIAL1 ); // Pump sound.
  139. m_flPumpTime = -1;
  140. }
  141. if ( gpGlobals->curtime > m_flTimeWeaponIdle)
  142. {
  143. if (Clip1() == 0 && m_fInSpecialReload == 0 && pOwner->GetAmmoCount( GetPrimaryAmmoType() ) >= m_iShellsReloaded)
  144. {
  145. Reload( );
  146. }
  147. else if (m_fInSpecialReload != 0)
  148. {
  149. if (Clip1() != GetMaxClip1() && pOwner->GetAmmoCount( GetPrimaryAmmoType() ) >= m_iShellsReloaded)
  150. {
  151. Reload( );
  152. }
  153. else
  154. {
  155. // play pumping sound
  156. SendWeaponAnim( ACT_VM_PULLBACK_HIGH );
  157. WeaponSound( SPECIAL1 ); // Pump sound.
  158. m_fInSpecialReload = 0;
  159. m_flTimeWeaponIdle = gpGlobals->curtime + 1.5;
  160. }
  161. }
  162. else
  163. {
  164. SendWeaponAnim( ACT_VM_IDLE );
  165. m_flTimeWeaponIdle = gpGlobals->curtime + GetViewModelSequenceDuration();
  166. }
  167. }
  168. }
  169. #ifdef CLIENT_DLL
  170. // ------------------------------------------------------------------------------------------------ //
  171. // ------------------------------------------------------------------------------------------------ //
  172. // CLIENT DLL SPECIFIC CODE
  173. // ------------------------------------------------------------------------------------------------ //
  174. // ------------------------------------------------------------------------------------------------ //
  175. #else
  176. // ------------------------------------------------------------------------------------------------ //
  177. // ------------------------------------------------------------------------------------------------ //
  178. // GAME DLL SPECIFIC CODE
  179. // ------------------------------------------------------------------------------------------------ //
  180. // ------------------------------------------------------------------------------------------------ //
  181. #endif