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.

91 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implementation of CSharpshooterAward
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //------------------------------------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "SharpshooterAward.h"
  14. double CSharpshooterAward::HS_VALUE = 3.00;
  15. double CSharpshooterAward::SHOT_VALUE = 1.00;
  16. //------------------------------------------------------------------------------------------------------
  17. // Function: CSharpshooterAward::getWinner
  18. // Purpose: this totals up each sniper's score and determines a winner
  19. //------------------------------------------------------------------------------------------------------
  20. void CSharpshooterAward::getWinner()
  21. {
  22. CEventListIterator it;
  23. for (it=g_pMatchInfo->eventList()->begin(); it != g_pMatchInfo->eventList()->end(); ++it)
  24. {
  25. if ((*it)->getType()==CLogEvent::FRAG)
  26. {
  27. if (strcmp((*it)->getArgument(2)->getStringValue(),"sniperrifle")==0)
  28. {
  29. PID pid=(*it)->getArgument(0)->asPlayerGetPID();
  30. sharpshooterscore[pid]+=SHOT_VALUE;
  31. numshots[pid]++;
  32. }
  33. else if (strcmp((*it)->getArgument(2)->getStringValue(),"headshot")==0)
  34. {
  35. PID pid=(*it)->getArgument(0)->asPlayerGetPID();
  36. sharpshooterscore[pid]+=HS_VALUE;
  37. numhs[pid]++;
  38. }
  39. }
  40. }
  41. int winnerScore=0;
  42. winnerID=-1;
  43. fNoWinner=true;
  44. map<PID,int>::iterator it2=sharpshooterscore.begin();
  45. for (it2;it2!=sharpshooterscore.end();++it2)
  46. {
  47. PID pid=(*it2).first;
  48. int score=(*it2).second;
  49. if (score > winnerScore)
  50. {
  51. winnerID=pid;
  52. winnerScore=score;
  53. fNoWinner=false;
  54. }
  55. }
  56. }
  57. //------------------------------------------------------------------------------------------------------
  58. // Function: CSharpshooterAward::noWinner
  59. // Purpose: this writes html to indicate that no snipers got any kills
  60. // Input: html - the html file to write to
  61. //------------------------------------------------------------------------------------------------------
  62. void CSharpshooterAward::noWinner(CHTMLFile& html)
  63. {
  64. html.write("No one was sniped during this match");
  65. }
  66. //------------------------------------------------------------------------------------------------------
  67. // Function: CSharpshooterAward::extendedinfo
  68. // Purpose: this reports how many headshots and normal shots the winner got
  69. // Input: html - the html file to write to
  70. //------------------------------------------------------------------------------------------------------
  71. void CSharpshooterAward::extendedinfo(CHTMLFile& html)
  72. {
  73. int hs=numhs[winnerID];
  74. int shots=numshots[winnerID];
  75. if (hs && shots)
  76. html.write("%s got %li headshots and %li normal shots!",winnerName.c_str(),hs,shots);
  77. else if (hs && !shots)
  78. html.write("All of %s's %li snipes were headshots!",winnerName.c_str(),hs);
  79. else if (shots && !hs)
  80. html.write("%s sniped %li people!",winnerName.c_str(),shots);
  81. }