Counter Strike : Global Offensive Source Code
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.

125 lines
3.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "particles_simple.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. class C_WaterBullet : public C_BaseAnimating
  11. {
  12. public:
  13. DECLARE_CLIENTCLASS();
  14. DECLARE_CLASS( C_WaterBullet, C_BaseAnimating );
  15. C_WaterBullet( void )
  16. {
  17. AddToEntityList(ENTITY_LIST_SIMULATE);
  18. };
  19. ~C_WaterBullet( void ) {};
  20. void OnDataChanged( DataUpdateType_t updateType )
  21. {
  22. BaseClass::OnDataChanged( updateType );
  23. if ( updateType == DATA_UPDATE_CREATED )
  24. {
  25. m_pEmitter = CSimpleEmitter::Create( "FX_Bubble" );
  26. m_pEmitter->SetSortOrigin( GetAbsOrigin() );
  27. m_vecLastOrigin = GetAbsOrigin();
  28. }
  29. }
  30. #define BUBBLES_PER_INCH 0.2
  31. bool Simulate( void )
  32. {
  33. Vector direction = GetAbsOrigin() - m_vecLastOrigin;
  34. float flDist = VectorNormalize( direction );
  35. int numBubbles = (int) ( flDist * BUBBLES_PER_INCH );
  36. if ( numBubbles < 1 )
  37. numBubbles = 1;
  38. // Make bubbles
  39. SimpleParticle *sParticle;
  40. Vector offset;
  41. for ( int i = 0; i < numBubbles; i++ )
  42. {
  43. offset = m_vecLastOrigin + ( direction * ( flDist / numBubbles ) * i ) + RandomVector( -2.5f, 2.5f );
  44. sParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_pEmitter->GetPMaterial( "effects/bubble" ), offset );
  45. if ( sParticle )
  46. {
  47. sParticle->m_flLifetime = 0.0f;
  48. sParticle->m_flDieTime = random->RandomFloat( 0.75f, 1.25f );
  49. sParticle->m_flRoll = 0;
  50. sParticle->m_flRollDelta = 0;
  51. unsigned char color = random->RandomInt( 128, 255 );
  52. sParticle->m_uchColor[0] = color;
  53. sParticle->m_uchColor[1] = color;
  54. sParticle->m_uchColor[2] = color;
  55. sParticle->m_uchStartAlpha = 255;
  56. sParticle->m_uchEndAlpha = 0;
  57. sParticle->m_uchStartSize = random->RandomInt( 1, 2 );
  58. sParticle->m_uchEndSize = sParticle->m_uchStartSize;
  59. sParticle->m_vecVelocity = ( direction * 64.0f ) + Vector( 0, 0, 32 );
  60. }
  61. sParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_pEmitter->GetPMaterial( "effects/splash2" ), offset );
  62. if ( sParticle )
  63. {
  64. sParticle->m_flLifetime = 0.0f;
  65. sParticle->m_flDieTime = 0.2f;
  66. sParticle->m_flRoll = random->RandomInt( 0, 360 );
  67. sParticle->m_flRollDelta = random->RandomInt( -4, 4 );;
  68. unsigned char color = random->RandomInt( 200, 255 );
  69. sParticle->m_uchColor[0] = color;
  70. sParticle->m_uchColor[1] = color;
  71. sParticle->m_uchColor[2] = color;
  72. sParticle->m_uchStartAlpha = 128;
  73. sParticle->m_uchEndAlpha = 0;
  74. sParticle->m_uchStartSize = 2;
  75. sParticle->m_uchEndSize = sParticle->m_uchStartSize * 4;
  76. sParticle->m_vecVelocity = ( direction * 64.0f ) + Vector( 0, 0, 32 );
  77. }
  78. }
  79. // Save our last position
  80. m_vecLastOrigin = GetAbsOrigin();
  81. BaseClass::Simulate();
  82. return true;
  83. }
  84. bool ShouldDraw( void ) { return true; }
  85. private:
  86. C_WaterBullet( const C_WaterBullet & );
  87. CSmartPtr<CSimpleEmitter> m_pEmitter;
  88. Vector m_vecLastOrigin;
  89. };
  90. IMPLEMENT_CLIENTCLASS_DT( C_WaterBullet, DT_WaterBullet, CWaterBullet )
  91. END_RECV_TABLE()