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.

152 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "nailgun_nail.h"
  8. #define NAILGUN_MODEL "models/nail.mdl"
  9. LINK_ENTITY_TO_CLASS( tf_nailgun_nail, CTFNailgunNail );
  10. PRECACHE_REGISTER( tf_nailgun_nail );
  11. BEGIN_DATADESC( CTFNailgunNail )
  12. DEFINE_FUNCTION( NailTouch )
  13. END_DATADESC()
  14. CTFNailgunNail *CTFNailgunNail::CreateNail(
  15. bool fSendClientNail,
  16. Vector vecOrigin,
  17. QAngle vecAngles,
  18. CBaseEntity *pOwner,
  19. CBaseEntity *pLauncher,
  20. bool fMakeClientNail )
  21. {
  22. CTFNailgunNail *pNail = (CTFNailgunNail*)CreateEntityByName( "tf_nailgun_nail" );
  23. if ( !pNail )
  24. return NULL;
  25. pNail->SetAbsOrigin( vecOrigin );
  26. pNail->SetAbsAngles( vecAngles );
  27. pNail->SetOwnerEntity( pOwner );
  28. pNail->Spawn();
  29. pNail->SetTouch( &CTFNailgunNail::NailTouch );
  30. pNail->m_iDamage = 9;
  31. /*
  32. if ( fMakeClientNail )
  33. {
  34. edict_t *pOwner;
  35. int indexOwner;
  36. // don't send to clients.
  37. pNail->pev->effects |= EF_NODRAW;
  38. pOwner = ENT( pNail->pev->owner );
  39. indexOwner = ENTINDEX(pOwner);
  40. if ( fSendClientNail )
  41. UTIL_ClientProjectile( pNail->pev->origin, pNail->pev->velocity, g_sModelIndexNail, indexOwner, 6 );
  42. }
  43. */
  44. return pNail;
  45. }
  46. CTFNailgunNail *CTFNailgunNail::CreateSuperNail( Vector vecOrigin, QAngle vecAngles, CBaseEntity *pOwner, CBaseEntity *pLauncher )
  47. {
  48. // Super nails simply do more damage
  49. CTFNailgunNail *pNail = CreateNail( false, vecOrigin, vecAngles, pOwner, pLauncher, true );
  50. pNail->m_iDamage = 13;
  51. return pNail;
  52. }
  53. //=========================================================
  54. // CTFNailgunNail::Spawn
  55. //
  56. // Creates an nail entity on the server that is invisible
  57. // so that it won't be sent to clients. At the same time sends a
  58. // tiny message that creates a flying nail entity on all
  59. // clients. (sjb)
  60. //=========================================================
  61. void CTFNailgunNail::Spawn()
  62. {
  63. // motor
  64. SetMoveType( MOVETYPE_FLYGRAVITY );
  65. SetSolid( SOLID_BBOX );
  66. SetModel( NAILGUN_MODEL );
  67. SetSize( Vector( 0, 0, 0), Vector(0, 0, 0) );
  68. Vector vForward;
  69. AngleVectors( GetAbsAngles(), &vForward );
  70. SetAbsVelocity( vForward * 1000 );
  71. SetGravity( 0.5 );
  72. SetNextThink( gpGlobals->curtime + 6 );
  73. SetThink( &CTFNailgunNail::SUB_Remove );
  74. }
  75. void CTFNailgunNail::Precache()
  76. {
  77. PrecacheModel( NAILGUN_MODEL );
  78. BaseClass::Precache();
  79. }
  80. void CTFNailgunNail::NailTouch( CBaseEntity *pOther )
  81. {
  82. // Damage person hit by the nail
  83. CBaseEntity *pevOwner = GetOwnerEntity();
  84. if ( !pevOwner || !pOther )
  85. {
  86. UTIL_Remove( this );
  87. return;
  88. }
  89. // Nails don't touch each other.
  90. if ( dynamic_cast< CTFNailgunNail* >( pOther ) == NULL )
  91. {
  92. Vector vVelNorm = GetAbsVelocity();
  93. VectorNormalize( vVelNorm );
  94. Vector vDamageForce = vVelNorm;
  95. Vector vDamagePosition = GetAbsOrigin();
  96. int iStartHealth = pOther->GetHealth();
  97. CTakeDamageInfo info( this, pevOwner, vDamageForce, vDamagePosition, m_iDamage, DMG_SLASH );
  98. pOther->TakeDamage( info );
  99. // Did they take the damage?
  100. if ( pOther->GetHealth() < iStartHealth )
  101. {
  102. SpawnBlood( GetAbsOrigin(), GetAbsVelocity(), pOther->BloodColor(), m_iDamage );
  103. }
  104. // Do an impact trace in case we hit the world.
  105. trace_t tr;
  106. UTIL_TraceLine(
  107. GetAbsOrigin() - vVelNorm * 30,
  108. GetAbsOrigin() + vVelNorm * 50,
  109. MASK_SOLID_BRUSHONLY,
  110. pevOwner,
  111. COLLISION_GROUP_DEBRIS,
  112. &tr );
  113. if ( tr.fraction < 1 )
  114. {
  115. UTIL_ImpactTrace( &tr, DMG_SLASH );
  116. }
  117. UTIL_Remove( this );
  118. }
  119. }