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.

190 lines
5.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "tf_weapon_bonesaw.h"
  8. #include "tf_weapon_medigun.h"
  9. #ifdef GAME_DLL
  10. #include "tf_player.h"
  11. #else
  12. #include "c_tf_player.h"
  13. #endif
  14. #define UBERSAW_CHARGE_POSEPARAM "syringe_charge_level"
  15. //=============================================================================
  16. //
  17. // Weapon Bonesaw tables.
  18. //
  19. IMPLEMENT_NETWORKCLASS_ALIASED( TFBonesaw, DT_TFWeaponBonesaw )
  20. BEGIN_NETWORK_TABLE( CTFBonesaw, DT_TFWeaponBonesaw )
  21. END_NETWORK_TABLE()
  22. BEGIN_PREDICTION_DATA( CTFBonesaw )
  23. END_PREDICTION_DATA()
  24. LINK_ENTITY_TO_CLASS( tf_weapon_bonesaw, CTFBonesaw );
  25. PRECACHE_WEAPON_REGISTER( tf_weapon_bonesaw );
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. //-----------------------------------------------------------------------------
  29. void CTFBonesaw::Activate( void )
  30. {
  31. BaseClass::Activate();
  32. }
  33. //-----------------------------------------------------------------------------
  34. void CTFBonesaw::SecondaryAttack( void )
  35. {
  36. CTFPlayer *pPlayer = GetTFPlayerOwner();
  37. if ( !pPlayer )
  38. return;
  39. #ifdef GAME_DLL
  40. int iSpecialTaunt = 0;
  41. CALL_ATTRIB_HOOK_INT( iSpecialTaunt, special_taunt );
  42. if ( iSpecialTaunt )
  43. {
  44. pPlayer->Taunt( TAUNT_BASE_WEAPON );
  45. return;
  46. }
  47. #endif
  48. BaseClass::SecondaryAttack();
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. //-----------------------------------------------------------------------------
  53. bool CTFBonesaw::DefaultDeploy( char *szViewModel, char *szWeaponModel, int iActivity, char *szAnimExt )
  54. {
  55. if ( BaseClass::DefaultDeploy( szViewModel, szWeaponModel, iActivity, szAnimExt ) )
  56. {
  57. #ifdef CLIENT_DLL
  58. UpdateChargePoseParam();
  59. #endif
  60. return true;
  61. }
  62. return false;
  63. }
  64. //-----------------------------------------------------------------------------
  65. void CTFBonesaw::DoMeleeDamage( CBaseEntity* ent, trace_t& trace )
  66. {
  67. // We hit a target, take a head
  68. CTFPlayer *pPlayer = ToTFPlayer( GetOwnerEntity() );
  69. CTFPlayer *pVictim = ToTFPlayer( ent );
  70. int iTakeHeads = 0;
  71. CALL_ATTRIB_HOOK_INT( iTakeHeads, add_head_on_hit );
  72. if ( pPlayer && pVictim && iTakeHeads && (pVictim->GetTeamNumber() != pPlayer->GetTeamNumber() ) )
  73. {
  74. int iDecaps = pPlayer->m_Shared.GetDecapitations() + 1;
  75. pPlayer->m_Shared.SetDecapitations( iDecaps );
  76. pPlayer->TeamFortress_SetSpeed();
  77. }
  78. BaseClass::DoMeleeDamage( ent, trace );
  79. }
  80. //-----------------------------------------------------------------------------
  81. float CTFBonesaw::GetBoneSawSpeedMod( void )
  82. {
  83. const int MAX_HEADS_FOR_SPEED = 10;
  84. // Calculate Speed based on heads
  85. CTFPlayer *pPlayer = ToTFPlayer( GetOwnerEntity() );
  86. int iTakeHeads = 0;
  87. CALL_ATTRIB_HOOK_INT( iTakeHeads, add_head_on_hit );
  88. if ( pPlayer && iTakeHeads )
  89. {
  90. int iDecaps = Min( MAX_HEADS_FOR_SPEED, pPlayer->m_Shared.GetDecapitations() );
  91. return 1.f + (iDecaps * 0.05f);
  92. }
  93. return 1.f;
  94. }
  95. //-----------------------------------------------------------------------------
  96. int CTFBonesaw::GetCount( void )
  97. {
  98. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  99. if ( !pOwner )
  100. return 0;
  101. return pOwner->m_Shared.GetDecapitations();
  102. }
  103. #ifdef CLIENT_DLL
  104. //-----------------------------------------------------------------------------
  105. // Purpose:
  106. //-----------------------------------------------------------------------------
  107. void CTFBonesaw::OnDataChanged( DataUpdateType_t updateType )
  108. {
  109. BaseClass::OnDataChanged( updateType );
  110. UpdateChargePoseParam();
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose:
  114. //-----------------------------------------------------------------------------
  115. void CTFBonesaw::UpdateAttachmentModels( void )
  116. {
  117. BaseClass::UpdateAttachmentModels();
  118. if ( m_hViewmodelAttachment )
  119. {
  120. m_iUberChargePoseParam = m_hViewmodelAttachment->LookupPoseParameter( m_hViewmodelAttachment->GetModelPtr(), UBERSAW_CHARGE_POSEPARAM );
  121. }
  122. else
  123. {
  124. m_iUberChargePoseParam = LookupPoseParameter( GetModelPtr(), UBERSAW_CHARGE_POSEPARAM );
  125. }
  126. }
  127. //-----------------------------------------------------------------------------
  128. // Purpose:
  129. //-----------------------------------------------------------------------------
  130. void CTFBonesaw::UpdateChargePoseParam( void )
  131. {
  132. if ( m_iUberChargePoseParam >= 0 )
  133. {
  134. CTFPlayer *pTFPlayer = ToTFPlayer( GetOwner() );
  135. if ( pTFPlayer && pTFPlayer->IsPlayerClass( TF_CLASS_MEDIC ) )
  136. {
  137. CWeaponMedigun *pMedigun = (CWeaponMedigun *)pTFPlayer->Weapon_OwnsThisID( TF_WEAPON_MEDIGUN );
  138. if ( pMedigun )
  139. {
  140. m_flChargeLevel = pMedigun->GetChargeLevel();
  141. // On the local client, we push the pose parameters onto the attached model
  142. if ( m_hViewmodelAttachment )
  143. {
  144. m_hViewmodelAttachment->SetPoseParameter( m_iUberChargePoseParam, pMedigun->GetChargeLevel() );
  145. }
  146. }
  147. }
  148. }
  149. }
  150. //-----------------------------------------------------------------------------
  151. // Purpose:
  152. //-----------------------------------------------------------------------------
  153. void CTFBonesaw::GetPoseParameters( CStudioHdr *pStudioHdr, float poseParameter[MAXSTUDIOPOSEPARAM] )
  154. {
  155. if ( !pStudioHdr )
  156. return;
  157. BaseClass::GetPoseParameters( pStudioHdr, poseParameter );
  158. if ( m_iUberChargePoseParam >= 0 )
  159. {
  160. poseParameter[m_iUberChargePoseParam] = m_flChargeLevel;
  161. }
  162. }
  163. #endif