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.

219 lines
5.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "tf_weapon_shovel.h"
  8. #include "decals.h"
  9. // Client specific.
  10. #ifdef CLIENT_DLL
  11. #include "c_tf_player.h"
  12. // Server specific.
  13. #else
  14. #include "tf_player.h"
  15. #endif
  16. //=============================================================================
  17. //
  18. // Weapon Shovel tables.
  19. //
  20. IMPLEMENT_NETWORKCLASS_ALIASED( TFShovel, DT_TFWeaponShovel )
  21. BEGIN_NETWORK_TABLE( CTFShovel, DT_TFWeaponShovel )
  22. END_NETWORK_TABLE()
  23. BEGIN_PREDICTION_DATA( CTFShovel )
  24. END_PREDICTION_DATA()
  25. LINK_ENTITY_TO_CLASS( tf_weapon_shovel, CTFShovel );
  26. PRECACHE_WEAPON_REGISTER( tf_weapon_shovel );
  27. //=============================================================================
  28. //
  29. // Weapon Shovel functions.
  30. //
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. //-----------------------------------------------------------------------------
  34. CTFShovel::CTFShovel()
  35. {
  36. m_bHolstering = false;
  37. m_flLastHealthRatio = 1.f;
  38. }
  39. // -----------------------------------------------------------------------------
  40. void CTFShovel::PrimaryAttack()
  41. {
  42. CTFPlayer *pPlayer = GetTFPlayerOwner();
  43. if ( pPlayer && !(pPlayer->GetFlags() & FL_ONGROUND) )
  44. {
  45. int iFlappy = 0;
  46. CALL_ATTRIB_HOOK_INT( iFlappy, air_jump_on_attack );
  47. if ( iFlappy )
  48. {
  49. #ifdef GAME_DLL
  50. EmitSound_t params;
  51. params.m_pSoundName = "General.banana_slip";
  52. params.m_flSoundTime = 0;
  53. params.m_pflSoundDuration = 0;
  54. //params.m_bWarnOnDirectWaveReference = true;
  55. CPASFilter filter( pPlayer->GetAbsOrigin() );
  56. params.m_flVolume = 0.1f;
  57. params.m_SoundLevel = SNDLVL_25dB;
  58. params.m_nPitch = 100.0f;
  59. params.m_nFlags |= ( SND_CHANGE_PITCH | SND_CHANGE_VOL );
  60. pPlayer->StopSound( "General.banana_slip" );
  61. pPlayer->EmitSound( filter, pPlayer->entindex(), params );
  62. #endif
  63. Vector vForce = Vector(0,0,0);
  64. if ( pPlayer->GetAbsVelocity().z > 0 )
  65. {
  66. vForce.z = 275.0f;
  67. }
  68. else if ( pPlayer->m_Shared.InCond( TF_COND_BLASTJUMPING ) )
  69. {
  70. vForce.z = 500.0f;
  71. }
  72. else
  73. {
  74. vForce.z = 350.0f;
  75. }
  76. pPlayer->ApplyAbsVelocityImpulse( vForce );
  77. }
  78. }
  79. BaseClass::PrimaryAttack();
  80. }
  81. // -----------------------------------------------------------------------------
  82. // Purpose:
  83. // -----------------------------------------------------------------------------
  84. void CTFShovel::ItemPreFrame( void )
  85. {
  86. return BaseClass::ItemPreFrame();
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose:
  90. //-----------------------------------------------------------------------------
  91. float CTFShovel::GetMeleeDamage( CBaseEntity *pTarget, int* piDamageType, int* piCustomDamage )
  92. {
  93. float flDamage = BaseClass::GetMeleeDamage( pTarget, piDamageType, piCustomDamage );
  94. if ( !HasDamageBoost() )
  95. return flDamage;
  96. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  97. if ( !pOwner )
  98. return 0;
  99. float flOwnerHealthRatio = (float) pOwner->GetHealth() / (float) pOwner->GetMaxHealth();
  100. float flDamageScale = RemapValClamped( flOwnerHealthRatio, 0.f, 1.f, 1.65f, 0.5f );
  101. return flDamage * flDamageScale;
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Purpose:
  105. //-----------------------------------------------------------------------------
  106. float CTFShovel::GetSpeedMod( void )
  107. {
  108. if ( m_bHolstering || !HasSpeedBoost() )
  109. return 1.f;
  110. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  111. if ( !pOwner )
  112. return 0;
  113. float flOwnerHealthRatio = (float) pOwner->GetHealth() / (float) pOwner->GetMaxHealth();
  114. if ( flOwnerHealthRatio > 0.8 )
  115. return 1.f;
  116. else if ( flOwnerHealthRatio > 0.6 )
  117. return 1.1f;
  118. else if ( flOwnerHealthRatio > 0.4 )
  119. return 1.2f;
  120. else if ( flOwnerHealthRatio > 0.2 )
  121. return 1.4f;
  122. else
  123. return 1.6f;
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Purpose:
  127. //-----------------------------------------------------------------------------
  128. bool CTFShovel::Deploy( void )
  129. {
  130. bool ret = BaseClass::Deploy();
  131. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  132. if ( pOwner && HasSpeedBoost() )
  133. {
  134. SetContextThink( &CTFShovel::MoveSpeedThink, gpGlobals->curtime + 0.25f, "SHOVEL_SPEED_THINK" );
  135. }
  136. return ret;
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Purpose:
  140. //-----------------------------------------------------------------------------
  141. bool CTFShovel::Holster( CBaseCombatWeapon *pSwitchingTo )
  142. {
  143. m_bHolstering = true;
  144. bool ret = BaseClass::Holster( pSwitchingTo );
  145. m_bHolstering = false;
  146. return ret;
  147. }
  148. //-----------------------------------------------------------------------------
  149. // Purpose:
  150. //-----------------------------------------------------------------------------
  151. void CTFShovel::MoveSpeedThink( void )
  152. {
  153. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  154. if ( !pOwner || !pOwner->IsAlive() )
  155. return;
  156. if ( this != pOwner->GetActiveWeapon() )
  157. return;
  158. pOwner->TeamFortress_SetSpeed();
  159. SetContextThink( &CTFShovel::MoveSpeedThink, gpGlobals->curtime + 0.25f, "SHOVEL_SPEED_THINK" );
  160. }
  161. #ifndef CLIENT_DLL
  162. //-----------------------------------------------------------------------------
  163. // Purpose:
  164. //-----------------------------------------------------------------------------
  165. float CTFShovel::GetForceScale( void )
  166. {
  167. if ( HasDamageBoost() )
  168. {
  169. return BaseClass::GetForceScale() * 2.f;
  170. }
  171. else
  172. {
  173. return 1.f;
  174. }
  175. }
  176. //-----------------------------------------------------------------------------
  177. // Purpose:
  178. //-----------------------------------------------------------------------------
  179. int CTFShovel::GetDamageCustom()
  180. {
  181. if ( GetShovelType() == SHOVEL_SPEED_BOOST || GetShovelType() == SHOVEL_DAMAGE_BOOST )
  182. {
  183. return TF_DMG_CUSTOM_PICKAXE;
  184. }
  185. else
  186. {
  187. return BaseClass::GetDamageCustom();
  188. }
  189. }
  190. #endif