Guest User

Untitled

a guest
Jun 11th, 2014
1,184
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose: TF Concussion 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_concussion.h"
  12.  
  13. // Server specific.
  14. #ifdef GAME_DLL
  15. #include "tf_player.h"
  16. #include "items.h"
  17. #include "tf_weaponbase_grenadeproj.h"
  18. #include "soundent.h"
  19. #include "KeyValues.h"
  20.  
  21. #endif
  22.  
  23. #define GRENADE_CONCUSSION_TIMER 3.0f // seconds
  24.  
  25. //=============================================================================
  26. //
  27. // TF Concussion Grenade tables.
  28. //
  29.  
  30. IMPLEMENT_NETWORKCLASS_ALIASED( TFGrenadeConcussion, DT_TFGrenadeConcussion )
  31.  
  32. BEGIN_NETWORK_TABLE( CTFGrenadeConcussion, DT_TFGrenadeConcussion )
  33. END_NETWORK_TABLE()
  34.  
  35. BEGIN_PREDICTION_DATA( CTFGrenadeConcussion )
  36. END_PREDICTION_DATA()
  37.  
  38. LINK_ENTITY_TO_CLASS( tf_weapon_grenade_concussion, CTFGrenadeConcussion );
  39. PRECACHE_WEAPON_REGISTER( tf_weapon_grenade_concussion );
  40.  
  41. //=============================================================================
  42. //
  43. // TF Concussion Grenade functions.
  44. //
  45.  
  46. // Server specific.
  47. #ifdef GAME_DLL
  48.  
  49. BEGIN_DATADESC( CTFGrenadeConcussion )
  50. END_DATADESC()
  51.  
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. //-----------------------------------------------------------------------------
  55. CTFWeaponBaseGrenadeProj *CTFGrenadeConcussion::EmitGrenade( Vector vecSrc, QAngle vecAngles, Vector vecVel,
  56. AngularImpulse angImpulse, CBasePlayer *pPlayer, float flTime, int iflags )
  57. {
  58. return CTFGrenadeConcussionProjectile::Create( vecSrc, vecAngles, vecVel, angImpulse,
  59. pPlayer, GetTFWpnData(), flTime );
  60. }
  61.  
  62. #endif
  63.  
  64. //=============================================================================
  65. //
  66. // TF Concussion Grenade Projectile functions (Server specific).
  67. //
  68. #ifdef GAME_DLL
  69.  
  70. #define GRENADE_MODEL "models/weapons/w_models/w_grenade_conc.mdl"
  71.  
  72. LINK_ENTITY_TO_CLASS( tf_weapon_grenade_concussion_projectile, CTFGrenadeConcussionProjectile );
  73. PRECACHE_WEAPON_REGISTER( tf_weapon_grenade_concussion_projectile );
  74.  
  75. //-----------------------------------------------------------------------------
  76. // Purpose:
  77. //-----------------------------------------------------------------------------
  78. CTFGrenadeConcussionProjectile* CTFGrenadeConcussionProjectile::Create( const Vector &position, const QAngle &angles,
  79. const Vector &velocity, const AngularImpulse &angVelocity,
  80. CBaseCombatCharacter *pOwner, const CTFWeaponInfo &weaponInfo, float timer, int iFlags )
  81. {
  82. CTFGrenadeConcussionProjectile *pGrenade = static_cast<CTFGrenadeConcussionProjectile*>( CTFWeaponBaseGrenadeProj::Create( "tf_weapon_grenade_concussion_projectile", position, angles, velocity, angVelocity, pOwner, weaponInfo, timer, iFlags ) );
  83. if ( pGrenade )
  84. {
  85. pGrenade->ApplyLocalAngularVelocityImpulse( angVelocity );
  86. }
  87.  
  88. return pGrenade;
  89. }
  90.  
  91. //-----------------------------------------------------------------------------
  92. // Purpose:
  93. //-----------------------------------------------------------------------------
  94. void CTFGrenadeConcussionProjectile::Spawn()
  95. {
  96. SetModel( GRENADE_MODEL );
  97.  
  98. BaseClass::Spawn();
  99. }
  100.  
  101. //-----------------------------------------------------------------------------
  102. // Purpose:
  103. //-----------------------------------------------------------------------------
  104. void CTFGrenadeConcussionProjectile::Precache()
  105. {
  106. PrecacheModel( GRENADE_MODEL );
  107.  
  108. BaseClass::Precache();
  109. }
  110.  
  111. //-----------------------------------------------------------------------------
  112. // Purpose:
  113. //-----------------------------------------------------------------------------
  114. void CTFGrenadeConcussionProjectile::BounceSound( void )
  115. {
  116. EmitSound( "Weapon_Grenade_Concussion.Bounce" );
  117. }
  118.  
  119. //-----------------------------------------------------------------------------
  120. // Purpose:
  121. //-----------------------------------------------------------------------------
  122. void CTFGrenadeConcussionProjectile::Detonate()
  123. {
  124. if ( ShouldNotDetonate() )
  125. {
  126. RemoveGrenade();
  127. return;
  128. }
  129.  
  130. // The trace start/end.
  131. Vector vecStart = GetAbsOrigin() + Vector( 0.0f, 0.0f, 8.0f );
  132. Vector vecEnd = vecStart + Vector( 0.0f, 0.0f, -32.0f );
  133.  
  134. trace_t trace;
  135. UTIL_TraceLine ( vecStart, vecEnd, MASK_SHOT_HULL, this, COLLISION_GROUP_NONE, &trace );
  136.  
  137. // Explode (concuss).
  138. Explode( &trace, DMG_BLAST );
  139.  
  140. // Screen shake.
  141. if ( GetShakeAmplitude() )
  142. {
  143. UTIL_ScreenShake( GetAbsOrigin(), GetShakeAmplitude(), 150.0, 1.0, GetShakeRadius(), SHAKE_START );
  144. }
  145. }
  146.  
  147. extern ConVar tf_grenade_show_radius;
  148.  
  149. //-----------------------------------------------------------------------------
  150. // Purpose:
  151. //-----------------------------------------------------------------------------
  152. void CTFGrenadeConcussionProjectile::Explode( trace_t *pTrace, int bitsDamageType )
  153. {
  154. // Server specific.
  155. #ifdef GAME_DLL
  156.  
  157. // Invisible.
  158. SetModelName( NULL_STRING );
  159. AddSolidFlags( FSOLID_NOT_SOLID );
  160. m_takedamage = DAMAGE_NO;
  161.  
  162. // Move the impact point away from the surface a little bit.
  163. if ( pTrace->fraction != 1.0 )
  164. {
  165. SetLocalOrigin( pTrace->endpos + ( pTrace->plane.normal * 0.6 ) );
  166. }
  167.  
  168. // Explosion effect on client
  169. SendDispatchEffect();
  170.  
  171. // Explosion sound.
  172. CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), BASEGRENADE_EXPLOSION_VOLUME, 3.0 );
  173.  
  174. // Explosion damage, using the thrower's position as the report position.
  175. CTFPlayer *pPlayer = ToTFPlayer( GetThrower() );
  176. Vector vecReported = pPlayer ? pPlayer->GetAbsOrigin() : vec3_origin;
  177. CTakeDamageInfo info( this, pPlayer, GetBlastForce(), GetAbsOrigin(), m_flDamage, bitsDamageType, 0, &vecReported );
  178. RadiusDamage( info, GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL );
  179.  
  180. // Concussion.
  181. CBaseEntity *pEntityList[64];
  182. int nEntityCount = UTIL_EntitiesInSphere( pEntityList, 64, GetAbsOrigin(), m_DmgRadius, FL_CLIENT );
  183. for ( int iEntity = 0; iEntity < nEntityCount; ++iEntity )
  184. {
  185. CBaseEntity *pEntity = pEntityList[iEntity];
  186. CTFPlayer *pTestPlayer = ToTFPlayer( pEntity );
  187.  
  188. // You can concuss yourself.
  189. bool bIsThrower = ( pPlayer == pTestPlayer );
  190. if ( bIsThrower || ( pTestPlayer && !InSameTeam( pTestPlayer) ) )
  191. {
  192. pTestPlayer->m_Shared.Concussion( this, m_DmgRadius );
  193. }
  194. }
  195.  
  196. if ( tf_grenade_show_radius.GetBool() )
  197. {
  198. DrawRadius( m_DmgRadius );
  199. }
  200.  
  201. // Explosion decal.
  202. UTIL_DecalTrace( pTrace, "Scorch" );
  203.  
  204. // Reset.
  205. SetThink( &CBaseGrenade::SUB_Remove );
  206. SetTouch( NULL );
  207. AddEffects( EF_NODRAW );
  208. SetAbsVelocity( vec3_origin );
  209. SetNextThink( gpGlobals->curtime );
  210. #endif
  211. }
  212.  
  213. #endif
RAW Paste Data