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.

107 lines
3.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: An effect for a single bullet passing through a body of water.
  4. // The slug quickly decelerates, leaving a trail of bubbles behind it.
  5. //
  6. // TODO: make clientside
  7. //
  8. //=============================================================================//
  9. #include "cbase.h"
  10. #include "waterbullet.h"
  11. #include "ndebugoverlay.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. #define WATERBULLET_INITIAL_SPEED 1000.0
  15. #define WATERBULLET_STOP_TIME 0.5 // how long it takes a bullet in water to come to a stop!
  16. #define WATERBULLET_DECAY ( WATERBULLET_INITIAL_SPEED / WATERBULLET_STOP_TIME )
  17. BEGIN_DATADESC( CWaterBullet )
  18. // Function Pointers
  19. DEFINE_FUNCTION( Touch ),
  20. DEFINE_FUNCTION( BulletThink ),
  21. END_DATADESC()
  22. LINK_ENTITY_TO_CLASS( waterbullet, CWaterBullet );
  23. IMPLEMENT_SERVERCLASS_ST( CWaterBullet, DT_WaterBullet )
  24. END_SEND_TABLE()
  25. //-----------------------------------------------------------------------------
  26. // Purpose:
  27. //-----------------------------------------------------------------------------
  28. void CWaterBullet::Precache()
  29. {
  30. PrecacheModel( "models/weapons/w_bullet.mdl" );
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Purpose:
  34. //-----------------------------------------------------------------------------
  35. void CWaterBullet::Spawn( const Vector &vecOrigin, const Vector &vecDir )
  36. {
  37. Precache();
  38. SetSolid( SOLID_BBOX );
  39. SetModel( "models/weapons/w_bullet.mdl" );
  40. UTIL_SetSize( this, vec3_origin, vec3_origin );
  41. SetMoveType( MOVETYPE_FLY );
  42. SetGravity( 0.0 );
  43. QAngle angles;
  44. SetAbsOrigin( vecOrigin );
  45. SetAbsVelocity( vecDir * 1500.0f );
  46. VectorAngles( GetAbsVelocity(), angles );
  47. SetAbsAngles( angles );
  48. SetCollisionGroup( COLLISION_GROUP_DEBRIS );
  49. SetTouch( &CWaterBullet::Touch );
  50. SetThink( &CWaterBullet::BulletThink );
  51. SetNextThink( gpGlobals->curtime );
  52. }
  53. //-----------------------------------------------------------------------------
  54. //-----------------------------------------------------------------------------
  55. void CWaterBullet::BulletThink()
  56. {
  57. //NDebugOverlay::Line( GetAbsOrigin(), GetAbsOrigin() - GetAbsVelocity() * 0.1, 255, 255, 255, false, 1 );
  58. SetNextThink( gpGlobals->curtime + 0.05 );
  59. /*
  60. QAngle angles = GetAbsAngles();
  61. angles.x += random->RandomInt( -6, 6 );
  62. angles.y += random->RandomInt( -6, 6 );
  63. SetAbsAngles( angles );
  64. */
  65. Vector forward;
  66. AngleVectors( GetAbsAngles(), &forward );
  67. SetAbsVelocity( forward * 1500.0f );
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose:
  71. //-----------------------------------------------------------------------------
  72. void CWaterBullet::Touch( CBaseEntity *pOther )
  73. {
  74. Vector vecDir = GetAbsVelocity();
  75. float speed = VectorNormalize( vecDir );
  76. Vector vecStart = GetAbsOrigin() - ( vecDir * 8 );
  77. Vector vecEnd = GetAbsOrigin() + ( vecDir * speed );
  78. trace_t tr;
  79. UTIL_TraceLine( vecStart, vecEnd, MASK_SHOT, NULL, &tr );
  80. UTIL_ImpactTrace( &tr, DMG_BULLET );
  81. UTIL_Remove( this );
  82. }