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.

179 lines
6.1 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 "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: Breakable Model TE
  19. //-----------------------------------------------------------------------------
  20. class C_TEBreakModel : public C_BaseTempEntity
  21. {
  22. public:
  23. DECLARE_CLASS( C_TEBreakModel, C_BaseTempEntity );
  24. DECLARE_CLIENTCLASS();
  25. C_TEBreakModel( void );
  26. virtual ~C_TEBreakModel( void );
  27. virtual void PostDataUpdate( DataUpdateType_t updateType );
  28. public:
  29. Vector m_vecOrigin;
  30. QAngle m_angRotation;
  31. Vector m_vecSize;
  32. Vector m_vecVelocity;
  33. int m_nRandomization;
  34. int m_nModelIndex;
  35. int m_nCount;
  36. float m_fTime;
  37. int m_nFlags;
  38. };
  39. //-----------------------------------------------------------------------------
  40. // Networking
  41. //-----------------------------------------------------------------------------
  42. IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TEBreakModel, DT_TEBreakModel, CTEBreakModel)
  43. RecvPropVector( RECVINFO(m_vecOrigin)),
  44. RecvPropFloat( RECVINFO( m_angRotation[0] ) ),
  45. RecvPropFloat( RECVINFO( m_angRotation[1] ) ),
  46. RecvPropFloat( RECVINFO( m_angRotation[2] ) ),
  47. RecvPropVector( RECVINFO(m_vecSize)),
  48. RecvPropVector( RECVINFO(m_vecVelocity)),
  49. RecvPropInt( RECVINFO(m_nModelIndex)),
  50. RecvPropInt( RECVINFO(m_nRandomization)),
  51. RecvPropInt( RECVINFO(m_nCount)),
  52. RecvPropFloat( RECVINFO(m_fTime)),
  53. RecvPropInt( RECVINFO(m_nFlags)),
  54. END_RECV_TABLE()
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. //-----------------------------------------------------------------------------
  58. C_TEBreakModel::C_TEBreakModel( void )
  59. {
  60. m_vecOrigin.Init();
  61. m_angRotation.Init();
  62. m_vecSize.Init();
  63. m_vecVelocity.Init();
  64. m_nModelIndex = 0;
  65. m_nRandomization = 0;
  66. m_nCount = 0;
  67. m_fTime = 0.0;
  68. m_nFlags = 0;
  69. }
  70. C_TEBreakModel::~C_TEBreakModel( void )
  71. {
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Recording
  75. //-----------------------------------------------------------------------------
  76. static inline void RecordBreakModel( const Vector &start, const QAngle &angles, const Vector &size,
  77. const Vector &vel, int nModelIndex, int nRandomization, int nCount, float flDuration, int nFlags )
  78. {
  79. if ( !ToolsEnabled() )
  80. return;
  81. if ( clienttools->IsInRecordingMode() )
  82. {
  83. const model_t* pModel = (nModelIndex != 0) ? modelinfo->GetModel( nModelIndex ) : NULL;
  84. const char *pModelName = pModel ? modelinfo->GetModelName( pModel ) : "";
  85. KeyValues *msg = new KeyValues( "TempEntity" );
  86. msg->SetInt( "te", TE_BREAK_MODEL );
  87. msg->SetString( "name", "TE_BreakModel" );
  88. msg->SetFloat( "time", gpGlobals->curtime );
  89. msg->SetFloat( "originx", start.x );
  90. msg->SetFloat( "originy", start.y );
  91. msg->SetFloat( "originz", start.z );
  92. msg->SetFloat( "anglesx", angles.x );
  93. msg->SetFloat( "anglesy", angles.y );
  94. msg->SetFloat( "anglesz", angles.z );
  95. msg->SetFloat( "sizex", size.x );
  96. msg->SetFloat( "sizey", size.y );
  97. msg->SetFloat( "sizez", size.z );
  98. msg->SetFloat( "velx", vel.x );
  99. msg->SetFloat( "vely", vel.y );
  100. msg->SetFloat( "velz", vel.z );
  101. msg->SetString( "model", pModelName );
  102. msg->SetInt( "randomization", nRandomization );
  103. msg->SetInt( "count", nCount );
  104. msg->SetFloat( "duration", flDuration );
  105. msg->SetInt( "flags", nFlags );
  106. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  107. msg->deleteThis();
  108. }
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Purpose:
  112. //-----------------------------------------------------------------------------
  113. void TE_BreakModel( IRecipientFilter& filter, float delay,
  114. const Vector& pos, const QAngle &angles, const Vector& size, const Vector& vel,
  115. int modelindex, int randomization, int count, float time, int flags )
  116. {
  117. tempents->BreakModel( pos, angles, size, vel, randomization, time, count, modelindex, flags );
  118. RecordBreakModel( pos, angles, size, vel, randomization, time, count, modelindex, flags );
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Purpose:
  122. //-----------------------------------------------------------------------------
  123. void C_TEBreakModel::PostDataUpdate( DataUpdateType_t updateType )
  124. {
  125. VPROF( "C_TEBreakModel::PostDataUpdate" );
  126. tempents->BreakModel( m_vecOrigin, m_angRotation, m_vecSize, m_vecVelocity,
  127. m_nRandomization, m_fTime, m_nCount, m_nModelIndex, m_nFlags );
  128. RecordBreakModel( m_vecOrigin, m_angRotation, m_vecSize, m_vecVelocity,
  129. m_nRandomization, m_fTime, m_nCount, m_nModelIndex, m_nFlags );
  130. }
  131. void TE_BreakModel( IRecipientFilter& filter, float delay, KeyValues *pKeyValues )
  132. {
  133. Vector vecOrigin, vecSize, vecVel;
  134. QAngle angles;
  135. vecOrigin.x = pKeyValues->GetFloat( "originx" );
  136. vecOrigin.y = pKeyValues->GetFloat( "originy" );
  137. vecOrigin.z = pKeyValues->GetFloat( "originz" );
  138. angles.x = pKeyValues->GetFloat( "anglesx" );
  139. angles.y = pKeyValues->GetFloat( "anglesy" );
  140. angles.z = pKeyValues->GetFloat( "anglesz" );
  141. vecSize.x = pKeyValues->GetFloat( "sizex" );
  142. vecSize.y = pKeyValues->GetFloat( "sizey" );
  143. vecSize.z = pKeyValues->GetFloat( "sizez" );
  144. vecVel.x = pKeyValues->GetFloat( "velx" );
  145. vecVel.y = pKeyValues->GetFloat( "vely" );
  146. vecVel.z = pKeyValues->GetFloat( "velz" );
  147. Color c = pKeyValues->GetColor( "color" );
  148. const char *pModelName = pKeyValues->GetString( "model" );
  149. int nModelIndex = pModelName[0] ? modelinfo->GetModelIndex( pModelName ) : 0;
  150. int nRandomization = pKeyValues->GetInt( "randomization" );
  151. int nCount = pKeyValues->GetInt( "count" );
  152. float flDuration = pKeyValues->GetFloat( "duration" );
  153. int nFlags = pKeyValues->GetInt( "flags" );
  154. TE_BreakModel( filter, 0.0f, vecOrigin, angles, vecSize, vecVel,
  155. nModelIndex, nRandomization, nCount, flDuration, nFlags );
  156. }