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.

166 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "tf_weapon_rocketpack.h"
  8. // Client specific.
  9. #ifdef CLIENT_DLL
  10. #include "c_tf_player.h"
  11. // Server specific.
  12. #else
  13. #include "tf_player.h"
  14. #include "tf_ammo_pack.h"
  15. #include "ilagcompensationmanager.h"
  16. #include "tf_gamerules.h"
  17. #endif
  18. // TFRocketPack --
  19. IMPLEMENT_NETWORKCLASS_ALIASED( TFRocketPack, DT_TFWeaponRocketPack )
  20. BEGIN_NETWORK_TABLE( CTFRocketPack, DT_TFWeaponRocketPack )
  21. END_NETWORK_TABLE()
  22. BEGIN_PREDICTION_DATA( CTFRocketPack )
  23. END_PREDICTION_DATA()
  24. LINK_ENTITY_TO_CLASS( tf_weapon_rocketpack, CTFRocketPack );
  25. PRECACHE_WEAPON_REGISTER( tf_weapon_rocketpack );
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. //-----------------------------------------------------------------------------
  29. CTFRocketPack::CTFRocketPack()
  30. {
  31. m_flRefireTime = 0;
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. //-----------------------------------------------------------------------------
  36. void CTFRocketPack::PreCache( void )
  37. {
  38. PrecacheParticleSystem( "rocketbackblast" );
  39. PrecacheScriptSound( "Weapon_Liberty_Launcher.Single" );
  40. BaseClass::Precache();
  41. }
  42. #ifdef GAME_DLL
  43. //-----------------------------------------------------------------------------
  44. // Purpose:
  45. //-----------------------------------------------------------------------------
  46. bool CTFRocketPack::CanFire( void )
  47. {
  48. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  49. if ( !pOwner )
  50. return false;
  51. if ( !TFGameRules()->IsMannVsMachineMode() )
  52. return false;
  53. if ( TFGameRules() && (TFGameRules()->State_Get() == GR_STATE_PREROUND) )
  54. return false;
  55. if ( pOwner->m_Shared.IsLoser() )
  56. return false;
  57. if ( pOwner->m_Shared.InCond( TF_COND_STUNNED ) )
  58. return false;
  59. if ( pOwner->IsTaunting() )
  60. return false;
  61. if ( m_flRefireTime > gpGlobals->curtime )
  62. return false;
  63. if ( pOwner->GetAmmoCount( TF_AMMO_GRENADES1 ) > 0)
  64. return true;
  65. return false;
  66. }
  67. #endif // GAME_DLL
  68. //-----------------------------------------------------------------------------
  69. // Purpose:
  70. //-----------------------------------------------------------------------------
  71. void CTFRocketPack::PrimaryAttack( void )
  72. {
  73. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  74. if ( !pOwner )
  75. return;
  76. if ( !CanAttack() )
  77. return;
  78. #ifdef GAME_DLL
  79. if ( !CanFire() )
  80. return;
  81. // Launch
  82. if ( !pOwner->m_Shared.InCond( TF_COND_ROCKETPACK ) )
  83. {
  84. pOwner->m_Shared.AddCond( TF_COND_ROCKETPACK );
  85. pOwner->m_Shared.StunPlayer( 0.5f, 1.0f, TF_STUN_MOVEMENT );
  86. }
  87. Vector vecDir;
  88. pOwner->EyeVectors( &vecDir );
  89. pOwner->SetAbsVelocity( vec3_origin );
  90. Vector vecFlightDir = -vecDir;
  91. VectorNormalize( vecFlightDir );
  92. float flForce = 450.f;
  93. const float flPushScale = ( pOwner->GetFlags() & FL_ONGROUND ) ? 1.2f : 1.8f; // Greater force while airborne
  94. const float flVertPushScale = ( pOwner->GetFlags() & FL_ONGROUND ) ? 1.2f : 0.25f; // Less vertical force while airborne
  95. Vector vecForce = vecFlightDir * -flForce * flPushScale;
  96. vecForce.z += 1.f * flForce * flVertPushScale;
  97. pOwner->RemoveFlag( FL_ONGROUND );
  98. pOwner->ApplyAbsVelocityImpulse( vecForce );
  99. pOwner->RemoveAmmo( m_pWeaponInfo->GetWeaponData( m_iWeaponMode ).m_iAmmoPerShot, m_iPrimaryAmmoType );
  100. pOwner->EmitSound( "Weapon_Liberty_Launcher.Single" );
  101. m_flRefireTime = gpGlobals->curtime + 0.25f;
  102. #endif // GAME_DLL
  103. StartEffectBarRegen();
  104. if ( pOwner->GetAmmoCount( TF_AMMO_GRENADES1 ) == 0 )
  105. {
  106. g_pGameRules->SwitchToNextBestWeapon( pOwner, this );
  107. }
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose:
  111. //-----------------------------------------------------------------------------
  112. bool CTFRocketPack::Deploy( void )
  113. {
  114. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  115. if ( pOwner )
  116. {
  117. pOwner->m_Shared.SetRocketPackEquipped( true );
  118. }
  119. return BaseClass::Deploy();
  120. }
  121. //-----------------------------------------------------------------------------
  122. // Purpose:
  123. //-----------------------------------------------------------------------------
  124. bool CTFRocketPack::Holster( CBaseCombatWeapon *pSwitchingTo )
  125. {
  126. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  127. if ( pOwner )
  128. {
  129. pOwner->m_Shared.SetRocketPackEquipped( false );
  130. }
  131. return BaseClass::Holster( pSwitchingTo );
  132. }