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.

114 lines
2.4 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 CWeaponGalil C_WeaponGalil
  10. #include "c_cs_player.h"
  11. #else
  12. #include "cs_player.h"
  13. #endif
  14. class CWeaponGalil : public CWeaponCSBaseGun
  15. {
  16. public:
  17. DECLARE_CLASS( CWeaponGalil, CWeaponCSBaseGun );
  18. DECLARE_NETWORKCLASS();
  19. DECLARE_PREDICTABLE();
  20. CWeaponGalil();
  21. virtual void PrimaryAttack();
  22. virtual float GetInaccuracy() const;
  23. virtual CSWeaponID GetWeaponID( void ) const { return WEAPON_GALIL; }
  24. private:
  25. CWeaponGalil( const CWeaponGalil & );
  26. void GalilFire( float flSpread );
  27. };
  28. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponGalil, DT_WeaponGalil )
  29. BEGIN_NETWORK_TABLE( CWeaponGalil, DT_WeaponGalil )
  30. END_NETWORK_TABLE()
  31. BEGIN_PREDICTION_DATA( CWeaponGalil )
  32. END_PREDICTION_DATA()
  33. LINK_ENTITY_TO_CLASS( weapon_galil, CWeaponGalil );
  34. PRECACHE_WEAPON_REGISTER( weapon_galil );
  35. CWeaponGalil::CWeaponGalil()
  36. {
  37. }
  38. float CWeaponGalil::GetInaccuracy() const
  39. {
  40. if ( weapon_accuracy_model.GetInt() == 1 )
  41. {
  42. CCSPlayer *pPlayer = GetPlayerOwner();
  43. if ( !pPlayer )
  44. return 0.0f;
  45. if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  46. return 0.04f + 0.3f * m_flAccuracy;
  47. else if (pPlayer->GetAbsVelocity().Length2D() > 140)
  48. return 0.04f + 0.07f * m_flAccuracy;
  49. else
  50. return 0.0375f * m_flAccuracy;
  51. }
  52. else
  53. return BaseClass::GetInaccuracy();
  54. }
  55. void CWeaponGalil::PrimaryAttack()
  56. {
  57. CCSPlayer *pPlayer = GetPlayerOwner();
  58. if ( !pPlayer )
  59. return;
  60. // don't fire underwater
  61. if (pPlayer->GetWaterLevel() == 3)
  62. {
  63. PlayEmptySound( );
  64. m_flNextPrimaryAttack = gpGlobals->curtime + 0.15;
  65. return;
  66. }
  67. if ( !CSBaseGunFire( GetCSWpnData().m_flCycleTime, Primary_Mode ) )
  68. return;
  69. // CSBaseGunFire can kill us, forcing us to drop our weapon, if we shoot something that explodes
  70. pPlayer = GetPlayerOwner();
  71. if ( !pPlayer )
  72. return;
  73. if (pPlayer->GetAbsVelocity().Length2D() > 5)
  74. pPlayer->KickBack (1.0, 0.45, 0.28, 0.045, 3.75, 3, 7);
  75. else if ( !FBitSet( pPlayer->GetFlags(), FL_ONGROUND ) )
  76. pPlayer->KickBack (1.2, 0.5, 0.23, 0.15, 5.5, 3.5, 6);
  77. else if ( FBitSet( pPlayer->GetFlags(), FL_DUCKING ) )
  78. pPlayer->KickBack (0.6, 0.3, 0.2, 0.0125, 3.25, 2, 7);
  79. else
  80. pPlayer->KickBack (0.65, 0.35, 0.25, 0.015, 3.5, 2.25, 7);
  81. }