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.

91 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "cbase.h"
  14. #include "basetempentity.h"
  15. #include "te_effect_dispatch.h"
  16. #include "networkstringtable_gamedll.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. //-----------------------------------------------------------------------------
  20. // Purpose: This TE provides a simple interface to dispatch effects by name using DispatchEffect().
  21. //-----------------------------------------------------------------------------
  22. class CTEEffectDispatch : public CBaseTempEntity
  23. {
  24. public:
  25. DECLARE_CLASS( CTEEffectDispatch, CBaseTempEntity );
  26. CTEEffectDispatch( const char *name );
  27. virtual ~CTEEffectDispatch( void );
  28. DECLARE_SERVERCLASS();
  29. public:
  30. CEffectData m_EffectData;
  31. };
  32. //-----------------------------------------------------------------------------
  33. // Purpose:
  34. // Input : *name -
  35. //-----------------------------------------------------------------------------
  36. CTEEffectDispatch::CTEEffectDispatch( const char *name ) :
  37. CBaseTempEntity( name )
  38. {
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose:
  42. //-----------------------------------------------------------------------------
  43. CTEEffectDispatch::~CTEEffectDispatch( void )
  44. {
  45. }
  46. IMPLEMENT_SERVERCLASS_ST( CTEEffectDispatch, DT_TEEffectDispatch )
  47. SendPropDataTable( SENDINFO_DT( m_EffectData ), &REFERENCE_SEND_TABLE( DT_EffectData ) )
  48. END_SEND_TABLE()
  49. // Singleton to fire TEEffectDispatch objects
  50. static CTEEffectDispatch g_TEEffectDispatch( "EffectDispatch" );
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. //-----------------------------------------------------------------------------
  54. void TE_DispatchEffect( IRecipientFilter& filter, float delay, const Vector &pos, const char *pName, const CEffectData &data )
  55. {
  56. // Copy the supplied effect data.
  57. g_TEEffectDispatch.m_EffectData = data;
  58. // Get the entry index in the string table.
  59. g_TEEffectDispatch.m_EffectData.m_iEffectName = g_pStringTableEffectDispatch->AddString( CBaseEntity::IsServer(), pName );
  60. // Send it to anyone who can see the effect's origin.
  61. g_TEEffectDispatch.Create( filter, 0 );
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Purpose:
  65. //-----------------------------------------------------------------------------
  66. void DispatchEffect( const char *pName, const CEffectData &data )
  67. {
  68. CPASFilter filter( data.m_vOrigin );
  69. DispatchEffect( pName, data, filter );
  70. }
  71. void DispatchEffect( const char *pName, const CEffectData &data, CRecipientFilter &filter )
  72. {
  73. te->DispatchEffect( filter, 0.0, data.m_vOrigin, pName, data );
  74. }