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.

109 lines
3.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #include "cbase.h"
  8. #include "c_te_particlesystem.h"
  9. #include "fx.h"
  10. #include "ragdollexplosionenumerator.h"
  11. #include "tier1/KeyValues.h"
  12. #include "toolframework_client.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Concussive explosion entity
  17. //-----------------------------------------------------------------------------
  18. class C_TEConcussiveExplosion : public C_TEParticleSystem
  19. {
  20. public:
  21. DECLARE_CLASS( C_TEConcussiveExplosion, C_TEParticleSystem );
  22. DECLARE_CLIENTCLASS();
  23. virtual void PostDataUpdate( DataUpdateType_t updateType );
  24. void AffectRagdolls( void );
  25. Vector m_vecNormal;
  26. float m_flScale;
  27. int m_nRadius;
  28. int m_nMagnitude;
  29. };
  30. //-----------------------------------------------------------------------------
  31. // Networking
  32. //-----------------------------------------------------------------------------
  33. IMPLEMENT_CLIENTCLASS_EVENT_DT( C_TEConcussiveExplosion, DT_TEConcussiveExplosion, CTEConcussiveExplosion )
  34. RecvPropVector( RECVINFO(m_vecNormal)),
  35. RecvPropFloat( RECVINFO(m_flScale)),
  36. RecvPropInt( RECVINFO(m_nRadius)),
  37. RecvPropInt( RECVINFO(m_nMagnitude)),
  38. END_RECV_TABLE()
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. //-----------------------------------------------------------------------------
  42. void C_TEConcussiveExplosion::AffectRagdolls( void )
  43. {
  44. if ( ( m_nRadius == 0 ) || ( m_nMagnitude == 0 ) )
  45. return;
  46. CRagdollExplosionEnumerator ragdollEnum( m_vecOrigin, m_nRadius, m_nMagnitude );
  47. partition->EnumerateElementsInSphere( PARTITION_CLIENT_RESPONSIVE_EDICTS, m_vecOrigin, m_nRadius, false, &ragdollEnum );
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Recording
  51. //-----------------------------------------------------------------------------
  52. static inline void RecordConcussiveExplosion( const Vector& start, const Vector &vecDirection )
  53. {
  54. if ( !ToolsEnabled() )
  55. return;
  56. if ( clienttools->IsInRecordingMode() )
  57. {
  58. KeyValues *msg = new KeyValues( "TempEntity" );
  59. msg->SetInt( "te", TE_CONCUSSIVE_EXPLOSION );
  60. msg->SetString( "name", "TE_ConcussiveExplosion" );
  61. msg->SetFloat( "time", gpGlobals->curtime );
  62. msg->SetFloat( "originx", start.x );
  63. msg->SetFloat( "originy", start.y );
  64. msg->SetFloat( "originz", start.z );
  65. msg->SetFloat( "directionx", vecDirection.x );
  66. msg->SetFloat( "directiony", vecDirection.y );
  67. msg->SetFloat( "directionz", vecDirection.z );
  68. ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
  69. msg->deleteThis();
  70. }
  71. }
  72. //-----------------------------------------------------------------------------
  73. // Purpose:
  74. //-----------------------------------------------------------------------------
  75. void C_TEConcussiveExplosion::PostDataUpdate( DataUpdateType_t updateType )
  76. {
  77. AffectRagdolls();
  78. FX_ConcussiveExplosion( m_vecOrigin, m_vecNormal );
  79. RecordConcussiveExplosion( m_vecOrigin, m_vecNormal );
  80. }
  81. void TE_ConcussiveExplosion( IRecipientFilter& filter, float delay, KeyValues *pKeyValues )
  82. {
  83. Vector vecOrigin, vecDirection;
  84. vecOrigin.x = pKeyValues->GetFloat( "originx" );
  85. vecOrigin.y = pKeyValues->GetFloat( "originy" );
  86. vecOrigin.z = pKeyValues->GetFloat( "originz" );
  87. vecDirection.x = pKeyValues->GetFloat( "directionx" );
  88. vecDirection.y = pKeyValues->GetFloat( "directiony" );
  89. vecDirection.z = pKeyValues->GetFloat( "directionz" );
  90. FX_ConcussiveExplosion( vecOrigin, vecDirection );
  91. }