blob: 8b2bf19a20e06957516920e0b785ba10e8657e0c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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]);
}
|