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.

156 lines
4.2 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "c_entityflame.h"
  9. #include "particle_property.h"
  10. #include "iefx.h"
  11. #include "dlight.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //-----------------------------------------------------------------------------
  15. // Datadesc
  16. //-----------------------------------------------------------------------------
  17. IMPLEMENT_CLIENTCLASS_DT( C_EntityFlame, DT_EntityFlame, CEntityFlame )
  18. RecvPropEHandle(RECVINFO(m_hEntAttached)),
  19. RecvPropBool(RECVINFO(m_bCheapEffect)),
  20. END_RECV_TABLE()
  21. //-----------------------------------------------------------------------------
  22. // Purpose:
  23. //-----------------------------------------------------------------------------
  24. C_EntityFlame::C_EntityFlame( void ) : m_hEffect( NULL )
  25. {
  26. m_hOldAttached = NULL;
  27. AddToEntityList( ENTITY_LIST_SIMULATE );
  28. }
  29. //-----------------------------------------------------------------------------
  30. // Purpose:
  31. //-----------------------------------------------------------------------------
  32. C_EntityFlame::~C_EntityFlame( void )
  33. {
  34. StopEffect();
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose:
  38. //-----------------------------------------------------------------------------
  39. void C_EntityFlame::StopEffect( void )
  40. {
  41. if ( m_hEffect )
  42. {
  43. ParticleProp()->StopEmission( m_hEffect, true );
  44. m_hEffect = NULL;
  45. }
  46. if ( m_hEntAttached )
  47. {
  48. m_hEntAttached->RemoveFlag( FL_ONFIRE );
  49. m_hEntAttached->SetEffectEntity( NULL );
  50. m_hEntAttached->StopSound( "General.BurningFlesh" );
  51. m_hEntAttached->StopSound( "General.BurningObject" );
  52. m_hEntAttached = NULL;
  53. }
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. //-----------------------------------------------------------------------------
  58. void C_EntityFlame::UpdateOnRemove( void )
  59. {
  60. StopEffect();
  61. BaseClass::UpdateOnRemove();
  62. }
  63. void C_EntityFlame::CreateEffect( void )
  64. {
  65. if ( m_hEffect )
  66. {
  67. m_hOldAttached = m_hEntAttached;
  68. ParticleProp()->StopEmission( m_hEffect, true );
  69. m_hEffect = NULL;
  70. }
  71. C_BaseEntity *pEntity = m_hEntAttached;
  72. if ( pEntity && !pEntity->IsAbleToHaveFireEffect() )
  73. return;
  74. m_hEffect = ParticleProp()->Create( m_bCheapEffect ? "burning_gib_01" : "burning_character", PATTACH_ABSORIGIN_FOLLOW );
  75. if ( m_hEffect )
  76. {
  77. m_hOldAttached = m_hEntAttached;
  78. ParticleProp()->AddControlPoint( m_hEffect, 1, pEntity, PATTACH_ABSORIGIN_FOLLOW );
  79. m_hEffect->SetControlPoint( 0, GetAbsOrigin() );
  80. m_hEffect->SetControlPoint( 1, GetAbsOrigin() );
  81. m_hEffect->SetControlPointEntity( 0, pEntity );
  82. m_hEffect->SetControlPointEntity( 1, pEntity );
  83. }
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose:
  87. //-----------------------------------------------------------------------------
  88. void C_EntityFlame::OnDataChanged( DataUpdateType_t updateType )
  89. {
  90. if ( updateType == DATA_UPDATE_CREATED )
  91. {
  92. CreateEffect();
  93. }
  94. // FIXME: This is a bit of a shady path
  95. if ( updateType == DATA_UPDATE_DATATABLE_CHANGED )
  96. {
  97. // If our owner changed, then recreate the effect
  98. if ( m_hEntAttached != m_hOldAttached )
  99. {
  100. CreateEffect();
  101. }
  102. }
  103. BaseClass::OnDataChanged( updateType );
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Purpose:
  107. //-----------------------------------------------------------------------------
  108. bool C_EntityFlame::Simulate( void )
  109. {
  110. if ( gpGlobals->frametime <= 0.0f )
  111. return true;
  112. #ifdef HL2_EPISODIC
  113. if ( IsEffectActive(EF_BRIGHTLIGHT) || IsEffectActive(EF_DIMLIGHT) )
  114. {
  115. dlight_t *dl = effects->CL_AllocDlight( index );
  116. dl->origin = GetAbsOrigin();
  117. dl->origin[2] += 16;
  118. dl->color.r = 254;
  119. dl->color.g = 174;
  120. dl->color.b = 10;
  121. dl->radius = random->RandomFloat(400,431);
  122. dl->die = gpGlobals->curtime + 0.001;
  123. }
  124. #endif // HL2_EPISODIC
  125. return true;
  126. }
  127. //-----------------------------------------------------------------------------
  128. // Purpose:
  129. //-----------------------------------------------------------------------------
  130. void C_EntityFlame::ClientThink( void )
  131. {
  132. StopEffect();
  133. Release();
  134. }