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.

177 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //=======================================================================================//
  3. #if defined( REPLAY_ENABLED )
  4. #ifndef GENERICCLASSBASED_REPLAY_H
  5. #define GENERICCLASSBASED_REPLAY_H
  6. #ifdef _WIN32
  7. #pragma once
  8. #endif
  9. //----------------------------------------------------------------------------------------
  10. #include "replay/replay.h"
  11. #include "replay/iclientreplaycontext.h"
  12. #include "GameEventListener.h"
  13. // For RoundStats_t
  14. #include "replay/gamedefs.h"
  15. //----------------------------------------------------------------------------------------
  16. extern IClientReplayContext *g_pClientReplayContext;
  17. //----------------------------------------------------------------------------------------
  18. class CGenericClassBasedReplay : public CReplay,
  19. public CGameEventListener
  20. {
  21. typedef CReplay BaseClass;
  22. public:
  23. CGenericClassBasedReplay();
  24. ~CGenericClassBasedReplay();
  25. virtual void OnBeginRecording();
  26. virtual void OnEndRecording();
  27. virtual void OnComplete();
  28. virtual bool ShouldAllowDelete() const;
  29. virtual void OnDelete();
  30. virtual void FireGameEvent( IGameEvent *pEvent );
  31. virtual bool Read( KeyValues *pIn );
  32. virtual void Write( KeyValues *pOut );
  33. virtual void DumpGameSpecificData() const;
  34. void SetPlayerClass( int nPlayerClass );
  35. void SetPlayerTeam( int nPlayerTeam );
  36. void RecordPlayerDeath( const char *pKillerName, int nKillerClass );
  37. // Add a new kill to the list
  38. void AddKill( const char *pPlayerName, int nPlayerClass );
  39. // Get the player class as a string
  40. virtual const char *GetPlayerClass() const;
  41. // Get the player team as a string
  42. virtual const char *GetPlayerTeam() const = 0;
  43. // Utility to get the material-friendly player class (demoman->demo, heavyweapons->heavy)
  44. virtual const char *GetMaterialFriendlyPlayerClass() const;
  45. // Was there a killer?
  46. inline bool WasKilled() const { return m_szKillerName[0] != 0; }
  47. // Get killer name
  48. const char *GetKillerName() const;
  49. // Get the killer class, if there was a killer
  50. const char *GetKillerClass() const;
  51. int GetDownloadStatus() const;
  52. // Kill info
  53. struct KillData_t
  54. {
  55. char m_szPlayerName[MAX_OSPATH];
  56. int m_nPlayerClass;
  57. };
  58. inline int GetKillCount() const { return m_vecKills.Count(); }
  59. inline const KillData_t *GetKill( int nKillIndex ) { return m_vecKills[ nKillIndex ]; }
  60. // A generic info struct used for dominations, assisted dominations, revenges, assisted revenged...
  61. // Not all data members are necessarily used
  62. struct GenericStatInfo_t
  63. {
  64. GenericStatInfo_t() : m_nVictimFriendId( 0 ), m_nAssisterFriendId( 0 ) {}
  65. uint32 m_nVictimFriendId;
  66. uint32 m_nAssisterFriendId;
  67. };
  68. inline int GetDominationCount() const { return m_vecDominations.Count(); }
  69. inline const GenericStatInfo_t *GetDomination( int nIndex ) const { return m_vecDominations[ nIndex ]; }
  70. inline int GetAssisterDominationCount() const { return m_vecAssisterDominations.Count(); }
  71. inline const GenericStatInfo_t *GetAssisterDomination( int nIndex ) const { return m_vecAssisterDominations[ nIndex ]; }
  72. inline int GetRevengeCount() const { return m_vecRevenges.Count(); }
  73. inline const GenericStatInfo_t *GetRevenge( int nIndex ) const { return m_vecRevenges[ nIndex ]; }
  74. inline int GetAssisterRevengeCount() const { return m_vecAssisterRevenges.Count(); }
  75. inline const GenericStatInfo_t *GetAssisterRevenge( int nIndex ) const { return m_vecAssisterRevenges[ nIndex ]; }
  76. RoundStats_t const &GetStats() const { return m_lifeStats; }
  77. protected:
  78. int m_nPlayerClass;
  79. int m_nPlayerTeam;
  80. int m_nStatUndefined;
  81. char m_szKillerName[ MAX_OSPATH ];
  82. int m_nKillerClass;
  83. virtual bool IsValidClass( int nClass ) const = 0;
  84. virtual bool IsValidTeam( int iTeam ) const = 0;
  85. virtual bool GetCurrentStats( RoundStats_t &out ) = 0;
  86. virtual const char *GetStatString( int iStat ) const = 0;
  87. virtual const char *GetPlayerClass( int iClass ) const = 0;
  88. virtual void Update();
  89. // Domination
  90. void AddDomination( int nVictimID );
  91. void AddAssisterDomination( int nVictimID, int nAssiterID );
  92. void AddRevenge( int nVictimID );
  93. void AddAssisterRevenge( int nVictimID, int nAssiterID );
  94. float GetKillScreenshotDelay();
  95. RoundStats_t m_refStats; // Reference stats, used to compute current stats
  96. RoundStats_t m_lifeStats; // Stats for this life, based on reference stats (m_refStats)
  97. private:
  98. void MedicUpdate();
  99. bool GetFriendIdFromUserId( int nPlayerIndex, uint32 &nFriendIdOut ) const; // Get a friend ID based on player index. Returns true on success
  100. void AddKillStatFromUserIds( CUtlVector< GenericStatInfo_t * > &vec, int nVictimId, int nAssisterId = 0 );
  101. void AddKillStatFromFriendIds( CUtlVector< GenericStatInfo_t * > &vec, uint32 nVictimFriendId, uint32 nAssisterFriendId = 0 );
  102. void WriteKillStatVector( CUtlVector< GenericStatInfo_t * > const &vec, const char *pSubKeyName, const char *pElementKeyName,
  103. KeyValues *pRootKey, int nNumMembersToWrite ) const;
  104. void AddKillStats( CUtlVector< GenericStatInfo_t * > &vecKillStats, KeyValues *pIn, const char *pSubKeyName, int iStatIndex );
  105. void RecordUpdatedStats();
  106. CUtlVector< KillData_t * > m_vecKills;
  107. CUtlVector< GenericStatInfo_t * > m_vecDominations;
  108. CUtlVector< GenericStatInfo_t * > m_vecAssisterDominations;
  109. CUtlVector< GenericStatInfo_t * > m_vecRevenges;
  110. CUtlVector< GenericStatInfo_t * > m_vecAssisterRevenges;
  111. // TODO... dominations, achievements, etc.
  112. };
  113. //----------------------------------------------------------------------------------------
  114. inline CGenericClassBasedReplay *ToGenericClassBasedReplay( CReplay *pClientReplay )
  115. {
  116. return static_cast< CGenericClassBasedReplay * >( pClientReplay );
  117. }
  118. inline const CGenericClassBasedReplay *ToGenericClassBasedReplay( const CReplay *pClientReplay )
  119. {
  120. return static_cast< const CGenericClassBasedReplay * >( pClientReplay );
  121. }
  122. inline CGenericClassBasedReplay *GetGenericClassBasedReplay( ReplayHandle_t hReplay )
  123. {
  124. return ToGenericClassBasedReplay( g_pClientReplayContext->GetReplay( hReplay ) );
  125. }
  126. //----------------------------------------------------------------------------------------
  127. #endif // GENERICCLASSBASED_REPLAY_H
  128. #endif