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.

72 lines
2.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Game-specific impact effect hooks
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "decals.h"
  8. #include "iefx.h"
  9. #include "fx_impact.h"
  10. #include "tempent.h"
  11. #include "c_te_effect_dispatch.h"
  12. #include "c_te_legacytempents.h"
  13. void KnifeSlash( const CEffectData &data )
  14. {
  15. trace_t tr;
  16. Vector vecOrigin, vecStart, vecShotDir;
  17. int iMaterial, iDamageType, iHitbox;
  18. short nSurfaceProp;
  19. C_BaseEntity *pEntity = ParseImpactData( data, &vecOrigin, &vecStart, &vecShotDir, nSurfaceProp, iMaterial, iDamageType, iHitbox );
  20. if( pEntity == NULL )
  21. return;
  22. int decalNumber = decalsystem->GetDecalIndexForName( GetImpactDecal( pEntity, iMaterial, iDamageType ) );
  23. if ( decalNumber == -1 )
  24. return;
  25. // vector perpendicular to the slash direction
  26. // so we can align the slash decal to that
  27. Vector vecPerp;
  28. AngleVectors( data.m_vAngles, NULL, &vecPerp, NULL );
  29. const ConVar *decals =cvar->FindVar( "r_decals" );
  30. if ( decals && decals->GetInt() )
  31. {
  32. if ( (pEntity->entindex() == 0) && (iHitbox != 0) )
  33. {
  34. // Setup our shot information
  35. Vector shotDir = vecOrigin - vecStart;
  36. float flLength = VectorNormalize( shotDir );
  37. Vector traceExt;
  38. VectorMA( vecStart, flLength + 8.0f, shotDir, traceExt );
  39. // Special case for world entity with hitbox (that's a static prop):
  40. // In this case, we've hit a static prop. Decal it!
  41. staticpropmgr->AddDecalToStaticProp( vecStart, traceExt, iHitbox - 1, decalNumber, true, tr );
  42. }
  43. else
  44. {
  45. effects->DecalShoot( decalNumber,
  46. pEntity->entindex(),
  47. pEntity->GetModel(),
  48. pEntity->GetAbsOrigin(),
  49. pEntity->GetAbsAngles(),
  50. vecOrigin,
  51. &vecPerp,
  52. 0 );
  53. }
  54. }
  55. if( Impact( vecOrigin, vecStart, iMaterial, iDamageType, iHitbox, pEntity, tr, data.m_fFlags ) )
  56. {
  57. // Check for custom effects based on the Decal index
  58. PerformCustomEffects( vecOrigin, tr, vecShotDir, iMaterial, 1.0 );
  59. }
  60. }
  61. DECLARE_CLIENT_EFFECT( "KnifeSlash", KnifeSlash );