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.

133 lines
3.2 KiB

  1. //========= Copyright � 1996-2007, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Base class for simple projectiles that use studio models
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  10. // This file was made before I
  11. // realized Portal had already
  12. // made the same thing
  13. // (probably because it was
  14. // squirreled away in the PORTAL
  15. // source folder). Anyway, this
  16. // needs to be reconciled with that
  17. // file since clearly there is
  18. // demand for this feature (sjb) 11/27/07
  19. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  20. #include "cbase.h"
  21. #include "cbaseprojectile.h"
  22. // memdbgon must be the last include file in a .cpp file!!!
  23. #include "tier0/memdbgon.h"
  24. LINK_ENTITY_TO_CLASS( baseprojectile, CBaseProjectile );
  25. //---------------------------------------------------------
  26. // Save/Restore
  27. //---------------------------------------------------------
  28. BEGIN_DATADESC( CBaseProjectile )
  29. DEFINE_FIELD( m_iDmg, FIELD_INTEGER ),
  30. DEFINE_FIELD( m_iDmgType, FIELD_INTEGER ),
  31. DEFINE_FIELD( m_hIntendedTarget, FIELD_EHANDLE ),
  32. END_DATADESC()
  33. //---------------------------------------------------------
  34. //---------------------------------------------------------
  35. void CBaseProjectile::Spawn( char *pszModel,
  36. const Vector &vecOrigin,
  37. const Vector &vecVelocity,
  38. edict_t *pOwner,
  39. MoveType_t iMovetype,
  40. MoveCollide_t nMoveCollide,
  41. int iDamage,
  42. int iDamageType,
  43. CBaseEntity *pIntendedTarget )
  44. {
  45. Precache();
  46. SetModel( pszModel );
  47. m_iDmg = iDamage;
  48. m_iDmgType = iDamageType;
  49. SetMoveType( iMovetype, nMoveCollide );
  50. UTIL_SetSize( this, -Vector(1,1,1), Vector(1,1,1) );
  51. SetSolid( SOLID_BBOX );
  52. SetCollisionGroup( COLLISION_GROUP_PROJECTILE );
  53. UTIL_SetOrigin( this, vecOrigin );
  54. SetAbsVelocity( vecVelocity );
  55. SetOwnerEntity( Instance( pOwner ) );
  56. m_hIntendedTarget.Set( pIntendedTarget );
  57. QAngle angles;
  58. VectorAngles( vecVelocity, angles );
  59. SetAbsAngles( angles );
  60. // Call think for free the first time. It's up to derived classes to rethink.
  61. SetNextThink( gpGlobals->curtime );
  62. }
  63. //---------------------------------------------------------
  64. //---------------------------------------------------------
  65. void CBaseProjectile::Touch( CBaseEntity *pOther )
  66. {
  67. if ( pOther->IsSolidFlagSet(FSOLID_TRIGGER) )
  68. {
  69. return;
  70. }
  71. HandleTouch( pOther );
  72. }
  73. //---------------------------------------------------------
  74. //---------------------------------------------------------
  75. void CBaseProjectile::HandleTouch( CBaseEntity *pOther )
  76. {
  77. CBaseEntity *pOwner;
  78. pOwner = GetOwnerEntity();
  79. if( !pOwner )
  80. {
  81. pOwner = this;
  82. }
  83. trace_t tr;
  84. tr = BaseClass::GetTouchTrace( );
  85. CTakeDamageInfo info( this, pOwner, m_iDmg, m_iDmgType );
  86. GuessDamageForce( &info, (tr.endpos - tr.startpos), tr.endpos );
  87. pOther->TakeDamage( info );
  88. UTIL_Remove( this );
  89. }
  90. //---------------------------------------------------------
  91. //---------------------------------------------------------
  92. void CBaseProjectile::Think()
  93. {
  94. HandleThink();
  95. }
  96. //---------------------------------------------------------
  97. //---------------------------------------------------------
  98. void CBaseProjectile::HandleThink()
  99. {
  100. }