changeset 268:4ab49e42dd6a

UltraRogue: add logging. The log file's name is temporarily defined in main.c.
author John "Elwin" Edwards
date Sun, 26 Feb 2017 16:51:29 -0500
parents 911f0aa6e758
children a413bc97d3ea
files urogue/main.c urogue/rip.c urogue/rogue.h
diffstat 3 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/urogue/main.c	Sun Feb 26 14:58:49 2017 -0500
+++ b/urogue/main.c	Sun Feb 26 16:51:29 2017 -0500
@@ -28,8 +28,10 @@
 
 #define SAVEDIR "."
 #define SCOREFILE "/var/local/games/roguelike/urogue.scr"
+#define LOGFILE "/var/local/games/roguelike/urogue.log"
 
 FILE *fd_score = NULL;
+FILE *file_log = NULL;
 
 /* Command line options */
 
@@ -107,6 +109,10 @@
     if (fd_score == NULL)
         fd_score = fopen(score_file, "a+");
 
+#ifdef LOGFILE
+    file_log = fopen(LOGFILE, "a+");
+#endif
+
     if (!use_savedir)
         md_normaluser();
 
--- a/urogue/rip.c	Sun Feb 26 14:58:49 2017 -0500
+++ b/urogue/rip.c	Sun Feb 26 16:51:29 2017 -0500
@@ -53,6 +53,8 @@
     0
 };
 
+void writelog(long amount, int lvl, int flags, int monst);
+
 /*
     death()
         Do something really fun when he dies
@@ -205,6 +207,9 @@
 
     char    *packend;
 
+    if (flags != SCOREIT)
+        writelog(amount, lvl, flags, monst);
+
     if (flags != WINNER && flags != TOTAL && flags != SCOREIT)
     {
         if (flags == CHICKEN)
@@ -386,6 +391,31 @@
 }
 
 void
+writelog(long amount, int lvl, int flags, int monst)
+{
+    char fate[80];
+    if (file_log == NULL)
+        return;
+    if (flags == KILLED) {
+        strcpy(fate, "killed by ");
+        killname(monst, fate + 10);
+    }
+    else if (flags == CHICKEN) {
+        strcpy(fate, "quit");
+    }
+    else if (flags == WINNER || flags == TOTAL) {
+        strcpy(fate, "escaped");
+    }
+    else
+        return;
+    fprintf(file_log, "%d %d %s %d %s %d %d %d %s\n", time(NULL), amount, 
+		    whoami, lvl, which_class(player.t_ctype), level, max_level, 
+		    has_artifact, fate);
+    fclose(file_log);
+    return;
+}
+
+void
 total_winner(void)
 {
     struct linked_list  *item;
--- a/urogue/rogue.h	Sun Feb 26 14:58:49 2017 -0500
+++ b/urogue/rogue.h	Sun Feb 26 16:51:29 2017 -0500
@@ -1380,6 +1380,7 @@
 /* main.c */
 
 extern FILE *fd_score;
+extern FILE *file_log;
 extern int   summoned;
 extern coord dta;
 extern int   main(int argc, char *argv[]);