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.

294 lines
7.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "dod_baserocket.h"
  8. #include "explode.h"
  9. #include "dod_shareddefs.h"
  10. #include "dod_gamerules.h"
  11. #include "fx_dod_shared.h"
  12. BEGIN_DATADESC( CDODBaseRocket )
  13. // Function Pointers
  14. DEFINE_FUNCTION( RocketTouch ),
  15. DEFINE_THINKFUNC( FlyThink ),
  16. END_DATADESC()
  17. IMPLEMENT_SERVERCLASS_ST( CDODBaseRocket, DT_DODBaseRocket )
  18. SendPropVector( SENDINFO( m_vInitialVelocity ),
  19. 20, // nbits
  20. 0, // flags
  21. -3000, // low value
  22. 3000 // high value
  23. )
  24. END_NETWORK_TABLE()
  25. LINK_ENTITY_TO_CLASS( base_rocket, CDODBaseRocket );
  26. //-----------------------------------------------------------------------------
  27. // Constructor
  28. //-----------------------------------------------------------------------------
  29. CDODBaseRocket::CDODBaseRocket()
  30. {
  31. }
  32. CDODBaseRocket::~CDODBaseRocket()
  33. {
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Purpose:
  37. //-----------------------------------------------------------------------------
  38. void CDODBaseRocket::Precache( void )
  39. {
  40. PrecacheScriptSound( "Weapon_Bazooka.Shoot" );
  41. PrecacheParticleSystem( "rockettrail" );
  42. }
  43. ConVar mp_rocketdamage( "mp_rocketdamage", "150", FCVAR_GAMEDLL | FCVAR_CHEAT );
  44. ConVar mp_rocketradius( "mp_rocketradius", "200", FCVAR_GAMEDLL | FCVAR_CHEAT );
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48. void CDODBaseRocket::Spawn( void )
  49. {
  50. Precache();
  51. SetSolid( SOLID_BBOX );
  52. Assert( GetModel() ); //derived classes must have set model
  53. UTIL_SetSize( this, -Vector(2,2,2), Vector(2,2,2) );
  54. SetTouch( &CDODBaseRocket::RocketTouch );
  55. SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_CUSTOM );
  56. m_takedamage = DAMAGE_NO;
  57. SetGravity( 0.1 );
  58. SetDamage( mp_rocketdamage.GetFloat() );
  59. AddFlag( FL_OBJECT );
  60. SetCollisionGroup( COLLISION_GROUP_PROJECTILE );
  61. EmitSound( "Weapon_Bazooka.Shoot" );
  62. m_flCollideWithTeammatesTime = gpGlobals->curtime + 0.25;
  63. m_bCollideWithTeammates = false;
  64. SetThink( &CDODBaseRocket::FlyThink );
  65. SetNextThink( gpGlobals->curtime );
  66. }
  67. unsigned int CDODBaseRocket::PhysicsSolidMaskForEntity( void ) const
  68. {
  69. int teamContents = 0;
  70. if ( m_bCollideWithTeammates == false )
  71. {
  72. // Only collide with the other team
  73. teamContents = ( GetTeamNumber() == TEAM_ALLIES ) ? CONTENTS_TEAM1 : CONTENTS_TEAM2;
  74. }
  75. else
  76. {
  77. // Collide with both teams
  78. teamContents = CONTENTS_TEAM1 | CONTENTS_TEAM2;
  79. }
  80. return BaseClass::PhysicsSolidMaskForEntity() | CONTENTS_HITBOX | teamContents;
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose: Stops any kind of tracking and shoots dumb
  84. //-----------------------------------------------------------------------------
  85. void CDODBaseRocket::Fire( void )
  86. {
  87. SetThink( NULL );
  88. SetMoveType( MOVETYPE_FLY );
  89. SetModel("models/weapons/w_missile.mdl");
  90. UTIL_SetSize( this, vec3_origin, vec3_origin );
  91. EmitSound( "Weapon_Bazooka.Shoot" );
  92. }
  93. //-----------------------------------------------------------------------------
  94. // The actual explosion
  95. //-----------------------------------------------------------------------------
  96. void CDODBaseRocket::DoExplosion( trace_t *pTrace )
  97. {
  98. /*
  99. // Explode
  100. ExplosionCreate(
  101. GetAbsOrigin(), //DMG_ROCKET
  102. GetAbsAngles(),
  103. GetOwnerEntity(),
  104. GetDamage(), //magnitude
  105. mp_rocketradius.GetFloat(), //radius
  106. SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE,
  107. 0.0f, //explosion force
  108. this); //inflictor
  109. */
  110. // Pull out of the wall a bit
  111. if ( pTrace->fraction != 1.0 )
  112. {
  113. SetAbsOrigin( pTrace->endpos + (pTrace->plane.normal * 0.6) );
  114. }
  115. // Explosion effect on client
  116. Vector vecOrigin = GetAbsOrigin();
  117. CPVSFilter filter( vecOrigin );
  118. TE_DODExplosion( filter, 0.0f, vecOrigin, pTrace->plane.normal );
  119. CTakeDamageInfo info( this, GetOwnerEntity(), vec3_origin, GetAbsOrigin(), GetDamage(), DMG_BLAST, 0 );
  120. RadiusDamage( info, vecOrigin, mp_rocketradius.GetFloat() /* GetDamageRadius() */, CLASS_NONE, NULL );
  121. // stun players in a radius
  122. const float flStunDamage = 75;
  123. const float flRadius = 150;
  124. CTakeDamageInfo stunInfo( this, GetOwnerEntity(), vec3_origin, GetAbsOrigin(), flStunDamage, DMG_STUN );
  125. DODGameRules()->RadiusStun( stunInfo, GetAbsOrigin(), flRadius );
  126. }
  127. //-----------------------------------------------------------------------------
  128. // Purpose:
  129. //-----------------------------------------------------------------------------
  130. void CDODBaseRocket::Explode( void )
  131. {
  132. // Don't explode against the skybox. Just pretend that
  133. // the missile flies off into the distance.
  134. const trace_t &tr = CBaseEntity::GetTouchTrace();
  135. const trace_t *p = &tr;
  136. trace_t *newTrace = const_cast<trace_t*>(p);
  137. DoExplosion( newTrace );
  138. if ( newTrace->m_pEnt && !newTrace->m_pEnt->IsPlayer() )
  139. UTIL_DecalTrace( newTrace, "Scorch" );
  140. StopSound( "Weapon_Bazooka.Shoot" );
  141. UTIL_Remove( this );
  142. }
  143. //-----------------------------------------------------------------------------
  144. // Purpose:
  145. // Input : *pOther -
  146. //-----------------------------------------------------------------------------
  147. void CDODBaseRocket::RocketTouch( CBaseEntity *pOther )
  148. {
  149. Assert( pOther );
  150. if ( !pOther->IsSolid() || pOther->IsSolidFlagSet(FSOLID_VOLUME_CONTENTS) )
  151. return;
  152. if ( pOther->GetCollisionGroup() == COLLISION_GROUP_WEAPON )
  153. return;
  154. // if we hit the skybox, just disappear
  155. const trace_t &tr = CBaseEntity::GetTouchTrace();
  156. const trace_t *p = &tr;
  157. trace_t *newTrace = const_cast<trace_t*>(p);
  158. if( tr.surface.flags & SURF_SKY )
  159. {
  160. UTIL_Remove( this );
  161. return;
  162. }
  163. if( !pOther->IsPlayer() && pOther->m_takedamage == DAMAGE_YES )
  164. {
  165. CTakeDamageInfo info;
  166. info.SetAttacker( this );
  167. info.SetInflictor( this );
  168. info.SetDamage( 50 );
  169. info.SetDamageForce( vec3_origin ); // don't worry about this not having a damage force.
  170. // It will explode on touch and impart its own forces
  171. info.SetDamageType( DMG_CLUB );
  172. Vector dir;
  173. AngleVectors( GetAbsAngles(), &dir );
  174. pOther->DispatchTraceAttack( info, dir, newTrace );
  175. ApplyMultiDamage();
  176. if( pOther->IsAlive() )
  177. {
  178. Explode();
  179. }
  180. // if it's not alive, continue flying
  181. }
  182. else
  183. {
  184. Explode();
  185. }
  186. }
  187. void CDODBaseRocket::FlyThink( void )
  188. {
  189. QAngle angles;
  190. VectorAngles( GetAbsVelocity(), angles );
  191. SetAbsAngles( angles );
  192. if ( gpGlobals->curtime > m_flCollideWithTeammatesTime && m_bCollideWithTeammates == false )
  193. {
  194. m_bCollideWithTeammates = true;
  195. }
  196. SetNextThink( gpGlobals->curtime + 0.1f );
  197. }
  198. //-----------------------------------------------------------------------------
  199. // Purpose:
  200. //
  201. // Input : &vecOrigin -
  202. // &vecAngles -
  203. // NULL -
  204. //
  205. // Output : CDODBaseRocket
  206. //-----------------------------------------------------------------------------
  207. CDODBaseRocket *CDODBaseRocket::Create( const char *szClassname, const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner = NULL )
  208. {
  209. CDODBaseRocket *pMissile = (CDODBaseRocket *) CBaseEntity::Create( szClassname, vecOrigin, vecAngles, pOwner );
  210. pMissile->SetOwnerEntity( pOwner );
  211. pMissile->Spawn();
  212. Vector vecForward;
  213. AngleVectors( vecAngles, &vecForward );
  214. Vector vRocket = vecForward * 1300;
  215. pMissile->SetAbsVelocity( vRocket );
  216. pMissile->SetupInitialTransmittedGrenadeVelocity( vRocket );
  217. pMissile->SetAbsAngles( vecAngles );
  218. // remember what team we should be on
  219. pMissile->ChangeTeam( pOwner->GetTeamNumber() );
  220. return pMissile;
  221. }
  222. void CDODBaseRocket::SetupInitialTransmittedGrenadeVelocity( const Vector &velocity )
  223. {
  224. m_vInitialVelocity = velocity;
  225. }