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.

172 lines
4.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "tf_gamerules.h"
  8. #include "merasmus_dancer.h"
  9. #include "animation.h"
  10. //-----------------------------------------------------------------------------
  11. #include "tf_fx.h"
  12. //-----------------------------------------------------------------------------
  13. #define POOF_SOUND "Halloween.Merasmus_Hiding_Explode"
  14. //-----------------------------------------------------------------------------
  15. LINK_ENTITY_TO_CLASS( merasmus_dancer, CMerasmusDancer );
  16. IMPLEMENT_SERVERCLASS_ST( CMerasmusDancer, DT_MerasmusDancer )
  17. END_SEND_TABLE()
  18. //-----------------------------------------------------------------------------
  19. #define MERASMUS_MODEL_NAME "models/bots/merasmus/merasmus.mdl"
  20. //-----------------------------------------------------------------------------
  21. CMerasmusDancer::CMerasmusDancer()
  22. : m_bEmitParticleEffect( false )
  23. {
  24. }
  25. //-----------------------------------------------------------------------------
  26. CMerasmusDancer::~CMerasmusDancer()
  27. {
  28. }
  29. //-----------------------------------------------------------------------------
  30. void CMerasmusDancer::Spawn()
  31. {
  32. Precache();
  33. m_DieCountdownTimer.Invalidate();
  34. BaseClass::Spawn();
  35. SetModel( MERASMUS_MODEL_NAME );
  36. UseClientSideAnimation();
  37. SetThink( &CMerasmusDancer::DanceThink );
  38. SetNextThink( gpGlobals->curtime );
  39. m_bEmitParticleEffect = true;
  40. }
  41. //-----------------------------------------------------------------------------
  42. void CMerasmusDancer::PlaySequence( const char *pSeqName )
  43. {
  44. int iAnimSequence = LookupSequence( pSeqName ); // dance animation
  45. if ( iAnimSequence )
  46. {
  47. SetSequence( iAnimSequence );
  48. SetPlaybackRate( 1.0f );
  49. SetCycle( 0 );
  50. ResetSequenceInfo();
  51. HideStaff();
  52. }
  53. }
  54. //-----------------------------------------------------------------------------
  55. void CMerasmusDancer::PlayActivity( int iActivity )
  56. {
  57. int iAnimSequence = ::SelectWeightedSequence( GetModelPtr(), iActivity, GetSequence() );
  58. if ( iAnimSequence )
  59. {
  60. SetSequence( iAnimSequence );
  61. SetPlaybackRate( 1.0f );
  62. SetCycle( 0 );
  63. ResetSequenceInfo();
  64. HideStaff();
  65. }
  66. }
  67. //-----------------------------------------------------------------------------
  68. void CMerasmusDancer::HideStaff()
  69. {
  70. int nStaffBodyGroup = FindBodygroupByName( "staff" );
  71. SetBodygroup( nStaffBodyGroup, 2 );
  72. }
  73. //-----------------------------------------------------------------------------
  74. void CMerasmusDancer::Dance()
  75. {
  76. PlaySequence( "taunt06" );
  77. }
  78. //-----------------------------------------------------------------------------
  79. void CMerasmusDancer::Vanish()
  80. {
  81. m_bEmitParticleEffect = true;
  82. m_DieCountdownTimer.Start( 0.0f );
  83. }
  84. //-----------------------------------------------------------------------------
  85. void CMerasmusDancer::BlastOff()
  86. {
  87. m_bEmitParticleEffect = true;
  88. m_DieCountdownTimer.Start( 0.3f );
  89. PlayActivity( ACT_FLY );
  90. }
  91. //-----------------------------------------------------------------------------
  92. void CMerasmusDancer::Precache()
  93. {
  94. BaseClass::Precache();
  95. int model = PrecacheModel( MERASMUS_MODEL_NAME );
  96. PrecacheGibsForModel( model );
  97. PrecacheParticleSystem( "merasmus_tp" ); // puff effect
  98. PrecacheScriptSound( POOF_SOUND );
  99. // We deliberately allow late precaches here.
  100. bool bAllowPrecache = CBaseAnimating::IsPrecacheAllowed();
  101. CBaseAnimating::SetAllowPrecache( bAllowPrecache );
  102. }
  103. //-----------------------------------------------------------------------------
  104. bool CMerasmusDancer::ShouldDelete() const
  105. {
  106. return m_DieCountdownTimer.HasStarted() && m_DieCountdownTimer.IsElapsed();
  107. }
  108. //-----------------------------------------------------------------------------
  109. void CMerasmusDancer::DanceThink()
  110. {
  111. // Emit the initial effect here, rather than in Spawn(), since GetAbsOrigin() and GetAbsAngles() don't return useful values then.
  112. if ( m_bEmitParticleEffect )
  113. {
  114. DispatchParticleEffect( "merasmus_tp", GetAbsOrigin(), GetAbsAngles() );
  115. m_bEmitParticleEffect = false;
  116. EmitSound( POOF_SOUND );
  117. }
  118. if ( ShouldDelete() )
  119. {
  120. EmitSound( POOF_SOUND );
  121. UTIL_Remove( this );
  122. return;
  123. }
  124. SetNextThink( gpGlobals->curtime );
  125. }