Skip to content

Commit

Permalink
Fix -levelstat command
Browse files Browse the repository at this point in the history
Co-Authored-By: Roman Fomin <rfomin@gmail.com>
  • Loading branch information
JNechaevsky and rfomin committed Dec 25, 2024
1 parent e1e5eb9 commit cd1ca3d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
25 changes: 17 additions & 8 deletions src/doom/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ static void G_FormatLevelStatTime(char *str, int tics)
// [crispy] Write level statistics upon exit
static void G_WriteLevelStat(void)
{
static FILE *fstream = NULL;
FILE *fstream;

int i, playerKills = 0, playerItems = 0, playerSecrets = 0;

Expand All @@ -2071,15 +2071,22 @@ static void G_WriteLevelStat(void)
char totalTimeString[TIMESTRSIZE];
char *decimal;

if (fstream == NULL)
static boolean firsttime = true;

if (firsttime)
{
firsttime = false;
fstream = M_fopen("levelstat.txt", "w");
}
else
{
fstream = fopen("levelstat.txt", "w");
fstream = M_fopen("levelstat.txt", "a");
}

if (fstream == NULL)
{
fprintf(stderr, "G_WriteLevelStat: Unable to open levelstat.txt for writing!\n");
return;
}
if (fstream == NULL)
{
fprintf(stderr, "G_WriteLevelStat: Unable to open levelstat.txt for writing!\n");
return;
}

if (gamemode == commercial)
Expand Down Expand Up @@ -2116,6 +2123,8 @@ static void G_WriteLevelStat(void)
levelString, (secretexit ? "s" : ""),
levelTimeString, totalTimeString, playerKills, totalkills,
playerItems, totalitems, playerSecrets, totalsecret);

fclose(fstream);
}

void G_DoCompleted (void)
Expand Down
33 changes: 23 additions & 10 deletions src/heretic/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -2224,25 +2224,36 @@ static void G_FormatLevelStatTime(char *str, int tics)
// [crispy] Write level statistics upon exit
static void G_WriteLevelStat(void)
{
static FILE *fstream = NULL;
FILE *fstream;

int i, playerKills = 0, playerItems = 0, playerSecrets = 0;

char levelString[8];
char levelTimeString[TIMESTRSIZE];
char totalTimeString[TIMESTRSIZE];
char *decimal;

if (fstream == NULL)
static boolean firsttime = true;

if (firsttime)
{
fstream = fopen("levelstat.txt", "w");
firsttime = false;
fstream = M_fopen("levelstat.txt", "w");
}
else
{
fstream = M_fopen("levelstat.txt", "a");
}

if (fstream == NULL)
{
fprintf(stderr, "G_WriteLevelStat: Unable to open levelstat.txt for writing!\n");
return;
}
if (fstream == NULL)
{
fprintf(stderr, "G_WriteLevelStat: Unable to open levelstat.txt for writing!\n");
return;
}

M_snprintf(levelString, sizeof(levelString), "E%dM%d",
gameepisode, gamemap);

G_FormatLevelStatTime(levelTimeString, leveltime);
G_FormatLevelStatTime(totalTimeString, totalleveltimes + leveltime);

Expand All @@ -2263,10 +2274,12 @@ static void G_WriteLevelStat(void)
}
}

fprintf(fstream, "E%dM%d%s - %s (%s) K: %d/%d I: %d/%d S: %d/%d\n",
gameepisode, gamemap, (secretexit ? "s" : ""),
fprintf(fstream, "%s%s - %s (%s) K: %d/%d I: %d/%d S: %d/%d\n",
levelString, (secretexit ? "s" : ""),
levelTimeString, totalTimeString, playerKills, totalkills,
playerItems, totalitems, playerSecrets, totalsecret);

fclose(fstream);
}

void G_DoCompleted(void)
Expand Down

0 comments on commit cd1ca3d

Please sign in to comment.