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.

80 lines
2.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implementation of CTalkativeAward
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //------------------------------------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "TalkativeAward.h"
  14. //------------------------------------------------------------------------------------------------------
  15. // Function: CTalkativeAward::getWinner
  16. // Purpose: accumulates text for each player, and determines a winner
  17. //------------------------------------------------------------------------------------------------------
  18. void CTalkativeAward::getWinner()
  19. {
  20. CEventListIterator it;
  21. for (it=g_pMatchInfo->eventList()->begin(); it != g_pMatchInfo->eventList()->end(); ++it)
  22. {
  23. if ((*it)->getType()==CLogEvent::SAY ||(*it)->getType()==CLogEvent::SAY_TEAM)
  24. {
  25. PID mouth=(*it)->getArgument(0)->asPlayerGetPID();
  26. fulltalktext[mouth]+=" ";
  27. fulltalktext[mouth]+=(*it)->getArgument(1)->getStringValue();
  28. numtalks[mouth]++;
  29. winnerID=mouth;
  30. fNoWinner=false;
  31. }
  32. }
  33. map<PID,int>::iterator talkiter;
  34. for (talkiter=numtalks.begin();talkiter!=numtalks.end();++talkiter)
  35. {
  36. int currID=(*talkiter).first;
  37. if (numtalks[currID]>numtalks[winnerID])
  38. winnerID=currID;
  39. }
  40. }
  41. //------------------------------------------------------------------------------------------------------
  42. // Function: CTalkativeAward::noWinner
  43. // Purpose: writes html to indicate that no one won this award.
  44. // Input: html - the html file to write to
  45. //------------------------------------------------------------------------------------------------------
  46. void CTalkativeAward::noWinner(CHTMLFile& html)
  47. {
  48. html.write("No one talked during this match.");
  49. }
  50. //------------------------------------------------------------------------------------------------------
  51. // Function: CTalkativeAward::extendedinfo
  52. // Purpose: calculates how many words a player said, and reports that.
  53. // Input: html - the html file to write to
  54. //------------------------------------------------------------------------------------------------------
  55. void CTalkativeAward::extendedinfo(CHTMLFile& html)
  56. {
  57. int i=0;
  58. char seps[]=" ";
  59. char* string= new char[fulltalktext[winnerID].length()+1];
  60. strcpy(string,fulltalktext[winnerID].c_str());
  61. char* token = strtok( string, seps );
  62. while( token != NULL )
  63. {
  64. token = strtok( NULL, seps );
  65. i++;
  66. }
  67. if (i==1)
  68. html.write("%s said only 1 word.",winnerName.c_str());
  69. else
  70. html.write("%s spoke %li words.",winnerName.c_str(),i);
  71. delete [] string;
  72. }