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.

122 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Fizzle effects for portal.
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "clienteffectprecachesystem.h"
  8. #include "fx.h"
  9. #include "fx_sparks.h"
  10. #include "iefx.h"
  11. #include "c_te_effect_dispatch.h"
  12. #include "particles_ez.h"
  13. #include "decals.h"
  14. #include "engine/IEngineSound.h"
  15. #include "fx_quad.h"
  16. #include "engine/ivdebugoverlay.h"
  17. #include "shareddefs.h"
  18. #include "portal_shareddefs.h"
  19. #include "effect_color_tables.h"
  20. // memdbgon must be the last include file in a .cpp file!!!
  21. #include "tier0/memdbgon.h"
  22. class C_PortalBlast : public C_BaseEntity
  23. {
  24. DECLARE_CLASS( C_PortalBlast, C_BaseAnimating );
  25. public:
  26. static void Create( bool bIsPortal2, PortalPlacedByType ePlacedBy, const Vector &vStart, const Vector &vEnd, const QAngle &qAngles, float fDeathTime );
  27. void Init( bool bIsPortal2, PortalPlacedByType ePlacedBy, const Vector &vStart, const Vector &vEnd, const QAngle &qAngles, float fDeathTime );
  28. virtual void ClientThink( void );
  29. private:
  30. Vector m_ptCreationPoint;
  31. Vector m_ptDeathPoint;
  32. Vector m_ptAimPoint;
  33. float m_fCreationTime;
  34. float m_fDeathTime;
  35. };
  36. void C_PortalBlast::Create( bool bIsPortal2, PortalPlacedByType ePlacedBy, const Vector &vStart, const Vector &vEnd, const QAngle &qAngles, float fDeathTime )
  37. {
  38. C_PortalBlast *pPortalBlast = new C_PortalBlast;
  39. pPortalBlast->Init( bIsPortal2, ePlacedBy, vStart, vEnd, qAngles, fDeathTime );
  40. }
  41. void C_PortalBlast::Init( bool bIsPortal2, PortalPlacedByType ePlacedBy, const Vector &vStart, const Vector &vEnd, const QAngle &qAngles, float fDeathTime )
  42. {
  43. ClientEntityList().AddNonNetworkableEntity( this );
  44. ClientThinkList()->SetNextClientThink( GetClientHandle(), CLIENT_THINK_ALWAYS );
  45. AddToLeafSystem( RENDER_GROUP_OPAQUE_ENTITY );
  46. SetThink( &C_PortalBlast::ClientThink );
  47. SetNextClientThink( CLIENT_THINK_ALWAYS );
  48. m_ptCreationPoint = vStart;
  49. m_ptDeathPoint = vEnd;
  50. SetAbsOrigin( m_ptCreationPoint );
  51. m_fCreationTime = gpGlobals->curtime;
  52. m_fDeathTime = fDeathTime;
  53. if ( m_fDeathTime - 0.1f < m_fCreationTime )
  54. {
  55. m_fDeathTime = m_fCreationTime + 0.1f;
  56. }
  57. Vector vForward;
  58. AngleVectors( qAngles, &vForward );
  59. m_ptAimPoint = m_ptCreationPoint + vForward * m_ptCreationPoint.DistTo( m_ptDeathPoint );
  60. if ( ePlacedBy == PORTAL_PLACED_BY_PLAYER )
  61. ParticleProp()->Create( ( ( bIsPortal2 ) ? ( "portal_2_projectile_stream" ) : ( "portal_1_projectile_stream" ) ), PATTACH_ABSORIGIN_FOLLOW );
  62. else
  63. ParticleProp()->Create( ( ( bIsPortal2 ) ? ( "portal_2_projectile_stream_pedestal" ) : ( "portal_1_projectile_stream_pedestal" ) ), PATTACH_ABSORIGIN_FOLLOW );
  64. }
  65. void C_PortalBlast::ClientThink( void )
  66. {
  67. if ( m_fCreationTime == 0.0f && m_fDeathTime == 0.0f )
  68. {
  69. // Die!
  70. Remove();
  71. return;
  72. }
  73. float fT = ( gpGlobals->curtime - m_fCreationTime ) / ( m_fDeathTime - m_fCreationTime );
  74. if ( fT >= 1.0f )
  75. {
  76. // Ready to die! But we want one more frame in the final position
  77. SetAbsOrigin( m_ptDeathPoint );
  78. m_fCreationTime = 0.0f;
  79. m_fDeathTime = 0.0f;
  80. return;
  81. }
  82. // Set the interpolated position
  83. Vector vTarget = m_ptAimPoint * ( 1.0f - fT ) + m_ptDeathPoint * fT;
  84. SetAbsOrigin( m_ptCreationPoint * ( 1.0f - fT ) + vTarget * fT );
  85. }
  86. void PortalBlastCallback( const CEffectData & data )
  87. {
  88. C_PortalBlast::Create( ( data.m_nColor == 1 ) ? ( false ) : ( true ), (PortalPlacedByType)data.m_nDamageType, data.m_vOrigin, data.m_vStart, data.m_vAngles, data.m_flScale );
  89. }
  90. DECLARE_CLIENT_EFFECT( "PortalBlast", PortalBlastCallback );