rogue3: add the option of logging all games to a text file
This commit is contained in:
parent
437daf6c31
commit
bd3b2e4e53
5 changed files with 86 additions and 1 deletions
80
rogue3/rip.c
80
rogue3/rip.c
|
|
@ -77,6 +77,7 @@ death(int monst)
|
|||
mvaddstr(18, 26, prbuf);
|
||||
move(LINES-1, 0);
|
||||
draw(stdscr);
|
||||
log(purse, 0, monst);
|
||||
score(purse, 0, monst);
|
||||
/* Make sure all the output gets through ssh and
|
||||
anything else that might be in the way. */
|
||||
|
|
@ -118,6 +119,31 @@ open_score(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
#if 0 /* not necessary */
|
||||
/* Same thing, but for the log file. Maybe combine them eventually. */
|
||||
/* FIXME you don't know what this does */
|
||||
void open_log(void)
|
||||
{
|
||||
#ifdef LOGFILE
|
||||
if (logf != NULL) {
|
||||
rewind(logf);
|
||||
return;
|
||||
}
|
||||
|
||||
logf = fopen(LOGFILE, "a");
|
||||
|
||||
if (logf == NULL)
|
||||
{
|
||||
fprintf(stderr, "Could not open %s for appending: %s\n", LOGFILE, strerror(errno));
|
||||
fflush(stderr);
|
||||
}
|
||||
#else
|
||||
logf == NULL;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* VARARGS2 */
|
||||
void
|
||||
score(int amount, int flags, int monst)
|
||||
|
|
@ -288,6 +314,59 @@ score(int amount, int flags, int monst)
|
|||
fclose(outf);
|
||||
}
|
||||
|
||||
void log(int amount, int flags, int monst)
|
||||
{
|
||||
char logmessage[160], ltemp[80];
|
||||
char *killer;
|
||||
|
||||
if (waswizard)
|
||||
return;
|
||||
#ifdef LOGFILE
|
||||
sprintf(logmessage, "%d %d %.20s ", time(NULL), amount, whoami);
|
||||
if (flags == 0) /* died */
|
||||
{
|
||||
strcat(logmessage, "killed by a");
|
||||
killer = killname(monst);
|
||||
if (*killer == 'a' || *killer == 'e' || *killer == 'i' ||
|
||||
*killer == 'o' || *killer == 'u')
|
||||
strcat(logmessage, "n ");
|
||||
else
|
||||
strcat(logmessage, " ");
|
||||
strcat(logmessage, killer);
|
||||
if (max_level > level)
|
||||
sprintf(ltemp, " on level %d [max %d]\n", level, max_level);
|
||||
else
|
||||
sprintf(ltemp, " on level %d\n", level);
|
||||
strcat(logmessage, ltemp);
|
||||
}
|
||||
else if (flags == 1) /* quit */
|
||||
{
|
||||
if (max_level > level)
|
||||
sprintf(ltemp, "quit on level %d [max %d]\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 found on level %d\n", max_level);
|
||||
strcat(logmessage, ltemp);
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
logf = fopen(LOGFILE, "a"); /* permissions? */
|
||||
if (logf == NULL)
|
||||
return;
|
||||
/* and write it */
|
||||
md_lockfile(logf);
|
||||
fprintf(logf, "%s", logmessage);
|
||||
md_unlockfile(logf);
|
||||
fclose(logf);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
total_winner()
|
||||
{
|
||||
|
|
@ -394,6 +473,7 @@ total_winner()
|
|||
}
|
||||
mvprintw(c - 'a' + 1, 0," %5d Gold Peices ", oldpurse);
|
||||
refresh();
|
||||
log(purse, 2, 0);
|
||||
score(purse, 2, 0);
|
||||
exit(0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue