Counter Strike : Global Offensive Source Code
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.

648 lines
14 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef CS_GAMESTATS_SHARED_H
  7. #define CS_GAMESTATS_SHARED_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "cbase.h"
  12. // #include "tier1/utlvector.h"
  13. // #include "tier1/utldict.h"
  14. #include "shareddefs.h"
  15. #include "cs_shareddefs.h"
  16. #include "cs_weapon_parse.h"
  17. #define CS_NUM_LEVELS 18
  18. //=============================================================================
  19. // Helper class for simple manipulation of bit arrays.
  20. // Used for server->client packets containing delta stats
  21. //=============================================================================
  22. template <int BitLength>
  23. class BitArray
  24. {
  25. enum { ByteLength = (BitLength + 7) / 8 };
  26. public:
  27. BitArray() { ClearAll(); }
  28. void SetBit(int n) { m_bytes[n / 8] |= 1 << (n & 7); }
  29. void ClearBit(int n) { m_bytes[n / 8] &= (~(1 << (n & 7))); }
  30. bool IsBitSet(int n) const { return (m_bytes[n / 8] & (1 << (n & 7))) != 0;}
  31. void ClearAll() { V_memset(m_bytes, 0, sizeof(m_bytes)); }
  32. int NumBits() { return BitLength; }
  33. int NumBytes() { return ByteLength; }
  34. byte* RawPointer() { return m_bytes; }
  35. private:
  36. byte m_bytes[ByteLength];
  37. };
  38. //=============================================================================
  39. //
  40. // CS Game Stats Enums
  41. //
  42. // approprate location.
  43. enum CSStatType_t
  44. {
  45. CSSTAT_UNDEFINED = -1,
  46. CSSTAT_SHOTS_HIT,
  47. CSSTAT_SHOTS_FIRED,
  48. CSSTAT_KILLS,
  49. CSSTAT_DEATHS,
  50. CSSTAT_DAMAGE,
  51. CSSTAT_NUM_BOMBS_PLANTED,
  52. CSSTAT_NUM_BOMBS_DEFUSED,
  53. CSSTAT_TR_NUM_BOMBS_PLANTED,
  54. CSSTAT_TR_NUM_BOMBS_DEFUSED,
  55. CSSTAT_PLAYTIME,
  56. CSSTAT_ROUNDS_WON,
  57. CSSTAT_T_ROUNDS_WON,
  58. CSSTAT_CT_ROUNDS_WON,
  59. CSSTAT_ROUNDS_PLAYED,
  60. CSSTAT_PISTOLROUNDS_WON,
  61. CSTAT_GUNGAME_ROUNDS_WON,
  62. CSTAT_GUNGAME_ROUNDS_PLAYED,
  63. CSSTAT_MONEY_EARNED,
  64. CSSTAT_OBJECTIVES_COMPLETED,
  65. CSSTAT_BOMBS_DEFUSED_WITHKIT,
  66. CSSTAT_KILLS_DEAGLE,
  67. CSSTAT_KILLS_USP,
  68. CSSTAT_KILLS_GLOCK,
  69. CSSTAT_KILLS_P228,
  70. CSSTAT_KILLS_ELITE,
  71. CSSTAT_KILLS_FIVESEVEN,
  72. CSSTAT_KILLS_AWP,
  73. CSSTAT_KILLS_AK47,
  74. CSSTAT_KILLS_M4A1,
  75. CSSTAT_KILLS_AUG,
  76. CSSTAT_KILLS_SG552,
  77. CSSTAT_KILLS_SG550,
  78. CSSTAT_KILLS_GALIL,
  79. CSSTAT_KILLS_GALILAR,
  80. CSSTAT_KILLS_FAMAS,
  81. CSSTAT_KILLS_SCOUT,
  82. CSSTAT_KILLS_G3SG1,
  83. CSSTAT_KILLS_P90,
  84. CSSTAT_KILLS_MP5NAVY,
  85. CSSTAT_KILLS_TMP,
  86. CSSTAT_KILLS_MAC10,
  87. CSSTAT_KILLS_UMP45,
  88. CSSTAT_KILLS_M3,
  89. CSSTAT_KILLS_XM1014,
  90. CSSTAT_KILLS_M249,
  91. CSSTAT_KILLS_KNIFE,
  92. CSSTAT_KILLS_HEGRENADE,
  93. CSSTAT_KILLS_MOLOTOV,
  94. CSSTAT_KILLS_DECOY,
  95. CSSTAT_KILLS_BIZON,
  96. CSSTAT_KILLS_MAG7,
  97. CSSTAT_KILLS_NEGEV,
  98. CSSTAT_KILLS_SAWEDOFF,
  99. CSSTAT_KILLS_TEC9,
  100. CSSTAT_KILLS_TASER,
  101. CSSTAT_KILLS_HKP2000,
  102. CSSTAT_KILLS_MP7,
  103. CSSTAT_KILLS_MP9,
  104. CSSTAT_KILLS_NOVA,
  105. CSSTAT_KILLS_P250,
  106. CSSTAT_KILLS_SCAR17,
  107. CSSTAT_KILLS_SCAR20,
  108. CSSTAT_KILLS_SG556,
  109. CSSTAT_KILLS_SSG08,
  110. CSSTAT_SHOTS_DEAGLE,
  111. CSSTAT_SHOTS_USP,
  112. CSSTAT_SHOTS_GLOCK,
  113. CSSTAT_SHOTS_P228,
  114. CSSTAT_SHOTS_ELITE,
  115. CSSTAT_SHOTS_FIVESEVEN,
  116. CSSTAT_SHOTS_AWP,
  117. CSSTAT_SHOTS_AK47,
  118. CSSTAT_SHOTS_M4A1,
  119. CSSTAT_SHOTS_AUG,
  120. CSSTAT_SHOTS_SG552,
  121. CSSTAT_SHOTS_SG550,
  122. CSSTAT_SHOTS_GALIL,
  123. CSSTAT_SHOTS_GALILAR,
  124. CSSTAT_SHOTS_FAMAS,
  125. CSSTAT_SHOTS_SCOUT,
  126. CSSTAT_SHOTS_G3SG1,
  127. CSSTAT_SHOTS_P90,
  128. CSSTAT_SHOTS_MP5NAVY,
  129. CSSTAT_SHOTS_TMP,
  130. CSSTAT_SHOTS_MAC10,
  131. CSSTAT_SHOTS_UMP45,
  132. CSSTAT_SHOTS_M3,
  133. CSSTAT_SHOTS_XM1014,
  134. CSSTAT_SHOTS_M249,
  135. CSSTAT_SHOTS_BIZON,
  136. CSSTAT_SHOTS_MAG7,
  137. CSSTAT_SHOTS_NEGEV,
  138. CSSTAT_SHOTS_SAWEDOFF,
  139. CSSTAT_SHOTS_TEC9,
  140. CSSTAT_SHOTS_TASER,
  141. CSSTAT_SHOTS_HKP2000,
  142. CSSTAT_SHOTS_MP7,
  143. CSSTAT_SHOTS_MP9,
  144. CSSTAT_SHOTS_NOVA,
  145. CSSTAT_SHOTS_P250,
  146. CSSTAT_SHOTS_SCAR17,
  147. CSSTAT_SHOTS_SCAR20,
  148. CSSTAT_SHOTS_SG556,
  149. CSSTAT_SHOTS_SSG08,
  150. CSSTAT_HITS_DEAGLE,
  151. CSSTAT_HITS_USP,
  152. CSSTAT_HITS_GLOCK,
  153. CSSTAT_HITS_P228,
  154. CSSTAT_HITS_ELITE,
  155. CSSTAT_HITS_FIVESEVEN,
  156. CSSTAT_HITS_AWP,
  157. CSSTAT_HITS_AK47,
  158. CSSTAT_HITS_M4A1,
  159. CSSTAT_HITS_AUG,
  160. CSSTAT_HITS_SG552,
  161. CSSTAT_HITS_SG550,
  162. CSSTAT_HITS_GALIL,
  163. CSSTAT_HITS_GALILAR,
  164. CSSTAT_HITS_FAMAS,
  165. CSSTAT_HITS_SCOUT,
  166. CSSTAT_HITS_G3SG1,
  167. CSSTAT_HITS_P90,
  168. CSSTAT_HITS_MP5NAVY,
  169. CSSTAT_HITS_TMP,
  170. CSSTAT_HITS_MAC10,
  171. CSSTAT_HITS_UMP45,
  172. CSSTAT_HITS_M3,
  173. CSSTAT_HITS_XM1014,
  174. CSSTAT_HITS_M249,
  175. CSSTAT_HITS_BIZON,
  176. CSSTAT_HITS_MAG7,
  177. CSSTAT_HITS_NEGEV,
  178. CSSTAT_HITS_SAWEDOFF,
  179. CSSTAT_HITS_TEC9,
  180. CSSTAT_HITS_TASER,
  181. CSSTAT_HITS_HKP2000,
  182. CSSTAT_HITS_MP7,
  183. CSSTAT_HITS_MP9,
  184. CSSTAT_HITS_NOVA,
  185. CSSTAT_HITS_P250,
  186. CSSTAT_HITS_SCAR17,
  187. CSSTAT_HITS_SCAR20,
  188. CSSTAT_HITS_SG556,
  189. CSSTAT_HITS_SSG08,
  190. CSSTAT_DAMAGE_DEAGLE,
  191. CSSTAT_DAMAGE_USP,
  192. CSSTAT_DAMAGE_GLOCK,
  193. CSSTAT_DAMAGE_P228,
  194. CSSTAT_DAMAGE_ELITE,
  195. CSSTAT_DAMAGE_FIVESEVEN,
  196. CSSTAT_DAMAGE_AWP,
  197. CSSTAT_DAMAGE_AK47,
  198. CSSTAT_DAMAGE_M4A1,
  199. CSSTAT_DAMAGE_AUG,
  200. CSSTAT_DAMAGE_SG552,
  201. CSSTAT_DAMAGE_SG550,
  202. CSSTAT_DAMAGE_GALIL,
  203. CSSTAT_DAMAGE_GALILAR,
  204. CSSTAT_DAMAGE_FAMAS,
  205. CSSTAT_DAMAGE_SCOUT,
  206. CSSTAT_DAMAGE_G3SG1,
  207. CSSTAT_DAMAGE_P90,
  208. CSSTAT_DAMAGE_MP5NAVY,
  209. CSSTAT_DAMAGE_TMP,
  210. CSSTAT_DAMAGE_MAC10,
  211. CSSTAT_DAMAGE_UMP45,
  212. CSSTAT_DAMAGE_M3,
  213. CSSTAT_DAMAGE_XM1014,
  214. CSSTAT_DAMAGE_M249,
  215. CSSTAT_DAMAGE_BIZON,
  216. CSSTAT_DAMAGE_MAG7,
  217. CSSTAT_DAMAGE_NEGEV,
  218. CSSTAT_DAMAGE_SAWEDOFF,
  219. CSSTAT_DAMAGE_TEC9,
  220. CSSTAT_DAMAGE_TASER,
  221. CSSTAT_DAMAGE_HKP2000,
  222. CSSTAT_DAMAGE_MP7,
  223. CSSTAT_DAMAGE_MP9,
  224. CSSTAT_DAMAGE_NOVA,
  225. CSSTAT_DAMAGE_P250,
  226. CSSTAT_DAMAGE_SCAR17,
  227. CSSTAT_DAMAGE_SCAR20,
  228. CSSTAT_DAMAGE_SG556,
  229. CSSTAT_DAMAGE_SSG08,
  230. CSSTAT_KILLS_HEADSHOT,
  231. CSSTAT_KILLS_ENEMY_BLINDED,
  232. CSSTAT_KILLS_WHILE_BLINDED,
  233. CSSTAT_KILLS_WITH_LAST_ROUND,
  234. CSSTAT_KILLS_ENEMY_WEAPON,
  235. CSSTAT_KILLS_KNIFE_FIGHT,
  236. CSSTAT_KILLS_WHILE_DEFENDING_BOMB,
  237. CSSTAT_KILLS_WITH_STATTRAK_WEAPON,
  238. CSSTAT_DECAL_SPRAYS,
  239. CSSTAT_TOTAL_JUMPS,
  240. CSSTAT_KILLS_WHILE_LAST_PLAYER_ALIVE,
  241. CSSTAT_KILLS_ENEMY_WOUNDED,
  242. CSSTAT_FALL_DAMAGE,
  243. CSSTAT_NUM_HOSTAGES_RESCUED,
  244. CSSTAT_NUM_BROKEN_WINDOWS,
  245. CSSTAT_PROPSBROKEN_ALL,
  246. CSSTAT_PROPSBROKEN_MELON,
  247. CSSTAT_PROPSBROKEN_OFFICEELECTRONICS,
  248. CSSTAT_PROPSBROKEN_OFFICERADIO,
  249. CSSTAT_PROPSBROKEN_OFFICEJUNK,
  250. CSSTAT_PROPSBROKEN_ITALY_MELON,
  251. CSSTAT_KILLS_AGAINST_ZOOMED_SNIPER,
  252. CSSTAT_WEAPONS_DONATED,
  253. CSSTAT_ITEMS_PURCHASED,
  254. CSSTAT_MONEY_SPENT,
  255. CSSTAT_DOMINATIONS,
  256. CSSTAT_DOMINATION_OVERKILLS,
  257. CSSTAT_REVENGES,
  258. CSSTAT_MVPS,
  259. CSSTAT_CONTRIBUTION_SCORE,
  260. CSSTAT_GG_PROGRESSIVE_CONTRIBUTION_SCORE,
  261. CSSTAT_GRENADE_DAMAGE,
  262. CSSTAT_GRENADE_POSTHUMOUSKILLS,
  263. CSSTAT_GRENADES_THROWN,
  264. CSTAT_ITEMS_DROPPED_VALUE,
  265. //Map win stats
  266. CSSTAT_MAP_WINS_CS_MILITIA,
  267. CSSTAT_MAP_WINS_CS_ASSAULT,
  268. CSSTAT_MAP_WINS_CS_ITALY,
  269. CSSTAT_MAP_WINS_CS_OFFICE,
  270. CSSTAT_MAP_WINS_DE_AZTEC,
  271. CSSTAT_MAP_WINS_DE_CBBLE,
  272. CSSTAT_MAP_WINS_DE_DUST2,
  273. CSSTAT_MAP_WINS_DE_DUST,
  274. CSSTAT_MAP_WINS_DE_INFERNO,
  275. CSSTAT_MAP_WINS_DE_NUKE,
  276. CSSTAT_MAP_WINS_DE_PIRANESI,
  277. CSSTAT_MAP_WINS_DE_PRODIGY,
  278. CSSTAT_MAP_WINS_DE_LAKE,
  279. CSSTAT_MAP_WINS_DE_SAFEHOUSE,
  280. CSSTAT_MAP_WINS_DE_SHORTTRAIN,
  281. CSSTAT_MAP_WINS_DE_TRAIN,
  282. CSSTAT_MAP_WINS_DE_SUGARCANE,
  283. CSSTAT_MAP_WINS_DE_STMARC,
  284. CSSTAT_MAP_WINS_DE_BANK,
  285. CSSTAT_MAP_WINS_DE_EMBASSY,
  286. CSSTAT_MAP_WINS_DE_DEPOT,
  287. CSSTAT_MAP_WINS_DE_VERTIGO,
  288. CSSTAT_MAP_WINS_DE_BALKAN,
  289. CSSTAT_MAP_WINS_AR_MONASTERY,
  290. CSSTAT_MAP_WINS_AR_SHOOTS,
  291. CSSTAT_MAP_WINS_AR_BAGGAGE,
  292. CSSTAT_MAP_ROUNDS_CS_MILITIA,
  293. CSSTAT_MAP_ROUNDS_CS_ASSAULT,
  294. CSSTAT_MAP_ROUNDS_CS_ITALY,
  295. CSSTAT_MAP_ROUNDS_CS_OFFICE,
  296. CSSTAT_MAP_ROUNDS_DE_AZTEC,
  297. CSSTAT_MAP_ROUNDS_DE_CBBLE,
  298. CSSTAT_MAP_ROUNDS_DE_DUST2,
  299. CSSTAT_MAP_ROUNDS_DE_DUST,
  300. CSSTAT_MAP_ROUNDS_DE_INFERNO,
  301. CSSTAT_MAP_ROUNDS_DE_NUKE,
  302. CSSTAT_MAP_ROUNDS_DE_PIRANESI,
  303. CSSTAT_MAP_ROUNDS_DE_PRODIGY,
  304. CSSTAT_MAP_ROUNDS_DE_LAKE,
  305. CSSTAT_MAP_ROUNDS_DE_SAFEHOUSE,
  306. CSSTAT_MAP_ROUNDS_DE_SHORTTRAIN,
  307. CSSTAT_MAP_ROUNDS_DE_TRAIN,
  308. CSSTAT_MAP_ROUNDS_DE_SUGARCANE,
  309. CSSTAT_MAP_ROUNDS_DE_STMARC,
  310. CSSTAT_MAP_ROUNDS_DE_BANK,
  311. CSSTAT_MAP_ROUNDS_DE_EMBASSY,
  312. CSSTAT_MAP_ROUNDS_DE_DEPOT,
  313. CSSTAT_MAP_ROUNDS_DE_VERTIGO,
  314. CSSTAT_MAP_ROUNDS_DE_BALKAN,
  315. CSSTAT_MAP_ROUNDS_AR_MONASTERY,
  316. CSSTAT_MAP_ROUNDS_AR_SHOOTS,
  317. CSSTAT_MAP_ROUNDS_AR_BAGGAGE,
  318. CSSTAT_MAP_MATCHES_WON_SHOOTS,
  319. CSSTAT_MAP_MATCHES_WON_BAGGAGE,
  320. CSSTAT_MAP_MATCHES_WON_LAKE,
  321. CSSTAT_MAP_MATCHES_WON_SUGARCANE,
  322. CSSTAT_MAP_MATCHES_WON_STMARC,
  323. CSSTAT_MAP_MATCHES_WON_BANK,
  324. CSSTAT_MAP_MATCHES_WON_EMBASSY,
  325. CSSTAT_MAP_MATCHES_WON_DEPOT,
  326. CSSTAT_MAP_MATCHES_WON_SAFEHOUSE,
  327. CSSTAT_MAP_MATCHES_WON_SHORTTRAIN,
  328. CSSTAT_MAP_MATCHES_WON_TRAIN,
  329. CSSTAT_MATCHES_WON,
  330. CSSTAT_MATCHES_DRAW,
  331. CSSTAT_MATCHES_PLAYED,
  332. CSSTAT_GUN_GAME_MATCHES_WON,
  333. CSSTAT_GUN_GAME_MATCHES_PLAYED,
  334. CSSTAT_GUN_GAME_PROGRESSIVE_MATCHES_WON,
  335. CSSTAT_GUN_GAME_SELECT_MATCHES_WON,
  336. CSSTAT_GUN_GAME_TRBOMB_MATCHES_WON,
  337. CSSTAT_LASTMATCH_CONTRIBUTION_SCORE,
  338. CSSTAT_LASTMATCH_GG_PROGRESSIVE_CONTRIBUTION_SCORE,
  339. CSSTAT_LASTMATCH_T_ROUNDS_WON,
  340. CSSTAT_LASTMATCH_CT_ROUNDS_WON,
  341. CSSTAT_LASTMATCH_ROUNDS_WON,
  342. CSTAT_LASTMATCH_ROUNDS_PLAYED,
  343. CSSTAT_LASTMATCH_KILLS,
  344. CSSTAT_LASTMATCH_DEATHS,
  345. CSSTAT_LASTMATCH_MVPS,
  346. CSSTAT_LASTMATCH_DAMAGE,
  347. CSSTAT_LASTMATCH_MONEYSPENT,
  348. CSSTAT_LASTMATCH_DOMINATIONS,
  349. CSSTAT_LASTMATCH_REVENGES,
  350. CSSTAT_LASTMATCH_MAX_PLAYERS,
  351. CSSTAT_LASTMATCH_FAVWEAPON_ID,
  352. CSSTAT_LASTMATCH_FAVWEAPON_SHOTS,
  353. CSSTAT_LASTMATCH_FAVWEAPON_HITS,
  354. CSSTAT_LASTMATCH_FAVWEAPON_KILLS,
  355. CSSTAT_MAX //Must be last entry.
  356. };
  357. #define CSSTAT_FIRST (CSSTAT_UNDEFINED+1)
  358. #define CSSTAT_LAST (CSSTAT_MAX-1)
  359. //
  360. // CS Game Stats Flags
  361. //
  362. #define CSSTAT_PRIORITY_MASK 0x000F
  363. #define CSSTAT_PRIORITY_NEVER 0x0000 // not sent to client
  364. #define CSSTAT_PRIORITY_ENDROUND 0x0001 // sent at end of round
  365. #define CSSTAT_PRIORITY_LOW 0x0002 // sent every 2500ms
  366. #define CSSTAT_PRIORITY_HIGH 0x0003 // sent every 250ms
  367. struct CSStatProperty
  368. {
  369. const char* szSteamName; // name of the stat on steam
  370. const char* szLocalizationToken; // localization token for the stat
  371. uint flags; // priority flags for sending to client
  372. };
  373. extern CSStatProperty CSStatProperty_Table[];
  374. //=============================================================================
  375. //
  376. // CS Player Round Stats
  377. //
  378. struct StatsCollection_t
  379. {
  380. StatsCollection_t() { Reset(); }
  381. void Reset()
  382. {
  383. for ( int i = 0; i < ARRAYSIZE( m_iValue ); i++ )
  384. {
  385. m_iValue[i] = 0;
  386. }
  387. }
  388. int operator[] ( int index ) const
  389. {
  390. Assert(index >= 0 && index < ARRAYSIZE(m_iValue));
  391. return m_iValue[index];
  392. }
  393. int& operator[] ( int index )
  394. {
  395. Assert(index >= 0 && index < ARRAYSIZE(m_iValue));
  396. return m_iValue[index];
  397. }
  398. void Aggregate( const StatsCollection_t& other );
  399. private:
  400. int m_iValue[CSSTAT_MAX];
  401. };
  402. struct RoundStatsDirectAverage_t
  403. {
  404. float m_fStat[CSSTAT_MAX];
  405. RoundStatsDirectAverage_t()
  406. {
  407. Reset();
  408. }
  409. void Reset()
  410. {
  411. for ( int i = 0; i < ARRAYSIZE( m_fStat ); i++ )
  412. {
  413. m_fStat[i] = 0;
  414. }
  415. }
  416. RoundStatsDirectAverage_t& operator +=( const StatsCollection_t &other )
  417. {
  418. for ( int i = 0; i < ARRAYSIZE( m_fStat ); i++ )
  419. {
  420. m_fStat[i] += other[i];
  421. }
  422. return *this;
  423. }
  424. RoundStatsDirectAverage_t& operator /=( const float &divisor)
  425. {
  426. if (divisor > 0)
  427. {
  428. for ( int i = 0; i < ARRAYSIZE( m_fStat ); i++ )
  429. {
  430. m_fStat[i] /= divisor;
  431. }
  432. }
  433. return *this;
  434. }
  435. RoundStatsDirectAverage_t& operator *=( const float &divisor)
  436. {
  437. for ( int i = 0; i < ARRAYSIZE( m_fStat ); i++ )
  438. {
  439. m_fStat[i] *= divisor;
  440. }
  441. return *this;
  442. }
  443. };
  444. struct RoundStatsRollingAverage_t
  445. {
  446. float m_fStat[CSSTAT_MAX];
  447. int m_numberOfDataSets;
  448. RoundStatsRollingAverage_t()
  449. {
  450. Reset();
  451. }
  452. void Reset()
  453. {
  454. for ( int i = 0; i < ARRAYSIZE( m_fStat ); i++ )
  455. {
  456. m_fStat[i] = 0;
  457. }
  458. m_numberOfDataSets = 0;
  459. }
  460. RoundStatsRollingAverage_t& operator +=( const RoundStatsRollingAverage_t &other )
  461. {
  462. for ( int i = 0; i < ARRAYSIZE( m_fStat ); i++ )
  463. {
  464. m_fStat[i] += other.m_fStat[i];
  465. }
  466. return *this;
  467. }
  468. RoundStatsRollingAverage_t& operator +=( const StatsCollection_t &other )
  469. {
  470. for ( int i = 0; i < ARRAYSIZE( m_fStat ); i++ )
  471. {
  472. m_fStat[i] += other[i];
  473. }
  474. return *this;
  475. }
  476. RoundStatsRollingAverage_t& operator /=( const float &divisor)
  477. {
  478. if (divisor > 0)
  479. {
  480. for ( int i = 0; i < ARRAYSIZE( m_fStat ); i++ )
  481. {
  482. m_fStat[i] /= divisor;
  483. }
  484. }
  485. return *this;
  486. }
  487. void RollDataSetIntoAverage ( const RoundStatsRollingAverage_t &other )
  488. {
  489. for ( int i = 0; i < ARRAYSIZE( m_fStat ); i++ )
  490. {
  491. m_fStat[i] *= m_numberOfDataSets;
  492. m_fStat[i] += other.m_fStat[i];
  493. m_fStat[i] /= (m_numberOfDataSets + 1);
  494. }
  495. m_numberOfDataSets++;
  496. }
  497. };
  498. enum CSGameStatsVersions_t
  499. {
  500. CS_GAMESTATS_FILE_VERSION = 006,
  501. CS_GAMESTATS_MAGIC = 0xDEADBEEF
  502. };
  503. struct CS_Gamestats_Version_t
  504. {
  505. int m_iMagic; // always CS_GAMESTATS_MAGIC
  506. int m_iVersion;
  507. };
  508. struct KillStats_t
  509. {
  510. KillStats_t() { Reset(); }
  511. void Reset()
  512. {
  513. Q_memset( iNumKilled, 0, sizeof( iNumKilled ) );
  514. Q_memset( iNumKilledBy, 0, sizeof( iNumKilledBy ) );
  515. Q_memset( iNumKilledByUnanswered, 0, sizeof( iNumKilledByUnanswered ) );
  516. }
  517. int iNumKilled[MAX_PLAYERS+1]; // how many times this player has killed each other player
  518. int iNumKilledBy[MAX_PLAYERS+1]; // how many times this player has been killed by each other player
  519. int iNumKilledByUnanswered[MAX_PLAYERS+1]; // how many unanswered kills this player has been dealt by each other player
  520. };
  521. //=============================================================================
  522. //
  523. // CS Player Stats
  524. //
  525. struct PlayerStats_t
  526. {
  527. PlayerStats_t()
  528. {
  529. Reset();
  530. }
  531. void Reset()
  532. {
  533. statsDelta.Reset();
  534. statsCurrentRound.Reset();
  535. statsCurrentMatch.Reset();
  536. statsKills.Reset();
  537. }
  538. PlayerStats_t( const PlayerStats_t &other )
  539. {
  540. statsDelta = other.statsDelta;
  541. statsCurrentRound = other.statsCurrentRound;
  542. statsCurrentMatch = other.statsCurrentMatch;
  543. }
  544. StatsCollection_t statsDelta;
  545. StatsCollection_t statsCurrentRound;
  546. StatsCollection_t statsCurrentMatch;
  547. KillStats_t statsKills;
  548. };
  549. struct WeaponName_StatId
  550. {
  551. CSWeaponID weaponId;
  552. CSStatType_t killStatId;
  553. CSStatType_t shotStatId;
  554. CSStatType_t hitStatId;
  555. CSStatType_t damageStatId;
  556. };
  557. struct MapName_MapStatId
  558. {
  559. char* szMapName;
  560. CSStatType_t statWinsId;
  561. CSStatType_t statRoundsId;
  562. CSStatType_t matchesWonId;
  563. };
  564. extern const MapName_MapStatId MapName_StatId_Table[];
  565. //A mapping from weapon names to weapon stat IDs
  566. extern const WeaponName_StatId WeaponName_StatId_Table[];
  567. //Used to look up the appropriate entry by the ID of the actual weapon
  568. const WeaponName_StatId& GetWeaponTableEntryFromWeaponId(CSWeaponID id);
  569. #endif // CS_GAMESTATS_SHARED_H