diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/tfstats/survivalistaward.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'utils/tfstats/survivalistaward.cpp')
| -rw-r--r-- | utils/tfstats/survivalistaward.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/utils/tfstats/survivalistaward.cpp b/utils/tfstats/survivalistaward.cpp new file mode 100644 index 0000000..8b2bf19 --- /dev/null +++ b/utils/tfstats/survivalistaward.cpp @@ -0,0 +1,110 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Implementation of CSurvivalistAward +// +// $Workfile: $ +// $Date: $ +// +//------------------------------------------------------------------------------------------------------ +// $Log: $ +// +// $NoKeywords: $ +//=============================================================================// +#include "SurvivalistAward.h" + +//------------------------------------------------------------------------------------------------------ +// Function: CSurvivalistAward::getWinner +// Purpose: generates a winner for this award by determining who died the least +// while playing a scout +//------------------------------------------------------------------------------------------------------ +void CSurvivalistAward::getWinner() +{ + map<PID,bool> isScout; //to keep track of whether or not a player is a scout now + map<PID,bool> wasScout; //true if a player ever was a scout (and therefore is in contention for the award) + + CEventListIterator it; + for (it=g_pMatchInfo->eventList()->begin(); it != g_pMatchInfo->eventList()->end(); ++it) + { + switch((*it)->getType()) + { + case CLogEvent::CLASS_CHANGE: + { + PID pid=(*it)->getArgument(0)->asPlayerGetPID(); + player_class newpc=playerClassNameToClassID((*it)->getArgument(1)->getStringValue()); + + if (newpc == PC_SCOUT) + { + wasScout[pid]=isScout[pid]=true; + numdeaths[pid]=0; + } + else + isScout[pid]=false; + } + break; + case CLogEvent::FRAG: + case CLogEvent::TEAM_FRAG: + { + PID dead=(*it)->getArgument(1)->asPlayerGetPID(); + if (isScout[dead]) + numdeaths[dead]++; + } + break; + case CLogEvent::SUICIDE: + case CLogEvent::KILLED_BY_WORLD: + { + PID dead=(*it)->getArgument(0)->asPlayerGetPID(); + if (isScout[dead]) + numdeaths[dead]++; + } + break; + } + } + + fNoWinner=true; + winnerID=-1; + + map<PID,int>::iterator deathiter; + + for (deathiter=numdeaths.begin();deathiter!=numdeaths.end();++deathiter) + { + PID pid=(*deathiter).first; + int deaths=(*deathiter).second; + + if (fNoWinner) + { + fNoWinner=false; + winnerID=pid; + continue; + } + + if (deaths <= numdeaths[winnerID]) + winnerID=pid; + } + +} + +//------------------------------------------------------------------------------------------------------ +// Function: CSurvivalistAward::noWinner +// Purpose: writes html to indicate that no one won this award +// Input: html - the html file to output to +//------------------------------------------------------------------------------------------------------ +void CSurvivalistAward::noWinner(CHTMLFile& html) +{ + html.write("No one was cured during this match."); +} + +//------------------------------------------------------------------------------------------------------ +// Function: CSurvivalistAward::extendedinfo +// Purpose: reports how many times the winner died +// Input: html - the html file to write to +//------------------------------------------------------------------------------------------------------ +void CSurvivalistAward::extendedinfo(CHTMLFile& html) +{ + if (numdeaths[winnerID]==0) + html.write("%s didn't die at all as a scout!",winnerName.c_str()); + else if (numdeaths[winnerID]==1) + html.write("%s only died once as a scout!",winnerName.c_str()); + else + html.write("%s only died %li times as a scout!",winnerName.c_str(),numdeaths[winnerID]); +} + |