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.

120 lines
2.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "dod_smokegrenade.h"
  8. #include "particle_parse.h"
  9. LINK_ENTITY_TO_CLASS( grenade_smoke, CDODSmokeGrenade );
  10. PRECACHE_WEAPON_REGISTER( grenade_smoke );
  11. BEGIN_DATADESC( CDODSmokeGrenade )
  12. DEFINE_THINKFUNC( Think_Emit ),
  13. DEFINE_THINKFUNC( Think_Fade ),
  14. DEFINE_THINKFUNC( Think_Remove )
  15. END_DATADESC()
  16. IMPLEMENT_SERVERCLASS_ST( CDODSmokeGrenade, DT_DODSmokeGrenade )
  17. SendPropTime(SENDINFO(m_flSmokeSpawnTime) ),
  18. END_SEND_TABLE()
  19. void CDODSmokeGrenade::Spawn()
  20. {
  21. BaseClass::Spawn();
  22. SetThink( &CDODSmokeGrenade::Think_Emit );
  23. SetNextThink( gpGlobals->curtime + 0.5 );
  24. m_bInitialSmoke = false;
  25. m_flRemoveTime = -1;
  26. m_flSmokeSpawnTime = 0;
  27. }
  28. void CDODSmokeGrenade::Precache()
  29. {
  30. PrecacheScriptSound( "SmokeGrenade.Bounce" );
  31. PrecacheParticleSystem( "smokegrenade" );
  32. PrecacheParticleSystem( "smokegrenade_jet" );
  33. BaseClass::Precache();
  34. }
  35. void CDODSmokeGrenade::BounceSound( void )
  36. {
  37. EmitSound( "SmokeGrenade.Bounce" );
  38. }
  39. void CDODSmokeGrenade::Think_Emit( void )
  40. {
  41. // if we're stationary and have not yet created smoke, do so now
  42. Vector vel;
  43. AngularImpulse a;
  44. VPhysicsGetObject()->GetVelocity( &vel, &a );
  45. if ( vel.Length() < 15.0 && !m_bInitialSmoke )
  46. {
  47. VPhysicsGetObject()->EnableMotion( false );
  48. // Smoke Cloud
  49. DispatchParticleEffect( "smokegrenade", GetAbsOrigin(), vec3_angle );
  50. // Smoke Jet
  51. DispatchParticleEffect( "smokegrenade_jet", PATTACH_POINT, this, "jet" );
  52. EmitSound( "BaseSmokeEffect.Sound" );
  53. m_flRemoveTime = gpGlobals->curtime + 10;
  54. m_bInitialSmoke = true;
  55. m_flSmokeSpawnTime = gpGlobals->curtime;
  56. }
  57. // if its past our bedtime, fade out
  58. if ( m_flRemoveTime > 0 && gpGlobals->curtime > m_flRemoveTime )
  59. {
  60. m_nRenderMode = kRenderTransColor;
  61. SetThink( &CDODSmokeGrenade::Think_Fade );
  62. }
  63. SetNextThink( gpGlobals->curtime + 0.1 );
  64. }
  65. // Fade the projectile out over time before making it disappear
  66. void CDODSmokeGrenade::Think_Fade()
  67. {
  68. m_bFading = true;
  69. SetNextThink( gpGlobals->curtime );
  70. color32 c = GetRenderColor();
  71. c.a -= 1;
  72. SetRenderColor( c.r, c.b, c.g, c.a );
  73. if ( !c.a )
  74. {
  75. SetModelName( NULL_STRING );//invisible
  76. SetNextThink( gpGlobals->curtime + 10 );
  77. SetThink( &CDODSmokeGrenade::Think_Remove ); // Spit out smoke for 10 seconds.
  78. SetSolid( SOLID_NONE );
  79. }
  80. }
  81. void CDODSmokeGrenade::Think_Remove()
  82. {
  83. // stop all effects
  84. StopParticleEffects( this );
  85. SetModelName( NULL_STRING );//invisible
  86. SetSolid( SOLID_NONE );
  87. SetMoveType( MOVETYPE_NONE );
  88. UTIL_Remove( this );
  89. }
  90. void CDODSmokeGrenade::Detonate( void )
  91. {
  92. // Intentionally blank - our detonate does nothing
  93. }