changeset 130:1a64fd0bfea6

arogue7: record completed games in a logfile.
author John "Elwin" Edwards
date Tue, 12 May 2015 09:55:05 -0400
parents 9c4e50b5825c
children 796e2a10cd41
files arogue7/command.c arogue7/rip.c arogue7/rogue.h
diffstat 3 files changed, 49 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/arogue7/command.c	Mon May 11 19:41:46 2015 -0400
+++ b/arogue7/command.c	Tue May 12 09:55:05 2015 -0400
@@ -602,6 +602,7 @@
 	clear();
 	move(lines-1, 0);
 	draw(stdscr);
+	writelog(pstats.s_exp + (long) purse, CHICKEN, 0);
 	score(pstats.s_exp + (long) purse, CHICKEN, 0);
 #ifdef PC7300
 	endhardwin();
--- a/arogue7/rip.c	Mon May 11 19:41:46 2015 -0400
+++ b/arogue7/rip.c	Tue May 12 09:55:05 2015 -0400
@@ -17,6 +17,8 @@
 #define EDITSCORE 2	/* Edit the current score file */
 #define ADDSCORE 3	/* Add a new score */
 
+#define LOGFILE "arogue7.log"
+
 #define NAMELEN	80
 
 /*
@@ -138,6 +140,7 @@
     mvaddstr(18, 26, (sprintf(prbuf, "%4d", 1900+lt->tm_year), prbuf));
     move(lines-1, 0);
     refresh();
+    writelog(pstats.s_exp, KILLED, monst);
     score(pstats.s_exp, KILLED, monst);
     endwin();
 #ifdef PC7300
@@ -199,7 +202,49 @@
     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;
+    /* 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.
  */
@@ -823,6 +868,7 @@
     }
     mvprintw(c - 'a' + 1, 0,"   %5d  Gold Pieces          ", oldpurse);
     refresh();
+    writelog(pstats.s_exp + (long) purse, WINNER, '\0');
     score(pstats.s_exp + (long) purse, WINNER, '\0');
     endwin();
 #ifdef PC7300
--- a/arogue7/rogue.h	Mon May 11 19:41:46 2015 -0400
+++ b/arogue7/rogue.h	Tue May 12 09:55:05 2015 -0400
@@ -1150,6 +1150,7 @@
 	add_constitution(), add_charisma(), res_intelligence(), res_strength(int),
 	res_wisdom(), res_dexterity(), res_constitution(), res_charisma();
 
+void writelog(unsigned long amount, int flags, short monst);
 
 #ifdef CHECKTIME
 int checkout();