rogue4: add logging all games

This commit is contained in:
John "Elwin" Edwards 2009-11-26 03:02:13 +00:00
parent f9c589b480
commit 4bc7038945
6 changed files with 75 additions and 2 deletions

View file

@ -236,6 +236,63 @@ char monst;
fclose(outf);
}
void writelog(int amount, int flags, char monst)
{
FILE *logfi;
char logmessage[160], ltemp[80];
char *killer;
if (waswizard)
return;
#ifdef LOGFILE
if (lfd >= 0)
logfi = fdopen(lfd, "a");
else
return;
if (logfi == NULL)
return;
/* otherwise writing should work */
sprintf(logmessage, "%d %d %.20s %d ", time(NULL), amount, whoami,
pstats.s_lvl);
if (flags == 0) /* died */
{
strcat(logmessage, "killed by ");
killer = killname(monst, TRUE);
strcat(logmessage, killer);
if (amulet)
sprintf(ltemp, " on level %d [max %d] with the Amulet\n",
level, max_level);
else
sprintf(ltemp, " on level %d\n", level);
strcat(logmessage, ltemp);
}
else if (flags == 1) /* quit */
{
if (amulet)
sprintf(ltemp, "quit on level %d [max %d] with the Amulet\n",
level, max_level);
else
sprintf(ltemp, "quit on level %d\n", level);
strcat(logmessage, ltemp);
}
else if (flags == 2) /* won */
{
sprintf(ltemp, "escaped with the Amulet [deepest level :%d]\n",
max_level);
strcat(logmessage, ltemp);
}
else
{
fclose(logfi);
return;
}
/* then write */
fprintf(logfi, "%s", logmessage);
fclose(logfi);
#endif
return;
}
/*
* death:
* Do something really fun when he dies
@ -271,6 +328,7 @@ register char monst;
mvaddstr(18, 26, prbuf);
move(LINES-1, 0);
refresh();
writelog(purse, 0, monst);
score(purse, 0, monst);
/* Make sure the output gets through */
printf("[Press return to exit]\n");
@ -390,6 +448,7 @@ total_winner()
}
mvprintw(c - 'a' + 1, 0," %5d Gold Pieces ", oldpurse);
refresh();
writelog(purse, 2, 0);
score(purse, 2, 0);
exit(0);
}