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.

217 lines
5.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "player.h"
  10. #include "soundenvelope.h"
  11. #include "engine/IEngineSound.h"
  12. #include "explode.h"
  13. #include "Sprite.h"
  14. #include "grenade_satchel.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. #define SLAM_SPRITE "sprites/redglow1.vmt"
  18. ConVar sk_plr_dmg_satchel ( "sk_plr_dmg_satchel","0");
  19. ConVar sk_npc_dmg_satchel ( "sk_npc_dmg_satchel","0");
  20. ConVar sk_satchel_radius ( "sk_satchel_radius","0");
  21. BEGIN_DATADESC( CSatchelCharge )
  22. DEFINE_FIELD( m_flNextBounceSoundTime, FIELD_TIME ),
  23. DEFINE_FIELD( m_bInAir, FIELD_BOOLEAN ),
  24. DEFINE_FIELD( m_vLastPosition, FIELD_POSITION_VECTOR ),
  25. DEFINE_FIELD( m_pMyWeaponSLAM, FIELD_CLASSPTR ),
  26. DEFINE_FIELD( m_bIsAttached, FIELD_BOOLEAN ),
  27. // Function Pointers
  28. DEFINE_THINKFUNC( SatchelThink ),
  29. // Inputs
  30. DEFINE_INPUTFUNC( FIELD_VOID, "Explode", InputExplode),
  31. END_DATADESC()
  32. LINK_ENTITY_TO_CLASS( npc_satchel, CSatchelCharge );
  33. //=========================================================
  34. // Deactivate - do whatever it is we do to an orphaned
  35. // satchel when we don't want it in the world anymore.
  36. //=========================================================
  37. void CSatchelCharge::Deactivate( void )
  38. {
  39. AddSolidFlags( FSOLID_NOT_SOLID );
  40. UTIL_Remove( this );
  41. if ( m_hGlowSprite != NULL )
  42. {
  43. UTIL_Remove( m_hGlowSprite );
  44. m_hGlowSprite = NULL;
  45. }
  46. }
  47. void CSatchelCharge::Spawn( void )
  48. {
  49. Precache( );
  50. SetModel( "models/Weapons/w_slam.mdl" );
  51. VPhysicsInitNormal( SOLID_BBOX, GetSolidFlags() | FSOLID_TRIGGER, false );
  52. SetMoveType( MOVETYPE_VPHYSICS );
  53. SetCollisionGroup( COLLISION_GROUP_WEAPON );
  54. UTIL_SetSize(this, Vector( -6, -6, -2), Vector(6, 6, 2));
  55. SetThink( &CSatchelCharge::SatchelThink );
  56. SetNextThink( gpGlobals->curtime + 0.1f );
  57. m_flDamage = sk_plr_dmg_satchel.GetFloat();
  58. m_DmgRadius = sk_satchel_radius.GetFloat();
  59. m_takedamage = DAMAGE_YES;
  60. m_iHealth = 1;
  61. SetGravity( UTIL_ScaleForGravity( 560 ) ); // slightly lower gravity
  62. SetFriction( 1.0 );
  63. SetSequence( 1 );
  64. SetDamage( 150 );
  65. m_bIsAttached = false;
  66. m_bInAir = true;
  67. m_flNextBounceSoundTime = 0;
  68. m_vLastPosition = vec3_origin;
  69. m_hGlowSprite = NULL;
  70. CreateEffects();
  71. }
  72. //-----------------------------------------------------------------------------
  73. // Purpose: Start up any effects for us
  74. //-----------------------------------------------------------------------------
  75. void CSatchelCharge::CreateEffects( void )
  76. {
  77. // Only do this once
  78. if ( m_hGlowSprite != NULL )
  79. return;
  80. // Create a blinking light to show we're an active SLAM
  81. m_hGlowSprite = CSprite::SpriteCreate( SLAM_SPRITE, GetAbsOrigin(), false );
  82. m_hGlowSprite->SetAttachment( this, 0 );
  83. m_hGlowSprite->SetTransparency( kRenderTransAdd, 255, 255, 255, 255, kRenderFxStrobeFast );
  84. m_hGlowSprite->SetBrightness( 255, 1.0f );
  85. m_hGlowSprite->SetScale( 0.2f, 0.5f );
  86. m_hGlowSprite->TurnOn();
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose:
  90. // Input :
  91. // Output :
  92. //-----------------------------------------------------------------------------
  93. void CSatchelCharge::InputExplode( inputdata_t &inputdata )
  94. {
  95. ExplosionCreate( GetAbsOrigin() + Vector( 0, 0, 16 ), GetAbsAngles(), GetThrower(), GetDamage(), 200,
  96. SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE, 0.0f, this);
  97. UTIL_Remove( this );
  98. }
  99. void CSatchelCharge::SatchelThink( void )
  100. {
  101. // If attached resize so player can pick up off wall
  102. if (m_bIsAttached)
  103. {
  104. UTIL_SetSize(this, Vector( -2, -2, -6), Vector(2, 2, 6));
  105. }
  106. // See if I can lose my owner (has dropper moved out of way?)
  107. // Want do this so owner can shoot the satchel charge
  108. if (GetOwnerEntity())
  109. {
  110. trace_t tr;
  111. Vector vUpABit = GetAbsOrigin();
  112. vUpABit.z += 5.0;
  113. CBaseEntity* saveOwner = GetOwnerEntity();
  114. SetOwnerEntity( NULL );
  115. UTIL_TraceEntity( this, GetAbsOrigin(), vUpABit, MASK_SOLID, &tr );
  116. if ( tr.startsolid || tr.fraction != 1.0 )
  117. {
  118. SetOwnerEntity( saveOwner );
  119. }
  120. }
  121. // Bounce movement code gets this think stuck occasionally so check if I've
  122. // succeeded in moving, otherwise kill my motions.
  123. else if ((GetAbsOrigin() - m_vLastPosition).LengthSqr()<1)
  124. {
  125. SetAbsVelocity( vec3_origin );
  126. QAngle angVel = GetLocalAngularVelocity();
  127. angVel.y = 0;
  128. SetLocalAngularVelocity( angVel );
  129. // Clear think function
  130. SetThink(NULL);
  131. return;
  132. }
  133. m_vLastPosition= GetAbsOrigin();
  134. StudioFrameAdvance( );
  135. SetNextThink( gpGlobals->curtime + 0.1f );
  136. if (!IsInWorld())
  137. {
  138. UTIL_Remove( this );
  139. return;
  140. }
  141. // Is it attached to a wall?
  142. if (m_bIsAttached)
  143. {
  144. return;
  145. }
  146. }
  147. void CSatchelCharge::Precache( void )
  148. {
  149. PrecacheModel("models/Weapons/w_slam.mdl");
  150. PrecacheModel(SLAM_SPRITE);
  151. }
  152. void CSatchelCharge::BounceSound( void )
  153. {
  154. if (gpGlobals->curtime > m_flNextBounceSoundTime)
  155. {
  156. m_flNextBounceSoundTime = gpGlobals->curtime + 0.1;
  157. }
  158. }
  159. //-----------------------------------------------------------------------------
  160. // Purpose: Constructor
  161. // Input :
  162. // Output :
  163. //-----------------------------------------------------------------------------
  164. CSatchelCharge::CSatchelCharge(void)
  165. {
  166. m_vLastPosition.Init();
  167. m_pMyWeaponSLAM = NULL;
  168. }
  169. CSatchelCharge::~CSatchelCharge(void)
  170. {
  171. if ( m_hGlowSprite != NULL )
  172. {
  173. UTIL_Remove( m_hGlowSprite );
  174. m_hGlowSprite = NULL;
  175. }
  176. }