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.

145 lines
4.6 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 "basetempentity.h"
  11. #include "vstdlib/random.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Dispatches model smash pieces
  16. //-----------------------------------------------------------------------------
  17. class CTEBreakModel : public CBaseTempEntity
  18. {
  19. public:
  20. DECLARE_CLASS( CTEBreakModel, CBaseTempEntity );
  21. CTEBreakModel( const char *name );
  22. virtual ~CTEBreakModel( void );
  23. virtual void Test( const Vector& current_origin, const QAngle& current_angles );
  24. virtual void Precache( void );
  25. DECLARE_SERVERCLASS();
  26. public:
  27. CNetworkVector( m_vecOrigin );
  28. CNetworkVector( m_vecSize );
  29. CNetworkVector( m_vecVelocity );
  30. CNetworkQAngle( m_angRotation );
  31. CNetworkVar( int, m_nRandomization );
  32. CNetworkVar( int, m_nModelIndex );
  33. CNetworkVar( int, m_nCount );
  34. CNetworkVar( float, m_fTime );
  35. CNetworkVar( int, m_nFlags );
  36. };
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. // Input : *name -
  40. //-----------------------------------------------------------------------------
  41. CTEBreakModel::CTEBreakModel( const char *name ) :
  42. CBaseTempEntity( name )
  43. {
  44. m_vecOrigin.Init();
  45. m_vecSize.Init();
  46. m_vecVelocity.Init();
  47. m_angRotation.Init();
  48. m_nModelIndex = 0;
  49. m_nRandomization = 0;
  50. m_nCount = 0;
  51. m_fTime = 0.0;
  52. m_nFlags = 0;
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Purpose:
  56. //-----------------------------------------------------------------------------
  57. CTEBreakModel::~CTEBreakModel( void )
  58. {
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. //-----------------------------------------------------------------------------
  63. void CTEBreakModel::Precache( void )
  64. {
  65. CBaseEntity::PrecacheModel( "models/gibs/hgibs.mdl" );
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. // Input : *current_origin -
  70. // *current_angles -
  71. //-----------------------------------------------------------------------------
  72. void CTEBreakModel::Test( const Vector& current_origin, const QAngle& current_angles )
  73. {
  74. // Fill in data
  75. m_nModelIndex = CBaseEntity::PrecacheModel( "models/gibs/hgibs.mdl" );
  76. m_vecOrigin = current_origin;
  77. m_angRotation = current_angles;
  78. m_vecSize.Init( 16, 16, 16 );
  79. m_vecVelocity.Init( random->RandomFloat( -10, 10 ), random->RandomFloat( -10, 10 ), random->RandomFloat( 0, 20 ) );
  80. m_nRandomization = 100;
  81. m_nCount = 10;
  82. m_fTime = 5.0;
  83. m_nFlags = 0;
  84. Vector forward, right;
  85. m_vecOrigin += Vector( 0, 0, 24 );
  86. AngleVectors( current_angles, &forward, &right, 0 );
  87. forward[2] = 0.0;
  88. VectorNormalize( forward );
  89. VectorMA( m_vecOrigin, 50.0, forward, m_vecOrigin.GetForModify() );
  90. VectorMA( m_vecOrigin, 25.0, right, m_vecOrigin.GetForModify() );
  91. CBroadcastRecipientFilter filter;
  92. Create( filter, 0.0 );
  93. }
  94. IMPLEMENT_SERVERCLASS_ST(CTEBreakModel, DT_TEBreakModel)
  95. SendPropVector( SENDINFO(m_vecOrigin), -1, SPROP_COORD),
  96. SendPropAngle( SENDINFO_VECTORELEM(m_angRotation, 0), 13 ),
  97. SendPropAngle( SENDINFO_VECTORELEM(m_angRotation, 1), 13 ),
  98. SendPropAngle( SENDINFO_VECTORELEM(m_angRotation, 2), 13 ),
  99. SendPropVector( SENDINFO(m_vecSize), -1, SPROP_COORD),
  100. SendPropVector( SENDINFO(m_vecVelocity), -1, SPROP_COORD),
  101. SendPropModelIndex( SENDINFO(m_nModelIndex) ),
  102. SendPropInt( SENDINFO(m_nRandomization), 9, SPROP_UNSIGNED ),
  103. SendPropInt( SENDINFO(m_nCount), 8, SPROP_UNSIGNED ),
  104. SendPropFloat( SENDINFO(m_fTime), 10, 0, 0, 102.4 ),
  105. SendPropInt( SENDINFO(m_nFlags), 8, SPROP_UNSIGNED ),
  106. END_SEND_TABLE()
  107. // Singleton to fire TEBreakModel objects
  108. static CTEBreakModel g_TEBreakModel( "breakmodel" );
  109. void TE_BreakModel( IRecipientFilter& filter, float delay,
  110. const Vector& pos, const QAngle& angles, const Vector& size, const Vector& vel, int modelindex, int randomization,
  111. int count, float time, int flags )
  112. {
  113. g_TEBreakModel.m_vecOrigin = pos;
  114. g_TEBreakModel.m_angRotation = angles;
  115. g_TEBreakModel.m_vecSize = size;
  116. g_TEBreakModel.m_vecVelocity = vel;
  117. g_TEBreakModel.m_nModelIndex = modelindex;
  118. g_TEBreakModel.m_nRandomization = randomization;
  119. g_TEBreakModel.m_nCount = count;
  120. g_TEBreakModel.m_fTime = time;
  121. g_TEBreakModel.m_nFlags = flags;
  122. // Send it over the wire
  123. g_TEBreakModel.Create( filter, delay );
  124. }