summaryrefslogtreecommitdiff
path: root/utils/tfstats/dialoguereadout.cpp
blob: 0581cce46f1903937f2ae0cd170e41ff8d3c3f0a (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
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Implementation of CDialogueReadout
//
// $Workfile:     $
// $Date:         $
//
//------------------------------------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//
#include "DialogueReadout.h"
#include "util.h"


//------------------------------------------------------------------------------------------------------
// Function:	CDialogueReadout::writeHTML
// Purpose:	generates and writes the report. generate() is not used in this object
// because there is no real intermediate data. Really data is just taken from the 
// event list, massaged abit, and written out to the html file. There is no calculation
// of stats or figures so no intermedidate data creation is needed.
// Input:	html - the html file that we want to write to. 
//------------------------------------------------------------------------------------------------------
void CDialogueReadout::writeHTML(CHTMLFile& html)
{
	html.write("<img src=\"%s/game.dialog.on.gif\">\n",g_pApp->supportHTTPPath.c_str()); 
	html.div("dialog");
	CEventListIterator it;
	bool MM2Messages=false;

	if (g_pApp->cmdLineSwitches["displaymm2"]=="on" || 
		g_pApp->cmdLineSwitches["displaymm2"]=="yes" || 
		g_pApp->cmdLineSwitches["displaymm2"]=="true" || 
		g_pApp->cmdLineSwitches["displaymm2"]=="1")
		MM2Messages=true;

	
	for (it=g_pMatchInfo->eventList()->begin(); it != g_pMatchInfo->eventList()->end(); ++it)
	{
		if ((*it)->getType()==CLogEvent::SAY || (MM2Messages && ((*it)->getType()==CLogEvent::SAY_TEAM)))
		{
			char talked[512]={0};
			PID talkerPID=(*it)->getArgument(0)->asPlayerGetPID();
			string talkerName=(*it)->getArgument(0)->asPlayerGetName();
			
			for (int i=1;(*it)->getArgument(i);i++)
			{
				char temp[512];
				(*it)->getArgument(i)->getStringValue(temp);
				strcat(talked,"\"");
				strcat(talked,temp);
				strcat(talked,"\"");				
			}
			
			bool isTeamMsg= (*it)->getType()==CLogEvent::SAY_TEAM;
			int teamID=g_pMatchInfo->playerList()[talkerPID].teams.atTime((*it)->getTime());
			
			const char* aa;
			const char* bb;

			if (teamID<4 && teamID >= 0)
			{
				aa="player";
				bb=Util::teamcolormap[teamID];
			}
			else
			{
				aa="whitetext";
				bb="";
			}
			
			html.write("<tr><td><font class=%s%s>%s%s:</font><font color=white>  %s</font></tr></td>\n",aa,bb,talkerName.c_str(),isTeamMsg?" (Team)":"",talked);
			html.br();
		}
		else if ( (*it)->getType()==CLogEvent::KILLED_BY_WORLD)
		{
			PID plr=(*it)->getArgument(0)->asPlayerGetPID();
			string plrName=(*it)->getArgument(0)->asPlayerGetName();
			int teamID=g_pMatchInfo->playerList()[plr].teams.atTime((*it)->getTime());
			html.write("<tr><td><font class=player%s>%s</font><font color=white> died.</font></tr></td>\n",Util::teamcolormap[teamID],plrName.c_str());
			html.br();
		}
		else if ((*it)->getType()==CLogEvent::SUICIDE)
		{
			PID plr=(*it)->getArgument(0)->asPlayerGetPID();
			string plrName=(*it)->getArgument(0)->asPlayerGetName();
			int teamID=g_pMatchInfo->playerList()[plr].teams.atTime((*it)->getTime());
			html.write("<tr><td><font class=player%s>%s</font><font color=white> committed suicide.</font></tr></td>\n",Util::teamcolormap[teamID],plrName.c_str());
			html.br();
		}		
		else if ((*it)->getType()==CLogEvent::TEAM_JOIN)
		{
			PID plr=(*it)->getArgument(0)->asPlayerGetPID();
			string plrName=(*it)->getArgument(0)->asPlayerGetName();
			time_t eventtime=(*it)->getTime();
			bool firstJoin=!g_pMatchInfo->playerList()[plr].teams.anythingAtTime(eventtime-1);
			int oldTeamID=g_pMatchInfo->playerList()[plr].teams.atTime(eventtime-1);
			int teamID=g_pMatchInfo->playerList()[plr].teams.atTime(eventtime);
			string teamName=g_pMatchInfo->teamName(teamID);
			if (firstJoin)
				html.write("<tr><td><font class=player%s>%s</font><font color=white> joined team <font class=player%s>%s</font>.</font></tr></td>\n",Util::teamcolormap[teamID],plrName.c_str(),Util::teamcolormap[teamID],teamName.c_str());
			else
				html.write("<tr><td><font class=player%s>%s</font><font color=white> changed teams to <font class=player%s>%s</font>.</font></tr></td>\n",Util::teamcolormap[oldTeamID],plrName.c_str(),Util::teamcolormap[teamID],teamName.c_str());
			html.br();
		}		
		else if ((*it)->getType()==CLogEvent::FRAG)
		{
			PID killer=(*it)->getArgument(0)->asPlayerGetPID();
			string  killerName=(*it)->getArgument(0)->asPlayerGetName();
			PID killee=(*it)->getArgument(1)->asPlayerGetPID();
			string killeeName=(*it)->getArgument(1)->asPlayerGetName();
			string weaponName = (*it)->getArgument(2)->getStringValue();
			
			int killerTeamID=g_pMatchInfo->playerList()[killer].teams.atTime((*it)->getTime());
			int killeeTeamID=g_pMatchInfo->playerList()[killee].teams.atTime((*it)->getTime());
			
			bool countKill=true;

			//gotta account for timer/infection double kills for medics!
			if (weaponName=="infection")
			{
				//test to see if the previous event was a timer from the same player, and a kill, and with the timer.
				CEventListIterator it2=it;
				if ((--it2)!=g_pMatchInfo->eventList()->begin())
				{
					if ((*it2)->getType() == CLogEvent::FRAG)
						if ((*it2)->getArgument(2)->getStringValue()=="timer")
							if ((*it2)->getArgument(0)->asPlayerGetPID()==killer)
								countKill=false;
				}
			}
			if (countKill)
			{
				html.write("<tr><td><font class=player%s>%s</font><font color=white> killed </font><font class=player%s>%s</font><font color=white> with  %s. </font></tr></td>\n",
								Util::teamcolormap[killerTeamID],killerName.c_str(),Util::teamcolormap[killeeTeamID],killeeName.c_str(),weaponName.c_str());
				html.br();
			}
			
		}
		else if ((*it)->getType()==CLogEvent::TEAM_FRAG)
		{
			PID killer=(*it)->getArgument(0)->asPlayerGetPID();
			string  killerName=(*it)->getArgument(0)->asPlayerGetName();
			PID killee=(*it)->getArgument(1)->asPlayerGetPID();
			string killeeName=(*it)->getArgument(1)->asPlayerGetName();
			
			int killerTeamID=g_pMatchInfo->playerList()[killer].teams.atTime((*it)->getTime());
			int killeeTeamID=g_pMatchInfo->playerList()[killee].teams.atTime((*it)->getTime());
			html.write("<tr><td><font class=player%s>%s</font><font color=white> teamkilled </font><font class=player%s>%s.</font></tr></td>\n",
								Util::teamcolormap[killerTeamID],killerName.c_str(),Util::teamcolormap[killeeTeamID],killeeName.c_str());
			html.br();
		}

	}
	
	html.enddiv();
}