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.

146 lines
4.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. // $NoKeywords: $
  5. //
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "c_basetempentity.h"
  9. #include "c_te_legacytempents.h"
  10. #include "tier1/KeyValues.h"
  11. #include "toolframework_client.h"
  12. #include "tier0/vprof.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Sprite Spray TE
  17. //-----------------------------------------------------------------------------
  18. class C_TESpriteSpray : public C_BaseTempEntity
  19. {
  20. public:
  21. DECLARE_CLASS( C_TESpriteSpray, C_BaseTempEntity );
  22. DECLARE_CLIENTCLASS();
  23. C_TESpriteSpray( void );
  24. virtual ~C_TESpriteSpray( void );
  25. virtual void PostDataUpdate( DataUpdateType_t updateType );
  26. public:
  27. Vector m_vecOrigin;
  28. Vector m_vecDirection;
  29. int m_nModelIndex;
  30. int m_nSpeed;
  31. float m_fNoise;
  32. int m_nCount;
  33. };
  34. //-----------------------------------------------------------------------------
  35. // Networking
  36. //-----------------------------------------------------------------------------
  37. IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TESpriteSpray, DT_TESpriteSpray, CTESpriteSpray)
  38. RecvPropVector( RECVINFO(m_vecOrigin)),
  39. RecvPropVector( RECVINFO(m_vecDirection)),
  40. RecvPropInt( RECVINFO(m_nModelIndex)),
  41. RecvPropFloat( RECVINFO(m_fNoise )),
  42. RecvPropInt( RECVINFO(m_nCount)),
  43. RecvPropInt( RECVINFO(m_nSpeed)),
  44. END_RECV_TABLE()
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48. C_TESpriteSpray::C_TESpriteSpray( void )
  49. {
  50. m_vecOrigin.Init();
  51. m_vecDirection.Init();
  52. m_nModelIndex = 0;
  53. m_fNoise = 0;
  54. m_nSpeed = 0;
  55. m_nCount = 0;
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. //-----------------------------------------------------------------------------
  60. C_TESpriteSpray::~C_TESpriteSpray( void )
  61. {
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Recording
  65. //-----------------------------------------------------------------------------
  66. static inline void RecordSpriteSpray( const Vector& start, const Vector &direction,
  67. int nModelIndex, int nSpeed, float flNoise, int nCount )
  68. {
  69. if ( !ToolsEnabled() )
  70. return;
  71. if ( clienttools->IsInRecordingMode() )
  72. {
  73. const model_t* pModel = (nModelIndex != 0) ? modelinfo->GetModel( nModelIndex ) : NULL;
  74. const char *pModelName = pModel ? modelinfo->GetModelName( pModel ) : "";
  75. KeyValues *msg = new KeyValues( "TempEntity" );
  76. msg->SetInt( "te", TE_SPRITE_SPRAY );
  77. msg->SetString( "name", "TE_SpriteSpray" );
  78. msg->SetFloat( "time", gpGlobals->curtime );
  79. msg->SetFloat( "originx", start.x );
  80. msg->SetFloat( "originy", start.y );
  81. msg->SetFloat( "originz", start.z );
  82. msg->SetFloat( "directionx", direction.x );
  83. msg->SetFloat( "directiony", direction.y );
  84. msg->SetFloat( "directionz", direction.z );
  85. msg->SetString( "model", pModelName );
  86. msg->SetInt( "speed", nSpeed );
  87. msg->SetFloat( "noise", flNoise );
  88. msg->SetInt( "count", nCount );
  89. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  90. msg->deleteThis();
  91. }
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Purpose:
  95. //-----------------------------------------------------------------------------
  96. void C_TESpriteSpray::PostDataUpdate( DataUpdateType_t updateType )
  97. {
  98. VPROF( "C_TESpriteSpray::PostDataUpdate" );
  99. tempents->Sprite_Spray( m_vecOrigin, m_vecDirection, m_nModelIndex, m_nCount, m_nSpeed * 0.2, m_fNoise * 100.0 );
  100. RecordSpriteSpray( m_vecOrigin, m_vecDirection, m_nModelIndex, m_nSpeed, m_fNoise, m_nCount );
  101. }
  102. void TE_SpriteSpray( IRecipientFilter& filter, float delay,
  103. const Vector* pos, const Vector* dir, int modelindex, int speed, float noise, int count )
  104. {
  105. tempents->Sprite_Spray( *pos, *dir, modelindex, count, speed * 0.2, noise * 100.0 );
  106. RecordSpriteSpray( *pos, *dir, modelindex, speed, noise, count );
  107. }
  108. void TE_SpriteSpray( IRecipientFilter& filter, float delay, KeyValues *pKeyValues )
  109. {
  110. Vector vecOrigin, vecDirection;
  111. vecOrigin.x = pKeyValues->GetFloat( "originx" );
  112. vecOrigin.y = pKeyValues->GetFloat( "originy" );
  113. vecOrigin.z = pKeyValues->GetFloat( "originz" );
  114. vecDirection.x = pKeyValues->GetFloat( "directionx" );
  115. vecDirection.y = pKeyValues->GetFloat( "directiony" );
  116. vecDirection.z = pKeyValues->GetFloat( "directionz" );
  117. const char *pModelName = pKeyValues->GetString( "model" );
  118. int nModelIndex = pModelName[0] ? modelinfo->GetModelIndex( pModelName ) : 0;
  119. int nSpeed = pKeyValues->GetInt( "speed" );
  120. float flNoise = pKeyValues->GetFloat( "noise" );
  121. int nCount = pKeyValues->GetInt( "count" );
  122. TE_SpriteSpray( filter, delay, &vecOrigin, &vecDirection, nModelIndex, nSpeed, flNoise, nCount );
  123. }