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.

172 lines
7.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef TF_GAMESTATS_H
  7. #define TF_GAMESTATS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "gamestats.h"
  12. #include "tf_obj.h"
  13. #include "tf_gamestats_shared.h"
  14. #include "GameEventListener.h"
  15. class CTFPlayer;
  16. //=============================================================================
  17. //
  18. // TF Game Stats Class
  19. //
  20. class CTFGameStats : public CBaseGameStats, public CGameEventListener, public CAutoGameSystem
  21. {
  22. public:
  23. // Constructor/Destructor.
  24. CTFGameStats( void );
  25. ~CTFGameStats( void );
  26. virtual void Clear( void );
  27. virtual bool UseOldFormat() { return false; }
  28. virtual bool AddDataForSend( KeyValues *pKV, StatSendType_t sendType );
  29. void AddMapData( KeyValues *pKV, TF_Gamestats_LevelStats_t *pCurrentMap );
  30. virtual bool Init();
  31. virtual void LevelInitPreEntity();
  32. virtual void LevelShutdownPreClearSteamAPIContext();
  33. // Events.
  34. virtual void Event_LevelInit( void );
  35. virtual void Event_LevelShutdown( float flElapsed );
  36. virtual void Event_PlayerKilled( CBasePlayer *pPlayer, const CTakeDamageInfo &info );
  37. void Event_RoundStart();
  38. void Event_RoundEnd( int iWinningTeam, bool bFullRound, float flRoundTime, bool bWasSuddenDeathWin );
  39. void Event_GameEnd();
  40. void Event_PlayerConnected( CBasePlayer *pPlayer );
  41. void Event_PlayerDisconnected( CTFPlayer *pPlayer ) {}
  42. void Event_PlayerDisconnectedTF( CTFPlayer *pPlayer );
  43. void Event_PlayerChangedClass( CTFPlayer *pPlayer, int iOldClass, int iNewClass );
  44. void Event_PlayerSpawned( CTFPlayer *pPlayer );
  45. void Event_PlayerForceRespawn( CTFPlayer *pPlayer );
  46. void Event_PlayerLeachedHealth( CTFPlayer *pPlayer, bool bDispenserHeal, float amount );
  47. void Event_PlayerHealedOther( CTFPlayer *pPlayer, float amount );
  48. void Event_PlayerHealedOtherAssist( CTFPlayer *pPlayer, float amount );
  49. void Event_PlayerBlockedDamage( CTFPlayer *pPlayer, int nAmount );
  50. void Event_AssistKill( CTFPlayer *pPlayer, CBaseEntity *pVictim );
  51. void Event_PlayerInvulnerable( CTFPlayer *pPlayer );
  52. void Event_PlayerCreatedBuilding( CTFPlayer *pPlayer, CBaseObject *pBuilding );
  53. void Event_PlayerDestroyedBuilding( CTFPlayer *pPlayer, CBaseObject *pBuilding );
  54. void Event_AssistDestroyBuilding( CTFPlayer *pPlayer, CBaseObject *pBuilding );
  55. void Event_Headshot( CTFPlayer *pKiller, bool bBowShot=false );
  56. void Event_Backstab( CTFPlayer *pKiller );
  57. void Event_PlayerUsedTeleport( CTFPlayer *pTeleportOwner, CTFPlayer *pTeleportingPlayer );
  58. void Event_PlayerFiredWeapon( CTFPlayer *pPlayer, bool bCritical );
  59. void Event_PlayerDamage( CBasePlayer *pPlayer, const CTakeDamageInfo &info, int iDamageTaken );
  60. void Event_PlayerDamageAssist( CBasePlayer *pProvider, int iBonusDamage );
  61. void Event_BossDamage( CBasePlayer *pAttacker, int iDamage );
  62. void Event_PlayerKilledOther( CBasePlayer *pAttacker, CBaseEntity *pVictim, const CTakeDamageInfo &info );
  63. void Event_PlayerCapturedPoint( CTFPlayer *pPlayer );
  64. void Event_PlayerReturnedFlag( CTFPlayer *pPlayer );
  65. void Event_PlayerScoresEscortPoints( CTFPlayer *pPlayer, int iPoints );
  66. void Event_PlayerDefendedPoint( CTFPlayer *pPlayer );
  67. void Event_PlayerDominatedOther( CTFPlayer *pAttacker );
  68. void Event_PlayerRevenge( CTFPlayer *pAttacker );
  69. void Event_PlayerStunBall( CTFPlayer *pAttacker, bool bSpecial );
  70. void Event_PlayerAwardBonusPoints( CTFPlayer *pPlayer, CBaseEntity *pSource, int nCount );
  71. void Event_PlayerHealthkitPickup( CTFPlayer *pTFPlayer );
  72. void Event_PlayerAmmokitPickup( CTFPlayer *pTFPlayer );
  73. void Event_PlayerSuicide( CBasePlayer *pPlayer );
  74. void Event_KillDetail( CTFPlayer* pKiller, CTFPlayer* pVictim, CTFPlayer* pAssister, IGameEvent* event /*player_death*/, const CTakeDamageInfo &info );
  75. void Event_TeamChange( CTFPlayer* pPlayer, int oldTeam, int newTeam );
  76. void Event_PlayerCollectedCurrency( CBasePlayer *pPlayer, int nAmount );
  77. void Event_PlayerLoadoutChanged( CTFPlayer *pPlayer, bool bForceReport );
  78. void Event_PlayerRevived( CTFPlayer *pPlayer );
  79. void Event_PlayerThrowableHit( CTFPlayer *pPlayer );
  80. void Event_PlayerThrowableKill( CTFPlayer *pPlayer );
  81. void Event_PlayerEarnedKillStreak( CTFPlayer *pPlayer );
  82. void Event_HalloweenBossEvent( uint8 unBossType, uint16 unBossLevel, uint8 unEventType, uint8 unPlayersInvolved, float fElapsedTime );
  83. virtual void FireGameEvent( IGameEvent * event );
  84. bool IsRealGameplay( TF_Gamestats_LevelStats_t *game );
  85. void AccumulateGameData();
  86. void AccumulateVoteData( void );
  87. bool GetVoteData( const char *szIssueName, int nNumOptions, CUtlVector <const char*> &vecNames );
  88. void ClearCurrentGameData();
  89. // SteamWorks GameStats
  90. void SW_GameStats_WriteMap();
  91. void SW_GameStats_WriteRound( int iWinningTeam, bool bFullRound, int iEndReason );
  92. void SW_GameStats_WritePlayer( CTFPlayer *pPlayer, bool bDisconnected=false );
  93. void SW_GameStats_WriteKill( CTFPlayer* pKiller, CTFPlayer* pVictim, CTFPlayer* pAssister, IGameEvent* event /*player_death*/, const CTakeDamageInfo &info );
  94. void SW_ClassChange( CTFPlayer* pPlayer, int oldClass, int newClass );
  95. void SW_GameEvent( CTFPlayer* pPlayer, const char* pszScoreType, int iPoints );
  96. void SW_FlagEvent( int iPlayer, int iCarrier, int iEventType );
  97. void SW_CapEvent( int iPoint, int iPlayer, const char* pszEventID, int iPoints );
  98. void SW_WriteHostsRow();
  99. // Passtime
  100. void SW_PasstimeRoundEnded();
  101. // PowerUp Mode
  102. void Event_PowerUpModeDeath( CTFPlayer *pKiller, CTFPlayer *pVictim );
  103. void Event_PowerUpRuneDuration( CTFPlayer *pKiller, int iDuration, int nRune );
  104. // Utilities.
  105. TF_Gamestats_LevelStats_t *GetCurrentMap( void ) { return m_reportedStats.m_pCurrentGame; }
  106. TF_Gamestats_RoundStats_t* GetRoundStatsForTeam( int iTeamNumber );
  107. void StoreGameEndReason( const char* reason );
  108. struct PlayerStats_t * FindPlayerStats( CBasePlayer *pPlayer );
  109. void ResetPlayerStats( CTFPlayer *pPlayer );
  110. void ResetKillHistory( CTFPlayer *pPlayer );
  111. void ResetRoundStats();
  112. protected:
  113. void IncrementStat( CTFPlayer *pPlayer, TFStatType_t statType, int iValue );
  114. void SendStatsToPlayer( CTFPlayer *pPlayer, bool bIsAlive );
  115. void AccumulateAndResetPerLifeStats( CTFPlayer *pPlayer );
  116. void TrackKillStats( CBasePlayer *pAttacker, CBasePlayer *pVictim );
  117. public:
  118. TFReportedStats_t m_reportedStats; // Stats which are uploaded from TF server to Steam
  119. PlayerStats_t m_aPlayerStats[MAX_PLAYERS+1]; // List of stats for each player for current life - reset after each death or class change
  120. // Stats structs used for the new steamworks reporting.
  121. TF_Gamestats_RoundStats_t m_currentRoundRed;
  122. TF_Gamestats_RoundStats_t m_currentRoundBlue;
  123. TF_Gamestats_KillStats_t m_currentKill;
  124. TF_Gamestats_LevelStats_t m_currentMap;
  125. bool m_bRoundActive;
  126. int m_iRoundsPlayed;
  127. bool m_bServerShutdown;
  128. int m_iGameEndReason;
  129. // Unique Column Keys
  130. int m_iEvents;
  131. int m_iKillCount;
  132. int m_iPlayerUpdates;
  133. int m_iLoadoutChangesCount;
  134. // Robot Destruction Struct
  135. RobotDestructionStats_t m_rdStats;
  136. // Passtime
  137. PasstimeStats_t m_passtimeStats;
  138. private:
  139. CUtlMap< CUtlConstString, int > m_MapsPlaytime;
  140. char m_szNextMap[32];
  141. };
  142. extern CTFGameStats CTF_GameStats;
  143. #endif // TF_GAMESTATS_H