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.

154 lines
3.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "npcevent.h"
  8. #include "in_buttons.h"
  9. #ifdef CLIENT_DLL
  10. #include "c_hl2mp_player.h"
  11. #else
  12. #include "hl2mp_player.h"
  13. #endif
  14. #include "weapon_hl2mpbasehlmpcombatweapon.h"
  15. #ifdef CLIENT_DLL
  16. #define CWeapon357 C_Weapon357
  17. #endif
  18. //-----------------------------------------------------------------------------
  19. // CWeapon357
  20. //-----------------------------------------------------------------------------
  21. class CWeapon357 : public CBaseHL2MPCombatWeapon
  22. {
  23. DECLARE_CLASS( CWeapon357, CBaseHL2MPCombatWeapon );
  24. public:
  25. CWeapon357( void );
  26. void PrimaryAttack( void );
  27. DECLARE_NETWORKCLASS();
  28. DECLARE_PREDICTABLE();
  29. #ifndef CLIENT_DLL
  30. DECLARE_ACTTABLE();
  31. #endif
  32. private:
  33. CWeapon357( const CWeapon357 & );
  34. };
  35. IMPLEMENT_NETWORKCLASS_ALIASED( Weapon357, DT_Weapon357 )
  36. BEGIN_NETWORK_TABLE( CWeapon357, DT_Weapon357 )
  37. END_NETWORK_TABLE()
  38. BEGIN_PREDICTION_DATA( CWeapon357 )
  39. END_PREDICTION_DATA()
  40. LINK_ENTITY_TO_CLASS( weapon_357, CWeapon357 );
  41. PRECACHE_WEAPON_REGISTER( weapon_357 );
  42. #ifndef CLIENT_DLL
  43. acttable_t CWeapon357::m_acttable[] =
  44. {
  45. { ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_PISTOL, false },
  46. { ACT_HL2MP_RUN, ACT_HL2MP_RUN_PISTOL, false },
  47. { ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_PISTOL, false },
  48. { ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_PISTOL, false },
  49. { ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_PISTOL, false },
  50. { ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_PISTOL, false },
  51. { ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_PISTOL, false },
  52. { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_PISTOL, false },
  53. };
  54. IMPLEMENT_ACTTABLE( CWeapon357 );
  55. #endif
  56. //-----------------------------------------------------------------------------
  57. // Purpose: Constructor
  58. //-----------------------------------------------------------------------------
  59. CWeapon357::CWeapon357( void )
  60. {
  61. m_bReloadsSingly = false;
  62. m_bFiresUnderwater = false;
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Purpose:
  66. //-----------------------------------------------------------------------------
  67. void CWeapon357::PrimaryAttack( void )
  68. {
  69. // Only the player fires this way so we can cast
  70. CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
  71. if ( !pPlayer )
  72. {
  73. return;
  74. }
  75. if ( m_iClip1 <= 0 )
  76. {
  77. if ( !m_bFireOnEmpty )
  78. {
  79. Reload();
  80. }
  81. else
  82. {
  83. WeaponSound( EMPTY );
  84. m_flNextPrimaryAttack = 0.15;
  85. }
  86. return;
  87. }
  88. WeaponSound( SINGLE );
  89. pPlayer->DoMuzzleFlash();
  90. SendWeaponAnim( ACT_VM_PRIMARYATTACK );
  91. pPlayer->SetAnimation( PLAYER_ATTACK1 );
  92. m_flNextPrimaryAttack = gpGlobals->curtime + 0.75;
  93. m_flNextSecondaryAttack = gpGlobals->curtime + 0.75;
  94. m_iClip1--;
  95. Vector vecSrc = pPlayer->Weapon_ShootPosition();
  96. Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
  97. FireBulletsInfo_t info( 1, vecSrc, vecAiming, vec3_origin, MAX_TRACE_LENGTH, m_iPrimaryAmmoType );
  98. info.m_pAttacker = pPlayer;
  99. // Fire the bullets, and force the first shot to be perfectly accuracy
  100. pPlayer->FireBullets( info );
  101. //Disorient the player
  102. QAngle angles = pPlayer->GetLocalAngles();
  103. angles.x += random->RandomInt( -1, 1 );
  104. angles.y += random->RandomInt( -1, 1 );
  105. angles.z = 0;
  106. #ifndef CLIENT_DLL
  107. pPlayer->SnapEyeAngles( angles );
  108. #endif
  109. pPlayer->ViewPunch( QAngle( -8, random->RandomFloat( -2, 2 ), 0 ) );
  110. if ( !m_iClip1 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 )
  111. {
  112. // HEV suit - indicate out of ammo condition
  113. pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 );
  114. }
  115. }