Counter Strike : Global Offensive Source Code
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.

146 lines
3.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: contains entities who have no physical representation in the game, and who
  4. // must be triggered by other entities to cause their effects.
  5. //
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "player.h"
  10. #include "tier1/strtools.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. //-----------------------------------------------------------------------------
  14. // Purpose: when fired, it changes which track the CD is playing
  15. //-----------------------------------------------------------------------------
  16. class CTargetCDAudioRep : public CPointEntity
  17. {
  18. public:
  19. DECLARE_CLASS( CTargetCDAudioRep, CPointEntity );
  20. void InputChangeCDTrack( inputdata_t &inputdata );
  21. DECLARE_DATADESC();
  22. private:
  23. int m_iTrack; // CD track to change to when fired
  24. };
  25. LINK_ENTITY_TO_CLASS( target_cdaudio, CTargetCDAudioRep );
  26. BEGIN_DATADESC( CTargetCDAudioRep )
  27. DEFINE_KEYFIELD( m_iTrack, FIELD_INTEGER, "track" ),
  28. DEFINE_INPUTFUNC( FIELD_VOID, "ChangeCDTrack", InputChangeCDTrack ),
  29. END_DATADESC()
  30. //-----------------------------------------------------------------------------
  31. // Purpose: Changes the current playing CD track
  32. //-----------------------------------------------------------------------------
  33. void CTargetCDAudioRep::InputChangeCDTrack( inputdata_t &inputdata )
  34. {
  35. int iTrack = m_iTrack;
  36. edict_t *pClient = NULL;
  37. if ( gpGlobals->maxClients == 1 )
  38. {
  39. pClient = INDEXENT( 1 );
  40. }
  41. else
  42. {
  43. // In multiplayer, send it back to the activator
  44. CBasePlayer *player = dynamic_cast< CBasePlayer * >( inputdata.pActivator );
  45. if ( player )
  46. {
  47. pClient = player->edict();
  48. }
  49. }
  50. // Can't play if the client is not connected!
  51. if ( !pClient )
  52. return;
  53. if ( iTrack < -1 || iTrack > 30 )
  54. {
  55. Warning( "TargetCDAudio - Track %d out of range\n", iTrack );
  56. return;
  57. }
  58. if ( iTrack == -1 )
  59. {
  60. engine->ClientCommand( pClient, "cd pause\n");
  61. }
  62. else
  63. {
  64. engine->ClientCommand ( pClient, "cd play %3d\n", iTrack );
  65. }
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose: changes the gravity of the player who activates this entity
  69. //-----------------------------------------------------------------------------
  70. class CTargetChangeGravity : public CPointEntity
  71. {
  72. public:
  73. DECLARE_CLASS( CTargetChangeGravity, CPointEntity );
  74. DECLARE_DATADESC();
  75. void InputChangeGrav( inputdata_t &inputdata );
  76. void InputResetGrav( inputdata_t &inputdata );
  77. int m_iGravity;
  78. int m_iOldGrav;
  79. };
  80. LINK_ENTITY_TO_CLASS( target_changegravity, CTargetChangeGravity );
  81. BEGIN_DATADESC( CTargetChangeGravity )
  82. DEFINE_KEYFIELD( m_iGravity, FIELD_INTEGER, "gravity" ),
  83. DEFINE_FIELD( m_iOldGrav, FIELD_INTEGER ),
  84. DEFINE_INPUTFUNC( FIELD_VOID, "ChangeGrav", InputChangeGrav ),
  85. DEFINE_INPUTFUNC( FIELD_VOID, "ResetGrav", InputResetGrav ),
  86. END_DATADESC()
  87. //-----------------------------------------------------------------------------
  88. // Purpose: Input handler for changing the activator's gravity.
  89. //-----------------------------------------------------------------------------
  90. void CTargetChangeGravity::InputChangeGrav( inputdata_t &inputdata )
  91. {
  92. CBasePlayer *pl = ToBasePlayer( inputdata.pActivator );
  93. if ( !pl )
  94. return;
  95. // Save the gravity to restore it in InputResetGrav
  96. if ( m_iOldGrav )
  97. m_iOldGrav = pl->GetGravity();
  98. pl->SetGravity(m_iGravity);
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose: Input handler for resetting the activator's gravity.
  102. //-----------------------------------------------------------------------------
  103. void CTargetChangeGravity::InputResetGrav( inputdata_t &inputdata )
  104. {
  105. CBasePlayer *pl = ToBasePlayer( inputdata.pActivator );
  106. if ( !pl )
  107. return;
  108. pl->SetGravity(m_iOldGrav);
  109. }