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.

163 lines
4.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef CS_STEAMSTATS_H
  8. #define CS_STEAMSTATS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "steam/steam_api.h"
  13. #include "GameEventListener.h"
  14. #include "../game/shared/cstrike/cs_gamestats_shared.h"
  15. struct SRoundData : public BaseStatData
  16. {
  17. SRoundData( const StatsCollection_t *pRoundData )
  18. {
  19. nRoundTime = (*pRoundData)[CSSTAT_PLAYTIME];
  20. nWasKilled = (*pRoundData)[CSSTAT_DEATHS];
  21. nIsMVP = (*pRoundData)[CSSTAT_MVPS];
  22. nMoneySpent = (*pRoundData)[CSSTAT_MONEY_SPENT];
  23. nStartingMoney = -1;// We'll get this data separately
  24. nRoundEndReason = Invalid_Round_End_Reason;// We'll get this data separately
  25. nRevenges = (*pRoundData)[CSSTAT_REVENGES];
  26. nDamageDealt = (*pRoundData)[CSSTAT_DAMAGE];
  27. if ( (*pRoundData)[CSSTAT_T_ROUNDS_WON] )
  28. {
  29. nWinningTeamID = TEAM_TERRORIST;
  30. if ( (*pRoundData)[CSSTAT_ROUNDS_WON] )
  31. {
  32. nTeamID = TEAM_TERRORIST;
  33. }
  34. else
  35. {
  36. nTeamID = TEAM_CT;
  37. }
  38. }
  39. else
  40. {
  41. nWinningTeamID = TEAM_CT;
  42. if ( (*pRoundData)[CSSTAT_ROUNDS_WON] )
  43. {
  44. nTeamID = TEAM_CT;
  45. }
  46. else
  47. {
  48. nTeamID = TEAM_TERRORIST;
  49. }
  50. }
  51. }
  52. uint32 nRoundTime;
  53. int nTeamID;
  54. int nWinningTeamID;
  55. int nWasKilled;
  56. int nIsMVP;
  57. int nDamageDealt;
  58. int nMoneySpent;
  59. int nStartingMoney;
  60. int nRevenges;
  61. int nRoundEndReason;
  62. BEGIN_STAT_TABLE( "CSSRoundData" )
  63. REGISTER_STAT_NAMED( nRoundTime, "RoundTime" )
  64. REGISTER_STAT_NAMED( nTeamID, "TeamID" )
  65. REGISTER_STAT_NAMED( nWinningTeamID, "WinningTeamID" )
  66. REGISTER_STAT_NAMED( nWasKilled, "WasKilled" )
  67. REGISTER_STAT_NAMED( nIsMVP, "IsMvp" )
  68. REGISTER_STAT_NAMED( nDamageDealt, "DamageDealt" )
  69. REGISTER_STAT_NAMED( nMoneySpent, "MoneySpent" )
  70. REGISTER_STAT_NAMED( nStartingMoney, "StartingMoney" )
  71. REGISTER_STAT_NAMED( nRevenges, "Revenges" )
  72. REGISTER_STAT_NAMED( nRoundEndReason, "RoundEndReason" )
  73. END_STAT_TABLE()
  74. };
  75. typedef CUtlVector< SRoundData* > VectorRoundData;
  76. struct PlayerStatData_t
  77. {
  78. wchar_t* pStatDisplayName; // Localized display name of the stat
  79. int iStatId; // CSStatType_t enum value of stat
  80. int32 iStatValue; // Value of the stat
  81. };
  82. class CCSClientGameStats : public CAutoGameSystem, public CGameEventListener, public IGameStatTracker
  83. {
  84. public:
  85. CCSClientGameStats();
  86. virtual void PostInit();
  87. virtual void LevelShutdownPreEntity();
  88. virtual void Shutdown();
  89. virtual void LevelShutdownPreClearSteamAPIContext();
  90. int GetStatCount();
  91. PlayerStatData_t GetStatByIndex(int index);
  92. PlayerStatData_t GetStatById(int id);
  93. void ResetAllStats( void );
  94. void ResetMatchStats();
  95. void UploadRoundData( void );
  96. const StatsCollection_t& GetLifetimeStats() { return m_lifetimeStats; }
  97. const StatsCollection_t& GetMatchStats() { return m_matchStats; }
  98. RoundStatsDirectAverage_t* GetDirectCTStatsAverages() { return &m_directCTStatAverages; }
  99. RoundStatsDirectAverage_t* GetDirectTStatsAverages() { return &m_directTStatAverages; }
  100. RoundStatsDirectAverage_t* GetDirectPlayerStatsAverages() { return &m_directPlayerStatAverages; }
  101. void MsgFunc_MatchStatsUpdate( bf_read &msg );
  102. void MsgFunc_PlayerStatsUpdate( bf_read &msg );
  103. // Steamworks Gamestats
  104. virtual void SubmitGameStats( KeyValues *pKV )
  105. {
  106. int listCount = s_StatLists->Count();
  107. for( int i=0; i < listCount; ++i )
  108. {
  109. // Create a master key value that has stats everybody should share (map name, session ID, etc)
  110. (*s_StatLists)[i]->SendData(pKV);
  111. (*s_StatLists)[i]->Clear();
  112. }
  113. }
  114. virtual StatContainerList_t* GetStatContainerList( void )
  115. {
  116. return s_StatLists;
  117. }
  118. protected:
  119. void FireGameEvent( IGameEvent *event );
  120. void UpdateSteamStats();
  121. void RetrieveSteamStats();
  122. void UpdateStats( const StatsCollection_t &stats );
  123. void CalculateMatchFavoriteWeapons();
  124. void UpdateLastMatchStats();
  125. private:
  126. StatsCollection_t m_lifetimeStats;
  127. StatsCollection_t m_matchStats;
  128. StatsCollection_t m_roundStats;
  129. RoundStatsDirectAverage_t m_directCTStatAverages;
  130. RoundStatsDirectAverage_t m_directTStatAverages;
  131. RoundStatsDirectAverage_t m_directPlayerStatAverages;
  132. int m_matchMaxPlayerCount;
  133. bool m_bSteamStatsDownload;
  134. VectorRoundData m_RoundStatData;
  135. int m_RoundEndReason;
  136. // A static list of all the stat containers, one for each data structure being tracked
  137. static StatContainerList_t * s_StatLists;
  138. };
  139. extern CCSClientGameStats g_CSClientGameStats;
  140. #endif //CS_STEAMSTATS_H