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.

202 lines
4.0 KiB

  1. //========= Copyright 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 CWeaponFiveSeven C_WeaponFiveSeven
  11. #include "c_cs_player.h"
  12. #else
  13. #include "cs_player.h"
  14. #endif
  15. class CWeaponFiveSeven : public CWeaponCSBase
  16. {
  17. public:
  18. DECLARE_CLASS( CWeaponFiveSeven, CWeaponCSBase );
  19. DECLARE_NETWORKCLASS();
  20. DECLARE_PREDICTABLE();
  21. CWeaponFiveSeven();
  22. virtual void Spawn();
  23. virtual void PrimaryAttack();
  24. virtual void SecondaryAttack();
  25. virtual bool Deploy();
  26. virtual bool Reload();
  27. virtual void WeaponIdle();
  28. virtual float GetInaccuracy() const;
  29. virtual CSWeaponID GetWeaponID( void ) const { return WEAPON_FIVESEVEN; }
  30. private:
  31. CWeaponFiveSeven( const CWeaponFiveSeven & );
  32. float m_flLastFire;
  33. };
  34. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponFiveSeven, DT_WeaponFiveSeven )
  35. BEGIN_NETWORK_TABLE( CWeaponFiveSeven, DT_WeaponFiveSeven )
  36. END_NETWORK_TABLE()
  37. #if defined CLIENT_DLL
  38. BEGIN_PREDICTION_DATA( CWeaponFiveSeven )
  39. DEFINE_FIELD( m_flLastFire, FIELD_FLOAT ),
  40. END_PREDICTION_DATA()
  41. #endif
  42. LINK_ENTITY_TO_CLASS( weapon_fiveseven, CWeaponFiveSeven );
  43. PRECACHE_WEAPON_REGISTER( weapon_fiveseven );
  44. CWeaponFiveSeven::CWeaponFiveSeven()
  45. {
  46. m_flLastFire = gpGlobals->curtime;
  47. }
  48. void CWeaponFiveSeven::Spawn( )
  49. {
  50. BaseClass::Spawn();
  51. m_flAccuracy = 0.92;
  52. }
  53. bool CWeaponFiveSeven::Deploy()
  54. {
  55. m_flAccuracy = 0.92;
  56. return BaseClass::Deploy();
  57. }
  58. float CWeaponFiveSeven::GetInaccuracy() const
  59. {
  60. if ( weapon_accuracy_model.GetInt() == 1 )
  61. {
  62. CCSPlayer *pPlayer = GetPlayerOwner();
  63. if ( !pPlayer )
  64. return 0.0f;
  65. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  66. return 1.5f * (1 - m_flAccuracy);
  67. else if (pPlayer->GetAbsVelocity().Length2D() > 5)
  68. return 0.255f * (1 - m_flAccuracy);
  69. else if ( FBitSet( pPlayer->GetFlags(), FL_DUCKING ) )
  70. return 0.075f * (1 - m_flAccuracy);
  71. else
  72. return 0.15f * (1 - m_flAccuracy);
  73. }
  74. else
  75. return BaseClass::GetInaccuracy();
  76. }
  77. void CWeaponFiveSeven::PrimaryAttack()
  78. {
  79. CCSPlayer *pPlayer = GetPlayerOwner();
  80. if ( !pPlayer )
  81. return;
  82. // Mark the time of this shot and determine the accuracy modifier based on the last shot fired...
  83. m_flAccuracy -= (0.25)*(0.275 - (gpGlobals->curtime - m_flLastFire));
  84. if (m_flAccuracy > 0.92)
  85. m_flAccuracy = 0.92;
  86. else if (m_flAccuracy < 0.725)
  87. m_flAccuracy = 0.725;
  88. m_flLastFire = gpGlobals->curtime;
  89. if (m_iClip1 <= 0)
  90. {
  91. if ( m_bFireOnEmpty )
  92. {
  93. PlayEmptySound();
  94. m_flNextPrimaryAttack = gpGlobals->curtime + 0.1f;
  95. m_bFireOnEmpty = false;
  96. }
  97. return;
  98. }
  99. pPlayer->m_iShotsFired++;
  100. m_iClip1--;
  101. pPlayer->DoMuzzleFlash();
  102. SendWeaponAnim( ACT_VM_PRIMARYATTACK );
  103. // player "shoot" animation
  104. pPlayer->SetAnimation( PLAYER_ATTACK1 );
  105. FX_FireBullets(
  106. pPlayer->entindex(),
  107. pPlayer->Weapon_ShootPosition(),
  108. pPlayer->EyeAngles() + 2.0f * pPlayer->GetPunchAngle(),
  109. GetWeaponID(),
  110. Primary_Mode,
  111. CBaseEntity::GetPredictionRandomSeed() & 255,
  112. GetInaccuracy(),
  113. GetSpread());
  114. m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + GetCSWpnData().m_flCycleTime;
  115. if (!m_iClip1 && pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0)
  116. {
  117. // HEV suit - indicate out of ammo condition
  118. pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
  119. }
  120. SetWeaponIdleTime( gpGlobals->curtime + 2 );
  121. // update accuracy
  122. m_fAccuracyPenalty += GetCSWpnData().m_fInaccuracyImpulseFire[Primary_Mode];
  123. QAngle angle = pPlayer->GetPunchAngle();
  124. angle.x -= 2;
  125. pPlayer->SetPunchAngle( angle );
  126. }
  127. void CWeaponFiveSeven::SecondaryAttack()
  128. {
  129. }
  130. bool CWeaponFiveSeven::Reload()
  131. {
  132. if ( !DefaultPistolReload() )
  133. return false;
  134. m_flAccuracy = 0.92;
  135. return true;
  136. }
  137. void CWeaponFiveSeven::WeaponIdle()
  138. {
  139. if (m_flTimeWeaponIdle > gpGlobals->curtime)
  140. return;
  141. // only idle if the slid isn't back
  142. if (m_iClip1 != 0)
  143. {
  144. SetWeaponIdleTime( gpGlobals->curtime + 4 );
  145. SendWeaponAnim( ACT_VM_IDLE );
  146. }
  147. }