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.

105 lines
2.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 CWeaponM249 C_WeaponM249
  10. #include "c_cs_player.h"
  11. #else
  12. #include "cs_player.h"
  13. #endif
  14. class CWeaponM249 : public CWeaponCSBaseGun
  15. {
  16. public:
  17. DECLARE_CLASS( CWeaponM249, CWeaponCSBaseGun );
  18. DECLARE_NETWORKCLASS();
  19. DECLARE_PREDICTABLE();
  20. CWeaponM249();
  21. virtual void PrimaryAttack();
  22. virtual float GetInaccuracy() const;
  23. virtual CSWeaponID GetWeaponID( void ) const { return WEAPON_M249; }
  24. private:
  25. CWeaponM249( const CWeaponM249 & );
  26. };
  27. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponM249, DT_WeaponM249 )
  28. BEGIN_NETWORK_TABLE( CWeaponM249, DT_WeaponM249 )
  29. END_NETWORK_TABLE()
  30. BEGIN_PREDICTION_DATA( CWeaponM249 )
  31. END_PREDICTION_DATA()
  32. LINK_ENTITY_TO_CLASS( weapon_m249, CWeaponM249 );
  33. PRECACHE_WEAPON_REGISTER( weapon_m249 );
  34. CWeaponM249::CWeaponM249()
  35. {
  36. }
  37. float CWeaponM249::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.045f + 0.5f * m_flAccuracy;
  46. else if (pPlayer->GetAbsVelocity().Length2D() > 140)
  47. return 0.045f + 0.095f * m_flAccuracy;
  48. else
  49. return 0.03f * m_flAccuracy;
  50. }
  51. else
  52. return BaseClass::GetInaccuracy();
  53. }
  54. void CWeaponM249::PrimaryAttack( void )
  55. {
  56. CCSPlayer *pPlayer = GetPlayerOwner();
  57. if ( !pPlayer )
  58. return;
  59. if ( !CSBaseGunFire( GetCSWpnData().m_flCycleTime, Primary_Mode ) )
  60. return;
  61. pPlayer = GetPlayerOwner();
  62. // CSBaseGunFire can kill us, forcing us to drop our weapon, if we shoot something that explodes
  63. if ( !pPlayer )
  64. return;
  65. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  66. pPlayer->KickBack (1.8, 0.65, 0.45, 0.125, 5, 3.5, 8);
  67. else if (pPlayer->GetAbsVelocity().Length2D() > 5)
  68. pPlayer->KickBack (1.1, 0.5, 0.3, 0.06, 4, 3, 8);
  69. else if ( FBitSet( pPlayer->GetFlags(), FL_DUCKING ) )
  70. pPlayer->KickBack (0.75, 0.325, 0.25, 0.025, 3.5, 2.5, 9);
  71. else
  72. pPlayer->KickBack (0.8, 0.35, 0.3, 0.03, 3.75, 3, 9);
  73. }