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.

162 lines
4.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "hegrenade_projectile.h"
  8. #include "soundent.h"
  9. #include "cs_player.h"
  10. #include "keyvalues.h"
  11. #include "weapon_csbase.h"
  12. #include "decals.h"
  13. #include "bot_manager.h"
  14. #define GRENADE_MODEL "models/Weapons/w_eq_fraggrenade_dropped.mdl"
  15. LINK_ENTITY_TO_CLASS( hegrenade_projectile, CHEGrenadeProjectile );
  16. PRECACHE_REGISTER( hegrenade_projectile );
  17. #if !defined( CLIENT_DLL )
  18. BEGIN_DATADESC( CHEGrenadeProjectile )
  19. // Inputs
  20. DEFINE_INPUTFUNC( FIELD_VOID, "InitializeSpawnFromWorld", InitializeSpawnFromWorld ),
  21. END_DATADESC()
  22. #endif
  23. CHEGrenadeProjectile* CHEGrenadeProjectile::Create(
  24. const Vector &position,
  25. const QAngle &angles,
  26. const Vector &velocity,
  27. const AngularImpulse &angVelocity,
  28. CBaseCombatCharacter *pOwner,
  29. const CCSWeaponInfo& weaponInfo,
  30. float timer )
  31. {
  32. CHEGrenadeProjectile *pGrenade = (CHEGrenadeProjectile*)CBaseEntity::Create( "hegrenade_projectile", position, angles, pOwner );
  33. // Set the timer for 1 second less than requested. We're going to issue a SOUND_DANGER
  34. // one second before detonation.
  35. pGrenade->SetDetonateTimerLength( 1.5 );
  36. pGrenade->SetAbsVelocity( velocity );
  37. pGrenade->SetupInitialTransmittedGrenadeVelocity( velocity );
  38. pGrenade->SetThrower( pOwner );
  39. pGrenade->SetGravity( BaseClass::GetGrenadeGravity() );
  40. pGrenade->SetFriction( BaseClass::GetGrenadeFriction() );
  41. pGrenade->SetElasticity( BaseClass::GetGrenadeElasticity() );
  42. pGrenade->ChangeTeam( pOwner->GetTeamNumber() );
  43. pGrenade->ApplyLocalAngularVelocityImpulse( angVelocity );
  44. // make NPCs afaid of it while in the air
  45. pGrenade->SetThink( &CHEGrenadeProjectile::DangerSoundThink );
  46. pGrenade->SetNextThink( gpGlobals->curtime );
  47. pGrenade->m_pWeaponInfo = &weaponInfo;
  48. pGrenade->m_flDamage = (float)weaponInfo.GetDamage(); // 100;
  49. pGrenade->m_DmgRadius = weaponInfo.GetRange(); // pGrenade->m_flDamage * 3.5f;
  50. pGrenade->SetCollisionGroup( COLLISION_GROUP_PROJECTILE );
  51. return pGrenade;
  52. }
  53. void CHEGrenadeProjectile::Spawn()
  54. {
  55. SetModel( GRENADE_MODEL );
  56. BaseClass::Spawn();
  57. SetBodygroupPreset( "thrown" );
  58. }
  59. void CHEGrenadeProjectile::Precache()
  60. {
  61. PrecacheModel( GRENADE_MODEL );
  62. PrecacheScriptSound( "HEGrenade.Bounce" );
  63. BaseClass::Precache();
  64. }
  65. void CHEGrenadeProjectile::BounceSound( void )
  66. {
  67. EmitSound( "HEGrenade.Bounce" );
  68. }
  69. void CHEGrenadeProjectile::Detonate()
  70. {
  71. // tell the bots an HE grenade has exploded (and record the event in the log)
  72. if ( CCSPlayer *player = ToCSPlayer( GetThrower() ) )
  73. {
  74. IGameEvent * event = gameeventmanager->CreateEvent( "hegrenade_detonate" );
  75. if ( event )
  76. {
  77. event->SetInt( "userid", player->GetUserID() );
  78. event->SetInt( "entityid", this->entindex() );
  79. event->SetFloat( "x", GetAbsOrigin().x );
  80. event->SetFloat( "y", GetAbsOrigin().y );
  81. event->SetFloat( "z", GetAbsOrigin().z );
  82. gameeventmanager->FireEvent( event );
  83. }
  84. }
  85. BaseClass::Detonate();
  86. }
  87. const char *CHEGrenadeProjectile::GetParticleSystemName( int pointContents, surfacedata_t *pdata )
  88. {
  89. if ( pointContents & MASK_WATER )
  90. return "explosion_basic_water";
  91. // [msmith] If the grenade goes off near smoke, then we need to make sure that it doesn't
  92. // spawn any of it's own smoke (the explosion_hegrenade_brief effect has no smoke).
  93. // This fixes an exploit that allowed players to "see through" the smokegrenade smoke.
  94. const Vector *detonatePosition = &GetAbsOrigin();
  95. if ( TheBots->IsInsideSmokeCloud( detonatePosition, HEGrenadeRadius ) )
  96. return "explosion_hegrenade_brief";
  97. if ( pdata )
  98. {
  99. switch( pdata->game.material )
  100. {
  101. case CHAR_TEX_DIRT:
  102. case CHAR_TEX_SAND:
  103. case CHAR_TEX_GRASS:
  104. case CHAR_TEX_MUD:
  105. case CHAR_TEX_FOLIAGE:
  106. return "explosion_hegrenade_dirt";
  107. case CHAR_TEX_SNOW:
  108. return "explosion_hegrenade_snow";
  109. }
  110. }
  111. return "explosion_basic";
  112. }
  113. void CHEGrenadeProjectile::InitializeSpawnFromWorld( inputdata_t &inputdata )
  114. {
  115. SetDetonateTimerLength( 1.5 );
  116. SetGravity( GetGrenadeGravity() );
  117. SetFriction( GetGrenadeFriction() );
  118. SetElasticity( GetGrenadeElasticity() );
  119. //pGrenade->ChangeTeam( pOwner->GetTeamNumber() );
  120. ApplyLocalAngularVelocityImpulse( AngularImpulse(600,random->RandomInt(-1200,1200),0) );
  121. // make NPCs afaid of it while in the air
  122. SetThink( &CHEGrenadeProjectile::DangerSoundThink );
  123. SetNextThink( gpGlobals->curtime );
  124. m_pWeaponInfo = GetWeaponInfo( WEAPON_HEGRENADE );
  125. //m_flDamage = (float)m_pWeaponInfo.GetDamage(); // 100;
  126. //m_DmgRadius = m_pWeaponInfo.GetRange(); // pGrenade->m_flDamage * 3.5f;
  127. SetCollisionGroup( COLLISION_GROUP_PROJECTILE );
  128. }