Counter Strike : Global Offensive Source Code
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.

140 lines
4.1 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "baseprojectile.h"
  8. // NOTE: This has to be the last file included!
  9. #include "tier0/memdbgon.h"
  10. BEGIN_DATADESC( CBaseProjectile )
  11. DEFINE_FIELD( m_flDamage, FIELD_FLOAT ),
  12. DEFINE_FIELD( m_iDamageType, FIELD_INTEGER ),
  13. DEFINE_FIELD( m_flDamageScale, FIELD_FLOAT ),
  14. DEFINE_FUNCTION( ProjectileTouch ),
  15. DEFINE_THINKFUNC( FlyThink ),
  16. END_DATADESC()
  17. LINK_ENTITY_TO_CLASS( proj_base, CBaseProjectile );
  18. //-----------------------------------------------------------------------------
  19. // Purpose:
  20. //-----------------------------------------------------------------------------
  21. void CBaseProjectile::Spawn( void )
  22. {
  23. Precache();
  24. SetModel( STRING( GetModelName() ) );
  25. SetSolid( SOLID_BBOX );
  26. SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_CUSTOM );
  27. AddFlag( FL_OBJECT );
  28. UTIL_SetSize( this, -Vector( 1.0f, 1.0f, 1.0f ), Vector( 1.0f, 1.0f, 1.0f ) );
  29. // Setup attributes.
  30. SetGravity( 0.001f );
  31. m_takedamage = DAMAGE_NO;
  32. // Setup the touch and think functions.
  33. SetTouch( &CBaseProjectile::ProjectileTouch );
  34. SetThink( &CBaseProjectile::FlyThink );
  35. SetNextThink( gpGlobals->curtime );
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. //-----------------------------------------------------------------------------
  40. void CBaseProjectile::Precache( void )
  41. {
  42. BaseClass::Precache();
  43. PrecacheModel( STRING( GetModelName() ) );
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48. CBaseProjectile *CBaseProjectile::Create( baseprojectilecreate_t &pCreate )
  49. {
  50. CBaseProjectile *pProjectile = static_cast<CBaseProjectile*>( CBaseEntity::CreateNoSpawn( "proj_base", pCreate.vecOrigin, vec3_angle, pCreate.pOwner ) );
  51. if ( !pProjectile )
  52. return NULL;
  53. pProjectile->SetModelName( pCreate.iszModel );
  54. pProjectile->SetDamage( pCreate.flDamage );
  55. pProjectile->SetDamageType( pCreate.iDamageType );
  56. pProjectile->SetDamageScale( pCreate.flDamageScale );
  57. pProjectile->SetAbsVelocity( pCreate.vecVelocity );
  58. // Setup the initial angles.
  59. QAngle angles;
  60. VectorAngles( -pCreate.vecVelocity, angles );
  61. pProjectile->SetAbsAngles( angles );
  62. // Spawn & Activate
  63. DispatchSpawn( pProjectile );
  64. pProjectile->Activate();
  65. return pProjectile;
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. //-----------------------------------------------------------------------------
  70. unsigned int CBaseProjectile::PhysicsSolidMaskForEntity( void ) const
  71. {
  72. return BaseClass::PhysicsSolidMaskForEntity() | CONTENTS_HITBOX;
  73. }
  74. //-----------------------------------------------------------------------------
  75. // Purpose:
  76. //-----------------------------------------------------------------------------
  77. void CBaseProjectile::ProjectileTouch( CBaseEntity *pOther )
  78. {
  79. // Verify a correct "other."
  80. Assert( pOther );
  81. if ( !pOther->IsSolid() || pOther->IsSolidFlagSet( FSOLID_VOLUME_CONTENTS ) )
  82. return;
  83. // Handle hitting skybox (disappear).
  84. const trace_t *pTrace = &CBaseEntity::GetTouchTrace();
  85. trace_t *pNewTrace = const_cast<trace_t*>( pTrace );
  86. if( pTrace->surface.flags & SURF_SKY )
  87. {
  88. UTIL_Remove( this );
  89. return;
  90. }
  91. CTakeDamageInfo info;
  92. info.SetAttacker( GetOwnerEntity() );
  93. info.SetInflictor( this );
  94. info.SetDamage( GetDamage() );
  95. info.SetDamageType( GetDamageType() );
  96. CalculateMeleeDamageForce( &info, GetAbsVelocity(), GetAbsOrigin(), GetDamageScale() );
  97. Vector dir;
  98. AngleVectors( GetAbsAngles(), &dir );
  99. pOther->DispatchTraceAttack( info, dir, pNewTrace );
  100. ApplyMultiDamage();
  101. UTIL_Remove( this );
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Purpose: Orient the projectile along its velocity
  105. //-----------------------------------------------------------------------------
  106. void CBaseProjectile::FlyThink( void )
  107. {
  108. QAngle angles;
  109. VectorAngles( -(GetAbsVelocity()), angles );
  110. SetAbsAngles( angles );
  111. SetNextThink( gpGlobals->curtime + 0.1f );
  112. }