# HG changeset patch # User John "Elwin" Edwards # Date 1430839442 14400 # Node ID dd137c35c3b1c049e54164fdcbc6f90323b64a36 # Parent 443c8bd3e29080b0fd84f44a8601700bd4aa63e9 xrogue: record the result of each game in a logfile. diff -r 443c8bd3e290 -r dd137c35c3b1 xrogue/command.c --- a/xrogue/command.c Sat May 02 07:31:14 2015 -0400 +++ b/xrogue/command.c Tue May 05 11:24:02 2015 -0400 @@ -699,6 +699,7 @@ 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); } diff -r 443c8bd3e290 -r dd137c35c3b1 xrogue/rip.c --- a/xrogue/rip.c Sat May 02 07:31:14 2015 -0400 +++ b/xrogue/rip.c Tue May 05 11:24:02 2015 -0400 @@ -20,6 +20,8 @@ #define EDITSCORE 2 /* Edit the current score file */ #define ADDSCORE 3 /* Add a new score */ +#define LOGFILE "xrogue.log" + #include #include #include @@ -80,6 +82,7 @@ char buf[LINELEN]; struct tm *localtime(); + writelog(pstats.s_exp, KILLED, monst); time(&date); lt = localtime(&date); clear(); @@ -130,6 +133,54 @@ 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 @@ } 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); } diff -r 443c8bd3e290 -r dd137c35c3b1 xrogue/rogue.h --- a/xrogue/rogue.h Sat May 02 07:31:14 2015 -0400 +++ b/xrogue/rogue.h Tue May 05 11:24:02 2015 -0400 @@ -1259,6 +1259,8 @@ 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(),