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.

171 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #include "cbase.h"
  10. #include "hl1_grenade_spit.h"
  11. #include "soundent.h"
  12. #include "decals.h"
  13. #include "smoke_trail.h"
  14. #include "hl2_shareddefs.h"
  15. #include "vstdlib/random.h"
  16. #include "engine/IEngineSound.h"
  17. ConVar sk_bullsquid_dmg_spit ( "sk_bullsquid_dmg_spit", "0" );
  18. BEGIN_DATADESC( CGrenadeSpit )
  19. // Function pointers
  20. DEFINE_THINKFUNC( SpitThink ),
  21. DEFINE_ENTITYFUNC( GrenadeSpitTouch ),
  22. //DEFINE_FIELD( m_nSquidSpitSprite, FIELD_INTEGER ),
  23. DEFINE_FIELD( m_fSpitDeathTime, FIELD_TIME ),
  24. END_DATADESC()
  25. LINK_ENTITY_TO_CLASS( grenade_spit, CGrenadeSpit );
  26. void CGrenadeSpit::Spawn( void )
  27. {
  28. Precache( );
  29. SetSolid( SOLID_BBOX );
  30. SetMoveType( MOVETYPE_FLYGRAVITY );
  31. // FIXME, if these is a sprite, then we need a base class derived from CSprite rather than
  32. // CBaseAnimating. pev->scale becomes m_flSpriteScale in that case.
  33. SetModel( "models/spitball_large.mdl" );
  34. UTIL_SetSize(this, Vector(-3, -3, -3), Vector(3, 3, 3));
  35. m_nRenderMode = kRenderTransAdd;
  36. SetRenderColor( 255, 255, 255, 255 );
  37. m_nRenderFX = kRenderFxNone;
  38. SetThink( &CGrenadeSpit::SpitThink );
  39. SetUse( &CBaseGrenade::DetonateUse );
  40. SetTouch( &CGrenadeSpit::GrenadeSpitTouch );
  41. SetNextThink( gpGlobals->curtime + 0.1f );
  42. m_flDamage = sk_bullsquid_dmg_spit.GetFloat();
  43. m_DmgRadius = 60.0f;
  44. m_takedamage = DAMAGE_YES;
  45. m_iHealth = 1;
  46. SetGravity( SPIT_GRAVITY );
  47. SetFriction( 0.8 );
  48. SetSequence( 1 );
  49. SetCollisionGroup( HL2COLLISION_GROUP_SPIT );
  50. }
  51. void CGrenadeSpit::SetSpitSize(int nSize)
  52. {
  53. switch (nSize)
  54. {
  55. case SPIT_LARGE:
  56. {
  57. SetModel( "models/spitball_large.mdl" );
  58. break;
  59. }
  60. case SPIT_MEDIUM:
  61. {
  62. SetModel( "models/spitball_medium.mdl" );
  63. break;
  64. }
  65. case SPIT_SMALL:
  66. {
  67. SetModel( "models/spitball_small.mdl" );
  68. break;
  69. }
  70. }
  71. }
  72. void CGrenadeSpit::Event_Killed( const CTakeDamageInfo &info )
  73. {
  74. Detonate( );
  75. }
  76. void CGrenadeSpit::GrenadeSpitTouch( CBaseEntity *pOther )
  77. {
  78. if (m_fSpitDeathTime != 0)
  79. {
  80. return;
  81. }
  82. if ( pOther->GetCollisionGroup() == HL2COLLISION_GROUP_SPIT)
  83. {
  84. return;
  85. }
  86. if ( !pOther->m_takedamage )
  87. {
  88. // make a splat on the wall
  89. trace_t tr;
  90. UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + GetAbsVelocity() * 10, MASK_SOLID, this, COLLISION_GROUP_NONE, &tr );
  91. UTIL_DecalTrace(&tr, "BeerSplash" );
  92. // make some flecks
  93. CPVSFilter filter( tr.endpos );
  94. te->SpriteSpray( filter, 0.0,
  95. &tr.endpos, &tr.plane.normal, m_nSquidSpitSprite, random->RandomInt( 90, 160 ), 50, random->RandomInt ( 5, 15 ) );
  96. }
  97. else
  98. {
  99. RadiusDamage ( CTakeDamageInfo( this, GetThrower(), m_flDamage, DMG_BLAST ), GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL );
  100. }
  101. Detonate();
  102. }
  103. void CGrenadeSpit::SpitThink( void )
  104. {
  105. if (m_fSpitDeathTime != 0 &&
  106. m_fSpitDeathTime < gpGlobals->curtime)
  107. {
  108. UTIL_Remove( this );
  109. }
  110. SetNextThink( gpGlobals->curtime + 0.1f );
  111. }
  112. void CGrenadeSpit::Detonate(void)
  113. {
  114. m_takedamage = DAMAGE_NO;
  115. int iPitch;
  116. // splat sound
  117. iPitch = random->RandomFloat( 90, 110 );
  118. EmitSound( "GrenadeSpit.Acid" );
  119. EmitSound( "GrenadeSpit.Hit" );
  120. UTIL_Remove( this );
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose:
  124. //-----------------------------------------------------------------------------
  125. void CGrenadeSpit::Precache( void )
  126. {
  127. m_nSquidSpitSprite = PrecacheModel("sprites/bigspit.vmt");// client side spittle.
  128. PrecacheModel("models/spitball_large.mdl");
  129. PrecacheModel("models/spitball_medium.mdl");
  130. PrecacheModel("models/spitball_small.mdl");
  131. PrecacheScriptSound( "GrenadeSpit.Acid" );
  132. PrecacheScriptSound( "GrenadeSpit.Hit" );
  133. }
  134. CGrenadeSpit::CGrenadeSpit(void)
  135. {
  136. }