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.

125 lines
3.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "particle_smokegrenade.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. IMPLEMENT_SERVERCLASS_ST(ParticleSmokeGrenade, DT_ParticleSmokeGrenade)
  13. SendPropTime( SENDINFO(m_flSpawnTime) ),
  14. SendPropFloat( SENDINFO(m_FadeStartTime), 0, SPROP_NOSCALE),
  15. SendPropFloat( SENDINFO(m_FadeEndTime), 0, SPROP_NOSCALE),
  16. SendPropVector( SENDINFO(m_MinColor), 0, SPROP_NOSCALE),
  17. SendPropVector( SENDINFO(m_MaxColor), 0, SPROP_NOSCALE),
  18. SendPropInt( SENDINFO(m_CurrentStage), 1, SPROP_UNSIGNED),
  19. END_SEND_TABLE()
  20. LINK_ENTITY_TO_CLASS( env_particlesmokegrenade, ParticleSmokeGrenade );
  21. BEGIN_DATADESC( ParticleSmokeGrenade )
  22. DEFINE_FIELD( m_CurrentStage, FIELD_CHARACTER ),
  23. DEFINE_FIELD( m_FadeStartTime, FIELD_TIME ),
  24. DEFINE_FIELD( m_FadeEndTime, FIELD_TIME ),
  25. DEFINE_FIELD( m_MinColor, FIELD_VECTOR ),
  26. DEFINE_FIELD( m_MaxColor, FIELD_VECTOR ),
  27. DEFINE_FIELD( m_flSpawnTime, FIELD_TIME ),
  28. END_DATADESC()
  29. ParticleSmokeGrenade::ParticleSmokeGrenade()
  30. {
  31. m_CurrentStage = 0;
  32. m_FadeStartTime = 17;
  33. m_FadeEndTime = 22;
  34. m_MinColor = Vector(MIN_SMOKE_TINT, MIN_SMOKE_TINT, MIN_SMOKE_TINT);
  35. m_MaxColor = Vector(MAX_SMOKE_TINT, MAX_SMOKE_TINT, MAX_SMOKE_TINT);
  36. m_flSpawnTime = gpGlobals->curtime;
  37. }
  38. ParticleSmokeGrenade::~ParticleSmokeGrenade()
  39. {
  40. }
  41. // Smoke grenade particles should always transmitted to clients. If not, a client who
  42. // enters the PVS late will see the smoke start billowing from then, allowing better vision.
  43. int ParticleSmokeGrenade::UpdateTransmitState( void )
  44. {
  45. if ( IsEffectActive( EF_NODRAW ) )
  46. return SetTransmitState( FL_EDICT_DONTSEND );
  47. return SetTransmitState( FL_EDICT_ALWAYS );
  48. }
  49. void ParticleSmokeGrenade::Spawn()
  50. {
  51. BaseClass::Spawn();
  52. SetNextThink( gpGlobals->curtime );
  53. m_creatorPlayer = NULL;
  54. }
  55. void ParticleSmokeGrenade::SetCreator(CBasePlayer *creator)
  56. {
  57. m_creatorPlayer = creator;
  58. }
  59. CBasePlayer* ParticleSmokeGrenade::GetCreator()
  60. {
  61. return (CBasePlayer*)m_creatorPlayer.Get();
  62. }
  63. void ParticleSmokeGrenade::FillVolume()
  64. {
  65. m_CurrentStage = 1;
  66. CollisionProp()->SetCollisionBounds( Vector( -50, -50, -50 ), Vector( 50, 50, 50 ) );
  67. }
  68. void ParticleSmokeGrenade::SetFadeTime(float startTime, float endTime)
  69. {
  70. m_FadeStartTime = startTime;
  71. m_FadeEndTime = endTime;
  72. }
  73. // Fade start and end are relative to current time
  74. void ParticleSmokeGrenade::SetRelativeFadeTime(float startTime, float endTime)
  75. {
  76. float flCurrentTime = gpGlobals->curtime - m_flSpawnTime;
  77. m_FadeStartTime = flCurrentTime + startTime;
  78. m_FadeEndTime = flCurrentTime + endTime;
  79. }
  80. // Fade start and end are relative to current time
  81. void ParticleSmokeGrenade::SetSmokeColor( Vector color )
  82. {
  83. m_MinColor = color * MIN_SMOKE_TINT;
  84. m_MaxColor = color * MAX_SMOKE_TINT;
  85. }
  86. void ParticleSmokeGrenade::Think()
  87. {
  88. // Override, don't extend. (Baseclass's Think just deletes.)
  89. float now = gpGlobals->curtime;
  90. if( now >= (m_flSpawnTime + m_FadeEndTime) )
  91. {
  92. // We are done
  93. UTIL_Remove(this);
  94. return;
  95. }
  96. const float PSG_THINK_DELAY = 1.0f;
  97. SetNextThink(now + PSG_THINK_DELAY);
  98. }