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.

159 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "model_types.h"
  8. #include "clienteffectprecachesystem.h"
  9. #include "fx.h"
  10. #include "c_te_effect_dispatch.h"
  11. #include "beamdraw.h"
  12. CLIENTEFFECT_REGISTER_BEGIN( PrecacheEffectCrossbow )
  13. CLIENTEFFECT_MATERIAL( "effects/muzzleflash1" )
  14. CLIENTEFFECT_REGISTER_END()
  15. //
  16. // Crossbow bolt
  17. //
  18. class C_CrossbowBolt : public C_BaseCombatCharacter
  19. {
  20. DECLARE_CLASS( C_CrossbowBolt, C_BaseCombatCharacter );
  21. DECLARE_CLIENTCLASS();
  22. public:
  23. C_CrossbowBolt( void );
  24. virtual RenderGroup_t GetRenderGroup( void )
  25. {
  26. // We want to draw translucent bits as well as our main model
  27. return RENDER_GROUP_TWOPASS;
  28. }
  29. virtual void ClientThink( void );
  30. virtual void OnDataChanged( DataUpdateType_t updateType );
  31. virtual int DrawModel( int flags );
  32. private:
  33. C_CrossbowBolt( const C_CrossbowBolt & ); // not defined, not accessible
  34. Vector m_vecLastOrigin;
  35. bool m_bUpdated;
  36. };
  37. IMPLEMENT_CLIENTCLASS_DT( C_CrossbowBolt, DT_CrossbowBolt, CCrossbowBolt )
  38. END_RECV_TABLE()
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. //-----------------------------------------------------------------------------
  42. C_CrossbowBolt::C_CrossbowBolt( void )
  43. {
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. // Input : updateType -
  48. //-----------------------------------------------------------------------------
  49. void C_CrossbowBolt::OnDataChanged( DataUpdateType_t updateType )
  50. {
  51. BaseClass::OnDataChanged( updateType );
  52. if ( updateType == DATA_UPDATE_CREATED )
  53. {
  54. m_bUpdated = false;
  55. m_vecLastOrigin = GetAbsOrigin();
  56. SetNextClientThink( CLIENT_THINK_ALWAYS );
  57. }
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Purpose:
  61. // Input : flags -
  62. // Output : int
  63. //-----------------------------------------------------------------------------
  64. int C_CrossbowBolt::DrawModel( int flags )
  65. {
  66. // See if we're drawing the motion blur
  67. if ( flags & STUDIO_TRANSPARENCY )
  68. {
  69. float color[3];
  70. IMaterial *pBlurMaterial = materials->FindMaterial( "effects/muzzleflash1", NULL, false );
  71. Vector vecDir = GetAbsOrigin() - m_vecLastOrigin;
  72. float speed = VectorNormalize( vecDir );
  73. speed = clamp( speed, 0, 32 );
  74. if ( speed > 0 )
  75. {
  76. float stepSize = MIN( ( speed * 0.5f ), 4.0f );
  77. Vector spawnPos = GetAbsOrigin() + ( vecDir * 24.0f );
  78. Vector spawnStep = -vecDir * stepSize;
  79. CMatRenderContextPtr pRenderContext( materials );
  80. pRenderContext->Bind( pBlurMaterial );
  81. float alpha;
  82. // Draw the motion blurred trail
  83. for ( int i = 0; i < 20; i++ )
  84. {
  85. spawnPos += spawnStep;
  86. alpha = RemapValClamped( i, 5, 11, 0.25f, 0.05f );
  87. color[0] = color[1] = color[2] = alpha;
  88. DrawHalo( pBlurMaterial, spawnPos, 3.0f, color );
  89. }
  90. }
  91. if ( gpGlobals->frametime > 0.0f && !m_bUpdated)
  92. {
  93. m_bUpdated = true;
  94. m_vecLastOrigin = GetAbsOrigin();
  95. }
  96. return 1;
  97. }
  98. // Draw the normal portion
  99. return BaseClass::DrawModel( flags );
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose:
  103. //-----------------------------------------------------------------------------
  104. void C_CrossbowBolt::ClientThink( void )
  105. {
  106. m_bUpdated = false;
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. // Input : &data -
  111. //-----------------------------------------------------------------------------
  112. void CrosshairLoadCallback( const CEffectData &data )
  113. {
  114. IClientRenderable *pRenderable = data.GetRenderable( );
  115. if ( !pRenderable )
  116. return;
  117. Vector position;
  118. QAngle angles;
  119. // If we found the attachment, emit sparks there
  120. if ( pRenderable->GetAttachment( data.m_nAttachmentIndex, position, angles ) )
  121. {
  122. FX_ElectricSpark( position, 1.0f, 1.0f, NULL );
  123. }
  124. }
  125. DECLARE_CLIENT_EFFECT( "CrossbowLoad", CrosshairLoadCallback );