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.

132 lines
4.2 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. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. //-----------------------------------------------------------------------------
  14. // Purpose: create clientside physics prop, as breaks model if needed
  15. //-----------------------------------------------------------------------------
  16. class CTEPhysicsProp : public CBaseTempEntity
  17. {
  18. public:
  19. DECLARE_CLASS( CTEPhysicsProp, CBaseTempEntity );
  20. CTEPhysicsProp( const char *name );
  21. virtual ~CTEPhysicsProp( void );
  22. virtual void Test( const Vector& current_origin, const QAngle& current_angles );
  23. virtual void Precache( void );
  24. DECLARE_SERVERCLASS();
  25. public:
  26. CNetworkVector( m_vecOrigin );
  27. CNetworkQAngle( m_angRotation );
  28. CNetworkVector( m_vecVelocity );
  29. CNetworkVar( int, m_nModelIndex );
  30. CNetworkVar( int, m_nSkin );
  31. CNetworkVar( int, m_nFlags );
  32. CNetworkVar( int, m_nEffects );
  33. };
  34. //-----------------------------------------------------------------------------
  35. // Purpose:
  36. // Input : *name -
  37. //-----------------------------------------------------------------------------
  38. CTEPhysicsProp::CTEPhysicsProp( const char *name ) :
  39. CBaseTempEntity( name )
  40. {
  41. m_vecOrigin.Init();
  42. m_angRotation.Init();
  43. m_vecVelocity.Init();
  44. m_nModelIndex = 0;
  45. m_nSkin = 0;
  46. m_nFlags = 0;
  47. m_nEffects = 0;
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Purpose:
  51. //-----------------------------------------------------------------------------
  52. CTEPhysicsProp::~CTEPhysicsProp( void )
  53. {
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. //-----------------------------------------------------------------------------
  58. void CTEPhysicsProp::Precache( void )
  59. {
  60. CBaseEntity::PrecacheModel( "models/gibs/hgibs.mdl" );
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose:
  64. // Input : *current_origin -
  65. // *current_angles -
  66. //-----------------------------------------------------------------------------
  67. void CTEPhysicsProp::Test( const Vector& current_origin, const QAngle& current_angles )
  68. {
  69. // Fill in data
  70. m_nModelIndex = CBaseEntity::PrecacheModel( "models/gibs/hgibs.mdl" );
  71. m_nSkin = 0;
  72. m_vecOrigin = current_origin;
  73. m_angRotation = current_angles;
  74. m_vecVelocity.Init( random->RandomFloat( -10, 10 ), random->RandomFloat( -10, 10 ), random->RandomFloat( 0, 20 ) );
  75. m_nFlags = 0;
  76. m_nEffects = 0;
  77. Vector forward, right;
  78. m_vecOrigin += Vector( 0, 0, 24 );
  79. AngleVectors( current_angles, &forward, &right, 0 );
  80. forward[2] = 0.0;
  81. VectorNormalize( forward );
  82. VectorMA( m_vecOrigin, 50.0, forward, m_vecOrigin.GetForModify() );
  83. VectorMA( m_vecOrigin, 25.0, right, m_vecOrigin.GetForModify() );
  84. CBroadcastRecipientFilter filter;
  85. Create( filter, 0.0 );
  86. }
  87. IMPLEMENT_SERVERCLASS_ST(CTEPhysicsProp, DT_TEPhysicsProp)
  88. SendPropVector( SENDINFO(m_vecOrigin), -1, SPROP_COORD),
  89. SendPropAngle( SENDINFO_VECTORELEM(m_angRotation, 0), 13 ),
  90. SendPropAngle( SENDINFO_VECTORELEM(m_angRotation, 1), 13 ),
  91. SendPropAngle( SENDINFO_VECTORELEM(m_angRotation, 2), 13 ),
  92. SendPropVector( SENDINFO(m_vecVelocity), -1, SPROP_COORD),
  93. SendPropModelIndex( SENDINFO(m_nModelIndex) ),
  94. SendPropInt( SENDINFO(m_nSkin), ANIMATION_SKIN_BITS),
  95. SendPropInt( SENDINFO(m_nFlags), 2, SPROP_UNSIGNED ),
  96. SendPropInt( SENDINFO(m_nEffects), EF_MAX_BITS, SPROP_UNSIGNED),
  97. END_SEND_TABLE()
  98. // Singleton to fire TEBreakModel objects
  99. static CTEPhysicsProp s_TEPhysicsProp( "physicsprop" );
  100. void TE_PhysicsProp( IRecipientFilter& filter, float delay,
  101. int modelindex, int skin, const Vector& pos, const QAngle &angles, const Vector& vel, int flags, int effects )
  102. {
  103. s_TEPhysicsProp.m_vecOrigin = pos;
  104. s_TEPhysicsProp.m_angRotation = angles;
  105. s_TEPhysicsProp.m_vecVelocity = vel;
  106. s_TEPhysicsProp.m_nModelIndex = modelindex;
  107. s_TEPhysicsProp.m_nSkin = skin;
  108. s_TEPhysicsProp.m_nFlags = flags;
  109. s_TEPhysicsProp.m_nEffects = effects;
  110. // Send it over the wire
  111. s_TEPhysicsProp.Create( filter, delay );
  112. }