static void StoreLevelStats() { unsigned int i; if (gamestate != GS_LEVEL) return; if (!(level.flags2&LEVEL2_NOSTATISTICS)) // don't consider maps that were excluded from statistics { for(i=0;i<LevelData.Size();i++) { if (!stricmp(LevelData[i].levelname, level.MapName)) break; } if (i==LevelData.Size()) { LevelData.Reserve(1); strncpy(LevelData[i].levelname, level.MapName, 8); LevelData[i].levelname[8] = 0; } LevelData[i].totalkills = level.total_monsters; LevelData[i].killcount = level.killed_monsters; LevelData[i].totalsecrets = level.total_secrets; LevelData[i].secretcount = level.found_secrets; LevelData[i].leveltime = AdjustTics(level.maptime); // Check for living monsters. On some maps it can happen // that the counter misses some. TThinkerIterator<AActor> it; AActor *ac; int mc = 0; while ((ac = it.Next())) { if ((ac->flags & MF_COUNTKILL) && ac->health > 0) mc++; } if (mc == 0) LevelData[i].killcount = LevelData[i].totalkills; } }
void STAT_ChangeLevel(const char *newl) { // record the current level's stats. StoreLevelStats(); level_info_t *thisinfo = level.info; level_info_t *nextinfo = NULL; if (strncmp(newl, "enDSeQ", 6)) { level_info_t *l = FindLevelInfo (newl); nextinfo = l->CheckLevelRedirect (); if (nextinfo == NULL) nextinfo = l; } if (savestatistics == 1) { if ((nextinfo == NULL || (nextinfo->flags2 & LEVEL2_ENDGAME)) && StartEpisode != NULL) { // we reached the end of this episode int wad = 0; MapData * map = P_OpenMapData(StartEpisode->mEpisodeMap, false); if (map != NULL) { wad = Wads.GetLumpFile(map->lumpnum); delete map; } const char * name = Wads.GetWadName(wad); FString section = ExtractFileBase(name) + "." + StartEpisode->mEpisodeMap; section.ToUpper(); const char *ep_name = StartEpisode->mEpisodeName; if (*ep_name == '$') ep_name = GStrings[ep_name+1]; FStatistics *sl = GetStatisticsList(EpisodeStatistics, section, ep_name); int statvals[4] = {0,0,0,0}; FString infostring; int validlevels = LevelData.Size(); for(unsigned i = 0; i < LevelData.Size(); i++) { statvals[0] += LevelData[i].killcount; statvals[1] += LevelData[i].totalkills; statvals[2] += LevelData[i].secretcount; statvals[3] += LevelData[i].totalsecrets; } infostring.Format("%4d/%4d, %3d/%3d, %2d", statvals[0], statvals[1], statvals[2], statvals[3], validlevels); FSessionStatistics *es = StatisticsEntry(sl, infostring, AdjustTics(level.totaltime)); for(unsigned i = 0; i < LevelData.Size(); i++) { FString lsection = LevelData[i].Levelname; lsection.ToUpper(); infostring.Format("%4d/%4d, %3d/%3d", LevelData[i].killcount, LevelData[i].totalkills, LevelData[i].secretcount, LevelData[i].totalsecrets); LevelStatEntry(es, lsection, infostring, LevelData[i].leveltime); } SaveStatistics(statfile, EpisodeStatistics); } } else if (savestatistics == 2) // todo: handle single level statistics. { } }