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.

140 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: TF Napalm Grenade.
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "tf_weaponbase.h"
  8. #include "tf_gamerules.h"
  9. #include "npcevent.h"
  10. #include "engine/IEngineSound.h"
  11. #include "tf_weapon_grenade_napalm.h"
  12. // Server specific.
  13. #ifdef GAME_DLL
  14. #include "tf_player.h"
  15. #include "items.h"
  16. #include "tf_weaponbase_grenadeproj.h"
  17. #include "soundent.h"
  18. #include "KeyValues.h"
  19. #endif
  20. //=============================================================================
  21. //
  22. // TF Napalm Grenade tables.
  23. //
  24. IMPLEMENT_NETWORKCLASS_ALIASED( TFGrenadeNapalm, DT_TFGrenadeNapalm )
  25. BEGIN_NETWORK_TABLE( CTFGrenadeNapalm, DT_TFGrenadeNapalm )
  26. END_NETWORK_TABLE()
  27. BEGIN_PREDICTION_DATA( CTFGrenadeNapalm )
  28. END_PREDICTION_DATA()
  29. LINK_ENTITY_TO_CLASS( tf_weapon_grenade_napalm, CTFGrenadeNapalm );
  30. PRECACHE_WEAPON_REGISTER( tf_weapon_grenade_napalm );
  31. //=============================================================================
  32. //
  33. // TF Napalm Grenade functions.
  34. //
  35. // Server specific.
  36. #ifdef GAME_DLL
  37. BEGIN_DATADESC( CTFGrenadeNapalm )
  38. END_DATADESC()
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. //-----------------------------------------------------------------------------
  42. CTFWeaponBaseGrenadeProj *CTFGrenadeNapalm::EmitGrenade( Vector vecSrc, QAngle vecAngles, Vector vecVel,
  43. AngularImpulse angImpulse, CBasePlayer *pPlayer, float flTime, int iflags )
  44. {
  45. return CTFGrenadeNapalmProjectile::Create( vecSrc, vecAngles, vecVel, angImpulse,
  46. pPlayer, GetTFWpnData(), flTime );
  47. }
  48. #endif
  49. //=============================================================================
  50. //
  51. // TF Napalm Grenade Projectile functions (Server specific).
  52. //
  53. #ifdef GAME_DLL
  54. #define GRENADE_MODEL "models/weapons/w_models/w_grenade_napalm.mdl"
  55. LINK_ENTITY_TO_CLASS( tf_weapon_grenade_napalm_projectile, CTFGrenadeNapalmProjectile );
  56. PRECACHE_WEAPON_REGISTER( tf_weapon_grenade_napalm_projectile );
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. //-----------------------------------------------------------------------------
  60. CTFGrenadeNapalmProjectile* CTFGrenadeNapalmProjectile::Create( const Vector &position, const QAngle &angles,
  61. const Vector &velocity, const AngularImpulse &angVelocity,
  62. CBaseCombatCharacter *pOwner, const CTFWeaponInfo &weaponInfo, float timer, int iFlags )
  63. {
  64. CTFGrenadeNapalmProjectile *pGrenade = static_cast<CTFGrenadeNapalmProjectile*>( CTFWeaponBaseGrenadeProj::Create( "tf_weapon_grenade_napalm_projectile", position, angles, velocity, angVelocity, pOwner, weaponInfo, timer, iFlags ) );
  65. if ( pGrenade )
  66. {
  67. pGrenade->ApplyLocalAngularVelocityImpulse( angVelocity );
  68. }
  69. return pGrenade;
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose:
  73. //-----------------------------------------------------------------------------
  74. void CTFGrenadeNapalmProjectile::Spawn()
  75. {
  76. SetModel( GRENADE_MODEL );
  77. BaseClass::Spawn();
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. //-----------------------------------------------------------------------------
  82. void CTFGrenadeNapalmProjectile::Precache()
  83. {
  84. PrecacheModel( GRENADE_MODEL );
  85. BaseClass::Precache();
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Purpose:
  89. //-----------------------------------------------------------------------------
  90. void CTFGrenadeNapalmProjectile::BounceSound( void )
  91. {
  92. EmitSound( "Weapon_Grenade_Nail.Bounce" );
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Purpose:
  96. //-----------------------------------------------------------------------------
  97. void CTFGrenadeNapalmProjectile::Detonate()
  98. {
  99. if ( ShouldNotDetonate() )
  100. {
  101. RemoveGrenade();
  102. return;
  103. }
  104. BaseClass::Detonate();
  105. #if 0
  106. // Tell the bots an HE grenade has exploded
  107. CTFPlayer *pPlayer = ToTFPlayer( GetThrower() );
  108. if ( pPlayer )
  109. {
  110. KeyValues *pEvent = new KeyValues( "tf_weapon_grenade_detonate" );
  111. pEvent->SetInt( "userid", pPlayer->GetUserID() );
  112. gameeventmanager->FireEventServerOnly( pEvent );
  113. }
  114. #endif
  115. }
  116. #endif