Save item statistics

Items are now saved into save games and are displayed on the statfile

(cherry picked from commit c91d4750f3)
This commit is contained in:
Erick Tenorio 2018-06-15 21:21:14 -05:00 committed by drfrag666
parent 087f709637
commit a94778ca4d

View file

@ -87,6 +87,7 @@ CVAR(String, statfile, "zdoomstat.txt", CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
struct OneLevel struct OneLevel
{ {
int totalkills, killcount; int totalkills, killcount;
int totalitems, itemcount;
int totalsecrets, secretcount; int totalsecrets, secretcount;
int leveltime; int leveltime;
FString Levelname; FString Levelname;
@ -99,10 +100,10 @@ static FEpisode *StartEpisode;
// The statistics for one level // The statistics for one level
struct FLevelStatistics struct FLevelStatistics
{ {
char info[30]; char info[60];
short skill; short skill;
short playerclass; short playerclass;
char name[12]; char name[24];
int timeneeded; int timeneeded;
}; };
@ -154,9 +155,9 @@ static void ParseStatistics(const char *fn, TArray<FStatistics> &statlist)
sc.MustGetString(); sc.MustGetString();
sc.MustGetString(); sc.MustGetString();
strncpy(session.name, sc.String, 12); strncpy(session.name, sc.String, 24);
sc.MustGetString(); sc.MustGetString();
strncpy(session.info, sc.String, 30); strncpy(session.info, sc.String, 60);
int h,m,s; int h,m,s;
sc.MustGetString(); sc.MustGetString();
@ -172,9 +173,9 @@ static void ParseStatistics(const char *fn, TArray<FStatistics> &statlist)
FLevelStatistics &lstats = session.levelstats[session.levelstats.Reserve(1)]; FLevelStatistics &lstats = session.levelstats[session.levelstats.Reserve(1)];
sc.MustGetString(); sc.MustGetString();
strncpy(lstats.name, sc.String, 12); strncpy(lstats.name, sc.String, 24);
sc.MustGetString(); sc.MustGetString();
strncpy(lstats.info, sc.String, 30); strncpy(lstats.info, sc.String, 60);
int h,m,s; int h,m,s;
sc.MustGetString(); sc.MustGetString();
@ -277,7 +278,7 @@ static void SaveStatistics(const char *fn, TArray<FStatistics> &statlist)
FSessionStatistics *sst = &ep_stats.stats[j]; FSessionStatistics *sst = &ep_stats.stats[j];
if (sst->info[0]>0) if (sst->info[0]>0)
{ {
fw->Printf("\t%2i. %10s \"%-22s\" %02d:%02d:%02d %i\n", j+1, sst->name, sst->info, fw->Printf("\t%2i. %10s \"%-33s\" %02d:%02d:%02d %i\n", j+1, sst->name, sst->info,
hours(sst->timeneeded), minutes(sst->timeneeded), seconds(sst->timeneeded), sst->skill); hours(sst->timeneeded), minutes(sst->timeneeded), seconds(sst->timeneeded), sst->skill);
TArray<FLevelStatistics> &ls = sst->levelstats; TArray<FLevelStatistics> &ls = sst->levelstats;
@ -289,7 +290,7 @@ static void SaveStatistics(const char *fn, TArray<FStatistics> &statlist)
for(unsigned k=0;k<ls.Size ();k++) for(unsigned k=0;k<ls.Size ();k++)
{ {
fw->Printf("\t\t%-8s \"%-22s\" %02d:%02d:%02d\n", ls[k].name, ls[k].info, fw->Printf("\t\t%-8s \"%-33s\" %02d:%02d:%02d\n", ls[k].name, ls[k].info,
hours(ls[k].timeneeded), minutes(ls[k].timeneeded), seconds(ls[k].timeneeded)); hours(ls[k].timeneeded), minutes(ls[k].timeneeded), seconds(ls[k].timeneeded));
} }
fw->Printf("\t}\n"); fw->Printf("\t}\n");
@ -419,6 +420,8 @@ static void StoreLevelStats()
} }
LevelData[i].totalkills = level.total_monsters; LevelData[i].totalkills = level.total_monsters;
LevelData[i].killcount = level.killed_monsters; LevelData[i].killcount = level.killed_monsters;
LevelData[i].totalitems = level.total_items;
LevelData[i].itemcount = level.found_items;
LevelData[i].totalsecrets = level.total_secrets; LevelData[i].totalsecrets = level.total_secrets;
LevelData[i].secretcount = level.found_secrets; LevelData[i].secretcount = level.found_secrets;
LevelData[i].leveltime = level.maptime; LevelData[i].leveltime = level.maptime;
@ -479,26 +482,28 @@ void STAT_ChangeLevel(const char *newl)
if (*ep_name == '$') ep_name = GStrings[ep_name+1]; if (*ep_name == '$') ep_name = GStrings[ep_name+1];
FStatistics *sl = GetStatisticsList(EpisodeStatistics, section, ep_name); FStatistics *sl = GetStatisticsList(EpisodeStatistics, section, ep_name);
int statvals[4] = {0,0,0,0}; int statvals[6] = {0,0,0,0,0,0};
FString infostring; FString infostring;
int validlevels = LevelData.Size(); int validlevels = LevelData.Size();
for(unsigned i = 0; i < LevelData.Size(); i++) for(unsigned i = 0; i < LevelData.Size(); i++)
{ {
statvals[0] += LevelData[i].killcount; statvals[0] += LevelData[i].killcount;
statvals[1] += LevelData[i].totalkills; statvals[1] += LevelData[i].totalkills;
statvals[2] += LevelData[i].secretcount; statvals[2] += LevelData[i].itemcount;
statvals[3] += LevelData[i].totalsecrets; statvals[3] += LevelData[i].totalitems;
statvals[4] += LevelData[i].secretcount;
statvals[5] += LevelData[i].totalsecrets;
} }
infostring.Format("%4d/%4d, %3d/%3d, %2d", statvals[0], statvals[1], statvals[2], statvals[3], validlevels); infostring.Format("%4d/%4d, %4d/%4d, %3d/%3d, %2d", statvals[0], statvals[1], statvals[2], statvals[3], statvals[4], statvals[5], validlevels);
FSessionStatistics *es = StatisticsEntry(sl, infostring, level.totaltime); FSessionStatistics *es = StatisticsEntry(sl, infostring, level.totaltime);
for(unsigned i = 0; i < LevelData.Size(); i++) for(unsigned i = 0; i < LevelData.Size(); i++)
{ {
FString lsection = LevelData[i].Levelname; FString lsection = LevelData[i].Levelname;
lsection.ToUpper(); lsection.ToUpper();
infostring.Format("%4d/%4d, %3d/%3d", infostring.Format("%4d/%4d, %4d/%4d, %3d/%3d",
LevelData[i].killcount, LevelData[i].totalkills, LevelData[i].secretcount, LevelData[i].totalsecrets); LevelData[i].killcount, LevelData[i].totalkills, LevelData[i].itemcount, LevelData[i].totalitems, LevelData[i].secretcount, LevelData[i].totalsecrets);
LevelStatEntry(es, lsection, infostring, LevelData[i].leveltime); LevelStatEntry(es, lsection, infostring, LevelData[i].leveltime);
} }
@ -523,6 +528,8 @@ FSerializer &Serialize(FSerializer &arc, const char *key, OneLevel &l, OneLevel
{ {
arc("totalkills", l.totalkills) arc("totalkills", l.totalkills)
("killcount", l.killcount) ("killcount", l.killcount)
("totalitems", l.totalitems)
("itemcount", l.itemcount)
("totalsecrets", l.totalsecrets) ("totalsecrets", l.totalsecrets)
("secretcount", l.secretcount) ("secretcount", l.secretcount)
("leveltime", l.leveltime) ("leveltime", l.leveltime)
@ -576,8 +583,8 @@ FString GetStatString()
for(unsigned i = 0; i < LevelData.Size(); i++) for(unsigned i = 0; i < LevelData.Size(); i++)
{ {
OneLevel *l = &LevelData[i]; OneLevel *l = &LevelData[i];
compose.AppendFormat("Level %s - Kills: %d/%d - Secrets: %d/%d - Time: %d:%02d\n", compose.AppendFormat("Level %s - Kills: %d/%d - Items: %d/%d - Secrets: %d/%d - Time: %d:%02d\n",
l->Levelname.GetChars(), l->killcount, l->totalkills, l->secretcount, l->totalsecrets, l->Levelname.GetChars(), l->killcount, l->totalkills, l->itemcount, l->totalitems, l->secretcount, l->totalsecrets,
l->leveltime/(60*TICRATE), (l->leveltime/TICRATE)%60); l->leveltime/(60*TICRATE), (l->leveltime/TICRATE)%60);
} }
return compose; return compose;