Team Fortress 2 Source Code as on 22/4/2020
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.

94 lines
2.5 KiB

  1. //========= Copyright 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. #define GRENADE_MODEL "models/Weapons/w_eq_fraggrenade_thrown.mdl"
  13. LINK_ENTITY_TO_CLASS( hegrenade_projectile, CHEGrenadeProjectile );
  14. PRECACHE_WEAPON_REGISTER( hegrenade_projectile );
  15. CHEGrenadeProjectile* CHEGrenadeProjectile::Create(
  16. const Vector &position,
  17. const QAngle &angles,
  18. const Vector &velocity,
  19. const AngularImpulse &angVelocity,
  20. CBaseCombatCharacter *pOwner,
  21. float timer )
  22. {
  23. CHEGrenadeProjectile *pGrenade = (CHEGrenadeProjectile*)CBaseEntity::Create( "hegrenade_projectile", position, angles, pOwner );
  24. // Set the timer for 1 second less than requested. We're going to issue a SOUND_DANGER
  25. // one second before detonation.
  26. pGrenade->SetDetonateTimerLength( 1.5 );
  27. pGrenade->SetAbsVelocity( velocity );
  28. pGrenade->SetupInitialTransmittedGrenadeVelocity( velocity );
  29. pGrenade->SetThrower( pOwner );
  30. pGrenade->SetGravity( BaseClass::GetGrenadeGravity() );
  31. pGrenade->SetFriction( BaseClass::GetGrenadeFriction() );
  32. pGrenade->SetElasticity( BaseClass::GetGrenadeElasticity() );
  33. pGrenade->m_flDamage = 100;
  34. pGrenade->m_DmgRadius = pGrenade->m_flDamage * 3.5f;
  35. pGrenade->ChangeTeam( pOwner->GetTeamNumber() );
  36. pGrenade->ApplyLocalAngularVelocityImpulse( angVelocity );
  37. // make NPCs afaid of it while in the air
  38. pGrenade->SetThink( &CHEGrenadeProjectile::DangerSoundThink );
  39. pGrenade->SetNextThink( gpGlobals->curtime );
  40. pGrenade->m_pWeaponInfo = GetWeaponInfo( WEAPON_HEGRENADE );
  41. return pGrenade;
  42. }
  43. void CHEGrenadeProjectile::Spawn()
  44. {
  45. SetModel( GRENADE_MODEL );
  46. BaseClass::Spawn();
  47. }
  48. void CHEGrenadeProjectile::Precache()
  49. {
  50. PrecacheModel( GRENADE_MODEL );
  51. PrecacheScriptSound( "HEGrenade.Bounce" );
  52. BaseClass::Precache();
  53. }
  54. void CHEGrenadeProjectile::BounceSound( void )
  55. {
  56. EmitSound( "HEGrenade.Bounce" );
  57. }
  58. void CHEGrenadeProjectile::Detonate()
  59. {
  60. BaseClass::Detonate();
  61. // tell the bots an HE grenade has exploded
  62. CCSPlayer *player = ToCSPlayer(GetThrower());
  63. if ( player )
  64. {
  65. IGameEvent * event = gameeventmanager->CreateEvent( "hegrenade_detonate" );
  66. if ( event )
  67. {
  68. event->SetInt( "userid", player->GetUserID() );
  69. event->SetFloat( "x", GetAbsOrigin().x );
  70. event->SetFloat( "y", GetAbsOrigin().y );
  71. event->SetFloat( "z", GetAbsOrigin().z );
  72. gameeventmanager->FireEvent( event );
  73. }
  74. }
  75. }