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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#pragma warning (disable:4786)
//=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
//
// The copyright to the contents herein is the property of Valve, L.L.C.
// The contents may be used and/or copied only with the written permission of
// Valve, L.L.C., or in accordance with the terms and conditions stipulated in
// the agreement/contract under which the contents have been supplied.
//
// Purpose: Implementation of CCustomAward
//
// $Workfile: $
// $Date: $
//
//------------------------------------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================
#include <string.h>
#include "TFStatsApplication.h"
#include "CustomAward.h"
#include "TextFile.h"
#include "memdbg.h"
//------------------------------------------------------------------------------------------------------
// Function: CCustomAward::extendedinfo
// Purpose: writes extra info about the award winner, like their score or something.
// The extra info string is defined by the user in the configuration file like the
//rest of a custom award's properties.
// Input: html - the html file to write to
//------------------------------------------------------------------------------------------------------
void CCustomAward::extendedinfo(CHTMLFile& html)
{
if (extraInfoMsg.empty())
return;
char str[500];
char outputstring[2000]={0};
strcpy(str,extraInfoMsg.c_str());
char delims[]={" \n\t"};
char* temp=NULL;
temp=strtok(str,delims);
while(temp!=NULL)
{
char word[500];
if (strnicmp(temp,"%player",strlen("%player"))==0)
{
char* more=&temp[strlen("%player")];
sprintf(word,"%s%s",winnerName.c_str(),more);
}
else if (strnicmp(temp,"%winner",strlen("%winner"))==0)
{
char* more=&temp[strlen("%winner")];
sprintf(word,"%s%s",winnerName.c_str(),more);
}
else if (strnicmp(temp,"%score",strlen("%score"))==0)
{
char* more=&temp[strlen("%score")];
if (!namemode)
sprintf(word,"%li%s",plrscores[winnerID],more);
else
sprintf(word,"%li%s",stringscores[winnerName],more);
}
else if (strnicmp(temp,"%number",strlen("%number"))==0)
{
//right now this is just the score
char* more=&temp[strlen("%number")];
if (!namemode)
sprintf(word,"%li%s",plrnums[winnerID],more);
else
sprintf(word,"%li%s",stringscores[winnerName],more);
}
else
strcpy(word,temp);
strcat(outputstring," ");
strcat(outputstring,word);
temp=strtok(NULL,delims);
}
html.write(outputstring);
}
//------------------------------------------------------------------------------------------------------
// Function: CCustomAward::noWinner
// Purpose: writes some html saying that no one won this award. The noWinnerMsg
// is defined by the user in the configuration file like all other custom
// award properties
// Input: html - the html file to write to
//------------------------------------------------------------------------------------------------------
void CCustomAward::noWinner(CHTMLFile& html)
{
if (noWinnerMsg.empty())
return;
html.write(noWinnerMsg.c_str());}
//------------------------------------------------------------------------------------------------------
// Function: CCustomAward::readCustomAward
// Purpose: Factory method to read an award from a config file and return an
// instance of the CCustomAward class
// Input: f - the configuration file to read from
// g_pMatchInfo - a pointer to a matchinfo object to give to the new award
// Output: CCustomAward*
//------------------------------------------------------------------------------------------------------
CCustomAward* CCustomAward::readCustomAward(CTextFile& f)
{
const char* token=f.getToken();
while (token)
{
if (!stricmp(token,"Award"))
break;
else if (!stricmp(token,"{"))
f.discardBlock();
token=f.getToken();
}
if (!token)
return NULL;
f.discard("{");
token=f.getToken();
CCustomAward* pCustAward=new TRACKED CCustomAward(g_pMatchInfo);
while (token)
{
if (stricmp(token,"trigger")==0)
{
CCustomAwardTrigger* ptrig=CCustomAwardTrigger::readTrigger(f);
pCustAward->triggers.push_back(ptrig);
}
else if (stricmp(token,"extraInfo")==0)
{
f.discard("=");
pCustAward->extraInfoMsg=f.readString();
f.discard(";");
}
else if (stricmp(token,"noWinnerMessage")==0)
{
f.discard("=");
pCustAward->noWinnerMsg=f.readString();
f.discard(";");
}
else if (stricmp(token,"name")==0)
{
f.discard("=");
pCustAward->awardName=f.readString();
f.discard(";");
}
else if (stricmp(token,"}")==0)
{
break;
}
else
g_pApp->fatalError("Unrecognized Award property name while parsing %s: \"%s\" is not a property of an Award!",f.fileName().c_str(),token);
token = f.getToken();
}
return pCustAward;
}
//------------------------------------------------------------------------------------------------------
// Function: CCustomAward::getWinner
// Purpose: generates the winner of this custom award.
//------------------------------------------------------------------------------------------------------
void CCustomAward::getWinner()
{
fNoWinner=true;
CEventListIterator it;
for (it=g_pMatchInfo->eventList()->begin();it!=g_pMatchInfo->eventList()->end();it++)
{
list<CCustomAwardTrigger*>::iterator tli;
for (tli=triggers.begin();tli!=triggers.end();++tli)
{
if ((*tli)->matches(*it))
{
//increase the players count by X score.
//scan for best at the end
//different triggers have the player name/id placed differently. :(
//if this returns -1, store based on name. (this way we can give awards to things other than player names
//while remaining in this award/trigger hierarchy structure)
PID ID =(*tli)->plrIDFromEvent(*it);
if (ID==-1)
{
string ws=(*tli)->getTrackString(*it);
stringscores[ws]+=(*tli)->plrValue;
stringnums[ws]++;
fNoWinner=false;
namemode=true;
}
else
{
plrscores[ID]+=(*tli)->plrValue;
plrnums[ID]++;
fNoWinner=false;
namemode=false;
}
}
}
}
if (fNoWinner)
return;
if (!namemode)
{
//now scan and find highest score.
map<PID,int>::iterator scores_it;
scores_it=plrscores.begin();
winnerID=(*scores_it).first;
int winnerScore=(*scores_it).second;
for (scores_it=plrscores.begin();scores_it!=plrscores.end();++scores_it)
{
int ID=(*scores_it).first;
int score=(*scores_it).second;
if (score > winnerScore)
{
winnerScore=score;
winnerID=ID;
}
}
}
else
{
//now scan and find highest score.
map<string,int>::iterator scores_it;
scores_it=stringscores.begin();
winnerID=-1;
winnerName=(*scores_it).first;
int winnerScore=(*scores_it).second;
for (scores_it=stringscores.begin();scores_it!=stringscores.end();++scores_it)
{
string name=(*scores_it).first;
int score=(*scores_it).second;
if (score > winnerScore)
{
winnerScore=score;
winnerName=name;
}
}
}
}
|