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.

126 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implementation of CScoreboard
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //------------------------------------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "Scoreboard.h"
  14. //------------------------------------------------------------------------------------------------------
  15. // Function: CScoreboard::init
  16. // Purpose: initializes the object
  17. //------------------------------------------------------------------------------------------------------
  18. void CScoreboard::init()
  19. {
  20. }
  21. //------------------------------------------------------------------------------------------------------
  22. // Function: CScoreboard::generate
  23. // Purpose: generates intermediate data based on match info
  24. //------------------------------------------------------------------------------------------------------
  25. void CScoreboard::generate()
  26. {
  27. }
  28. //------------------------------------------------------------------------------------------------------
  29. // Function: CScoreboard::writeHTML
  30. // Purpose: generates html from the intermediate data generated by generate()
  31. // Input: html - the html file to write the html code into
  32. //------------------------------------------------------------------------------------------------------
  33. void CScoreboard::writeHTML(CHTMLFile& html)
  34. {
  35. CPlayerListIterator i;
  36. int t;
  37. bool teamFound=false;
  38. for (t=0;t<MAX_TEAMS;t++)
  39. {
  40. if (!g_pMatchInfo->teamExists(t))
  41. continue;
  42. if (!teamFound)
  43. {
  44. html.write("<p>");
  45. html.write("<img src=\"%s/scores.gif\">",g_pApp->supportHTTPPath.c_str());
  46. teamFound=true;
  47. }
  48. int totalkills=0;
  49. int totaldeaths=0;
  50. double teamrank=0;
  51. int numplrs=0;
  52. html.write("<table cellpadding=3 cellspacing=0 border=0 class=scores>");
  53. html.write("<tr class=header>");
  54. html.write("<td ><font class=boardtext>%s</font></td>",g_pMatchInfo->teamName(t).c_str());
  55. html.write("<td><font class=boardtext>Kills</font></td>");
  56. html.write("<td><font class=boardtext>Deaths</font></td>");
  57. html.write("<td><font class=boardtext>Rank</font></td>");
  58. html.write("</tr>");
  59. multimap<double,CPlayer> ranksort;
  60. for (i=g_pMatchInfo->playerBegin();i!=g_pMatchInfo->playerEnd();++i)
  61. {
  62. pair<PID,CPlayer> plr=(*i);
  63. PID pid=plr.first;
  64. CPlayer& p=plr.second;
  65. if (p.teams.contains(t))
  66. {
  67. double rank=p.perteam[t].rank();
  68. pair<double,CPlayer> insertme(rank,p);
  69. ranksort.insert(insertme);
  70. //ranksort[rank]=p;
  71. }
  72. }
  73. multimap<double,CPlayer>::reverse_iterator i2;
  74. for (i2=ranksort.rbegin();i2!=ranksort.rend();++i2)
  75. {
  76. double rank=(*i2).first;
  77. CPlayer p=(*i2).second;
  78. if (!p.teams.contains(t))
  79. {
  80. continue;
  81. }
  82. html.write("<tr>\n");
  83. html.write("\n");
  84. html.write("<td width=140><font class=player%s>%s</font></td>\n",Util::teamcolormap[t],p.name.c_str());
  85. html.write("<td width=100><font class=boardtext>%li</font></td>\n",p.perteam[t].kills);
  86. html.write("<td width=100><font class=boardtext>%li</font></td>\n",p.perteam[t].deaths);
  87. html.write("<td width=100><font class=boardtext>%.2lf</font></td>\n",rank);
  88. html.write("</tr>\n");
  89. totalkills+=p.perteam[t].kills;
  90. totaldeaths+=p.perteam[t].deaths;
  91. teamrank+=rank;
  92. numplrs++;
  93. }
  94. html.write("<tr>");
  95. html.write("<td colspan=4><hr></td>");
  96. html.write("</tr>");
  97. html.write("<tr>");
  98. html.write("<td><font class=boardtext>totals</font></td>");
  99. html.write("<td><font class=boardtext>%li</font></td>",totalkills);
  100. html.write("<td><font class=boardtext>%li</font></td>",totaldeaths);
  101. html.write("<td><font class=boardtext>%.2lf (avg)</font></td>",teamrank/numplrs);
  102. html.write("</tr>");
  103. html.write("</table>\n<p>\n");
  104. }
  105. }