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.

182 lines
3.4 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 "in_buttons.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. #define DAMAGE_PER_SECOND 10
  16. #define MAX_SETTINGS 5
  17. float RateOfFire[ MAX_SETTINGS ] =
  18. {
  19. 0.1,
  20. 0.2,
  21. 0.5,
  22. 0.7,
  23. 1.0,
  24. };
  25. float Damage[ MAX_SETTINGS ] =
  26. {
  27. 2,
  28. 4,
  29. 10,
  30. 14,
  31. 20,
  32. };
  33. //=========================================================
  34. //=========================================================
  35. class CWeaponAR1 : public CHLMachineGun
  36. {
  37. DECLARE_DATADESC();
  38. public:
  39. DECLARE_CLASS( CWeaponAR1, CHLMachineGun );
  40. DECLARE_SERVERCLASS();
  41. CWeaponAR1();
  42. int m_ROF;
  43. void Precache( void );
  44. bool Deploy( void );
  45. float GetFireRate( void ) {return RateOfFire[ m_ROF ];}
  46. int CapabilitiesGet( void ) { return bits_CAP_WEAPON_RANGE_ATTACK1; }
  47. void SecondaryAttack( void );
  48. virtual void FireBullets( const FireBulletsInfo_t &info );
  49. virtual const Vector& GetBulletSpread( void )
  50. {
  51. static const Vector cone = VECTOR_CONE_10DEGREES;
  52. return cone;
  53. }
  54. void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator )
  55. {
  56. switch( pEvent->event )
  57. {
  58. case EVENT_WEAPON_AR1:
  59. {
  60. Vector vecShootOrigin, vecShootDir;
  61. vecShootOrigin = pOperator->Weapon_ShootPosition( );
  62. CAI_BaseNPC *npc = pOperator->MyNPCPointer();
  63. ASSERT( npc != NULL );
  64. vecShootDir = npc->GetActualShootTrajectory( vecShootOrigin );
  65. WeaponSound(SINGLE_NPC);
  66. pOperator->FireBullets( 1, vecShootOrigin, vecShootDir, VECTOR_CONE_PRECALCULATED, MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 2 );
  67. pOperator->DoMuzzleFlash();
  68. }
  69. break;
  70. default:
  71. CBaseCombatWeapon::Operator_HandleAnimEvent( pEvent, pOperator );
  72. break;
  73. }
  74. }
  75. DECLARE_ACTTABLE();
  76. };
  77. IMPLEMENT_SERVERCLASS_ST(CWeaponAR1, DT_WeaponAR1)
  78. END_SEND_TABLE()
  79. LINK_ENTITY_TO_CLASS( weapon_ar1, CWeaponAR1 );
  80. PRECACHE_WEAPON_REGISTER(weapon_ar1);
  81. acttable_t CWeaponAR1::m_acttable[] =
  82. {
  83. { ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_AR1, true },
  84. };
  85. IMPLEMENT_ACTTABLE(CWeaponAR1);
  86. //---------------------------------------------------------
  87. // Save/Restore
  88. //---------------------------------------------------------
  89. BEGIN_DATADESC( CWeaponAR1 )
  90. DEFINE_FIELD( m_ROF, FIELD_INTEGER ),
  91. END_DATADESC()
  92. CWeaponAR1::CWeaponAR1( )
  93. {
  94. m_ROF = 0;
  95. }
  96. void CWeaponAR1::Precache( void )
  97. {
  98. BaseClass::Precache();
  99. }
  100. bool CWeaponAR1::Deploy( void )
  101. {
  102. //CBaseCombatCharacter *pOwner = m_hOwner;
  103. return BaseClass::Deploy();
  104. }
  105. //=========================================================
  106. //=========================================================
  107. void CWeaponAR1::FireBullets( const FireBulletsInfo_t &info )
  108. {
  109. if(CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ))
  110. {
  111. pPlayer->FireBullets( info );
  112. }
  113. }
  114. void CWeaponAR1::SecondaryAttack( void )
  115. {
  116. CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
  117. if ( pPlayer )
  118. {
  119. pPlayer->m_nButtons &= ~IN_ATTACK2;
  120. }
  121. m_flNextSecondaryAttack = gpGlobals->curtime + 0.1;
  122. m_ROF += 1;
  123. if( m_ROF == MAX_SETTINGS )
  124. {
  125. m_ROF = 0;
  126. }
  127. int i;
  128. Msg( "\n" );
  129. for( i = 0 ; i < MAX_SETTINGS ; i++ )
  130. {
  131. if( i == m_ROF )
  132. {
  133. Msg( "|" );
  134. }
  135. else
  136. {
  137. Msg( "-" );
  138. }
  139. }
  140. Msg( "\n" );
  141. }