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.

139 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef PORTAL_GAMESTATS_H
  7. #define PORTAL_GAMESTATS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "gamestats.h"
  12. #define PORTAL_GAMESTATS_VERSION 001
  13. //#define PORTAL_GAMESTATS_VERBOSE //verbose logging of extra stats, only a good idea during internal tests, centralized here for easy on/off
  14. //NEVER REMOVE A STRUCTURE OR CHANGE A CHUNKID. If you need to change how a chunk works, make a new structure with a new ID
  15. struct Portal_Gamestats_LevelStats_t //most of this is only tracked in verbose mode
  16. {
  17. static const unsigned short CHUNKID = 1;
  18. //substructures
  19. struct PlayerDeaths_t
  20. {
  21. static const unsigned short CHUNKID = 1; //subchunks start over with id's
  22. static const unsigned short TRIMSIZE = 200; //trim logs if more than this many entries exist for a single map
  23. Vector ptPositionOfDeath;
  24. int iDamageType;
  25. char szAttackerClassName[32];
  26. };
  27. struct PortalPlacement_t
  28. {
  29. static const unsigned short CHUNKID = 2;
  30. static const unsigned short TRIMSIZE = 1000; //trim logs if more than this many entries exist for a single map
  31. Vector ptPlayerFiredFrom;
  32. Vector ptPlacementPosition;
  33. char iSuccessCode;
  34. };
  35. struct PlayerUse_t
  36. {
  37. static const unsigned short CHUNKID = 3;
  38. static const unsigned short TRIMSIZE = 500; //trim logs if more than this many entries exist for a single map
  39. Vector ptTraceStart;
  40. Vector vTraceDelta;
  41. char szUseEntityClassName[32];
  42. };
  43. struct StuckEvent_t
  44. {
  45. static const unsigned short CHUNKID = 4;
  46. static const unsigned short TRIMSIZE = 100; //trim logs if more than this many entries exist for a single map
  47. Vector ptPlayerPosition;
  48. QAngle qPlayerAngles;
  49. bool bNearPortal;
  50. bool bDucking;
  51. };
  52. struct JumpEvent_t
  53. {
  54. static const unsigned short CHUNKID = 5;
  55. static const unsigned short TRIMSIZE = 1000; //trim logs if more than this many entries exist for a single map
  56. Vector ptPlayerPositionAtJumpStart;
  57. Vector vPlayerVelocityAtJumpStart;
  58. };
  59. struct LeafTimes_t
  60. {
  61. static const unsigned short CHUNKID = 6;
  62. static const unsigned short TRIMSIZE = 10000; //trim logs if more than this many entries exist for a single map
  63. float fTimeSpentInVisLeaf;
  64. LeafTimes_t( void ) : fTimeSpentInVisLeaf( 0.0f ) { };
  65. };
  66. //these are created/destroyed by parent CPortalGameStats to avoid create/copy/destroy confusion
  67. CUtlVector<PlayerDeaths_t> *m_pDeaths;
  68. CUtlVector<PortalPlacement_t> *m_pPlacements;
  69. CUtlVector<PlayerUse_t> *m_pUseEvents;
  70. CUtlVector<StuckEvent_t> *m_pStuckSpots;
  71. CUtlVector<JumpEvent_t> *m_pJumps;
  72. CUtlVector<LeafTimes_t> *m_pTimeSpentInVisLeafs;
  73. void AppendSubChunksToBuffer( CUtlBuffer &SaveBuffer );
  74. void LoadSubChunksFromBuffer( CUtlBuffer &LoadBuffer, unsigned int iChunkEndPosition );
  75. void Clear( void );
  76. };
  77. class CPortal_Player;
  78. class CPortalGameStats : CBaseGameStats
  79. {
  80. typedef CBaseGameStats BaseClass;
  81. public:
  82. ~CPortalGameStats( void );
  83. CPortalGameStats( void );
  84. void Clear( void );
  85. virtual void Event_LevelInit( void );
  86. virtual void Event_MapChange( const char *szOldMapName, const char *szNewMapName );
  87. virtual void Event_PlayerKilled( CBasePlayer *pPlayer, const CTakeDamageInfo &info );
  88. void Event_PortalPlacement( const Vector &ptPlayerFiredFrom, const Vector &ptAttemptedPosition, char iSuccessCode );
  89. void Event_PlayerJump( const Vector &ptStartPosition, const Vector &vStartVelocity );
  90. void Event_PlayerUsed( const Vector &ptTraceStart, const Vector &vTraceDelta, CBaseEntity *pUsedEntity );
  91. void Event_PlayerStuck( CPortal_Player *pPlayer );
  92. virtual bool StatTrackingEnabledForMod( void ) { return true; }
  93. virtual bool UserPlayedAllTheMaps( void );
  94. #ifdef _DEBUG
  95. virtual bool AutoUpload_OnShutdown( void ) { return false; } //don't upload while we're debugging
  96. #endif
  97. virtual void AppendCustomDataToSaveBuffer( CUtlBuffer &SaveBuffer );
  98. virtual void LoadCustomDataFromBuffer( CUtlBuffer &LoadBuffer );
  99. Portal_Gamestats_LevelStats_t *m_pCurrentMapStats;
  100. protected:
  101. CUtlDict< Portal_Gamestats_LevelStats_t, unsigned short > m_CustomMapStats;
  102. Portal_Gamestats_LevelStats_t *FindOrAddMapStats( const char *szMapName );
  103. };
  104. extern CPortalGameStats g_PortalGameStats;
  105. void CreateLevelStatPointers( Portal_Gamestats_LevelStats_t *pFillIn );
  106. void DestroyLevelStatPointers( Portal_Gamestats_LevelStats_t *pDestroyFrom );
  107. #endif // PORTAL_GAMESTATS_H