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.

128 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "tf_weapon_parachute.h"
  8. #include "tf_gamerules.h"
  9. // Client specific.
  10. #ifdef CLIENT_DLL
  11. #include "c_tf_player.h"
  12. // Server specific.
  13. #else
  14. #include "tf_player.h"
  15. #include "tf_gamestats.h"
  16. #endif
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. //=============================================================================
  20. //
  21. // Weapon Buff Item tables.
  22. //
  23. CREATE_SIMPLE_WEAPON_TABLE( TFParachute, tf_weapon_parachute )
  24. CREATE_SIMPLE_WEAPON_TABLE( TFParachute_Primary, tf_weapon_parachute_primary )
  25. CREATE_SIMPLE_WEAPON_TABLE( TFParachute_Secondary, tf_weapon_parachute_secondary )
  26. //-----------------------------------------------------------------------------
  27. CTFParachute::CTFParachute()
  28. {
  29. #ifdef CLIENT_DLL
  30. m_iParachuteAnimState = EParachuteRetracted;
  31. #endif // CLIENT_DLL
  32. }
  33. //-----------------------------------------------------------------------------
  34. void CTFParachute::CreateBanner()
  35. {
  36. BaseClass::CreateBanner();
  37. #ifdef CLIENT_DLL
  38. if ( m_hBannerEntity )
  39. {
  40. m_iParachuteAnimState = EParachuteRetracted_Idle;
  41. int sequence = m_hBannerEntity->SelectWeightedSequence( ACT_PARACHUTE_RETRACT_IDLE );
  42. m_hBannerEntity->ResetSequence( sequence );
  43. }
  44. #endif // CLIENT_DLL
  45. }
  46. #ifdef CLIENT_DLL
  47. //-----------------------------------------------------------------------------
  48. void CTFParachute::ClientThink( void )
  49. {
  50. BaseClass::ClientThink();
  51. ParachuteAnimThink();
  52. }
  53. //-----------------------------------------------------------------------------
  54. void CTFParachute::ParachuteAnimThink( void )
  55. {
  56. if ( m_iBuffType == -1 || m_iBuffType == 0 )
  57. {
  58. m_iBuffType = GetBuffType();
  59. }
  60. if ( m_iBuffType != EParachute )
  61. return;
  62. CTFPlayer* pPlayer = ToTFPlayer( GetPlayerOwner() );
  63. if ( !pPlayer )
  64. return;
  65. CreateBanner();
  66. if ( !m_hBannerEntity )
  67. return;
  68. bool bInCondition = pPlayer->m_Shared.InCond( TF_COND_PARACHUTE_DEPLOYED );
  69. if ( pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_KART ) )
  70. {
  71. // Halloween Kart has its own parachute and we don't want to interfer with it here
  72. bInCondition = false;
  73. }
  74. // Track Anim State
  75. if ( m_iParachuteAnimState == EParachuteDeployed_Idle && !bInCondition )
  76. {
  77. // retract
  78. int sequence = m_hBannerEntity->SelectWeightedSequence( ACT_PARACHUTE_RETRACT );
  79. m_hBannerEntity->ResetSequence( sequence );
  80. m_flParachuteToIdleTime = m_hBannerEntity->SequenceDuration() + gpGlobals->curtime;
  81. m_iParachuteAnimState = EParachuteRetracted;
  82. }
  83. else if ( m_iParachuteAnimState == EParachuteRetracted_Idle && bInCondition )
  84. {
  85. // deploy
  86. int sequence = m_hBannerEntity->SelectWeightedSequence( ACT_PARACHUTE_DEPLOY );
  87. m_hBannerEntity->ResetSequence( sequence );
  88. m_flParachuteToIdleTime = m_hBannerEntity->SequenceDuration() + gpGlobals->curtime;
  89. m_iParachuteAnimState = EParachuteDeployed;
  90. }
  91. // To Idle
  92. if ( m_iParachuteAnimState == EParachuteRetracted && m_flParachuteToIdleTime < gpGlobals->curtime )
  93. {
  94. int sequence = m_hBannerEntity->SelectWeightedSequence( ACT_PARACHUTE_RETRACT_IDLE );
  95. m_hBannerEntity->ResetSequence( sequence );
  96. m_iParachuteAnimState = EParachuteRetracted_Idle;
  97. }
  98. else if ( m_iParachuteAnimState == EParachuteDeployed && m_flParachuteToIdleTime < gpGlobals->curtime )
  99. {
  100. int sequence = m_hBannerEntity->SelectWeightedSequence( ACT_PARACHUTE_DEPLOY_IDLE );
  101. m_hBannerEntity->ResetSequence( sequence );
  102. m_iParachuteAnimState = EParachuteDeployed_Idle;
  103. }
  104. }
  105. #endif // CLIENT_DLL