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.

96 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: CTF Powerup Volume.
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "tf_player.h"
  8. #include "tf_item.h"
  9. #include "tf_team.h"
  10. #include "func_powerupvolume.h"
  11. #include "tf_gamerules.h"
  12. #include "eventqueue.h"
  13. LINK_ENTITY_TO_CLASS( func_powerupvolume, CPowerupVolume );
  14. #define TF_POWERUPVOLUME_SOUND "Powerup.Volume.Use"
  15. #define TF_POWERUPVOLUME_ANNOUNCE "Announcer.Powerup.Volume.Starting"
  16. IMPLEMENT_AUTO_LIST( IFuncPowerupVolumeAutoList );
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Constructor
  19. //-----------------------------------------------------------------------------
  20. CPowerupVolume::CPowerupVolume()
  21. {
  22. m_bDisabled = false;
  23. }
  24. //-----------------------------------------------------------------------------
  25. // Purpose: Spawn function for the entity
  26. //-----------------------------------------------------------------------------
  27. void CPowerupVolume::Spawn( void )
  28. {
  29. Precache();
  30. InitTrigger();
  31. SetTouch( &CPowerupVolume::Touch );
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose: Precache function for the entity
  35. //-----------------------------------------------------------------------------
  36. void CPowerupVolume::Precache( void )
  37. {
  38. PrecacheScriptSound( TF_POWERUPVOLUME_SOUND );
  39. PrecacheScriptSound( TF_POWERUPVOLUME_ANNOUNCE );
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. //-----------------------------------------------------------------------------
  44. void CPowerupVolume::Touch( CBaseEntity *pOther )
  45. {
  46. if ( !IsDisabled() && pOther->IsPlayer() )
  47. {
  48. CTFPlayer *pPlayer = ToTFPlayer( pOther );
  49. if ( pPlayer && !( pPlayer->m_Shared.InCond( TF_COND_RUNE_IMBALANCE ) ) )
  50. {
  51. if ( pPlayer->IsTaunting() )
  52. return;
  53. if ( TFGameRules()->State_Get() == GR_STATE_TEAM_WIN )
  54. return;
  55. if ( TFGameRules()->InStalemate() )
  56. return;
  57. int iTeam = GetTeamNumber();
  58. if ( iTeam && ( pPlayer->GetTeamNumber() != iTeam ) )
  59. return;
  60. // call think function here so the first time the volume is used, it starts its timeout delay, and fires the tf_gamerules outputs when it times out
  61. pPlayer->m_Shared.AddCond( TF_COND_RUNE_IMBALANCE, 20.f );
  62. pPlayer->m_Shared.AddCond( TF_COND_CRITBOOSTED_RUNE_TEMP, 20.f );
  63. pPlayer->EmitSound( TF_POWERUPVOLUME_SOUND );
  64. m_nNumberOfTimesUsed++;
  65. }
  66. }
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Purpose:
  70. //-----------------------------------------------------------------------------
  71. bool CPowerupVolume::IsDisabled( void )
  72. {
  73. return m_bDisabled;
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Purpose:
  77. //-----------------------------------------------------------------------------
  78. void CPowerupVolume::SetDisabled( bool bDisabled )
  79. {
  80. m_bDisabled = bDisabled;
  81. }