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.

114 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "weapon_sdkbase.h"
  8. #include "gamerules.h"
  9. #include "npcevent.h"
  10. #include "engine/IEngineSound.h"
  11. #include "weapon_grenade.h"
  12. #ifdef CLIENT_DLL
  13. #else
  14. #include "sdk_player.h"
  15. #include "items.h"
  16. #include "sdk_basegrenade_projectile.h"
  17. #endif
  18. #define GRENADE_TIMER 3.0f //Seconds
  19. IMPLEMENT_NETWORKCLASS_ALIASED( SDKGrenade, DT_SDKGrenade )
  20. BEGIN_NETWORK_TABLE(CSDKGrenade, DT_SDKGrenade)
  21. END_NETWORK_TABLE()
  22. BEGIN_PREDICTION_DATA( CSDKGrenade )
  23. END_PREDICTION_DATA()
  24. LINK_ENTITY_TO_CLASS( weapon_grenade, CSDKGrenade );
  25. PRECACHE_WEAPON_REGISTER( weapon_grenade );
  26. #ifdef GAME_DLL
  27. #define GRENADE_MODEL "models/Weapons/w_eq_fraggrenade_thrown.mdl"
  28. class CGrenadeProjectile : public CBaseGrenadeProjectile
  29. {
  30. public:
  31. DECLARE_CLASS( CGrenadeProjectile, CBaseGrenadeProjectile );
  32. // Overrides.
  33. public:
  34. virtual void Spawn()
  35. {
  36. SetModel( GRENADE_MODEL );
  37. BaseClass::Spawn();
  38. }
  39. virtual void Precache()
  40. {
  41. PrecacheModel( GRENADE_MODEL );
  42. BaseClass::Precache();
  43. }
  44. // Grenade stuff.
  45. public:
  46. static CGrenadeProjectile* Create(
  47. const Vector &position,
  48. const QAngle &angles,
  49. const Vector &velocity,
  50. const AngularImpulse &angVelocity,
  51. CBaseCombatCharacter *pOwner,
  52. float timer )
  53. {
  54. CGrenadeProjectile *pGrenade = (CGrenadeProjectile*)CBaseEntity::Create( "grenade_projectile", position, angles, pOwner );
  55. // Set the timer for 1 second less than requested. We're going to issue a SOUND_DANGER
  56. // one second before detonation.
  57. pGrenade->SetDetonateTimerLength( 1.5 );
  58. pGrenade->SetAbsVelocity( velocity );
  59. pGrenade->SetupInitialTransmittedGrenadeVelocity( velocity );
  60. pGrenade->SetThrower( pOwner );
  61. pGrenade->SetGravity( BaseClass::GetGrenadeGravity() );
  62. pGrenade->SetFriction( BaseClass::GetGrenadeFriction() );
  63. pGrenade->SetElasticity( BaseClass::GetGrenadeElasticity() );
  64. pGrenade->m_flDamage = 100;
  65. pGrenade->m_DmgRadius = pGrenade->m_flDamage * 3.5f;
  66. pGrenade->ChangeTeam( pOwner->GetTeamNumber() );
  67. pGrenade->ApplyLocalAngularVelocityImpulse( angVelocity );
  68. // make NPCs afaid of it while in the air
  69. pGrenade->SetThink( &CGrenadeProjectile::DangerSoundThink );
  70. pGrenade->SetNextThink( gpGlobals->curtime );
  71. return pGrenade;
  72. }
  73. };
  74. LINK_ENTITY_TO_CLASS( grenade_projectile, CGrenadeProjectile );
  75. PRECACHE_WEAPON_REGISTER( grenade_projectile );
  76. BEGIN_DATADESC( CSDKGrenade )
  77. END_DATADESC()
  78. void CSDKGrenade::EmitGrenade( Vector vecSrc, QAngle vecAngles, Vector vecVel, AngularImpulse angImpulse, CBasePlayer *pPlayer )
  79. {
  80. CGrenadeProjectile::Create( vecSrc, vecAngles, vecVel, angImpulse, pPlayer, GRENADE_TIMER );
  81. }
  82. #endif