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.

116 lines
3.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "decals.h"
  8. #include "basecombatcharacter.h"
  9. #include "shake.h"
  10. #include "engine/IEngineSound.h"
  11. #include "soundent.h"
  12. #include "entitylist.h"
  13. #include "hl1_basegrenade.h"
  14. extern short g_sModelIndexFireball; // (in combatweapon.cpp) holds the index for the fireball
  15. extern short g_sModelIndexWExplosion; // (in combatweapon.cpp) holds the index for the underwater explosion
  16. unsigned int CHL1BaseGrenade::PhysicsSolidMaskForEntity( void ) const
  17. {
  18. return BaseClass::PhysicsSolidMaskForEntity() | CONTENTS_HITBOX;
  19. }
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. void CHL1BaseGrenade::Precache()
  24. {
  25. BaseClass::Precache();
  26. PrecacheScriptSound( "BaseGrenade.Explode" );
  27. }
  28. void CHL1BaseGrenade::Explode( trace_t *pTrace, int bitsDamageType )
  29. {
  30. float flRndSound;// sound randomizer
  31. SetModelName( NULL_STRING );//invisible
  32. AddSolidFlags( FSOLID_NOT_SOLID );
  33. m_takedamage = DAMAGE_NO;
  34. // Pull out of the wall a bit
  35. if ( pTrace->fraction != 1.0 )
  36. {
  37. SetLocalOrigin( pTrace->endpos + (pTrace->plane.normal * 0.6) );
  38. }
  39. Vector vecAbsOrigin = GetAbsOrigin();
  40. int contents = UTIL_PointContents ( vecAbsOrigin );
  41. if ( pTrace->fraction != 1.0 )
  42. {
  43. Vector vecNormal = pTrace->plane.normal;
  44. const surfacedata_t *pdata = physprops->GetSurfaceData( pTrace->surface.surfaceProps );
  45. CPASFilter filter( vecAbsOrigin );
  46. te->Explosion( filter, 0.0,
  47. &vecAbsOrigin,
  48. !( contents & MASK_WATER ) ? g_sModelIndexFireball : g_sModelIndexWExplosion,
  49. m_DmgRadius * .03,
  50. 25,
  51. TE_EXPLFLAG_NONE,
  52. m_DmgRadius,
  53. m_flDamage,
  54. &vecNormal,
  55. (char) pdata->game.material );
  56. }
  57. else
  58. {
  59. CPASFilter filter( vecAbsOrigin );
  60. te->Explosion( filter, 0.0,
  61. &vecAbsOrigin,
  62. !( contents & MASK_WATER ) ? g_sModelIndexFireball : g_sModelIndexWExplosion,
  63. m_DmgRadius * .03,
  64. 25,
  65. TE_EXPLFLAG_NONE,
  66. m_DmgRadius,
  67. m_flDamage );
  68. }
  69. CSoundEnt::InsertSound ( SOUND_COMBAT, GetAbsOrigin(), BASEGRENADE_EXPLOSION_VOLUME, 3.0 );
  70. // Use the owner's position as the reported position
  71. Vector vecReported = GetThrower() ? GetThrower()->GetAbsOrigin() : vec3_origin;
  72. CTakeDamageInfo info( this, GetThrower(), GetBlastForce(), GetAbsOrigin(), m_flDamage, bitsDamageType, 0, &vecReported );
  73. RadiusDamage( info, GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL );
  74. UTIL_DecalTrace( pTrace, "Scorch" );
  75. flRndSound = random->RandomFloat( 0 , 1 );
  76. EmitSound( "BaseGrenade.Explode" );
  77. SetTouch( NULL );
  78. AddEffects( EF_NODRAW );
  79. SetAbsVelocity( vec3_origin );
  80. SetThink( &CBaseGrenade::Smoke );
  81. SetNextThink( gpGlobals->curtime + 0.3);
  82. if ( GetWaterLevel() == 0 )
  83. {
  84. int sparkCount = random->RandomInt( 0,3 );
  85. QAngle angles;
  86. VectorAngles( pTrace->plane.normal, angles );
  87. for ( int i = 0; i < sparkCount; i++ )
  88. Create( "spark_shower", GetAbsOrigin(), angles, NULL );
  89. }
  90. }