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.

163 lines
4.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "c_te_particlesystem.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. //-----------------------------------------------------------------------------
  13. // Purpose: Large Funnel TE
  14. //-----------------------------------------------------------------------------
  15. class C_TELargeFunnel : public C_TEParticleSystem
  16. {
  17. public:
  18. DECLARE_CLASS( C_TELargeFunnel, C_TEParticleSystem );
  19. DECLARE_CLIENTCLASS();
  20. C_TELargeFunnel( void );
  21. virtual ~C_TELargeFunnel( void );
  22. virtual void PostDataUpdate( DataUpdateType_t updateType );
  23. public:
  24. void CreateFunnel( void );
  25. int m_nModelIndex;
  26. int m_nReversed;
  27. };
  28. //-----------------------------------------------------------------------------
  29. // Purpose:
  30. //-----------------------------------------------------------------------------
  31. C_TELargeFunnel::C_TELargeFunnel( void )
  32. {
  33. m_nModelIndex = 0;
  34. m_nReversed = 0;
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose:
  38. //-----------------------------------------------------------------------------
  39. C_TELargeFunnel::~C_TELargeFunnel( void )
  40. {
  41. }
  42. void C_TELargeFunnel::CreateFunnel( void )
  43. {
  44. CSmartPtr<CSimpleEmitter> pSimple = CSimpleEmitter::Create( "TELargeFunnel" );
  45. pSimple->SetSortOrigin( m_vecOrigin );
  46. int i, j;
  47. SimpleParticle *pParticle;
  48. Vector vecDir;
  49. Vector vecDest;
  50. float ratio = 0.25;
  51. float invratio = 1 / ratio;
  52. PMaterialHandle hMaterial = pSimple->GetPMaterial( "sprites/flare6" );
  53. for ( i = -256 ; i <= 256 ; i += 24 ) //24 from 32.. little more dense
  54. {
  55. for ( j = -256 ; j <= 256 ; j += 24 )
  56. {
  57. pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof( SimpleParticle ), hMaterial, m_vecOrigin );
  58. if( pParticle )
  59. {
  60. if ( m_nReversed )
  61. {
  62. pParticle->m_Pos = m_vecOrigin;
  63. vecDir[0] = i;
  64. vecDir[1] = j;
  65. vecDir[2] = random->RandomFloat(100, 800);
  66. pParticle->m_uchStartAlpha = 255;
  67. pParticle->m_uchEndAlpha = 0;
  68. }
  69. else
  70. {
  71. pParticle->m_Pos[0] = m_vecOrigin[0] + i;
  72. pParticle->m_Pos[1] = m_vecOrigin[1] + j;
  73. pParticle->m_Pos[2] = m_vecOrigin[2] + random->RandomFloat(100, 800);
  74. // send particle heading to org at a random speed
  75. vecDir = m_vecOrigin - pParticle->m_Pos;
  76. pParticle->m_uchStartAlpha = 0;
  77. pParticle->m_uchEndAlpha = 255;
  78. }
  79. vecDir *= ratio;
  80. pParticle->m_vecVelocity = vecDir;
  81. pParticle->m_flLifetime = 0;
  82. pParticle->m_flDieTime = invratio;
  83. if( random->RandomInt( 0, 10 ) < 5 )
  84. {
  85. // small green particle
  86. pParticle->m_uchColor[0] = 0;
  87. pParticle->m_uchColor[1] = 255;
  88. pParticle->m_uchColor[2] = 0;
  89. pParticle->m_uchStartSize = 4.0;
  90. }
  91. else
  92. {
  93. // large white particle
  94. pParticle->m_uchColor[0] = 255;
  95. pParticle->m_uchColor[1] = 255;
  96. pParticle->m_uchColor[2] = 255;
  97. pParticle->m_uchStartSize = 15.0;
  98. }
  99. pParticle->m_uchEndSize = pParticle->m_uchStartSize;
  100. pParticle->m_flRoll = i; // pseudorandom
  101. pParticle->m_flRollDelta = 0;
  102. pParticle->m_iFlags = 0;
  103. }
  104. }
  105. }
  106. return;
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. // Input : bool -
  111. //-----------------------------------------------------------------------------
  112. void C_TELargeFunnel::PostDataUpdate( DataUpdateType_t updateType )
  113. {
  114. CreateFunnel();
  115. }
  116. IMPLEMENT_CLIENTCLASS_EVENT_DT(C_TELargeFunnel, DT_TELargeFunnel, CTELargeFunnel)
  117. RecvPropInt( RECVINFO(m_nModelIndex)),
  118. RecvPropInt( RECVINFO(m_nReversed)),
  119. END_RECV_TABLE()
  120. void TE_LargeFunnel( IRecipientFilter& filter, float delay,
  121. const Vector* pos, int modelindex, int reversed )
  122. {
  123. // Major hack to simulate receiving network message
  124. __g_C_TELargeFunnel.m_vecOrigin = *pos;
  125. __g_C_TELargeFunnel.m_nModelIndex = modelindex;
  126. __g_C_TELargeFunnel.m_nReversed = reversed;
  127. __g_C_TELargeFunnel.PostDataUpdate( DATA_UPDATE_CREATED );
  128. }