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.

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