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.

234 lines
6.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "tf_weapon_fists.h"
  8. #include "decals.h"
  9. // Client specific.
  10. #ifdef CLIENT_DLL
  11. #include "c_tf_player.h"
  12. #include "c_tf_gamestats.h"
  13. // Server specific.
  14. #else
  15. #include "tf_player.h"
  16. #include "tf_gamestats.h"
  17. #endif
  18. //=============================================================================
  19. //
  20. // Weapon Fists tables.
  21. //
  22. IMPLEMENT_NETWORKCLASS_ALIASED( TFFists, DT_TFWeaponFists )
  23. BEGIN_NETWORK_TABLE( CTFFists, DT_TFWeaponFists )
  24. END_NETWORK_TABLE()
  25. BEGIN_PREDICTION_DATA( CTFFists )
  26. END_PREDICTION_DATA()
  27. LINK_ENTITY_TO_CLASS( tf_weapon_fists, CTFFists );
  28. PRECACHE_WEAPON_REGISTER( tf_weapon_fists );
  29. //=============================================================================
  30. //
  31. // Weapon Fists functions.
  32. //
  33. // -----------------------------------------------------------------------------
  34. // Purpose:
  35. // -----------------------------------------------------------------------------
  36. void CTFFists::ItemPreFrame( void )
  37. {
  38. return BaseClass::ItemPreFrame();
  39. }
  40. // -----------------------------------------------------------------------------
  41. // Purpose:
  42. // -----------------------------------------------------------------------------
  43. void CTFFists::PrimaryAttack()
  44. {
  45. if ( !CanAttack() )
  46. return;
  47. // Set the weapon usage mode - primary, secondary.
  48. // reversed for 360 because the primary attack is on the right side of the controller
  49. if ( IsX360() || IsViewModelFlipped() )
  50. {
  51. m_iWeaponMode = TF_WEAPON_SECONDARY_MODE;
  52. }
  53. else
  54. {
  55. m_iWeaponMode = TF_WEAPON_PRIMARY_MODE;
  56. }
  57. Punch();
  58. }
  59. // -----------------------------------------------------------------------------
  60. // Purpose:
  61. // -----------------------------------------------------------------------------
  62. void CTFFists::SecondaryAttack()
  63. {
  64. if ( !CanAttack() )
  65. return;
  66. CTFPlayer *pPlayer = GetTFPlayerOwner();
  67. if ( pPlayer && pPlayer->m_Shared.IsControlStunned() )
  68. {
  69. return;
  70. }
  71. // Set the weapon usage mode - primary, secondary.
  72. if ( IsX360() || IsViewModelFlipped() )
  73. {
  74. m_iWeaponMode = TF_WEAPON_PRIMARY_MODE;
  75. }
  76. else
  77. {
  78. m_iWeaponMode = TF_WEAPON_SECONDARY_MODE;
  79. }
  80. Punch();
  81. }
  82. // -----------------------------------------------------------------------------
  83. // Purpose:
  84. // -----------------------------------------------------------------------------
  85. bool CTFFists::Holster( CBaseCombatWeapon *pSwitchingTo )
  86. {
  87. return BaseClass::Holster( pSwitchingTo );
  88. }
  89. // -----------------------------------------------------------------------------
  90. // Purpose:
  91. // -----------------------------------------------------------------------------
  92. void CTFFists::Punch( void )
  93. {
  94. // Get the current player.
  95. CTFPlayer *pPlayer = GetTFPlayerOwner();
  96. if ( !pPlayer )
  97. return;
  98. // Swing the weapon.
  99. Swing( pPlayer );
  100. m_flNextSecondaryAttack = m_flNextPrimaryAttack;
  101. #if !defined( CLIENT_DLL )
  102. pPlayer->SpeakWeaponFire();
  103. CTF_GameStats.Event_PlayerFiredWeapon( pPlayer, IsCurrentAttackACrit() );
  104. if ( pPlayer->m_Shared.IsStealthed() )
  105. {
  106. pPlayer->RemoveInvisibility();
  107. }
  108. #else
  109. C_CTF_GameStats.Event_PlayerFiredWeapon( pPlayer, IsCurrentAttackACrit() );
  110. #endif
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose: Allow melee weapons to send different anim events
  114. // Input : -
  115. //-----------------------------------------------------------------------------
  116. void CTFFists::SendPlayerAnimEvent( CTFPlayer *pPlayer )
  117. {
  118. // Send extra activities to the weapon for breadgloves
  119. if ( IsCurrentAttackACrit() )
  120. {
  121. pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_SECONDARY );
  122. }
  123. else
  124. {
  125. pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
  126. }
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Purpose:
  130. //-----------------------------------------------------------------------------
  131. void CTFFists::DoViewModelAnimation( void )
  132. {
  133. Activity act;
  134. if ( IsCurrentAttackACrit() )
  135. {
  136. act = ACT_VM_SWINGHARD;
  137. }
  138. else
  139. {
  140. act = ( m_iWeaponMode == TF_WEAPON_PRIMARY_MODE ) ? ACT_VM_HITLEFT : ACT_VM_HITRIGHT;
  141. }
  142. SendWeaponAnim( act );
  143. // Send WeaponAnim actually sets all anims and we want an override for the world model
  144. //int iIsBreadgloves = 0;
  145. //CALL_ATTRIB_HOOK_INT( iIsBreadgloves, breadgloves_properties );
  146. //if ( iIsBreadgloves )
  147. //{
  148. // ResetSequence( SelectWeightedSequence( ACT_BREADMONSTER_GLOVES_HITRIGHT ) );
  149. // SetPlaybackRate( 0.0f );
  150. // ResetClientsideFrame();
  151. //}
  152. }
  153. //-----------------------------------------------------------------------------
  154. // Purpose:
  155. //-----------------------------------------------------------------------------
  156. bool CTFFists::AllowTaunts( void )
  157. {
  158. // Radial buff fists don't allow player to taunt manually
  159. return ( GetFistType() != FISTTYPE_RADIAL_BUFF );
  160. }
  161. #ifdef GAME_DLL
  162. //-----------------------------------------------------------------------------
  163. // Purpose:
  164. //-----------------------------------------------------------------------------
  165. void CTFFists::OnEntityHit( CBaseEntity *pEntity, CTakeDamageInfo *info )
  166. {
  167. CTFPlayer *pHitPlayer = ToTFPlayer( pEntity );
  168. if ( !pHitPlayer )
  169. return;
  170. // Get the current player.
  171. CTFPlayer *pPlayer = GetTFPlayerOwner();
  172. if ( !pPlayer )
  173. return;
  174. if ( pHitPlayer->GetTeamNumber() == pPlayer->GetTeamNumber() )
  175. return;
  176. if ( pPlayer->m_Shared.InCond( TF_COND_INVULNERABLE ) )
  177. {
  178. int iNumHealers = pPlayer->m_Shared.GetNumHealers();
  179. // for each medic healing me
  180. for ( int i=0;i<iNumHealers;i++ )
  181. {
  182. CTFPlayer *pMedic = ToTFPlayer( pPlayer->m_Shared.GetHealerByIndex( i ) );
  183. // if it's a medic and that medic is releasing charge
  184. if ( pMedic && pMedic->GetChargeEffectBeingProvided() == MEDIGUN_CHARGE_INVULN )
  185. {
  186. // they are invulning me - add pEntity to their list of people punched
  187. pMedic->HandleAchievement_Medic_AssistHeavy( pHitPlayer );
  188. }
  189. }
  190. }
  191. // If we've killed someone, check to see for the unique fist kill response
  192. if ( !pEntity->IsAlive() )
  193. {
  194. if ( GetFistType() == FISTTYPE_RADIAL_BUFF )
  195. {
  196. pPlayer->Taunt();
  197. }
  198. }
  199. }
  200. #endif