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.

132 lines
3.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "baseentity.h"
  9. #include "basegrenade_shared.h"
  10. #include "soundent.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. class CBaseGrenadeConcussion : public CBaseGrenade
  14. {
  15. DECLARE_DATADESC();
  16. public:
  17. DECLARE_CLASS( CBaseGrenadeConcussion, CBaseGrenade );
  18. void Spawn( void );
  19. void Precache( void );
  20. void FallThink(void);
  21. void ExplodeConcussion( CBaseEntity *pOther );
  22. protected:
  23. static int m_nTrailSprite;
  24. };
  25. int CBaseGrenadeConcussion::m_nTrailSprite = 0;
  26. LINK_ENTITY_TO_CLASS( npc_concussiongrenade, CBaseGrenadeConcussion );
  27. BEGIN_DATADESC( CBaseGrenadeConcussion )
  28. DEFINE_THINKFUNC( FallThink ),
  29. DEFINE_ENTITYFUNC( ExplodeConcussion ),
  30. END_DATADESC()
  31. void CBaseGrenadeConcussion::FallThink(void)
  32. {
  33. if (!IsInWorld())
  34. {
  35. Remove( );
  36. return;
  37. }
  38. CSoundEnt::InsertSound ( SOUND_DANGER, GetAbsOrigin() + GetAbsVelocity() * 0.5, GetAbsVelocity().Length( ), 0.2 );
  39. SetNextThink( gpGlobals->curtime + random->RandomFloat(0.05, 0.1) );
  40. if (GetWaterLevel() != 0)
  41. {
  42. SetAbsVelocity( GetAbsVelocity() * 0.5 );
  43. }
  44. Vector pos = GetAbsOrigin() + Vector(random->RandomFloat(-4, 4), random->RandomFloat(-4, 4), random->RandomFloat(-4, 4));
  45. CPVSFilter filter( GetAbsOrigin() );
  46. te->Sprite( filter, 0.0,
  47. &pos,
  48. m_nTrailSprite,
  49. random->RandomFloat(0.5, 0.8),
  50. 200 );
  51. }
  52. //
  53. // Contact grenade, explode when it touches something
  54. //
  55. void CBaseGrenadeConcussion::ExplodeConcussion( CBaseEntity *pOther )
  56. {
  57. trace_t tr;
  58. Vector vecSpot;// trace starts here!
  59. Vector velDir = GetAbsVelocity();
  60. VectorNormalize( velDir );
  61. vecSpot = GetAbsOrigin() - velDir * 32;
  62. UTIL_TraceLine( vecSpot, vecSpot + velDir * 64, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr );
  63. Explode( &tr, DMG_BLAST );
  64. }
  65. void CBaseGrenadeConcussion::Spawn( void )
  66. {
  67. // point sized, solid, bouncing
  68. SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE );
  69. SetSolid( SOLID_BBOX );
  70. SetCollisionGroup( COLLISION_GROUP_PROJECTILE );
  71. SetModel( "models/weapons/w_grenade.mdl" ); // BUG: wrong model
  72. UTIL_SetSize(this, vec3_origin, vec3_origin);
  73. // contact grenades arc lower
  74. SetGravity( UTIL_ScaleForGravity( 400 ) ); // use a lower gravity for grenades to make them easier to see
  75. QAngle angles;
  76. VectorAngles(GetAbsVelocity(), angles );
  77. SetLocalAngles( angles );
  78. m_nRenderFX = kRenderFxGlowShell;
  79. SetRenderColor( 200, 200, 20 );
  80. SetRenderAlpha( 255 );
  81. // make NPCs afaid of it while in the air
  82. SetThink( &CBaseGrenadeConcussion::FallThink );
  83. SetNextThink( gpGlobals->curtime );
  84. // Tumble in air
  85. QAngle vecAngVel( random->RandomFloat ( -100, -500 ), 0, 0 );
  86. SetLocalAngularVelocity( vecAngVel );
  87. // Explode on contact
  88. SetTouch( &CBaseGrenadeConcussion::ExplodeConcussion );
  89. m_flDamage = 80;
  90. // Allow player to blow this puppy up in the air
  91. m_takedamage = DAMAGE_YES;
  92. }
  93. void CBaseGrenadeConcussion::Precache( void )
  94. {
  95. BaseClass::Precache( );
  96. PrecacheModel("models/weapons/w_grenade.mdl");
  97. m_nTrailSprite = PrecacheModel("sprites/twinkle01.vmt");
  98. }