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.

126 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #ifndef TEAMPLAY_GAMERULES_H
  14. #define TEAMPLAY_GAMERULES_H
  15. #pragma once
  16. #include "gamerules.h"
  17. #include "multiplay_gamerules.h"
  18. #ifdef CLIENT_DLL
  19. #define CTeamplayRules C_TeamplayRules
  20. #else
  21. #include "takedamageinfo.h"
  22. #endif
  23. //
  24. // teamplay_gamerules.h
  25. //
  26. #define MAX_TEAMNAME_LENGTH 16
  27. #define MAX_TEAMS 32
  28. #define TEAMPLAY_TEAMLISTLENGTH MAX_TEAMS*MAX_TEAMNAME_LENGTH
  29. class CTeamplayRules : public CMultiplayRules
  30. {
  31. public:
  32. DECLARE_CLASS( CTeamplayRules, CMultiplayRules );
  33. // Return the value of this player towards capturing a point
  34. virtual int GetCaptureValueForPlayer( CBasePlayer *pPlayer ) { return 1; }
  35. virtual bool TeamMayCapturePoint( int iTeam, int iPointIndex ) { return true; }
  36. virtual bool PlayerMayCapturePoint( CBasePlayer *pPlayer, int iPointIndex, char *pszReason = NULL, int iMaxReasonLength = 0 ) { return true; }
  37. virtual bool PlayerMayBlockPoint( CBasePlayer *pPlayer, int iPointIndex, char *pszReason = NULL, int iMaxReasonLength = 0 ) { return false; }
  38. // Return false if players aren't allowed to cap points at this time (i.e. in WaitingForPlayers)
  39. virtual bool PointsMayBeCaptured( void ) { return true; }
  40. virtual void SetLastCapPointChanged( int iIndex ) { return; }
  41. #ifdef CLIENT_DLL
  42. #else
  43. CTeamplayRules();
  44. virtual ~CTeamplayRules() {};
  45. virtual void Precache( void );
  46. virtual bool ClientCommand( CBaseEntity *pEdict, const CCommand &args );
  47. virtual void ClientSettingsChanged( CBasePlayer *pPlayer );
  48. virtual bool IsTeamplay( void );
  49. virtual bool FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity *pAttacker, const CTakeDamageInfo &info );
  50. virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget );
  51. virtual bool PlayerCanHearChat( CBasePlayer *pListener, CBasePlayer *pSpeaker );
  52. virtual const char *GetTeamID( CBaseEntity *pEntity );
  53. virtual bool ShouldAutoAim( CBasePlayer *pPlayer, edict_t *target );
  54. virtual int IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled );
  55. virtual void InitHUD( CBasePlayer *pl );
  56. virtual void DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info );
  57. virtual const char *GetGameDescription( void ) { return "Teamplay"; } // this is the game name that gets seen in the server browser
  58. virtual void PlayerKilled( CBasePlayer *pVictim, const CTakeDamageInfo &info );
  59. virtual void Think ( void );
  60. virtual int GetTeamIndex( const char *pTeamName );
  61. virtual const char *GetIndexedTeamName( int teamIndex );
  62. virtual bool IsValidTeam( const char *pTeamName );
  63. virtual const char *SetDefaultPlayerTeam( CBasePlayer *pPlayer );
  64. virtual void ChangePlayerTeam( CBasePlayer *pPlayer, const char *pTeamName, bool bKill, bool bGib );
  65. virtual void ClientDisconnected( edict_t *pClient );
  66. virtual bool TimerMayExpire( void ) { return true; }
  67. // A game has been won by the specified team
  68. virtual void SetWinningTeam( int team, int iWinReason, bool bForceMapReset = true, bool bSwitchTeams = false, bool bDontAddScore = false, bool bFinal = false ) { return; }
  69. virtual void SetStalemate( int iReason, bool bForceMapReset = true, bool bSwitchTeams = false ) { return; }
  70. // Used to determine if all players should switch teams
  71. virtual void SetSwitchTeams( bool bSwitch ){ m_bSwitchTeams = bSwitch; }
  72. virtual bool ShouldSwitchTeams( void ){ return m_bSwitchTeams; }
  73. virtual void HandleSwitchTeams( void ){ return; }
  74. // Used to determine if we should scramble the teams
  75. virtual void SetScrambleTeams( bool bScramble ){ m_bScrambleTeams = bScramble; }
  76. virtual bool ShouldScrambleTeams( void ){ return m_bScrambleTeams; }
  77. virtual void HandleScrambleTeams( void ){ return; }
  78. virtual bool PointsMayAlwaysBeBlocked(){ return false; }
  79. protected:
  80. bool m_DisableDeathMessages;
  81. private:
  82. void RecountTeams( void );
  83. const char *TeamWithFewestPlayers( void );
  84. bool m_DisableDeathPenalty;
  85. bool m_teamLimit; // This means the server set only some teams as valid
  86. char m_szTeamList[TEAMPLAY_TEAMLISTLENGTH];
  87. bool m_bSwitchTeams;
  88. bool m_bScrambleTeams;
  89. #endif
  90. };
  91. inline CTeamplayRules* TeamplayGameRules()
  92. {
  93. return static_cast<CTeamplayRules*>(g_pGameRules);
  94. }
  95. #endif // TEAMPLAY_GAMERULES_H