xrogue: record the result of each game in a logfile.

This commit is contained in:
John "Elwin" Edwards 2015-05-05 11:24:02 -04:00
parent 283506baf9
commit 9c0cafd74d
3 changed files with 55 additions and 0 deletions

View file

@ -699,6 +699,7 @@ int sig;
clear();
move(lines-1, 0);
draw(stdscr);
writelog(pstats.s_exp + (long) purse, CHICKEN, 0);
score(pstats.s_exp + (long) purse, CHICKEN, 0);
exit_game(EXIT_ENDWIN);
}

View file

@ -20,6 +20,8 @@
#define EDITSCORE 2 /* Edit the current score file */
#define ADDSCORE 3 /* Add a new score */
#define LOGFILE "xrogue.log"
#include <curses.h>
#include <time.h>
#include <signal.h>
@ -80,6 +82,7 @@ register short monst;
char buf[LINELEN];
struct tm *localtime();
writelog(pstats.s_exp, KILLED, monst);
time(&date);
lt = localtime(&date);
clear();
@ -130,6 +133,54 @@ register short monst;
return (deaths[i].name);
}
/* Writes an entry in the log file */
void
writelog(unsigned long amount, int flags, short monst)
{
FILE *logwriter;
char had_quest = '0';
char fate[LINELEN];
struct linked_list *item;
struct object *obj;
#ifdef LOGFILE
if (waswizard)
return;
/* Adjustments to the score */
if (level == 0 && max_level == 0)
amount = 0;
if (flags == CHICKEN)
amount /= 100;
/* Check for quest item */
for (item = pack; item != NULL; item = next(item)) {
obj = OBJPTR(item);
if (obj->o_type == RELIC && obj->o_which == quest_item)
had_quest = '1';
}
/* Describe what happened */
if (flags == KILLED) {
snprintf(fate, LINELEN, "killed by %s", killname(monst));
}
else if (flags == CHICKEN) {
strcpy(fate, "quit");
}
else if (flags == WINNER) {
strcpy(fate, "escaped");
}
else
return;
/* Open and write */
logwriter = fopen(LOGFILE, "a");
if (logwriter == NULL)
return;
fprintf(logwriter, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
whoami, pstats.s_lvl, char_class[char_type].name, level, max_level,
quest_item, had_quest, fate);
fclose(logwriter);
#endif
return;
}
/*
* score -- figure score and post it.
*/
@ -599,6 +650,7 @@ total_winner()
}
mvprintw(c - 'a' + 1, 0," %5ld Gold Pieces ", oldpurse);
refresh();
writelog(pstats.s_exp + (long) purse, WINNER, '\0');
score(pstats.s_exp + (long) purse, WINNER, '\0');
exit_game(EXIT_ENDWIN);
}

View file

@ -1259,6 +1259,8 @@ void byebye(int sig), genmonsters(), quit(int sig),
void teleport();
void writelog(unsigned long amount, int flags, short monst);
int undance(), land(), cloak_charge(), wghtchk();
int add_intelligence(), add_strength(), add_wisdom(), add_dexterity(),