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.

155 lines
5.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "cbase.h"
  14. #include "basetempentity.h"
  15. #include "shattersurfacetypes.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. //-----------------------------------------------------------------------------
  19. // Purpose: Dispatches Glass Shatter tempentity
  20. //-----------------------------------------------------------------------------
  21. class CTEShatterSurface : public CBaseTempEntity
  22. {
  23. public:
  24. DECLARE_CLASS( CTEShatterSurface, CBaseTempEntity );
  25. CTEShatterSurface( const char *name );
  26. virtual void Test( const Vector& current_origin, const QAngle& current_angles );
  27. DECLARE_SERVERCLASS();
  28. public:
  29. CNetworkVector( m_vecOrigin );
  30. CNetworkQAngle( m_vecAngles );
  31. CNetworkVector( m_vecForce );
  32. CNetworkVector( m_vecForcePos );
  33. CNetworkVar( float, m_flWidth );
  34. CNetworkVar( float, m_flHeight );
  35. CNetworkVar( float, m_flShardSize );
  36. CNetworkVar( int, m_nSurfaceType );
  37. CNetworkArray( byte, m_uchFrontColor, 3 );
  38. CNetworkArray( byte, m_uchBackColor, 3 );
  39. };
  40. //-----------------------------------------------------------------------------
  41. // Purpose:
  42. // Input : *name -
  43. //-----------------------------------------------------------------------------
  44. CTEShatterSurface::CTEShatterSurface( const char *name ) :
  45. CBaseTempEntity( name )
  46. {
  47. m_vecOrigin.Init();
  48. m_vecAngles.Init();
  49. m_vecForce.Init();
  50. m_vecForcePos.Init();
  51. m_flWidth = 16.0f;
  52. m_flHeight = 16.0f;
  53. m_flShardSize = 3.0f;
  54. m_uchFrontColor.Set( 0, 255 );
  55. m_uchFrontColor.Set( 1, 255 );
  56. m_uchFrontColor.Set( 2, 255 );
  57. m_uchBackColor.Set( 0, 255 );
  58. m_uchBackColor.Set( 1, 255 );
  59. m_uchBackColor.Set( 2, 255 );
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Purpose:
  63. // Input : *current_origin -
  64. // *current_angles -
  65. //-----------------------------------------------------------------------------
  66. void CTEShatterSurface::Test( const Vector& current_origin, const QAngle& current_angles )
  67. {
  68. // Fill in data
  69. m_vecOrigin = current_origin;
  70. Vector vecEnd;
  71. Vector forward;
  72. m_vecOrigin.GetForModify()[2] += 24;
  73. AngleVectors( current_angles, &forward );
  74. forward[2] = 0.0;
  75. VectorNormalize( forward );
  76. VectorMA( m_vecOrigin, 50.0, forward, m_vecOrigin.GetForModify() );
  77. VectorMA( m_vecOrigin, 1024.0, forward, vecEnd );
  78. trace_t tr;
  79. UTIL_TraceLine( m_vecOrigin, vecEnd, MASK_SOLID_BRUSHONLY, NULL, COLLISION_GROUP_NONE, &tr );
  80. m_vecOrigin = tr.endpos;
  81. CBroadcastRecipientFilter filter;
  82. Create( filter, 0.0 );
  83. }
  84. IMPLEMENT_SERVERCLASS_ST(CTEShatterSurface, DT_TEShatterSurface)
  85. SendPropVector( SENDINFO(m_vecOrigin), -1, SPROP_COORD),
  86. SendPropVector( SENDINFO(m_vecAngles), -1, SPROP_COORD),
  87. SendPropVector( SENDINFO(m_vecForce), -1, SPROP_COORD),
  88. SendPropVector( SENDINFO(m_vecForcePos), -1, SPROP_COORD),
  89. SendPropFloat( SENDINFO(m_flWidth), 0, SPROP_NOSCALE ),
  90. SendPropFloat( SENDINFO(m_flHeight), 0, SPROP_NOSCALE ),
  91. SendPropFloat( SENDINFO(m_flShardSize), 0, SPROP_NOSCALE ),
  92. SendPropInt( SENDINFO(m_nSurfaceType), 2, SPROP_UNSIGNED ),
  93. SendPropInt( SENDINFO_ARRAYELEM( m_uchFrontColor, 0 ), 8, SPROP_UNSIGNED ),
  94. SendPropInt( SENDINFO_ARRAYELEM( m_uchFrontColor, 1 ), 8, SPROP_UNSIGNED ),
  95. SendPropInt( SENDINFO_ARRAYELEM( m_uchFrontColor, 2 ), 8, SPROP_UNSIGNED ),
  96. SendPropInt( SENDINFO_ARRAYELEM( m_uchBackColor, 0 ), 8, SPROP_UNSIGNED ),
  97. SendPropInt( SENDINFO_ARRAYELEM( m_uchBackColor, 1 ), 8, SPROP_UNSIGNED ),
  98. SendPropInt( SENDINFO_ARRAYELEM( m_uchBackColor, 2 ), 8, SPROP_UNSIGNED ),
  99. END_SEND_TABLE()
  100. // Singleton to fire TEShatterSurface objects
  101. static CTEShatterSurface g_TEShatterSurface( "Surface Shatter" );
  102. //-----------------------------------------------------------------------------
  103. // Purpose:
  104. // Input : msg_dest -
  105. // delay -
  106. // *origin -
  107. // *recipient -
  108. // *pos -
  109. // entity -
  110. // index -
  111. //-----------------------------------------------------------------------------
  112. void TE_ShatterSurface( IRecipientFilter& filter, float delay,
  113. const Vector* pos, const QAngle* angle, const Vector* force, const Vector* forcepos,
  114. float width, float height, float shardsize, ShatterSurface_t surfacetype,
  115. int front_r, int front_g, int front_b, int back_r, int back_g, int back_b)
  116. {
  117. g_TEShatterSurface.m_vecOrigin = *pos;
  118. g_TEShatterSurface.m_vecAngles = *angle;
  119. g_TEShatterSurface.m_vecForce = *force;
  120. g_TEShatterSurface.m_vecForcePos = *forcepos;
  121. g_TEShatterSurface.m_flWidth = width;
  122. g_TEShatterSurface.m_flHeight = height;
  123. g_TEShatterSurface.m_flShardSize = shardsize;
  124. g_TEShatterSurface.m_nSurfaceType = surfacetype;
  125. g_TEShatterSurface.m_uchFrontColor.Set( 0, front_r );
  126. g_TEShatterSurface.m_uchFrontColor.Set( 1, front_g );
  127. g_TEShatterSurface.m_uchFrontColor.Set( 2, front_b );
  128. g_TEShatterSurface.m_uchBackColor.Set( 0, back_r );
  129. g_TEShatterSurface.m_uchBackColor.Set( 1, back_g );
  130. g_TEShatterSurface.m_uchBackColor.Set( 2, back_b );
  131. // Send it over the wire
  132. g_TEShatterSurface.Create( filter, delay );
  133. }