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.

132 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: CTF ChangeClass Zone.
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "viewport_panel_names.h"
  8. #include "tf_player.h"
  9. #include "tf_item.h"
  10. #include "tf_team.h"
  11. #include "func_changeclass.h"
  12. LINK_ENTITY_TO_CLASS( func_changeclass, CChangeClassZone );
  13. #define TF_CHANGECLASS_SOUND "ChangeClass.Touch"
  14. #define TF_CHANGECLASS_NEXT_USE_TIME 10.0f
  15. //=============================================================================
  16. //
  17. // CTF ChangeClass Zone functions.
  18. //
  19. //-----------------------------------------------------------------------------
  20. // Purpose:
  21. //-----------------------------------------------------------------------------
  22. CChangeClassZone::CChangeClassZone()
  23. {
  24. m_bDisabled = false;
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Spawn function for the entity
  28. //-----------------------------------------------------------------------------
  29. void CChangeClassZone::Spawn( void )
  30. {
  31. Precache();
  32. InitTrigger();
  33. SetTouch( &CChangeClassZone::Touch );
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Purpose: Precache function for the entity
  37. //-----------------------------------------------------------------------------
  38. void CChangeClassZone::Precache( void )
  39. {
  40. PrecacheScriptSound( TF_CHANGECLASS_SOUND );
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. //-----------------------------------------------------------------------------
  45. void CChangeClassZone::Touch( CBaseEntity *pOther )
  46. {
  47. if ( !IsDisabled() )
  48. {
  49. CTFPlayer *pPlayer = ToTFPlayer( pOther );
  50. if ( pPlayer )
  51. {
  52. if ( pPlayer->GetNextChangeClassTime() > gpGlobals->curtime )
  53. return;
  54. int iTeam = GetTeamNumber();
  55. if ( iTeam && ( pPlayer->GetTeamNumber() != iTeam ) )
  56. return;
  57. // bring up the player's changeclass menu
  58. CCommand args;
  59. args.Tokenize( "changeclass" );
  60. pPlayer->ClientCommand( args );
  61. pPlayer->SetNextChangeClassTime( gpGlobals->curtime + TF_CHANGECLASS_NEXT_USE_TIME );
  62. CPASAttenuationFilter filter( pOther, TF_CHANGECLASS_SOUND );
  63. EmitSound( filter, pOther->entindex(), TF_CHANGECLASS_SOUND );
  64. }
  65. }
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. //-----------------------------------------------------------------------------
  70. void CChangeClassZone::EndTouch( CBaseEntity *pOther )
  71. {
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Purpose:
  75. //-----------------------------------------------------------------------------
  76. void CChangeClassZone::InputEnable( inputdata_t &inputdata )
  77. {
  78. SetDisabled( false );
  79. }
  80. //-----------------------------------------------------------------------------
  81. // Purpose:
  82. //-----------------------------------------------------------------------------
  83. void CChangeClassZone::InputDisable( inputdata_t &inputdata )
  84. {
  85. SetDisabled( true );
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Purpose:
  89. //-----------------------------------------------------------------------------
  90. bool CChangeClassZone::IsDisabled( void )
  91. {
  92. return m_bDisabled;
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Purpose:
  96. //-----------------------------------------------------------------------------
  97. void CChangeClassZone::InputToggle( inputdata_t &inputdata )
  98. {
  99. if ( m_bDisabled )
  100. {
  101. SetDisabled( false );
  102. }
  103. else
  104. {
  105. SetDisabled( true );
  106. }
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. //-----------------------------------------------------------------------------
  111. void CChangeClassZone::SetDisabled( bool bDisabled )
  112. {
  113. m_bDisabled = bDisabled;
  114. }