Mercurial > hg > early-roguelike
diff xrogue/rip.c @ 138:dd137c35c3b1
xrogue: record the result of each game in a logfile.
author | John "Elwin" Edwards |
---|---|
date | Tue, 05 May 2015 11:24:02 -0400 |
parents | ce0cf824c192 |
children | 7faf4568c295 |
line wrap: on
line diff
--- 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 <curses.h> #include <time.h> #include <signal.h> @@ -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); }