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.

106 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Game-specific explosion effects
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "c_te_effect_dispatch.h"
  8. #include "tempent.h"
  9. #include "c_te_legacytempents.h"
  10. #include "dod_shareddefs.h"
  11. #include "engine/IEngineSound.h"
  12. #include "c_basetempentity.h"
  13. #include "tier0/vprof.h"
  14. #include "fx_explosion.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose:
  17. //-----------------------------------------------------------------------------
  18. void DODExplosionCallback( const Vector &vecOrigin, const Vector &vecNormal )
  19. {
  20. // Calculate the angles, given the normal.
  21. bool bInAir = false;
  22. QAngle angExplosion( 0.0f, 0.0f, 0.0f );
  23. // Cannot use zeros here because we are sending the normal at a smaller bit size.
  24. if ( fabs( vecNormal.x ) < 0.05f && fabs( vecNormal.y ) < 0.05f && fabs( vecNormal.z ) < 0.05f )
  25. {
  26. bInAir = true;
  27. angExplosion.Init();
  28. }
  29. else
  30. {
  31. VectorAngles( vecNormal, angExplosion );
  32. bInAir = false;
  33. }
  34. // Base explosion effect and sound.
  35. char *pszEffect = "explosion";
  36. char *pszSound = "BaseExplosionEffect.Sound";
  37. // Explosions.
  38. if ( UTIL_PointContents( vecOrigin ) & CONTENTS_WATER )
  39. {
  40. WaterExplosionEffect().Create( vecOrigin, 1 /*m_nMagnitude*/, 1 /*m_fScale*/, 0 /*m_nFlags*/ );
  41. return;
  42. }
  43. else if ( bInAir )
  44. {
  45. pszEffect = "explosioncore_midair";
  46. }
  47. else
  48. {
  49. pszEffect = "explosioncore_floor";
  50. }
  51. CLocalPlayerFilter filter;
  52. C_BaseEntity::EmitSound( filter, SOUND_FROM_WORLD, pszSound, &vecOrigin );
  53. DispatchParticleEffect( pszEffect, vecOrigin, angExplosion );
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. //-----------------------------------------------------------------------------
  58. class C_TEDODExplosion : public C_BaseTempEntity
  59. {
  60. public:
  61. DECLARE_CLASS( C_TEDODExplosion, C_BaseTempEntity );
  62. DECLARE_CLIENTCLASS();
  63. C_TEDODExplosion( void );
  64. virtual void PostDataUpdate( DataUpdateType_t updateType );
  65. public:
  66. Vector m_vecOrigin;
  67. Vector m_vecNormal;
  68. };
  69. //-----------------------------------------------------------------------------
  70. // Purpose:
  71. //-----------------------------------------------------------------------------
  72. C_TEDODExplosion::C_TEDODExplosion( void )
  73. {
  74. m_vecOrigin.Init();
  75. m_vecNormal.Init();
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose:
  79. //-----------------------------------------------------------------------------
  80. void C_TEDODExplosion::PostDataUpdate( DataUpdateType_t updateType )
  81. {
  82. VPROF( "C_TETFExplosion::PostDataUpdate" );
  83. DODExplosionCallback( m_vecOrigin, m_vecNormal );
  84. }
  85. IMPLEMENT_CLIENTCLASS_EVENT_DT( C_TEDODExplosion, DT_TEDODExplosion, CTEDODExplosion )
  86. RecvPropFloat( RECVINFO( m_vecOrigin[0] ) ),
  87. RecvPropFloat( RECVINFO( m_vecOrigin[1] ) ),
  88. RecvPropFloat( RECVINFO( m_vecOrigin[2] ) ),
  89. RecvPropVector( RECVINFO( m_vecNormal ) ),
  90. END_RECV_TABLE()