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.

97 lines
2.0 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 CWeaponP90 C_WeaponP90
  10. #include "c_cs_player.h"
  11. #else
  12. #include "cs_player.h"
  13. #endif
  14. class CWeaponP90 : public CWeaponCSBaseGun
  15. {
  16. public:
  17. DECLARE_CLASS( CWeaponP90, CWeaponCSBaseGun );
  18. DECLARE_NETWORKCLASS();
  19. DECLARE_PREDICTABLE();
  20. CWeaponP90();
  21. virtual void PrimaryAttack();
  22. virtual float GetInaccuracy() const;
  23. virtual CSWeaponID GetWeaponID( void ) const { return WEAPON_P90; }
  24. private:
  25. CWeaponP90( const CWeaponP90 & );
  26. };
  27. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponP90, DT_WeaponP90 )
  28. BEGIN_NETWORK_TABLE( CWeaponP90, DT_WeaponP90 )
  29. END_NETWORK_TABLE()
  30. BEGIN_PREDICTION_DATA( CWeaponP90 )
  31. END_PREDICTION_DATA()
  32. LINK_ENTITY_TO_CLASS( weapon_p90, CWeaponP90 );
  33. PRECACHE_WEAPON_REGISTER( weapon_p90 );
  34. CWeaponP90::CWeaponP90()
  35. {
  36. }
  37. float CWeaponP90::GetInaccuracy() const
  38. {
  39. if ( weapon_accuracy_model.GetInt() == 1 )
  40. {
  41. CCSPlayer *pPlayer = GetPlayerOwner();
  42. if ( !pPlayer )
  43. return 0.0f;
  44. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  45. return 0.3f * m_flAccuracy;
  46. else if (pPlayer->GetAbsVelocity().Length2D() > 170)
  47. return 0.115f * m_flAccuracy;
  48. else
  49. return 0.045f * m_flAccuracy;
  50. }
  51. else
  52. return BaseClass::GetInaccuracy();
  53. }
  54. void CWeaponP90::PrimaryAttack()
  55. {
  56. CCSPlayer *pPlayer = GetPlayerOwner();
  57. if ( !pPlayer )
  58. return;
  59. if ( !CSBaseGunFire( GetCSWpnData().m_flCycleTime, Primary_Mode ) )
  60. return;
  61. // Kick the gun based on the state of the player.
  62. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  63. pPlayer->KickBack (0.9, 0.45, 0.35, 0.04, 5.25, 3.5, 4);
  64. else if (pPlayer->GetAbsVelocity().Length2D() > 5)
  65. pPlayer->KickBack (0.45, 0.3, 0.2, 0.0275, 4, 2.25, 7);
  66. else if ( FBitSet( pPlayer->GetFlags(), FL_DUCKING ) )
  67. pPlayer->KickBack (0.275, 0.2, 0.125, 0.02, 3, 1, 9);
  68. else
  69. pPlayer->KickBack (0.3, 0.225, 0.125, 0.02, 3.25, 1.25, 8);
  70. }