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.

160 lines
3.2 KiB

  1. //========= Copyright 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 CWeaponAug C_WeaponAug
  10. #include "c_cs_player.h"
  11. #else
  12. #include "cs_player.h"
  13. #endif
  14. class CWeaponAug : public CWeaponCSBaseGun
  15. {
  16. public:
  17. DECLARE_CLASS( CWeaponAug, CWeaponCSBaseGun );
  18. DECLARE_NETWORKCLASS();
  19. DECLARE_PREDICTABLE();
  20. CWeaponAug();
  21. virtual void SecondaryAttack();
  22. virtual void PrimaryAttack();
  23. virtual float GetInaccuracy() const;
  24. virtual bool Reload();
  25. virtual bool Deploy();
  26. virtual CSWeaponID GetWeaponID( void ) const { return WEAPON_AUG; }
  27. #ifdef CLIENT_DLL
  28. virtual bool HideViewModelWhenZoomed( void ) { return false; }
  29. #endif
  30. private:
  31. void AUGFire( float flSpread, bool bZoomed );
  32. CWeaponAug( const CWeaponAug & );
  33. };
  34. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponAug, DT_WeaponAug )
  35. BEGIN_NETWORK_TABLE( CWeaponAug, DT_WeaponAug )
  36. END_NETWORK_TABLE()
  37. BEGIN_PREDICTION_DATA( CWeaponAug )
  38. END_PREDICTION_DATA()
  39. LINK_ENTITY_TO_CLASS( weapon_aug, CWeaponAug );
  40. PRECACHE_WEAPON_REGISTER( weapon_aug );
  41. CWeaponAug::CWeaponAug()
  42. {
  43. }
  44. void CWeaponAug::SecondaryAttack()
  45. {
  46. CCSPlayer *pPlayer = GetPlayerOwner();
  47. if ( !pPlayer )
  48. return;
  49. if ( pPlayer->GetFOV() == pPlayer->GetDefaultFOV() )
  50. {
  51. pPlayer->SetFOV( pPlayer, 55, 0.2f );
  52. m_weaponMode = Secondary_Mode;
  53. }
  54. else if ( pPlayer->GetFOV() == 55 )
  55. {
  56. pPlayer->SetFOV( pPlayer, pPlayer->GetDefaultFOV(), 0.15f );
  57. m_weaponMode = Primary_Mode;
  58. }
  59. else
  60. {
  61. pPlayer->SetFOV( pPlayer, pPlayer->GetDefaultFOV() );
  62. m_weaponMode = Primary_Mode;
  63. }
  64. m_flNextSecondaryAttack = gpGlobals->curtime + 0.3;
  65. }
  66. float CWeaponAug::GetInaccuracy() const
  67. {
  68. if ( weapon_accuracy_model.GetInt() == 1 )
  69. {
  70. CCSPlayer *pPlayer = GetPlayerOwner();
  71. if ( !pPlayer )
  72. return 0.0f;
  73. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  74. return 0.035f + 0.4f * m_flAccuracy;
  75. else if ( pPlayer->GetAbsVelocity().Length2D() > 140 )
  76. return 0.035f + 0.07f * m_flAccuracy;
  77. else
  78. return 0.02f * m_flAccuracy;
  79. }
  80. else
  81. return BaseClass::GetInaccuracy();
  82. }
  83. void CWeaponAug::PrimaryAttack()
  84. {
  85. CCSPlayer *pPlayer = GetPlayerOwner();
  86. if ( !pPlayer )
  87. return;
  88. bool bZoomed = pPlayer->GetFOV() < pPlayer->GetDefaultFOV();
  89. float flCycleTime = GetCSWpnData().m_flCycleTime;
  90. if ( bZoomed )
  91. flCycleTime = 0.135f;
  92. if ( !CSBaseGunFire( flCycleTime, m_weaponMode ) )
  93. return;
  94. // CSBaseGunFire can kill us, forcing us to drop our weapon, if we shoot something that explodes
  95. pPlayer = GetPlayerOwner();
  96. if ( !pPlayer )
  97. return;
  98. if ( pPlayer->GetAbsVelocity().Length2D() > 5 )
  99. pPlayer->KickBack ( 1, 0.45, 0.275, 0.05, 4, 2.5, 7 );
  100. else if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  101. pPlayer->KickBack ( 1.25, 0.45, 0.22, 0.18, 5.5, 4, 5 );
  102. else if ( FBitSet( pPlayer->GetFlags(), FL_DUCKING ) )
  103. pPlayer->KickBack ( 0.575, 0.325, 0.2, 0.011, 3.25, 2, 8 );
  104. else
  105. pPlayer->KickBack ( 0.625, 0.375, 0.25, 0.0125, 3.5, 2.25, 8 );
  106. }
  107. bool CWeaponAug::Reload()
  108. {
  109. m_weaponMode = Primary_Mode;
  110. return BaseClass::Reload();
  111. }
  112. bool CWeaponAug::Deploy()
  113. {
  114. m_weaponMode = Primary_Mode;
  115. return BaseClass::Deploy();
  116. }