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.

108 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "c_tf_projectile_flare.h"
  8. #include "tf_weapon_flaregun.h"
  9. #include "c_tf_player.h"
  10. #include "particles_new.h"
  11. IMPLEMENT_NETWORKCLASS_ALIASED( TFProjectile_Flare, DT_TFProjectile_Flare )
  12. BEGIN_NETWORK_TABLE( C_TFProjectile_Flare, DT_TFProjectile_Flare )
  13. RecvPropBool( RECVINFO( m_bCritical ) ),
  14. END_NETWORK_TABLE()
  15. //-----------------------------------------------------------------------------
  16. // Purpose:
  17. //-----------------------------------------------------------------------------
  18. C_TFProjectile_Flare::C_TFProjectile_Flare( void )
  19. {
  20. pEffect = NULL;
  21. }
  22. //-----------------------------------------------------------------------------
  23. // Purpose:
  24. //-----------------------------------------------------------------------------
  25. C_TFProjectile_Flare::~C_TFProjectile_Flare( void )
  26. {
  27. if ( pEffect )
  28. {
  29. ParticleProp()->StopEmission( pEffect );
  30. pEffect = NULL;
  31. }
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. //-----------------------------------------------------------------------------
  36. void C_TFProjectile_Flare::OnDataChanged( DataUpdateType_t updateType )
  37. {
  38. BaseClass::OnDataChanged( updateType );
  39. if ( updateType == DATA_UPDATE_CREATED )
  40. {
  41. CreateTrails();
  42. }
  43. }
  44. //-----------------------------------------------------------------------------
  45. // Purpose:
  46. //-----------------------------------------------------------------------------
  47. const char *GetFlareTrailParticleName( int iTeamNumber, bool bCritical, int nType )
  48. {
  49. if ( nType == FLAREGUN_GRORDBORT )
  50. {
  51. return "drg_manmelter_projectile";
  52. }
  53. else if ( nType == FLAREGUN_SCORCHSHOT )
  54. {
  55. if ( iTeamNumber == TF_TEAM_BLUE )
  56. {
  57. return ( bCritical ? "scorchshot_trail_crit_blue" : "scorchshot_trail_blue" );
  58. }
  59. else
  60. {
  61. return ( bCritical ? "scorchshot_trail_crit_red" : "scorchshot_trail_red" );
  62. }
  63. }
  64. else
  65. {
  66. if ( iTeamNumber == TF_TEAM_BLUE )
  67. {
  68. return ( bCritical ? "flaregun_trail_crit_blue" : "flaregun_trail_blue" );
  69. }
  70. else
  71. {
  72. return ( bCritical ? "flaregun_trail_crit_red" : "flaregun_trail_red" );
  73. }
  74. }
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Purpose:
  78. //-----------------------------------------------------------------------------
  79. void C_TFProjectile_Flare::CreateTrails( void )
  80. {
  81. if ( IsDormant() )
  82. return;
  83. if ( pEffect )
  84. {
  85. ParticleProp()->StopEmission( pEffect );
  86. pEffect = NULL;
  87. }
  88. int nType = 0;
  89. C_TFFlareGun *pFlareGun = dynamic_cast< C_TFFlareGun* >( GetLauncher() );
  90. if ( pFlareGun )
  91. {
  92. nType = pFlareGun->GetFlareGunType();
  93. }
  94. pEffect = ParticleProp()->Create( GetFlareTrailParticleName( GetTeamNumber(), m_bCritical, nType ), PATTACH_ABSORIGIN_FOLLOW );
  95. }