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.

258 lines
9.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TF_MATCH_DESCRIPTION_H
  7. #define TF_MATCH_DESCRIPTION_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tf_matchmaking_shared.h"
  12. #ifdef CLIENT_DLL
  13. #include "basemodel_panel.h"
  14. #endif // CLIENT_DLL
  15. #ifdef GAME_DLL
  16. // Can't foward declare CMatchInfo::PlayerMatchData_t because C++. Bummer.
  17. #include "tf_gc_server.h"
  18. #endif
  19. #ifdef GC_DLL
  20. class CTFLobby;
  21. class CTFParty;
  22. struct MatchDescription_t;
  23. struct MatchParty_t;
  24. #endif
  25. class CSOTFLadderData;
  26. enum EMatchType_t
  27. {
  28. MATCH_TYPE_NONE = 0,
  29. MATCH_TYPE_MVM,
  30. MATCH_TYPE_COMPETITIVE,
  31. MATCH_TYPE_CASUAL
  32. };
  33. struct LevelInfo_t
  34. {
  35. uint32 m_nLevelNum;
  36. uint32 m_nStartXP; // Inclusive
  37. uint32 m_nEndXP; // Non-inclusive
  38. const char* m_pszLevelIcon; // Kill this when we do models
  39. const char* m_pszLevelTitle;
  40. const char* m_pszLevelUpSound;
  41. const char* m_pszLobbyBackgroundImage;
  42. };
  43. struct XPSourceDef_t
  44. {
  45. const char* m_pszSoundName;
  46. const char* m_pszFormattingLocToken;
  47. const char* m_pszTypeLocToken;
  48. float m_flValueMultiplier;
  49. };
  50. extern const XPSourceDef_t g_XPSourceDefs[ CMsgTFXPSource_XPSourceType_NUM_SOURCE_TYPES ];
  51. class IProgressionDesc
  52. {
  53. public:
  54. IProgressionDesc( EMatchGroup eMatchGroup
  55. , const char* pszBadgeName
  56. , const char* pszProgressionResFile
  57. , const char* pszLevelToken );
  58. #ifdef CLIENT_DLL
  59. virtual void SetupBadgePanel( CBaseModelPanel *pModelPanel, const LevelInfo_t& level ) const = 0;
  60. virtual const uint32 GetLocalPlayerLastAckdExperience() const = 0;
  61. virtual const uint32 GetPlayerExperienceBySteamID( CSteamID steamid ) const = 0;
  62. virtual const LevelInfo_t& YieldingGetLevelForSteamID( const CSteamID& steamID ) const;
  63. #endif // CLIENT_DLL
  64. #if defined GC_DLL
  65. // XXX(JohnS): This should go away once XP is just a rating type, no need for match description to have different
  66. // implementations of how the job does it.
  67. virtual bool BYldAcknowledgePlayerXPOnTransaction( CSQLAccess &transaction, CTFSharedObjectCache *pLockedSOCache ) const = 0;
  68. // XXX(JohnS): Same, this is super specific and hacky.
  69. virtual const bool BRankXPIsActuallyPrimaryMMRating() const = 0;
  70. #endif // defined GC_DLL
  71. virtual const LevelInfo_t& GetLevelForExperience( uint32 nExperience ) const;
  72. const LevelInfo_t& GetLevelByNumber( uint32 nNumber ) const;
  73. uint32 GetNumLevels() const { return m_vecLevels.Count(); }
  74. #if defined GC_DLL || ( defined STAGING_ONLY && defined CLIENT_DLL )
  75. virtual void DebugSpewLevels() const = 0;
  76. #endif
  77. const CUtlString m_strBadgeName;
  78. const char* m_pszLevelToken;
  79. const char* m_pszProgressionResFile;
  80. protected:
  81. #ifdef CLIENT_DLL
  82. void EnsureBadgePanelModel( CBaseModelPanel *pModelPanel ) const;
  83. #endif
  84. const EMatchGroup m_eMatchGroup;
  85. CUtlVector< LevelInfo_t > m_vecLevels;
  86. };
  87. struct MatchDesc_t
  88. {
  89. EMatchMode m_eLateJoinMode;
  90. EMMPenaltyPool m_ePenaltyPool;
  91. bool m_bUsesSkillRatings;
  92. bool m_bSupportsLowPriorityQueue;
  93. bool m_bRequiresMatchID;
  94. const ConVar* m_pmm_required_score;
  95. bool m_bUseMatchHud;
  96. const char* m_pszExecFileName;
  97. const ConVar* m_pmm_match_group_size;
  98. const ConVar* m_pmm_match_group_size_minimum; // Optional
  99. EMatchType_t m_eMatchType;
  100. bool m_bShowPreRoundDoors;
  101. bool m_bShowPostRoundDoors;
  102. const char* m_pszMatchEndKickWarning;
  103. const char* m_pszMatchStartSound;
  104. bool m_bAutoReady;
  105. bool m_bShowRankIcons;
  106. bool m_bUseMatchSummaryStage;
  107. bool m_bDistributePerformanceMedals;
  108. bool m_bIsCompetitiveMode;
  109. bool m_bUseFirstBlood;
  110. bool m_bUseReducedBonusTime;
  111. bool m_bUseAutoBalance;
  112. bool m_bAllowTeamChange;
  113. bool m_bRandomWeaponCrits;
  114. bool m_bFixedWeaponSpread;
  115. // If we should not allow match to complete without a complete set of players.
  116. bool m_bRequireCompleteMatch;
  117. bool m_bTrustedServersOnly;
  118. bool m_bForceClientSettings;
  119. bool m_bAllowDrawingAtMatchSummary;
  120. bool m_bAllowSpecModeChange;
  121. bool m_bAutomaticallyRequeueAfterMatchEnds;
  122. bool m_bUsesMapVoteOnRoundEnd;
  123. bool m_bUsesXP;
  124. bool m_bUsesDashboardOnRoundEnd;
  125. bool m_bUsesSurveys;
  126. // Be strict about finding quality matches, for more-competitive matchgroups that want to prioritize match quality
  127. // over speed.
  128. bool m_bStrictMatchmakerScoring;
  129. };
  130. class IMatchGroupDescription
  131. {
  132. public:
  133. IMatchGroupDescription( EMatchGroup eMatchGroup, const MatchDesc_t& params )
  134. : m_eMatchGroup( eMatchGroup )
  135. , m_params( params )
  136. , m_pProgressionDesc( NULL )
  137. {}
  138. #ifdef GC_DLL
  139. // What rating the matchmaker should use to evaluate players in this matchgroup
  140. virtual EMMRating PrimaryMMRatingBackend() const = 0;
  141. // What ratings match results in this ladder group should run updates on
  142. virtual const std::vector< EMMRating > &MatchResultRatingBackends() const = 0;
  143. // When creating a match from the first party, what to copy over
  144. virtual bool InitMatchFromParty( MatchDescription_t* pMatch, const MatchParty_t* pParty ) const = 0;
  145. // When finding late joiners for an already-in-play lobby
  146. virtual bool InitMatchFromLobby( MatchDescription_t* pMatch, CTFLobby* pLobby ) const = 0;
  147. // Sync a match party with a CTFParty
  148. virtual void SyncMatchParty( const CTFParty *pParty, MatchParty_t *pMatchParty ) const = 0;
  149. // A match has formed, what game mode paremeters do we want to set? (ie. MvM Popfile, 12v12 map, etc)
  150. virtual void SelectModeSpecificParameters( const MatchDescription_t* pMatch, CTFLobby* pLobby ) const = 0;
  151. // Get which server pool to use
  152. virtual int GetServerPoolIndex( EMatchGroup eGroup, EMMServerMode eMode ) const;
  153. // Get server details
  154. virtual void GetServerDetails( const CMsgGameServerMatchmakingStatus& msg, int& nChallengeIndex, const char* pszMap ) const = 0;
  155. virtual const char* GetUnauthorizedPartyReason( CTFParty* pParty ) const = 0;
  156. virtual void Dump( const char *pszLeader, int nSpewLevel, int nLogLevel, const MatchParty_t* pMatch ) const = 0;
  157. //
  158. // Threaded calls. These are called in work items, and should be pure functions
  159. //
  160. // Check if pMatch is compatible with pCandidateParty -- that is, if BIntersectMatchWithParty would succeed.
  161. virtual bool BThreadedPartyCompatibleWithMatch( const MatchDescription_t* pMatch, const MatchParty_t *pCurrentParty ) const = 0;
  162. // When adding a party to a match, what intersection of current state with the incoming party gets copied to the
  163. // match. This returns false if the party isn't compatible, e.g. if !BThreadedPartyCompatibleWithMatch
  164. virtual bool BThreadedIntersectMatchWithParty( MatchDescription_t* pMatch, const MatchParty_t* pParty ) const = 0;
  165. // Check if two parties are compatible, that is, if they could be added to the same match absent other criteria
  166. virtual bool BThreadedPartiesCompatible( const MatchParty_t *pLeftParty, const MatchParty_t *pRightParty ) const = 0;
  167. #endif
  168. #ifdef CLIENT_DLL
  169. virtual bool BGetRoundStartBannerParameters( int& nSkin, int& nBodyGroup ) const = 0;
  170. virtual bool BGetRoundDoorParameters( int& nSkin, int& nLogoBodyGroup ) const = 0;
  171. virtual const char *GetMapLoadBackgroundOverride( bool bWideScreen ) const = 0;
  172. #endif
  173. #ifdef GAME_DLL
  174. // ! Check return, we might fail to setup
  175. virtual bool InitServerSettingsForMatch( const CTFGSLobby* pLobby ) const;
  176. virtual void InitGameRulesSettings() const = 0;
  177. virtual void InitGameRulesSettingsPostEntity() const = 0;
  178. virtual void PostMatchClearServerSettings() const = 0;
  179. virtual bool ShouldRequestLateJoin() const = 0;
  180. virtual bool BMatchIsSafeToLeaveForPlayer( const CMatchInfo* pMatchInfo, const CMatchInfo::PlayerMatchData_t *pMatchPlayer ) const = 0;
  181. virtual bool BPlayWinMusic( int nWinningTeam, bool bGameOver ) const = 0;
  182. #endif
  183. // Accessors for param values
  184. inline int GetMatchSize() const { return m_params.m_pmm_match_group_size->GetInt(); }
  185. inline bool BShouldAutomaticallyRequeueOnMatchEnd() const { return m_params.m_bAutomaticallyRequeueAfterMatchEnds; }
  186. inline bool BUsesMapVoteAfterMatchEnds() const { return m_params.m_bUsesMapVoteOnRoundEnd; }
  187. inline bool BUsesXP() const { return m_params.m_bUsesXP; }
  188. inline bool BUsesDashboard() const { return m_params.m_bUsesDashboardOnRoundEnd; }
  189. inline bool BUsesStrictMatchmakerScoring() const { return m_params.m_bStrictMatchmakerScoring; }
  190. inline bool BRequiresCompleteMatches() const { return m_params.m_bRequireCompleteMatch; }
  191. inline bool BRequiresMatchID() const { return m_params.m_bRequiresMatchID; }
  192. // Meta-permissions that are based on other set flags
  193. //
  194. // Only match-vote modes need this ability right now
  195. inline bool BCanServerRequestNewMatchForLobby() const { return BUsesMapVoteAfterMatchEnds(); }
  196. // Auto-balance and anything that is allowed to roll new match lobbies needs to have this ability (for speculative
  197. // matches if the GC is unavailable). It should be possible to add a mode where we do rolling matches, but only
  198. // when the GC is responding, which would not need the unilateral-team-assignment ability
  199. inline bool BCanServerChangeMatchPlayerTeams() const { return BCanServerRequestNewMatchForLobby() || m_params.m_bUseAutoBalance; }
  200. #ifdef GC_DLL
  201. inline bool BUsesSkillRatings() const { return m_params.m_bUsesSkillRatings; }
  202. inline int GetMinimumMatchSize() const
  203. {
  204. int min = m_params.m_pmm_match_group_size_minimum ? m_params.m_pmm_match_group_size_minimum->GetInt() : -1;
  205. return ( min >= 0 ) ? min : GetMatchSize();
  206. }
  207. inline bool BUsesSurveys() const { return m_params.m_bUsesSurveys; }
  208. #endif
  209. inline bool BIsTrustedServersOnly() const { return m_params.m_bTrustedServersOnly; }
  210. const EMatchGroup m_eMatchGroup;
  211. const MatchDesc_t m_params;
  212. const IProgressionDesc* m_pProgressionDesc;
  213. };
  214. const IMatchGroupDescription* GetMatchGroupDescription( const EMatchGroup& eGroup );
  215. #endif //TF_MATCH_DESCRIPTION_H