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.

182 lines
6.3 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 "toolframework_client.h"
  14. #include "tier0/vprof.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_TEPhysicsProp : public C_BaseTempEntity
  21. {
  22. public:
  23. DECLARE_CLASS( C_TEPhysicsProp, C_BaseTempEntity );
  24. DECLARE_CLIENTCLASS();
  25. C_TEPhysicsProp( void );
  26. virtual ~C_TEPhysicsProp( void );
  27. virtual void PostDataUpdate( DataUpdateType_t updateType );
  28. public:
  29. Vector m_vecOrigin;
  30. QAngle m_angRotation;
  31. Vector m_vecVelocity;
  32. int m_nModelIndex;
  33. int m_nSkin;
  34. int m_nFlags;
  35. int m_nEffects;
  36. color32 m_clrRender;
  37. };
  38. //-----------------------------------------------------------------------------
  39. // Networking
  40. //-----------------------------------------------------------------------------
  41. IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TEPhysicsProp, DT_TEPhysicsProp, CTEPhysicsProp)
  42. RecvPropVector( RECVINFO(m_vecOrigin)),
  43. RecvPropFloat( RECVINFO( m_angRotation[0] ) ),
  44. RecvPropFloat( RECVINFO( m_angRotation[1] ) ),
  45. RecvPropFloat( RECVINFO( m_angRotation[2] ) ),
  46. RecvPropVector( RECVINFO(m_vecVelocity)),
  47. RecvPropInt( RECVINFO(m_nModelIndex)),
  48. RecvPropInt( RECVINFO(m_nFlags)),
  49. RecvPropInt( RECVINFO(m_nSkin)),
  50. RecvPropInt( RECVINFO(m_nEffects)),
  51. RecvPropInt( RECVINFO(m_clrRender), 0, RecvProxy_Int32ToColor32 ),
  52. END_RECV_TABLE()
  53. //-----------------------------------------------------------------------------
  54. // Purpose:
  55. //-----------------------------------------------------------------------------
  56. C_TEPhysicsProp::C_TEPhysicsProp( void )
  57. {
  58. color32 white = {255, 255, 255, 255};
  59. m_vecOrigin.Init();
  60. m_angRotation.Init();
  61. m_vecVelocity.Init();
  62. m_nModelIndex = 0;
  63. m_nSkin = 0;
  64. m_nFlags = 0;
  65. m_nEffects = 0;
  66. m_clrRender = white;
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Purpose:
  70. //-----------------------------------------------------------------------------
  71. C_TEPhysicsProp::~C_TEPhysicsProp( void )
  72. {
  73. }
  74. //-----------------------------------------------------------------------------
  75. // Recording
  76. //-----------------------------------------------------------------------------
  77. static inline void RecordPhysicsProp( const Vector& start, const QAngle &angles,
  78. const Vector& vel, int nModelIndex, int flags, int nSkin, int nEffects, color24 renderColor )
  79. {
  80. if ( !ToolsEnabled() )
  81. return;
  82. if ( clienttools->IsInRecordingMode() )
  83. {
  84. const model_t* pModel = (nModelIndex != 0) ? modelinfo->GetModel( nModelIndex ) : NULL;
  85. const char *pModelName = pModel ? modelinfo->GetModelName( pModel ) : "";
  86. Color convertedRenderColor((int)renderColor.r, (int)renderColor.g, (int)renderColor.b);
  87. KeyValues *msg = new KeyValues( "TempEntity" );
  88. msg->SetInt( "te", TE_PHYSICS_PROP );
  89. msg->SetString( "name", "TE_PhysicsProp" );
  90. msg->SetFloat( "time", gpGlobals->curtime );
  91. msg->SetFloat( "originx", start.x );
  92. msg->SetFloat( "originy", start.y );
  93. msg->SetFloat( "originz", start.z );
  94. msg->SetFloat( "anglesx", angles.x );
  95. msg->SetFloat( "anglesy", angles.y );
  96. msg->SetFloat( "anglesz", angles.z );
  97. msg->SetFloat( "velx", vel.x );
  98. msg->SetFloat( "vely", vel.y );
  99. msg->SetFloat( "velz", vel.z );
  100. msg->SetString( "model", pModelName );
  101. msg->SetInt( "breakmodel", flags );
  102. msg->SetInt( "skin", nSkin );
  103. msg->SetInt( "effects", nEffects );
  104. msg->SetColor( "rendercolor", convertedRenderColor );
  105. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  106. msg->deleteThis();
  107. }
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose:
  111. //-----------------------------------------------------------------------------
  112. void TE_PhysicsProp( IRecipientFilter& filter, float delay,
  113. int modelindex, int skin, const Vector& pos, const QAngle &angles, const Vector& vel, int flags, int effects, color24 renderColor )
  114. {
  115. tempents->PhysicsProp( modelindex, skin, pos, angles, vel, flags, effects, renderColor );
  116. RecordPhysicsProp( pos, angles, vel, modelindex, flags, skin, effects, renderColor );
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Purpose:
  120. //-----------------------------------------------------------------------------
  121. void C_TEPhysicsProp::PostDataUpdate( DataUpdateType_t updateType )
  122. {
  123. VPROF( "C_TEPhysicsProp::PostDataUpdate" );
  124. color24 clrRenderConverted;
  125. clrRenderConverted.r = m_clrRender.r;
  126. clrRenderConverted.g = m_clrRender.g;
  127. clrRenderConverted.b = m_clrRender.b;
  128. tempents->PhysicsProp( m_nModelIndex, m_nSkin, m_vecOrigin, m_angRotation, m_vecVelocity, m_nFlags, m_nEffects, clrRenderConverted );
  129. RecordPhysicsProp( m_vecOrigin, m_angRotation, m_vecVelocity, m_nModelIndex, m_nFlags, m_nSkin, m_nEffects, clrRenderConverted );
  130. }
  131. void TE_PhysicsProp( IRecipientFilter& filter, float delay, KeyValues *pKeyValues )
  132. {
  133. Vector vecOrigin, vecVel;
  134. QAngle angles;
  135. int nSkin;
  136. nSkin = pKeyValues->GetInt( "skin", 0 );
  137. vecOrigin.x = pKeyValues->GetFloat( "originx" );
  138. vecOrigin.y = pKeyValues->GetFloat( "originy" );
  139. vecOrigin.z = pKeyValues->GetFloat( "originz" );
  140. angles.x = pKeyValues->GetFloat( "anglesx" );
  141. angles.y = pKeyValues->GetFloat( "anglesy" );
  142. angles.z = pKeyValues->GetFloat( "anglesz" );
  143. vecVel.x = pKeyValues->GetFloat( "velx" );
  144. vecVel.y = pKeyValues->GetFloat( "vely" );
  145. vecVel.z = pKeyValues->GetFloat( "velz" );
  146. const char *pModelName = pKeyValues->GetString( "model" );
  147. int nModelIndex = pModelName[0] ? modelinfo->GetModelIndex( pModelName ) : 0;
  148. int flags = pKeyValues->GetInt( "breakmodel" );
  149. int nEffects = pKeyValues->GetInt( "effects" );
  150. Color renderColor = pKeyValues->GetColor( "rendercolor" );
  151. color24 convertedRenderColor;
  152. convertedRenderColor.r = (byte)renderColor.r();
  153. convertedRenderColor.g = (byte)renderColor.g();
  154. convertedRenderColor.b = (byte)renderColor.b();
  155. TE_PhysicsProp( filter, delay, nModelIndex, nSkin, vecOrigin, angles, vecVel, flags, nEffects, convertedRenderColor );
  156. }