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.

182 lines
5.4 KiB

  1. //========= Copyright 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 "IEffects.h"
  12. #include "tier1/KeyValues.h"
  13. #include "tier0/vprof.h"
  14. #include "toolframework_client.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Armor Ricochet TE
  19. //-----------------------------------------------------------------------------
  20. class C_TEMetalSparks : public C_BaseTempEntity
  21. {
  22. public:
  23. DECLARE_CLIENTCLASS();
  24. C_TEMetalSparks( void );
  25. virtual ~C_TEMetalSparks( void );
  26. virtual void PostDataUpdate( DataUpdateType_t updateType );
  27. virtual void Precache( void );
  28. public:
  29. Vector m_vecPos;
  30. Vector m_vecDir;
  31. const struct model_t *m_pModel;
  32. };
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. //-----------------------------------------------------------------------------
  36. C_TEMetalSparks::C_TEMetalSparks( void )
  37. {
  38. m_vecPos.Init();
  39. m_vecDir.Init();
  40. m_pModel = NULL;
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. //-----------------------------------------------------------------------------
  45. C_TEMetalSparks::~C_TEMetalSparks( void )
  46. {
  47. }
  48. void C_TEMetalSparks::Precache( void )
  49. {
  50. //m_pModel = engine->LoadModel( "sprites/richo1.vmt" );
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Recording
  54. //-----------------------------------------------------------------------------
  55. static inline void RecordMetalSparks( const Vector &start, const Vector &direction )
  56. {
  57. if ( !ToolsEnabled() )
  58. return;
  59. if ( clienttools->IsInRecordingMode() )
  60. {
  61. KeyValues *msg = new KeyValues( "TempEntity" );
  62. msg->SetInt( "te", TE_METAL_SPARKS );
  63. msg->SetString( "name", "TE_MetalSparks" );
  64. msg->SetFloat( "time", gpGlobals->curtime );
  65. msg->SetFloat( "originx", start.x );
  66. msg->SetFloat( "originy", start.y );
  67. msg->SetFloat( "originz", start.z );
  68. msg->SetFloat( "directionx", direction.x );
  69. msg->SetFloat( "directiony", direction.y );
  70. msg->SetFloat( "directionz", direction.z );
  71. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  72. msg->deleteThis();
  73. }
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Purpose:
  77. // Input : bool -
  78. //-----------------------------------------------------------------------------
  79. void C_TEMetalSparks::PostDataUpdate( DataUpdateType_t updateType )
  80. {
  81. VPROF( "C_TEMetalSparks::PostDataUpdate" );
  82. g_pEffects->MetalSparks( m_vecPos, m_vecDir );
  83. RecordMetalSparks( m_vecPos, m_vecDir );
  84. }
  85. void TE_MetalSparks( IRecipientFilter& filter, float delay,
  86. const Vector* pos, const Vector* dir )
  87. {
  88. g_pEffects->MetalSparks( *pos, *dir );
  89. RecordMetalSparks( *pos, *dir );
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Purpose: Armor Ricochet TE
  93. //-----------------------------------------------------------------------------
  94. class C_TEArmorRicochet : public C_TEMetalSparks
  95. {
  96. DECLARE_CLASS( C_TEArmorRicochet, C_TEMetalSparks );
  97. public:
  98. DECLARE_CLIENTCLASS();
  99. virtual void PostDataUpdate( DataUpdateType_t updateType );
  100. };
  101. //-----------------------------------------------------------------------------
  102. // Recording
  103. //-----------------------------------------------------------------------------
  104. static inline void RecordArmorRicochet( const Vector &start, const Vector &direction )
  105. {
  106. if ( !ToolsEnabled() )
  107. return;
  108. if ( clienttools->IsInRecordingMode() )
  109. {
  110. KeyValues *msg = new KeyValues( "TempEntity" );
  111. msg->SetInt( "te", TE_ARMOR_RICOCHET );
  112. msg->SetString( "name", "TE_ArmorRicochet" );
  113. msg->SetFloat( "time", gpGlobals->curtime );
  114. msg->SetFloat( "originx", start.x );
  115. msg->SetFloat( "originy", start.y );
  116. msg->SetFloat( "originz", start.z );
  117. msg->SetFloat( "directionx", direction.x );
  118. msg->SetFloat( "directiony", direction.y );
  119. msg->SetFloat( "directionz", direction.z );
  120. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  121. msg->deleteThis();
  122. }
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose: Client side version of API
  126. //-----------------------------------------------------------------------------
  127. void TE_ArmorRicochet( IRecipientFilter& filter, float delay,
  128. const Vector* pos, const Vector* dir )
  129. {
  130. g_pEffects->Ricochet( *pos, *dir );
  131. RecordArmorRicochet( *pos, *dir );
  132. }
  133. //-----------------------------------------------------------------------------
  134. // Purpose:
  135. // Input : bool -
  136. //-----------------------------------------------------------------------------
  137. void C_TEArmorRicochet::PostDataUpdate( DataUpdateType_t updateType )
  138. {
  139. g_pEffects->Ricochet( m_vecPos, m_vecDir );
  140. RecordArmorRicochet( m_vecPos, m_vecDir );
  141. }
  142. // Expose the TE to the engine.
  143. IMPLEMENT_CLIENTCLASS_EVENT( C_TEMetalSparks, DT_TEMetalSparks, CTEMetalSparks );
  144. BEGIN_RECV_TABLE_NOBASE(C_TEMetalSparks, DT_TEMetalSparks)
  145. RecvPropVector(RECVINFO(m_vecPos)),
  146. RecvPropVector(RECVINFO(m_vecDir)),
  147. END_RECV_TABLE()
  148. IMPLEMENT_CLIENTCLASS_EVENT( C_TEArmorRicochet, DT_TEArmorRicochet, CTEArmorRicochet );
  149. BEGIN_RECV_TABLE(C_TEArmorRicochet, DT_TEArmorRicochet)
  150. END_RECV_TABLE()