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.

127 lines
4.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=============================================================================
  4. #ifndef BASEMULTIPLAYERPLAYER_H
  5. #define BASEMULTIPLAYERPLAYER_H
  6. #pragma once
  7. #include "player.h"
  8. #include "ai_speech.h"
  9. //-----------------------------------------------------------------------------
  10. // Purpose:
  11. //-----------------------------------------------------------------------------
  12. class CBaseMultiplayerPlayer : public CAI_ExpresserHost<CBasePlayer>
  13. {
  14. DECLARE_CLASS( CBaseMultiplayerPlayer, CAI_ExpresserHost<CBasePlayer> );
  15. public:
  16. CBaseMultiplayerPlayer();
  17. ~CBaseMultiplayerPlayer();
  18. virtual void Spawn( void );
  19. virtual void PostConstructor( const char *szClassname );
  20. virtual void ModifyOrAppendCriteria( AI_CriteriaSet& criteriaSet );
  21. virtual bool SpeakIfAllowed( AIConcept_t concept, const char *modifiers = NULL, char *pszOutResponseChosen = NULL, size_t bufsize = 0, IRecipientFilter *filter = NULL );
  22. virtual IResponseSystem *GetResponseSystem();
  23. bool SpeakConcept( AI_Response& response, int iConcept );
  24. virtual bool SpeakConceptIfAllowed( int iConcept, const char *modifiers = NULL, char *pszOutResponseChosen = NULL, size_t bufsize = 0, IRecipientFilter *filter = NULL );
  25. virtual bool CanHearAndReadChatFrom( CBasePlayer *pPlayer );
  26. virtual bool CanSpeak( void ) { return true; }
  27. virtual bool CanBeAutobalanced() { return true; }
  28. virtual void Precache( void )
  29. {
  30. PrecacheParticleSystem( "achieved" );
  31. BaseClass::Precache();
  32. }
  33. virtual bool ClientCommand( const CCommand &args );
  34. virtual bool CanSpeakVoiceCommand( void ) { return true; }
  35. virtual bool ShouldShowVoiceSubtitleToEnemy( void );
  36. virtual void NoteSpokeVoiceCommand( const char *pszScenePlayed ) {}
  37. virtual void OnAchievementEarned( int iAchievement ) {}
  38. enum
  39. {
  40. CHAT_IGNORE_NONE = 0,
  41. CHAT_IGNORE_ALL,
  42. CHAT_IGNORE_TEAM,
  43. };
  44. int m_iIgnoreGlobalChat;
  45. //---------------------------------
  46. // Speech support
  47. virtual CAI_Expresser *GetExpresser() { return m_pExpresser; }
  48. virtual CMultiplayer_Expresser *GetMultiplayerExpresser() { return m_pExpresser; }
  49. void SetLastForcedChangeTeamTimeToNow( void ) { m_flLastForcedChangeTeamTime = gpGlobals->curtime; }
  50. float GetLastForcedChangeTeamTime( void ) { return m_flLastForcedChangeTeamTime; }
  51. void SetTeamBalanceScore( int iScore ) { m_iBalanceScore = iScore; }
  52. int GetTeamBalanceScore( void ) { return m_iBalanceScore; }
  53. virtual int CalculateTeamBalanceScore( void );
  54. void AwardAchievement( int iAchievement, int iCount = 1 );
  55. int GetPerLifeCounterKV( const char *name );
  56. void SetPerLifeCounterKV( const char *name, int value );
  57. void ResetPerLifeCounters( void );
  58. KeyValues *GetPerLifeCounterKeys( void ) { return m_pAchievementKV; }
  59. void EscortScoringThink( void );
  60. void StartScoringEscortPoints( float flRate );
  61. void StopScoringEscortPoints( void );
  62. float m_flAreaCaptureScoreAccumulator;
  63. float m_flCapPointScoreRate;
  64. float GetConnectionTime( void ) { return m_flConnectionTime; }
  65. // Command rate limiting.
  66. bool ShouldRunRateLimitedCommand( const CCommand &args );
  67. bool ShouldRunRateLimitedCommand( const char *pszCommand );
  68. protected:
  69. virtual CAI_Expresser *CreateExpresser( void );
  70. int m_iCurrentConcept;
  71. private:
  72. //---------------------------------
  73. CMultiplayer_Expresser *m_pExpresser;
  74. float m_flConnectionTime;
  75. float m_flLastForcedChangeTeamTime;
  76. int m_iBalanceScore; // a score used to determine which players are switched to balance the teams
  77. KeyValues *m_pAchievementKV;
  78. // This lets us rate limit the commands the players can execute so they don't overflow things like reliable buffers.
  79. CUtlDict<float,int> m_RateLimitLastCommandTimes;
  80. };
  81. //-----------------------------------------------------------------------------
  82. // Inline methods
  83. //-----------------------------------------------------------------------------
  84. inline CBaseMultiplayerPlayer *ToBaseMultiplayerPlayer( CBaseEntity *pEntity )
  85. {
  86. if ( !pEntity || !pEntity->IsPlayer() )
  87. return NULL;
  88. #if _DEBUG
  89. return dynamic_cast<CBaseMultiplayerPlayer *>( pEntity );
  90. #else
  91. return static_cast<CBaseMultiplayerPlayer *>( pEntity );
  92. #endif
  93. }
  94. #endif // BASEMULTIPLAYERPLAYER_H