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.

129 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #pragma warning (disable:4786)
  9. #include <string>
  10. #include "Player.h"
  11. #include "MatchInfo.h"
  12. using namespace std;
  13. CPlayer::CPlayer()
  14. :teams()
  15. {
  16. WONID=pid=svrPID=-1;
  17. logontime=logofftime=reconnects=0;
  18. name="uninitted";
  19. }
  20. void CPlayer::nameFound(time_t t, string alias)
  21. {
  22. if (aliases.atTime(t)!=alias)
  23. {
  24. aliases.add(t,alias);
  25. }
  26. name=aliases.favourite();
  27. }
  28. time_t CPlayer::plr_per_team_data::timeOn()
  29. {
  30. /*if (logofftime==0)
  31. {
  32. logofftime=g_pMatchInfo->logCloseTime();
  33. }
  34. return logofftime-logontime;
  35. */
  36. return timeon;
  37. }
  38. time_t CPlayer::totalTimeOn()
  39. {
  40. if (logofftime==0)
  41. {
  42. logofftime=g_pMatchInfo->logCloseTime();
  43. }
  44. return logofftime-logontime;
  45. }
  46. double CPlayer::plr_per_team_data::rank()
  47. {
  48. double d = (kills-deaths);
  49. double time=((double)timeOn())/1000.0;
  50. if (time < .000001)
  51. return d;
  52. return d/time;
  53. }
  54. string CPlayer::plr_per_team_data::faveWeapon()
  55. {
  56. if (faveweapon=="" && weaponKills.begin()!=weaponKills.end())
  57. {
  58. faveweapkills=0;
  59. //noKills=false;
  60. map<string,int>::iterator weapIt=weaponKills.begin();
  61. string& fave=(string&) (*weapIt).first;
  62. int faveKills=(*weapIt).second;
  63. for (weapIt;weapIt!=weaponKills.end();++weapIt)
  64. {
  65. const string& weapName=(*weapIt).first;
  66. int kills=(*weapIt).second;
  67. if (kills < faveKills)
  68. continue;
  69. fave=weapName;
  70. faveKills=kills;
  71. }
  72. faveweapkills=faveKills;
  73. faveweapon=fave;
  74. }
  75. return faveweapon;
  76. }
  77. int CPlayer::plr_per_team_data::faveWeapKills()
  78. {
  79. if (faveweapkills==0)
  80. {
  81. //calculate favourite weapon stats
  82. faveWeapon();
  83. }
  84. return faveweapkills;
  85. }
  86. void CPlayer::merge()
  87. {
  88. perteam[ALL_TEAMS].kills=perteam[0].kills+perteam[1].kills+perteam[2].kills+perteam[3].kills;
  89. perteam[ALL_TEAMS].deaths=perteam[0].deaths+perteam[1].deaths+perteam[2].deaths+perteam[3].deaths;
  90. perteam[ALL_TEAMS].suicides=perteam[0].suicides+perteam[1].suicides+perteam[2].suicides+perteam[3].suicides;
  91. perteam[ALL_TEAMS].teamkills=perteam[0].teamkills+perteam[1].teamkills+perteam[2].teamkills+perteam[3].teamkills;
  92. perteam[ALL_TEAMS].teamkilled=perteam[0].teamkilled+perteam[1].teamkilled+perteam[2].teamkilled+perteam[3].teamkilled;
  93. perteam[ALL_TEAMS].timeon=perteam[0].timeon+perteam[1].timeon+perteam[2].timeon+perteam[3].timeon;
  94. for (int i=0;i<MAX_TEAMS;i++)
  95. {
  96. map<std::string,int>::iterator it;
  97. for (it=perteam[i].weaponKills.begin();it!=perteam[i].weaponKills.end();++it)
  98. {
  99. string weapname=(*it).first;
  100. int kills=(*it).second;
  101. perteam[ALL_TEAMS].weaponKills[weapname]+=kills;
  102. }
  103. }
  104. //this is probably only a shallow copy, but that's ok
  105. perteam[ALL_TEAMS].classesplayed=allclassesplayed;
  106. }