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.

106 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 CWeaponTMP C_WeaponTMP
  10. #include "c_cs_player.h"
  11. #else
  12. #include "cs_player.h"
  13. #endif
  14. class CWeaponTMP : public CWeaponCSBaseGun
  15. {
  16. public:
  17. DECLARE_CLASS( CWeaponTMP, CWeaponCSBaseGun );
  18. DECLARE_NETWORKCLASS();
  19. DECLARE_PREDICTABLE();
  20. CWeaponTMP();
  21. virtual void PrimaryAttack();
  22. virtual CSWeaponID GetWeaponID( void ) const { return WEAPON_TMP; }
  23. virtual bool IsSilenced( void ) const { return true; }
  24. virtual float GetInaccuracy() const;
  25. private:
  26. CWeaponTMP( const CWeaponTMP & );
  27. void DoFireEffects( void );
  28. };
  29. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponTMP, DT_WeaponTMP )
  30. BEGIN_NETWORK_TABLE( CWeaponTMP, DT_WeaponTMP )
  31. END_NETWORK_TABLE()
  32. BEGIN_PREDICTION_DATA( CWeaponTMP )
  33. END_PREDICTION_DATA()
  34. LINK_ENTITY_TO_CLASS( weapon_tmp, CWeaponTMP );
  35. PRECACHE_WEAPON_REGISTER( weapon_tmp );
  36. CWeaponTMP::CWeaponTMP()
  37. {
  38. }
  39. float CWeaponTMP::GetInaccuracy() const
  40. {
  41. if ( weapon_accuracy_model.GetInt() == 1 )
  42. {
  43. CCSPlayer *pPlayer = GetPlayerOwner();
  44. if ( !pPlayer )
  45. return 0.0f;
  46. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  47. return 0.25f * m_flAccuracy;
  48. else
  49. return 0.03f * m_flAccuracy;
  50. }
  51. else
  52. return BaseClass::GetInaccuracy();
  53. }
  54. void CWeaponTMP::PrimaryAttack( void )
  55. {
  56. CCSPlayer *pPlayer = GetPlayerOwner();
  57. if ( !pPlayer )
  58. return;
  59. if ( !CSBaseGunFire( GetCSWpnData().m_flCycleTime, Primary_Mode ) )
  60. return;
  61. // CSBaseGunFire can kill us, forcing us to drop our weapon, if we shoot something that explodes
  62. pPlayer = GetPlayerOwner();
  63. if ( !pPlayer )
  64. return;
  65. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  66. pPlayer->KickBack (1.1, 0.5, 0.35, 0.045, 4.5, 3.5, 6);
  67. else if (pPlayer->GetAbsVelocity().Length2D() > 5)
  68. pPlayer->KickBack (0.8, 0.4, 0.2, 0.03, 3, 2.5, 7);
  69. else if ( FBitSet( pPlayer->GetFlags(), FL_DUCKING ) )
  70. pPlayer->KickBack (0.7, 0.35, 0.125, 0.025, 2.5, 2, 10);
  71. else
  72. pPlayer->KickBack (0.725, 0.375, 0.15, 0.025, 2.75, 2.25, 9);
  73. }
  74. void CWeaponTMP::DoFireEffects( void )
  75. {
  76. // TMP is silenced, so do nothing
  77. }