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.

175 lines
5.9 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //===========================================================================//
  9. #include "cbase.h"
  10. #include "c_basetempentity.h"
  11. #include "c_te_legacytempents.h"
  12. #include "fx.h"
  13. #include "tier1/keyvalues.h"
  14. #include "tier0/vprof.h"
  15. #include "toolframework_client.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. extern int g_sModelIndexBloodDrop;
  19. extern int g_sModelIndexBloodSpray;
  20. //-----------------------------------------------------------------------------
  21. // Purpose: Blood sprite
  22. //-----------------------------------------------------------------------------
  23. class C_TEBloodSprite : public C_BaseTempEntity
  24. {
  25. public:
  26. DECLARE_CLASS( C_TEBloodSprite, C_BaseTempEntity );
  27. DECLARE_CLIENTCLASS();
  28. C_TEBloodSprite( void );
  29. virtual ~C_TEBloodSprite( void );
  30. virtual void PostDataUpdate( DataUpdateType_t updateType );
  31. public:
  32. Vector m_vecOrigin;
  33. Vector m_vecDirection;
  34. int r, g, b, a;
  35. int m_nDropModel;
  36. int m_nSprayModel;
  37. int m_nSize;
  38. };
  39. // Expose it to the engine.
  40. IMPLEMENT_CLIENTCLASS_EVENT( C_TEBloodSprite, DT_TEBloodSprite, CTEBloodSprite );
  41. //-----------------------------------------------------------------------------
  42. // Networking
  43. //-----------------------------------------------------------------------------
  44. BEGIN_RECV_TABLE_NOBASE(C_TEBloodSprite, DT_TEBloodSprite)
  45. RecvPropVector( RECVINFO(m_vecOrigin)),
  46. RecvPropVector( RECVINFO(m_vecDirection)),
  47. RecvPropInt( RECVINFO(r)),
  48. RecvPropInt( RECVINFO(g)),
  49. RecvPropInt( RECVINFO(b)),
  50. RecvPropInt( RECVINFO(a)),
  51. RecvPropInt( RECVINFO(m_nSprayModel)),
  52. RecvPropInt( RECVINFO(m_nDropModel)),
  53. RecvPropInt( RECVINFO(m_nSize)),
  54. END_RECV_TABLE()
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. //-----------------------------------------------------------------------------
  58. C_TEBloodSprite::C_TEBloodSprite( void )
  59. {
  60. m_vecOrigin.Init();
  61. m_vecDirection.Init();
  62. r = g = b = a = 0;
  63. m_nSize = 0;
  64. m_nSprayModel = 0;
  65. m_nDropModel = 0;
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. //-----------------------------------------------------------------------------
  70. C_TEBloodSprite::~C_TEBloodSprite( void )
  71. {
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Recording
  75. //-----------------------------------------------------------------------------
  76. static inline void RecordBloodSprite( const Vector &start, const Vector &direction,
  77. int r, int g, int b, int a, int nSprayModelIndex, int nDropModelIndex, int size )
  78. {
  79. if ( !ToolsEnabled() )
  80. return;
  81. if ( clienttools->IsInRecordingMode() )
  82. {
  83. Color clr( r, g, b, a );
  84. const model_t* pSprayModel = (nSprayModelIndex != 0) ? modelinfo->GetModel( nSprayModelIndex ) : NULL;
  85. const model_t* pDropModel = (nDropModelIndex != 0) ? modelinfo->GetModel( nDropModelIndex ) : NULL;
  86. const char *pSprayModelName = pSprayModel ? modelinfo->GetModelName( pSprayModel ) : "";
  87. const char *pDropModelName = pDropModel ? modelinfo->GetModelName( pDropModel ) : "";
  88. KeyValues *msg = new KeyValues( "TempEntity" );
  89. msg->SetInt( "te", TE_BLOOD_SPRITE );
  90. msg->SetString( "name", "TE_BloodSprite" );
  91. msg->SetFloat( "time", gpGlobals->curtime );
  92. msg->SetFloat( "originx", start.x );
  93. msg->SetFloat( "originy", start.y );
  94. msg->SetFloat( "originz", start.z );
  95. msg->SetFloat( "directionx", direction.x );
  96. msg->SetFloat( "directiony", direction.y );
  97. msg->SetFloat( "directionz", direction.z );
  98. msg->SetColor( "color", clr );
  99. msg->SetString( "spraymodel", pSprayModelName );
  100. msg->SetString( "dropmodel", pDropModelName );
  101. msg->SetInt( "size", size );
  102. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  103. msg->deleteThis();
  104. }
  105. }
  106. //-----------------------------------------------------------------------------
  107. // Recording
  108. //-----------------------------------------------------------------------------
  109. void TE_BloodSprite( IRecipientFilter& filter, float delay,
  110. const Vector* org, const Vector *dir, int r, int g, int b, int a, int size )
  111. {
  112. Vector offset = *org + ( (*dir) * 4.0f );
  113. tempents->BloodSprite( offset, r, g, b, a, g_sModelIndexBloodSpray, g_sModelIndexBloodDrop, size );
  114. FX_Blood( offset, (Vector &)*dir, r, g, b, a );
  115. RecordBloodSprite( *org, *dir, r, g, b, a, g_sModelIndexBloodSpray, g_sModelIndexBloodDrop, size );
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Purpose:
  119. //-----------------------------------------------------------------------------
  120. void C_TEBloodSprite::PostDataUpdate( DataUpdateType_t updateType )
  121. {
  122. VPROF( "C_TEBloodSprite::PostDataUpdate" );
  123. Vector offset = m_vecOrigin + ( m_vecDirection * 4.0f );
  124. tempents->BloodSprite( offset, r, g, b, a, m_nSprayModel, m_nDropModel, m_nSize );
  125. FX_Blood( offset, m_vecDirection, r, g, b, a );
  126. RecordBloodSprite( m_vecOrigin, m_vecDirection, r, g, b, a, m_nSprayModel, m_nDropModel, m_nSize );
  127. }
  128. void TE_BloodSprite( IRecipientFilter& filter, float delay, KeyValues *pKeyValues )
  129. {
  130. #ifdef PORTAL2
  131. Error( "Attempted to create blood particle!\n" );
  132. #else
  133. Vector vecOrigin, vecDirection;
  134. vecOrigin.x = pKeyValues->GetFloat( "originx" );
  135. vecOrigin.y = pKeyValues->GetFloat( "originy" );
  136. vecOrigin.z = pKeyValues->GetFloat( "originz" );
  137. vecDirection.x = pKeyValues->GetFloat( "directionx" );
  138. vecDirection.y = pKeyValues->GetFloat( "directiony" );
  139. vecDirection.z = pKeyValues->GetFloat( "directionz" );
  140. Color c = pKeyValues->GetColor( "color" );
  141. // const char *pSprayModelName = pKeyValues->GetString( "spraymodel" );
  142. // const char *pDropModelName = pKeyValues->GetString( "dropmodel" );
  143. int nSize = pKeyValues->GetInt( "size" );
  144. TE_BloodSprite( filter, 0.0f, &vecOrigin, &vecDirection, c.r(), c.g(), c.b(), c.a(), nSize );
  145. #endif // P2
  146. }