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.

159 lines
6.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implementation of CDialogueReadout
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //------------------------------------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "DialogueReadout.h"
  14. #include "util.h"
  15. //------------------------------------------------------------------------------------------------------
  16. // Function: CDialogueReadout::writeHTML
  17. // Purpose: generates and writes the report. generate() is not used in this object
  18. // because there is no real intermediate data. Really data is just taken from the
  19. // event list, massaged abit, and written out to the html file. There is no calculation
  20. // of stats or figures so no intermedidate data creation is needed.
  21. // Input: html - the html file that we want to write to.
  22. //------------------------------------------------------------------------------------------------------
  23. void CDialogueReadout::writeHTML(CHTMLFile& html)
  24. {
  25. html.write("<img src=\"%s/game.dialog.on.gif\">\n",g_pApp->supportHTTPPath.c_str());
  26. html.div("dialog");
  27. CEventListIterator it;
  28. bool MM2Messages=false;
  29. if (g_pApp->cmdLineSwitches["displaymm2"]=="on" ||
  30. g_pApp->cmdLineSwitches["displaymm2"]=="yes" ||
  31. g_pApp->cmdLineSwitches["displaymm2"]=="true" ||
  32. g_pApp->cmdLineSwitches["displaymm2"]=="1")
  33. MM2Messages=true;
  34. for (it=g_pMatchInfo->eventList()->begin(); it != g_pMatchInfo->eventList()->end(); ++it)
  35. {
  36. if ((*it)->getType()==CLogEvent::SAY || (MM2Messages && ((*it)->getType()==CLogEvent::SAY_TEAM)))
  37. {
  38. char talked[512]={0};
  39. PID talkerPID=(*it)->getArgument(0)->asPlayerGetPID();
  40. string talkerName=(*it)->getArgument(0)->asPlayerGetName();
  41. for (int i=1;(*it)->getArgument(i);i++)
  42. {
  43. char temp[512];
  44. (*it)->getArgument(i)->getStringValue(temp);
  45. strcat(talked,"\"");
  46. strcat(talked,temp);
  47. strcat(talked,"\"");
  48. }
  49. bool isTeamMsg= (*it)->getType()==CLogEvent::SAY_TEAM;
  50. int teamID=g_pMatchInfo->playerList()[talkerPID].teams.atTime((*it)->getTime());
  51. const char* aa;
  52. const char* bb;
  53. if (teamID<4 && teamID >= 0)
  54. {
  55. aa="player";
  56. bb=Util::teamcolormap[teamID];
  57. }
  58. else
  59. {
  60. aa="whitetext";
  61. bb="";
  62. }
  63. html.write("<tr><td><font class=%s%s>%s%s:</font><font color=white> %s</font></tr></td>\n",aa,bb,talkerName.c_str(),isTeamMsg?" (Team)":"",talked);
  64. html.br();
  65. }
  66. else if ( (*it)->getType()==CLogEvent::KILLED_BY_WORLD)
  67. {
  68. PID plr=(*it)->getArgument(0)->asPlayerGetPID();
  69. string plrName=(*it)->getArgument(0)->asPlayerGetName();
  70. int teamID=g_pMatchInfo->playerList()[plr].teams.atTime((*it)->getTime());
  71. html.write("<tr><td><font class=player%s>%s</font><font color=white> died.</font></tr></td>\n",Util::teamcolormap[teamID],plrName.c_str());
  72. html.br();
  73. }
  74. else if ((*it)->getType()==CLogEvent::SUICIDE)
  75. {
  76. PID plr=(*it)->getArgument(0)->asPlayerGetPID();
  77. string plrName=(*it)->getArgument(0)->asPlayerGetName();
  78. int teamID=g_pMatchInfo->playerList()[plr].teams.atTime((*it)->getTime());
  79. html.write("<tr><td><font class=player%s>%s</font><font color=white> committed suicide.</font></tr></td>\n",Util::teamcolormap[teamID],plrName.c_str());
  80. html.br();
  81. }
  82. else if ((*it)->getType()==CLogEvent::TEAM_JOIN)
  83. {
  84. PID plr=(*it)->getArgument(0)->asPlayerGetPID();
  85. string plrName=(*it)->getArgument(0)->asPlayerGetName();
  86. time_t eventtime=(*it)->getTime();
  87. bool firstJoin=!g_pMatchInfo->playerList()[plr].teams.anythingAtTime(eventtime-1);
  88. int oldTeamID=g_pMatchInfo->playerList()[plr].teams.atTime(eventtime-1);
  89. int teamID=g_pMatchInfo->playerList()[plr].teams.atTime(eventtime);
  90. string teamName=g_pMatchInfo->teamName(teamID);
  91. if (firstJoin)
  92. html.write("<tr><td><font class=player%s>%s</font><font color=white> joined team <font class=player%s>%s</font>.</font></tr></td>\n",Util::teamcolormap[teamID],plrName.c_str(),Util::teamcolormap[teamID],teamName.c_str());
  93. else
  94. html.write("<tr><td><font class=player%s>%s</font><font color=white> changed teams to <font class=player%s>%s</font>.</font></tr></td>\n",Util::teamcolormap[oldTeamID],plrName.c_str(),Util::teamcolormap[teamID],teamName.c_str());
  95. html.br();
  96. }
  97. else if ((*it)->getType()==CLogEvent::FRAG)
  98. {
  99. PID killer=(*it)->getArgument(0)->asPlayerGetPID();
  100. string killerName=(*it)->getArgument(0)->asPlayerGetName();
  101. PID killee=(*it)->getArgument(1)->asPlayerGetPID();
  102. string killeeName=(*it)->getArgument(1)->asPlayerGetName();
  103. string weaponName = (*it)->getArgument(2)->getStringValue();
  104. int killerTeamID=g_pMatchInfo->playerList()[killer].teams.atTime((*it)->getTime());
  105. int killeeTeamID=g_pMatchInfo->playerList()[killee].teams.atTime((*it)->getTime());
  106. bool countKill=true;
  107. //gotta account for timer/infection double kills for medics!
  108. if (weaponName=="infection")
  109. {
  110. //test to see if the previous event was a timer from the same player, and a kill, and with the timer.
  111. CEventListIterator it2=it;
  112. if ((--it2)!=g_pMatchInfo->eventList()->begin())
  113. {
  114. if ((*it2)->getType() == CLogEvent::FRAG)
  115. if ((*it2)->getArgument(2)->getStringValue()=="timer")
  116. if ((*it2)->getArgument(0)->asPlayerGetPID()==killer)
  117. countKill=false;
  118. }
  119. }
  120. if (countKill)
  121. {
  122. html.write("<tr><td><font class=player%s>%s</font><font color=white> killed </font><font class=player%s>%s</font><font color=white> with %s. </font></tr></td>\n",
  123. Util::teamcolormap[killerTeamID],killerName.c_str(),Util::teamcolormap[killeeTeamID],killeeName.c_str(),weaponName.c_str());
  124. html.br();
  125. }
  126. }
  127. else if ((*it)->getType()==CLogEvent::TEAM_FRAG)
  128. {
  129. PID killer=(*it)->getArgument(0)->asPlayerGetPID();
  130. string killerName=(*it)->getArgument(0)->asPlayerGetName();
  131. PID killee=(*it)->getArgument(1)->asPlayerGetPID();
  132. string killeeName=(*it)->getArgument(1)->asPlayerGetName();
  133. int killerTeamID=g_pMatchInfo->playerList()[killer].teams.atTime((*it)->getTime());
  134. int killeeTeamID=g_pMatchInfo->playerList()[killee].teams.atTime((*it)->getTime());
  135. html.write("<tr><td><font class=player%s>%s</font><font color=white> teamkilled </font><font class=player%s>%s.</font></tr></td>\n",
  136. Util::teamcolormap[killerTeamID],killerName.c_str(),Util::teamcolormap[killeeTeamID],killeeName.c_str());
  137. html.br();
  138. }
  139. }
  140. html.enddiv();
  141. }