changeset 65:7aff18a8d508

arogue5: implement logging.
author elwin
date Fri, 10 Aug 2012 21:17:14 +0000
parents a98834ce7e04
children c56f672244f4
files arogue5/command.c arogue5/mach_dep.h arogue5/rip.c arogue5/rogue.h
diffstat 4 files changed, 54 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/arogue5/command.c	Fri Aug 10 05:16:08 2012 +0000
+++ b/arogue5/command.c	Fri Aug 10 21:17:14 2012 +0000
@@ -450,6 +450,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(0);
     }
--- a/arogue5/mach_dep.h	Fri Aug 10 05:16:08 2012 +0000
+++ b/arogue5/mach_dep.h	Fri Aug 10 21:17:14 2012 +0000
@@ -26,6 +26,7 @@
  * where scorefile should live
  */
 #define SCOREFILE	"/var/local/games/roguelike/arogue5.scr"
+#define LOGFILE		"/var/local/games/roguelike/arogue5.log"
 #define SAVEDIR		"/var/local/games/roguelike/arogue5save/"
 
 /*
--- a/arogue5/rip.c	Fri Aug 10 05:16:08 2012 +0000
+++ b/arogue5/rip.c	Fri Aug 10 21:17:14 2012 +0000
@@ -115,6 +115,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);
     exit(0);
 }
@@ -569,7 +570,55 @@
     scoreout(top_ten, outf);
     fclose(outf);
 }
-
+
+void writelog(unsigned long amount, int flags, short monst) {
+#ifdef LOGFILE
+  FILE *logfi;
+  char fate[100];
+  char *class;
+  struct linked_list *item;
+  struct object *obj;
+  char had_quest = '0';
+
+  if (waswizard)
+    return;
+  switch (player.t_ctype) {
+    case C_FIGHTER:	class = "Fighter";
+    when C_MAGICIAN:	class = "Magician";
+    when C_CLERIC:	class = "Cleric";
+    when C_THIEF:	class = "Thief";
+    otherwise:		class = "Unknown";
+  }
+  for (item = pack; item != NULL; item = next(item)) {
+    obj = OBJPTR(item);
+    if (obj->o_type == RELIC && obj->o_which == quest_item)
+      had_quest = '1';
+  }
+  if (flags == KILLED) {
+    sprintf(fate, "killed by %s", killname(monst));
+  }
+  else if (flags == CHICKEN) {
+    sprintf(fate, "quit");
+  }
+  else if (flags == WINNER) {
+    sprintf(fate, "escaped");
+  }
+  else
+    return;
+
+  logfi = fopen(LOGFILE, "a");
+  if (logfi == NULL) {
+    perror(LOGFILE);
+    return;
+  }
+  fprintf(logfi, "%d %d %.20s %d %s %d %d %d %c %s\n", time(NULL), amount, 
+          whoami, pstats.s_lvl, class, level, max_level, quest_item, had_quest, 
+          fate);
+  fclose(logfi);
+#endif
+  return;
+}
+
 /*
  * scorein:
  *	Convert a character string that has been translated from a
@@ -704,6 +753,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');
     exit(0);
 }
--- a/arogue5/rogue.h	Fri Aug 10 05:16:08 2012 +0000
+++ b/arogue5/rogue.h	Fri Aug 10 21:17:14 2012 +0000
@@ -965,6 +965,7 @@
 long	check_level();
 void	byebye(int sig), genmonsters();
 int     land(), undance();
+void    writelog(unsigned long amount, int flags, short monst);
 #ifdef CHECKTIME
 int checkout();
 #endif