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.

160 lines
3.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "hl1_grenade_mp5.h"
  9. #include "hl1mp_weapon_mp5.h"
  10. #include "soundent.h"
  11. #include "decals.h"
  12. #include "shake.h"
  13. #include "smoke_trail.h"
  14. #include "vstdlib/random.h"
  15. #include "engine/IEngineSound.h"
  16. #include "world.h"
  17. extern short g_sModelIndexFireball;
  18. extern short g_sModelIndexWExplosion;
  19. extern ConVar sk_plr_dmg_mp5_grenade;
  20. extern ConVar sk_max_mp5_grenade;
  21. extern ConVar sk_mp5_grenade_radius;
  22. BEGIN_DATADESC( CGrenadeMP5 )
  23. // SR-BUGBUG: These are borked!!!!
  24. // float m_fSpawnTime;
  25. // Function pointers
  26. DEFINE_ENTITYFUNC( GrenadeMP5Touch ),
  27. DEFINE_FIELD( m_fSpawnTime, FIELD_TIME ),
  28. END_DATADESC()
  29. LINK_ENTITY_TO_CLASS( grenade_mp5, CGrenadeMP5 );
  30. void CGrenadeMP5::Spawn( void )
  31. {
  32. Precache( );
  33. SetSolid( SOLID_BBOX );
  34. SetMoveType( MOVETYPE_FLY );
  35. AddFlag( FL_GRENADE );
  36. SetModel( "models/grenade.mdl" );
  37. //UTIL_SetSize(this, Vector(-3, -3, -3), Vector(3, 3, 3));
  38. UTIL_SetSize(this, Vector(0, 0, 0), Vector(0, 0, 0));
  39. SetUse( &CBaseGrenade::DetonateUse );
  40. SetTouch( &CGrenadeMP5::GrenadeMP5Touch );
  41. SetNextThink( gpGlobals->curtime + 0.1f );
  42. m_flDamage = sk_plr_dmg_mp5_grenade.GetFloat();
  43. m_DmgRadius = sk_mp5_grenade_radius.GetFloat();
  44. m_takedamage = DAMAGE_YES;
  45. m_bIsLive = true;
  46. m_iHealth = 1;
  47. SetGravity( UTIL_ScaleForGravity( 400 ) ); // use a lower gravity for grenades to make them easier to see
  48. SetFriction( 0.8 );
  49. SetSequence( 0 );
  50. m_fSpawnTime = gpGlobals->curtime;
  51. }
  52. void CGrenadeMP5::Event_Killed( CBaseEntity *pInflictor, CBaseEntity *pAttacker, float flDamage, int bitsDamageType )
  53. {
  54. Detonate( );
  55. }
  56. void CGrenadeMP5::GrenadeMP5Touch( CBaseEntity *pOther )
  57. {
  58. if ( !pOther->IsSolid() )
  59. return;
  60. // If I'm live go ahead and blow up
  61. if (m_bIsLive)
  62. {
  63. Detonate();
  64. }
  65. else
  66. {
  67. // If I'm not live, only blow up if I'm hitting an chacter that
  68. // is not the owner of the weapon
  69. CBaseCombatCharacter *pBCC = ToBaseCombatCharacter( pOther );
  70. if (pBCC && GetThrower() != pBCC)
  71. {
  72. m_bIsLive = true;
  73. Detonate();
  74. }
  75. }
  76. }
  77. void CGrenadeMP5::Detonate(void)
  78. {
  79. if (!m_bIsLive)
  80. {
  81. return;
  82. }
  83. m_bIsLive = false;
  84. m_takedamage = DAMAGE_NO;
  85. CPASFilter filter( GetAbsOrigin() );
  86. te->Explosion( filter, 0.0,
  87. &GetAbsOrigin(),
  88. GetWaterLevel() == 0 ? g_sModelIndexFireball : g_sModelIndexWExplosion,
  89. (m_flDamage - 50) * .60,
  90. 15,
  91. TE_EXPLFLAG_NONE,
  92. m_DmgRadius,
  93. m_flDamage );
  94. trace_t tr;
  95. tr = CBaseEntity::GetTouchTrace();
  96. if ( (tr.m_pEnt != GetWorldEntity()) || (tr.hitbox != 0) )
  97. {
  98. // non-world needs smaller decals
  99. UTIL_DecalTrace( &tr, "SmallScorch");
  100. }
  101. else
  102. {
  103. UTIL_DecalTrace( &tr, "Scorch" );
  104. }
  105. CSoundEnt::InsertSound ( SOUND_COMBAT, GetAbsOrigin(), BASEGRENADE_EXPLOSION_VOLUME, 3.0 );
  106. RadiusDamage ( CTakeDamageInfo( this, GetThrower(), m_flDamage, DMG_BLAST ), GetAbsOrigin(), m_flDamage * 2.5, CLASS_NONE, NULL );
  107. CPASAttenuationFilter filter2( this );
  108. EmitSound( filter2, entindex(), "GrenadeMP5.Detonate" );
  109. if ( GetWaterLevel() == 0 )
  110. {
  111. int sparkCount = random->RandomInt( 0,3 );
  112. QAngle angles;
  113. VectorAngles( tr.plane.normal, angles );
  114. for ( int i = 0; i < sparkCount; i++ )
  115. Create( "spark_shower", GetAbsOrigin(), angles, NULL );
  116. }
  117. UTIL_Remove( this );
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Purpose:
  121. //-----------------------------------------------------------------------------
  122. void CGrenadeMP5::Precache( void )
  123. {
  124. BaseClass::Precache();
  125. PrecacheModel( "models/grenade.mdl" );
  126. PrecacheScriptSound( "GrenadeMP5.Detonate" );
  127. }