//========= Copyright Valve Corporation, All rights reserved. ============// // // Purpose: Implementation of CWhoKilledWho // // $Workfile: $ // $Date: $ // //------------------------------------------------------------------------------------------------------ // $Log: $ // // $NoKeywords: $ //=============================================================================// #include "WhoKilledWho.h" //------------------------------------------------------------------------------------------------------ // Function: CWhoKilledWho::init // Purpose: initializes the object //------------------------------------------------------------------------------------------------------ void CWhoKilledWho::init() { nextbid=0; if (kills) delete [] kills; if (deaths) delete [] deaths; deaths=kills=NULL; } void CWhoKilledWho::makeBidMap() { int nextbid=0; for (int t=0;tplayerBegin(); for (it;it!=g_pMatchInfo->playerEnd();++it) { const PID& pid=(*it).first; CPlayer& p=(*it).second; if (!p.teams.contains(t)) continue; pair pr(t,pid); bidMap[pr]=nextbid; bidMap2[nextbid]=pr; nextbid++; } } size=nextbid; } //------------------------------------------------------------------------------------------------------ // Function: CWhoKilledWho::generate // Purpose: generates intermediate data from the match info //------------------------------------------------------------------------------------------------------ void CWhoKilledWho::generate() { init(); makeBidMap(); if (size==0) return; kills=new int[size*size]; memset(kills,0,sizeof(int)*size*size); deaths=new int[size]; memset(deaths,0,sizeof(int)*size); //now the pids table is all full of pids and you index it using Board IDs (bids) //also there is a bids table so you know which pid each board entry has. CEventListIterator it; for (it=g_pMatchInfo->eventList()->begin(); it != g_pMatchInfo->eventList()->end(); ++it) { if ((*it)->getType()==CLogEvent::SUICIDE || (*it)->getType()==CLogEvent::KILLED_BY_WORLD) { PID plr=(*it)->getArgument(0)->asPlayerGetPID(); int plrTeam=g_pMatchInfo->playerList()[plr].teams.atTime((*it)->getTime()); pair plrpr(plrTeam,plr); int plrbid=bidMap[plrpr]; kills[plrbid*size+plrbid]++; deaths[plrbid]++; } else if ((*it)->getType()==CLogEvent::FRAG || (*it)->getType()==CLogEvent::TEAM_FRAG) { PID killer=(*it)->getArgument(0)->asPlayerGetPID(); PID killee=(*it)->getArgument(1)->asPlayerGetPID(); int killerTeam=g_pMatchInfo->playerList()[killer].teams.atTime((*it)->getTime()); int killeeTeam=g_pMatchInfo->playerList()[killee].teams.atTime((*it)->getTime()); pair killerpr(killerTeam,killer); pair killeepr(killeeTeam,killee); int killerbid=bidMap[killerpr]; int killeebid=bidMap[killeepr]; kills[killerbid*size+killeebid]++; deaths[killeebid]++; } } } //------------------------------------------------------------------------------------------------------ // Function: CWhoKilledWho::getCellClass // Purpose: Helper function that returns the class of a cell on the board depending // on where it occurs in the board. // Input: u - the x position of the cell // v - the y position of the cell // Output: const char* //------------------------------------------------------------------------------------------------------ const char* CWhoKilledWho::getCellClass(int u,int v) { char* tdclass; if (u == v+1) tdclass="class=boardcell_br"; else if (u>v) tdclass="class=boardcell_r"; if (u == v-1) tdclass="class=boardcell_br"; else if (u",g_pApp->supportHTTPPath.c_str()); string jshttppath(g_pApp->supportHTTPPath); jshttppath+="/support.js"; html.write("\n",jshttppath.c_str()); html.write("\n"); html.write("\n",tableWid,numrows,numcols); //print columns html.write(" Player\n",playerNameWid); for (i=0;iplayerTeamID(pids[i]); //int tid=3; int tid=bidMap2[i].first; html.write("%2d\n",cellWid,Util::teamcolormap[tid],i); } html.write("Kills\n",lastColWid); html.write("\n"); int totalkills=0; int killerbid; for (killerbid=0;killerbidplayerName(bidMap2[killerbid].second).c_str(),20); truncatedPlayerName[20]=0; //int tid=g_pMatchInfo->playerTeamID(pids[killerbid]); int tid=bidMap2[killerbid].first; html.write("%d. %s\n",playerNameWid,Util::teamcolormap[tid], killerbid,truncatedPlayerName); int killeebid; for (killeebid=0;killeebid%i\n",cellWid,tdclass,kills[killerbid*size+killeebid]); if (killeebid != killerbid) tot+=kills[killerbid*size+killeebid]; else tot-=kills[killerbid*size+killeebid]; } totalkills+=tot; html.write("%i\n",lastColWid,tot); html.write("\n"); } html.write(" Deaths\n"); int totaldeaths=0; for (i=0;i%i\n",deaths[i]); totaldeaths+=deaths[i]; } //html.write("%3i\\%3i\n",totaldeaths,totalkills); html.write("\n"); html.write("\n"); html.write("\n"); } //------------------------------------------------------------------------------------------------------ // Function: CWhoKilledWho::~CWhoKilledWho // Purpose: destructor //------------------------------------------------------------------------------------------------------ CWhoKilledWho::~CWhoKilledWho() { if (kills) delete [] kills; if (deaths) delete [] deaths; }