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.

103 lines
2.3 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 CAK47 C_AK47
  10. #include "c_cs_player.h"
  11. #else
  12. #include "cs_player.h"
  13. #endif
  14. class CAK47 : public CWeaponCSBaseGun
  15. {
  16. public:
  17. DECLARE_CLASS( CAK47, CWeaponCSBaseGun );
  18. DECLARE_NETWORKCLASS();
  19. DECLARE_PREDICTABLE();
  20. CAK47();
  21. virtual void PrimaryAttack();
  22. virtual float GetInaccuracy() const;
  23. virtual CSWeaponID GetWeaponID( void ) const { return WEAPON_AK47; }
  24. private:
  25. CAK47( const CAK47 & );
  26. };
  27. IMPLEMENT_NETWORKCLASS_ALIASED( AK47, DT_WeaponAK47 )
  28. BEGIN_NETWORK_TABLE( CAK47, DT_WeaponAK47 )
  29. END_NETWORK_TABLE()
  30. BEGIN_PREDICTION_DATA( CAK47 )
  31. END_PREDICTION_DATA()
  32. LINK_ENTITY_TO_CLASS( weapon_ak47, CAK47 );
  33. PRECACHE_WEAPON_REGISTER( weapon_ak47 );
  34. // ---------------------------------------------------------------------------- //
  35. // CAK47 implementation.
  36. // ---------------------------------------------------------------------------- //
  37. CAK47::CAK47()
  38. {
  39. }
  40. float CAK47::GetInaccuracy() const
  41. {
  42. if ( weapon_accuracy_model.GetInt() == 1 )
  43. {
  44. CCSPlayer *pPlayer = GetPlayerOwner();
  45. if ( !pPlayer )
  46. return 0.0f;
  47. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  48. return 0.04f + 0.4f * m_flAccuracy;
  49. else if (pPlayer->GetAbsVelocity().Length2D() > 140)
  50. return 0.04f + 0.07f * m_flAccuracy;
  51. else
  52. return 0.0275f * m_flAccuracy;
  53. }
  54. else
  55. return BaseClass::GetInaccuracy();
  56. }
  57. void CAK47::PrimaryAttack()
  58. {
  59. CCSPlayer *pPlayer = GetPlayerOwner();
  60. if ( !pPlayer )
  61. return;
  62. if ( !CSBaseGunFire( GetCSWpnData().m_flCycleTime, Primary_Mode ) )
  63. return;
  64. // CSBaseGunFire can kill us, forcing us to drop our weapon, if we shoot something that explodes
  65. pPlayer = GetPlayerOwner();
  66. if ( !pPlayer )
  67. return;
  68. if (pPlayer->GetAbsVelocity().Length2D() > 5 )
  69. pPlayer->KickBack ( 1.5, 0.45, 0.225, 0.05, 6.5, 2.5, 7 );
  70. else if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  71. pPlayer->KickBack ( 2, 1.0, 0.5, 0.35, 9, 6, 5 );
  72. else if ( FBitSet( pPlayer->GetFlags(), FL_DUCKING ) )
  73. pPlayer->KickBack ( 0.9, 0.35, 0.15, 0.025, 5.5, 1.5, 9 );
  74. else
  75. pPlayer->KickBack ( 1, 0.375, 0.175, 0.0375, 5.75, 1.75, 8 );
  76. }