Counter Strike : Global Offensive Source Code
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.

207 lines
5.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "weapon_csbase.h"
  8. #include "gamerules.h"
  9. #include "npcevent.h"
  10. #include "engine/IEngineSound.h"
  11. #include "weapon_molotov.h"
  12. #ifdef CLIENT_DLL
  13. #include "c_cs_player.h"
  14. #else
  15. #include "cs_player.h"
  16. #include "items.h"
  17. #include "molotov_projectile.h"
  18. #include "Effects/inferno.h"
  19. #endif
  20. // NOTE: This has to be the last file included!
  21. #include "tier0/memdbgon.h"
  22. IMPLEMENT_NETWORKCLASS_ALIASED( MolotovGrenade, DT_MolotovGrenade )
  23. BEGIN_NETWORK_TABLE( CMolotovGrenade, DT_MolotovGrenade )
  24. END_NETWORK_TABLE()
  25. BEGIN_PREDICTION_DATA( CMolotovGrenade )
  26. END_PREDICTION_DATA()
  27. LINK_ENTITY_TO_CLASS_ALIASED( weapon_molotov, MolotovGrenade );
  28. PRECACHE_REGISTER( weapon_molotov );
  29. #if !defined( CLIENT_DLL )
  30. BEGIN_DATADESC( CMolotovGrenade )
  31. END_DATADESC()
  32. void CMolotovGrenade::EmitGrenade( Vector vecSrc, QAngle vecAngles, Vector vecVel, AngularImpulse angImpulse, CBasePlayer *pPlayer, const CCSWeaponInfo& weaponInfo )
  33. {
  34. // [mlowrance] were throwing the grenade, be sure to remove flame sound effect
  35. SetLoopingSoundPlaying( false );
  36. StopSound( "Molotov.IdleLoop" );
  37. //DevMsg( 1, "---------->Stopping Molotov.IdleLoop 2\n" );
  38. CMolotovProjectile::Create( vecSrc, vecAngles, vecVel, angImpulse, pPlayer, weaponInfo );
  39. }
  40. void CMolotovGrenade::Precache( void )
  41. {
  42. BaseClass::Precache();
  43. PrecacheScriptSound( "Molotov.IdleLoop" );
  44. }
  45. #else // GAME_DLL
  46. static int s_nMolotovFire;
  47. PRECACHE_REGISTER_BEGIN( GLOBAL, CMolotovGrenade )
  48. PRECACHE_INDEX( PARTICLE_SYSTEM, "weapon_molotov_held", s_nMolotovFire );
  49. PRECACHE_REGISTER_END()
  50. void CMolotovGrenade::UpdateParticles( void )
  51. {
  52. // FIXME: This is bogus; we need to make the particle property have particle system types:
  53. // first person, third person, owner, and logic in the particle property to know whether
  54. // to render a given system given these rules and knowledge of what mode the owner is in
  55. C_CSPlayer *pPlayer = ToCSPlayer( GetOwner() );
  56. if ( !pPlayer )
  57. return;
  58. int nRenderFlags = 0;
  59. CWeaponCSBase *pCSWeapon = (CWeaponCSBase*)pPlayer->GetActiveWeapon();
  60. if ( !pCSWeapon )
  61. return;
  62. int iWeaponId = pCSWeapon->GetCSWeaponID();
  63. if ( iWeaponId == WEAPON_MOLOTOV )
  64. {
  65. bool bIsFirstOrThirdpersonMolotovVisible = pCSWeapon->IsWeaponVisible();
  66. CBaseAnimating *pWeaponBaseAnimating = pCSWeapon->GetBaseAnimating();
  67. CBaseWeaponWorldModel *pWeaponWorldModel = pCSWeapon->GetWeaponWorldModel();
  68. if ( pWeaponWorldModel && pWeaponWorldModel->ShouldDraw() )
  69. {
  70. pWeaponBaseAnimating = pWeaponWorldModel->GetBaseAnimating();
  71. bIsFirstOrThirdpersonMolotovVisible = true;
  72. }
  73. if ( m_molotovParticleEffect.IsValid() )
  74. {
  75. // m_molotovParticleEffect->SetDormant( pPlayer->GetPlayerAnimState()->ShouldHideWeapon() ); // ShouldHideWeapon is a Terror Codebase function, not CStrike15
  76. m_molotovParticleEffect->SetDormant( !bIsFirstOrThirdpersonMolotovVisible ); // Is the weapon Hidden?
  77. }
  78. if ( bIsFirstOrThirdpersonMolotovVisible )
  79. {
  80. if ( m_bPinPulled )
  81. {
  82. if ( !m_molotovParticleEffect() )
  83. {
  84. // TEST: [mlowrance] This is to test for attachment.
  85. int iAttachment = -1;
  86. if ( pWeaponBaseAnimating )
  87. iAttachment = pWeaponBaseAnimating->LookupAttachment( "Wick" );
  88. if ( iAttachment >= 0 )
  89. {
  90. // FIXME: Precache 'Wick' attachment index
  91. m_molotovParticleEffect = pWeaponBaseAnimating->ParticleProp()->CreatePrecached( s_nMolotovFire, PATTACH_POINT_FOLLOW, iAttachment );
  92. EmitSound( "Molotov.IdleLoop" );
  93. SetLoopingSoundPlaying( true );
  94. //DevMsg( 1, "++++++++++>Playing Molotov.IdleLoop 1\n" );
  95. }
  96. }
  97. if ( m_molotovParticleEffect() )
  98. {
  99. if ( nRenderFlags != 3 )
  100. {
  101. m_molotovParticleEffect->SetDrawOnlyForSplitScreenUser( nRenderFlags - 1 );
  102. }
  103. else
  104. {
  105. m_molotovParticleEffect->SetDrawOnlyForSplitScreenUser( -1 );
  106. }
  107. }
  108. }
  109. }
  110. }
  111. else
  112. {
  113. if ( m_molotovParticleEffect.IsValid() )
  114. {
  115. StopSound( "Molotov.IdleLoop" );
  116. //DevMsg( 1, "---------->Stopping Molotov.IdleLoop 1\n" );
  117. m_molotovParticleEffect->StopEmission( false, false );
  118. m_molotovParticleEffect->SetRemoveFlag();
  119. m_molotovParticleEffect = NULL;
  120. }
  121. }
  122. }
  123. bool CMolotovGrenade::Simulate( void )
  124. {
  125. UpdateParticles();
  126. return BaseClass::Simulate();
  127. }
  128. //--------------------------------------------------------------------------------------------------------
  129. void CMolotovGrenade::OnParticleEffectDeleted( CNewParticleEffect *pParticleEffect )
  130. {
  131. if ( m_molotovParticleEffect() == pParticleEffect )
  132. {
  133. m_molotovParticleEffect = NULL;
  134. }
  135. }
  136. #endif // !CLIENT_DLL
  137. void CMolotovGrenade::Drop(const Vector& vecVelocity)
  138. {
  139. CBaseCSGrenade::Drop(vecVelocity);
  140. StopSound( "Molotov.IdleLoop" );
  141. SetLoopingSoundPlaying( false );
  142. }
  143. IMPLEMENT_NETWORKCLASS_ALIASED( IncendiaryGrenade, DT_IncendiaryGrenade )
  144. BEGIN_NETWORK_TABLE( CIncendiaryGrenade, DT_IncendiaryGrenade )
  145. END_NETWORK_TABLE()
  146. //BEGIN_PREDICTION_DATA( CIncendiaryGrenade )
  147. //END_PREDICTION_DATA()
  148. LINK_ENTITY_TO_CLASS_ALIASED( weapon_incgrenade, IncendiaryGrenade );
  149. PRECACHE_REGISTER( weapon_incgrenade );
  150. #if !defined( CLIENT_DLL )
  151. void CIncendiaryGrenade::EmitGrenade( Vector vecSrc, QAngle vecAngles, Vector vecVel, AngularImpulse angImpulse, CBasePlayer *pPlayer, const CCSWeaponInfo& weaponInfo )
  152. {
  153. // [mlowrance] were throwing the grenade, be sure to remove flame sound effect
  154. SetLoopingSoundPlaying( false );
  155. StopSound( "Molotov.IdleLoop" );
  156. //DevMsg( 1, "---------->Stopping Molotov.IdleLoop 2\n" );
  157. CMolotovProjectile::Create( vecSrc, vecAngles, vecVel, angImpulse, pPlayer, weaponInfo );
  158. }
  159. void CIncendiaryGrenade::Precache( void )
  160. {
  161. BaseClass::Precache();
  162. PrecacheScriptSound( "Molotov.IdleLoop" );
  163. }
  164. #else // GAME_DLL
  165. #endif // !CLIENT_DLL