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.

132 lines
2.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 CWeaponUMP45 C_WeaponUMP45
  10. #include "c_cs_player.h"
  11. #else
  12. #include "cs_player.h"
  13. #endif
  14. class CWeaponUMP45 : public CWeaponCSBaseGun
  15. {
  16. public:
  17. DECLARE_CLASS( CWeaponUMP45, CWeaponCSBaseGun );
  18. DECLARE_NETWORKCLASS();
  19. DECLARE_PREDICTABLE();
  20. CWeaponUMP45();
  21. virtual void Spawn();
  22. virtual void PrimaryAttack();
  23. virtual bool Deploy();
  24. virtual bool Reload();
  25. virtual float GetInaccuracy() const;
  26. virtual CSWeaponID GetWeaponID( void ) const { return WEAPON_UMP45; }
  27. private:
  28. CWeaponUMP45( const CWeaponUMP45 & );
  29. };
  30. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponUMP45, DT_WeaponUMP45 )
  31. BEGIN_NETWORK_TABLE( CWeaponUMP45, DT_WeaponUMP45 )
  32. END_NETWORK_TABLE()
  33. BEGIN_PREDICTION_DATA( CWeaponUMP45 )
  34. END_PREDICTION_DATA()
  35. LINK_ENTITY_TO_CLASS( weapon_ump45, CWeaponUMP45 );
  36. PRECACHE_WEAPON_REGISTER( weapon_ump45 );
  37. CWeaponUMP45::CWeaponUMP45()
  38. {
  39. }
  40. void CWeaponUMP45::Spawn()
  41. {
  42. BaseClass::Spawn();
  43. m_flAccuracy = 0.0;
  44. }
  45. bool CWeaponUMP45::Deploy()
  46. {
  47. bool ret = BaseClass::Deploy();
  48. m_flAccuracy = 0.0;
  49. return ret;
  50. }
  51. bool CWeaponUMP45::Reload()
  52. {
  53. bool ret = BaseClass::Reload();
  54. m_flAccuracy = 0.0;
  55. return ret;
  56. }
  57. float CWeaponUMP45::GetInaccuracy() const
  58. {
  59. if ( weapon_accuracy_model.GetInt() == 1 )
  60. {
  61. CCSPlayer *pPlayer = GetPlayerOwner();
  62. if ( !pPlayer )
  63. return 0.0f;
  64. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  65. return 0.24f * m_flAccuracy;
  66. else
  67. return 0.04f * m_flAccuracy;
  68. }
  69. else
  70. return BaseClass::GetInaccuracy();
  71. }
  72. void CWeaponUMP45::PrimaryAttack()
  73. {
  74. CCSPlayer *pPlayer = GetPlayerOwner();
  75. if ( !pPlayer )
  76. return;
  77. if ( !CSBaseGunFire( GetCSWpnData().m_flCycleTime, Primary_Mode ) )
  78. return;
  79. // CSBaseGunFire can kill us, forcing us to drop our weapon, if we shoot something that explodes
  80. pPlayer = GetPlayerOwner();
  81. if ( !pPlayer )
  82. return;
  83. // Kick the gun based on the state of the player.
  84. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  85. pPlayer->KickBack (0.125, 0.65, 0.55, 0.0475, 5.5, 4, 10);
  86. else if (pPlayer->GetAbsVelocity().Length2D() > 5)
  87. pPlayer->KickBack (0.55, 0.3, 0.225, 0.03, 3.5, 2.5, 10);
  88. else if ( FBitSet( pPlayer->GetFlags(), FL_DUCKING ) )
  89. pPlayer->KickBack (0.25, 0.175, 0.125, 0.02, 2.25, 1.25, 10);
  90. else
  91. pPlayer->KickBack (0.275, 0.2, 0.15, 0.0225, 2.5, 1.5, 10);
  92. }