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.

233 lines
7.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implementation of CWhoKilledWho
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //------------------------------------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "WhoKilledWho.h"
  14. //------------------------------------------------------------------------------------------------------
  15. // Function: CWhoKilledWho::init
  16. // Purpose: initializes the object
  17. //------------------------------------------------------------------------------------------------------
  18. void CWhoKilledWho::init()
  19. {
  20. nextbid=0;
  21. if (kills) delete [] kills;
  22. if (deaths) delete [] deaths;
  23. deaths=kills=NULL;
  24. }
  25. void CWhoKilledWho::makeBidMap()
  26. {
  27. int nextbid=0;
  28. for (int t=0;t<MAX_TEAMS;t++)
  29. {
  30. CPlayerListIterator it=g_pMatchInfo->playerBegin();
  31. for (it;it!=g_pMatchInfo->playerEnd();++it)
  32. {
  33. const PID& pid=(*it).first;
  34. CPlayer& p=(*it).second;
  35. if (!p.teams.contains(t))
  36. continue;
  37. pair<int,PID> pr(t,pid);
  38. bidMap[pr]=nextbid;
  39. bidMap2[nextbid]=pr;
  40. nextbid++;
  41. }
  42. }
  43. size=nextbid;
  44. }
  45. //------------------------------------------------------------------------------------------------------
  46. // Function: CWhoKilledWho::generate
  47. // Purpose: generates intermediate data from the match info
  48. //------------------------------------------------------------------------------------------------------
  49. void CWhoKilledWho::generate()
  50. {
  51. init();
  52. makeBidMap();
  53. if (size==0)
  54. return;
  55. kills=new int[size*size];
  56. memset(kills,0,sizeof(int)*size*size);
  57. deaths=new int[size];
  58. memset(deaths,0,sizeof(int)*size);
  59. //now the pids table is all full of pids and you index it using Board IDs (bids)
  60. //also there is a bids table so you know which pid each board entry has.
  61. CEventListIterator it;
  62. for (it=g_pMatchInfo->eventList()->begin(); it != g_pMatchInfo->eventList()->end(); ++it)
  63. {
  64. if ((*it)->getType()==CLogEvent::SUICIDE || (*it)->getType()==CLogEvent::KILLED_BY_WORLD)
  65. {
  66. PID plr=(*it)->getArgument(0)->asPlayerGetPID();
  67. int plrTeam=g_pMatchInfo->playerList()[plr].teams.atTime((*it)->getTime());
  68. pair<int,PID> plrpr(plrTeam,plr);
  69. int plrbid=bidMap[plrpr];
  70. kills[plrbid*size+plrbid]++;
  71. deaths[plrbid]++;
  72. }
  73. else if ((*it)->getType()==CLogEvent::FRAG || (*it)->getType()==CLogEvent::TEAM_FRAG)
  74. {
  75. PID killer=(*it)->getArgument(0)->asPlayerGetPID();
  76. PID killee=(*it)->getArgument(1)->asPlayerGetPID();
  77. int killerTeam=g_pMatchInfo->playerList()[killer].teams.atTime((*it)->getTime());
  78. int killeeTeam=g_pMatchInfo->playerList()[killee].teams.atTime((*it)->getTime());
  79. pair<int,PID> killerpr(killerTeam,killer);
  80. pair<int,PID> killeepr(killeeTeam,killee);
  81. int killerbid=bidMap[killerpr];
  82. int killeebid=bidMap[killeepr];
  83. kills[killerbid*size+killeebid]++;
  84. deaths[killeebid]++;
  85. }
  86. }
  87. }
  88. //------------------------------------------------------------------------------------------------------
  89. // Function: CWhoKilledWho::getCellClass
  90. // Purpose: Helper function that returns the class of a cell on the board depending
  91. // on where it occurs in the board.
  92. // Input: u - the x position of the cell
  93. // v - the y position of the cell
  94. // Output: const char*
  95. //------------------------------------------------------------------------------------------------------
  96. const char* CWhoKilledWho::getCellClass(int u,int v)
  97. {
  98. char* tdclass;
  99. if (u == v+1)
  100. tdclass="class=boardcell_br";
  101. else if (u>v)
  102. tdclass="class=boardcell_r";
  103. if (u == v-1)
  104. tdclass="class=boardcell_br";
  105. else if (u<v)
  106. tdclass="class=boardcell_b";
  107. else if (u == v)
  108. tdclass="class=boardcell_br";
  109. return tdclass;
  110. }
  111. //------------------------------------------------------------------------------------------------------
  112. // Function: CWhoKilledWho::writeHTML
  113. // Purpose: takes the intermediate data generated by generate() and writes out
  114. // HTML to the specified HTML file object
  115. // Input: html - the object to write the output to
  116. //------------------------------------------------------------------------------------------------------
  117. void CWhoKilledWho::writeHTML(CHTMLFile& html)
  118. {
  119. if (size==0)
  120. return;
  121. int numcols=size+2;
  122. int numrows=size+4;
  123. int i=0,j=0;
  124. int playerNameWid=120;
  125. int cellWid=20;
  126. int lastColWid=30;
  127. int tableWid=playerNameWid+size*cellWid+lastColWid;
  128. html.write("<img src=\"%s/detailed.gif\">",g_pApp->supportHTTPPath.c_str());
  129. string jshttppath(g_pApp->supportHTTPPath);
  130. jshttppath+="/support.js";
  131. html.write("<script language=\"JavaScript\" src=\"%s\"></script>\n",jshttppath.c_str());
  132. html.write("<script language=\"JavaScript\">\n<!--\nthisBrowser = new BrowserType();\nthisBrowser.VerifyIE5()//-->\n</script>\n");
  133. html.write("<script language=\"JavaScript\"> thisBrowser.writeDetailTableTag(%li,%li,%li); </script>\n",tableWid,numrows,numcols);
  134. //print columns
  135. html.write("<tr class=header align=center> <td width=%li align =left><font class=boardtext>Player</font></td>\n",playerNameWid);
  136. for (i=0;i<size;i++)
  137. {
  138. //int tid= g_pMatchInfo->playerTeamID(pids[i]);
  139. //int tid=3;
  140. int tid=bidMap2[i].first;
  141. html.write("<td width=%li><font class=player%s>%2d</font></th>\n",cellWid,Util::teamcolormap[tid],i);
  142. }
  143. html.write("<td align=left width=%li><font class=boardtext>Kills</font></th>\n",lastColWid);
  144. html.write("</tr>\n");
  145. int totalkills=0;
  146. int killerbid;
  147. for (killerbid=0;killerbid<size;++killerbid)
  148. {
  149. int tot=0;
  150. char truncatedPlayerName[21];
  151. strncpy(truncatedPlayerName, g_pMatchInfo->playerName(bidMap2[killerbid].second).c_str(),20);
  152. truncatedPlayerName[20]=0;
  153. //int tid=g_pMatchInfo->playerTeamID(pids[killerbid]);
  154. int tid=bidMap2[killerbid].first;
  155. html.write("<tr><td class=boardcell_b align=left width=%li><font class=player%s><nobr>%d. %s</nobr></font></th>\n",playerNameWid,Util::teamcolormap[tid], killerbid,truncatedPlayerName);
  156. int killeebid;
  157. for (killeebid=0;killeebid<size;++killeebid)
  158. {
  159. const char* tdclass=getCellClass(killeebid,killerbid);
  160. html.write("<td align=center width=%li %s><font class=boardtext>%i</font></td>\n",cellWid,tdclass,kills[killerbid*size+killeebid]);
  161. if (killeebid != killerbid)
  162. tot+=kills[killerbid*size+killeebid];
  163. else
  164. tot-=kills[killerbid*size+killeebid];
  165. }
  166. totalkills+=tot;
  167. html.write("<td align=center width=%li><font class=boardtext>%i</font></td>\n",lastColWid,tot);
  168. html.write("</tr>\n");
  169. }
  170. html.write("<tr align=left> <td><font class=boardtext>Deaths</font></th>\n");
  171. int totaldeaths=0;
  172. for (i=0;i<size;i++)
  173. {
  174. html.write("<td align=center><font class=boardtext>%i</font></td>\n",deaths[i]);
  175. totaldeaths+=deaths[i];
  176. }
  177. //html.write("<td align=left ><font class=boardtext>%3i\\%3i</font></td>\n",totaldeaths,totalkills);
  178. html.write("<td></td>\n");
  179. html.write("</tr>\n");
  180. html.write("</table>\n");
  181. }
  182. //------------------------------------------------------------------------------------------------------
  183. // Function: CWhoKilledWho::~CWhoKilledWho
  184. // Purpose: destructor
  185. //------------------------------------------------------------------------------------------------------
  186. CWhoKilledWho::~CWhoKilledWho()
  187. {
  188. if (kills) delete [] kills;
  189. if (deaths) delete [] deaths;
  190. }