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.

81 lines
2.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. /*
  9. ===== grenade_base.cpp ========================================================
  10. Base Handling for all the player's grenades
  11. */
  12. #include "cbase.h"
  13. #include "grenadethrown.h"
  14. #include "ammodef.h"
  15. #include "vstdlib/random.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. // Precaches a grenade and ensures clients know of it's "ammo"
  19. void UTIL_PrecacheOtherGrenade( const char *szClassname )
  20. {
  21. CBaseEntity *pEntity = CreateEntityByName( szClassname );
  22. if ( !pEntity )
  23. {
  24. Msg( "NULL Ent in UTIL_PrecacheOtherGrenade\n" );
  25. return;
  26. }
  27. CThrownGrenade *pGrenade = dynamic_cast<CThrownGrenade *>( pEntity );
  28. if (pGrenade)
  29. {
  30. pGrenade->Precache( );
  31. }
  32. UTIL_Remove( pEntity );
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Setup basic values for Thrown grens
  36. //-----------------------------------------------------------------------------
  37. void CThrownGrenade::Spawn( void )
  38. {
  39. // point sized, solid, bouncing
  40. SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE );
  41. SetSolid( SOLID_BBOX );
  42. UTIL_SetSize(this, vec3_origin, vec3_origin);
  43. // Movement
  44. SetGravity( UTIL_ScaleForGravity( 648 ) );
  45. SetFriction(0.6);
  46. QAngle angles;
  47. VectorAngles( GetAbsVelocity(), angles );
  48. SetLocalAngles( angles );
  49. QAngle vecAngVel( random->RandomFloat ( -100, -500 ), 0, 0 );
  50. SetLocalAngularVelocity( vecAngVel );
  51. SetTouch( &CThrownGrenade::BounceTouch );
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Purpose: Throw the grenade.
  55. // Input : vecOrigin - Starting position
  56. // vecVelocity - Starting velocity
  57. // flExplodeTime - Time at which to detonate
  58. //-----------------------------------------------------------------------------
  59. void CThrownGrenade::Thrown( Vector vecOrigin, Vector vecVelocity, float flExplodeTime )
  60. {
  61. // Throw
  62. SetLocalOrigin( vecOrigin );
  63. SetAbsVelocity( vecVelocity );
  64. // Explode in 3 seconds
  65. SetThink( &CThrownGrenade::Detonate );
  66. SetNextThink( gpGlobals->curtime + flExplodeTime );
  67. }