Team Fortress 2 Source Code as on 22/4/2020

123 lines
3.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "basehlcombatweapon.h"
  8. #include "NPCevent.h"
  9. #include "basecombatcharacter.h"
  10. #include "ai_basenpc.h"
  11. #include "player.h"
  12. #include "game.h"
  13. #include "in_buttons.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. class CWeaponSMG2 : public CHLSelectFireMachineGun
  17. {
  18. public:
  19. DECLARE_CLASS( CWeaponSMG2, CHLSelectFireMachineGun );
  20. CWeaponSMG2();
  21. DECLARE_SERVERCLASS();
  22. const Vector &GetBulletSpread( void );
  23. void Precache( void );
  24. void AddViewKick( void );
  25. void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator );
  26. float GetFireRate( void ) { return 0.1f; }
  27. int CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; }
  28. DECLARE_ACTTABLE();
  29. };
  30. IMPLEMENT_SERVERCLASS_ST(CWeaponSMG2, DT_WeaponSMG2)
  31. END_SEND_TABLE()
  32. LINK_ENTITY_TO_CLASS( weapon_smg2, CWeaponSMG2 );
  33. PRECACHE_WEAPON_REGISTER(weapon_smg2);
  34. acttable_t CWeaponSMG2::m_acttable[] =
  35. {
  36. { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_SMG2, true },
  37. };
  38. IMPLEMENT_ACTTABLE(CWeaponSMG2);
  39. //=========================================================
  40. CWeaponSMG2::CWeaponSMG2( )
  41. {
  42. m_fMaxRange1 = 2000;
  43. m_fMinRange1 = 32;
  44. m_iFireMode = FIREMODE_3RNDBURST;
  45. }
  46. void CWeaponSMG2::Precache( void )
  47. {
  48. BaseClass::Precache();
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. // Output : const Vector
  53. //-----------------------------------------------------------------------------
  54. const Vector &CWeaponSMG2::GetBulletSpread( void )
  55. {
  56. static const Vector cone = VECTOR_CONE_10DEGREES;
  57. return cone;
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Purpose:
  61. // Input : *pEvent -
  62. // *pOperator -
  63. //-----------------------------------------------------------------------------
  64. void CWeaponSMG2::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator )
  65. {
  66. switch( pEvent->event )
  67. {
  68. case EVENT_WEAPON_SMG2:
  69. {
  70. Vector vecShootOrigin, vecShootDir;
  71. vecShootOrigin = pOperator->Weapon_ShootPosition( );
  72. CAI_BaseNPC *npc = pOperator->MyNPCPointer();
  73. ASSERT( npc != NULL );
  74. vecShootDir = npc->GetActualShootTrajectory( vecShootOrigin );
  75. WeaponSound(SINGLE_NPC);
  76. pOperator->FireBullets( 1, vecShootOrigin, vecShootDir, VECTOR_CONE_PRECALCULATED, MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 2 );
  77. pOperator->DoMuzzleFlash();
  78. m_iClip1 = m_iClip1 - 1;
  79. }
  80. break;
  81. default:
  82. BaseClass::Operator_HandleAnimEvent( pEvent, pOperator );
  83. break;
  84. }
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose:
  88. //-----------------------------------------------------------------------------
  89. void CWeaponSMG2::AddViewKick( void )
  90. {
  91. #define EASY_DAMPEN 0.5f
  92. #define MAX_VERTICAL_KICK 2.0f //Degrees
  93. #define SLIDE_LIMIT 1.0f //Seconds
  94. //Get the view kick
  95. CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
  96. if (!pPlayer)
  97. return;
  98. DoMachineGunKick( pPlayer, EASY_DAMPEN, MAX_VERTICAL_KICK, m_fFireDuration, SLIDE_LIMIT );
  99. }