# HG changeset patch # User edwarj4 # Date 1257892726 0 # Node ID a731f515575e02c28262e4f4ac22e1ead6d31b41 # Parent 7ef854484e08ef2d09ecc446d2bb1ed5d1ffc827 rogue3: add the option of logging all games to a text file diff -r 7ef854484e08 -r a731f515575e rogue3/Makefile --- a/rogue3/Makefile Sat Oct 31 15:18:51 2009 +0000 +++ b/rogue3/Makefile Tue Nov 10 22:38:46 2009 +0000 @@ -40,7 +40,8 @@ ROPTS = COPTS = -O3 CFLAGS= $(COPTS) $(ROPTS) -DSCOREFILE=\"/usr/local/games/roguelike/rogue3.scr\" \ - -DSAVEDIR=\"/usr/local/games/roguelike/rogue3save/\" + -DSAVEDIR=\"/usr/local/games/roguelike/rogue3save/\" \ + -DLOGFILE=\"/usr/local/games/roguelike/rogue3.log\" LIBS = -lcurses RM = rm -f LD = $(CC) diff -r 7ef854484e08 -r a731f515575e rogue3/command.c --- a/rogue3/command.c Sat Oct 31 15:18:51 2009 +0000 +++ b/rogue3/command.c Tue Nov 10 22:38:46 2009 +0000 @@ -338,6 +338,7 @@ move(LINES-1, 0); draw(stdscr); endwin(); + log(purse, 1, 0); score(purse, 1, 0); exit(0); } diff -r 7ef854484e08 -r a731f515575e rogue3/main.c --- a/rogue3/main.c Sat Oct 31 15:18:51 2009 +0000 +++ b/rogue3/main.c Tue Nov 10 22:38:46 2009 +0000 @@ -23,6 +23,7 @@ WINDOW *hw; /* Used for the help command */ WINDOW *mw; /* Used to store mosnters */ FILE *scoreboard = NULL; +FILE *logf = NULL; main(argc, argv, envp) char **argv; diff -r 7ef854484e08 -r a731f515575e rogue3/rip.c --- a/rogue3/rip.c Sat Oct 31 15:18:51 2009 +0000 +++ b/rogue3/rip.c Tue Nov 10 22:38:46 2009 +0000 @@ -77,6 +77,7 @@ mvaddstr(18, 26, prbuf); move(LINES-1, 0); draw(stdscr); + log(purse, 0, monst); score(purse, 0, monst); /* Make sure all the output gets through ssh and anything else that might be in the way. */ @@ -118,6 +119,31 @@ #endif } +#if 0 /* not necessary */ +/* Same thing, but for the log file. Maybe combine them eventually. */ +/* FIXME you don't know what this does */ +void open_log(void) +{ +#ifdef LOGFILE + if (logf != NULL) { + rewind(logf); + return; + } + + logf = fopen(LOGFILE, "a"); + + if (logf == NULL) + { + fprintf(stderr, "Could not open %s for appending: %s\n", LOGFILE, strerror(errno)); + fflush(stderr); + } +#else + logf == NULL; +#endif + return; +} +#endif + /* VARARGS2 */ void score(int amount, int flags, int monst) @@ -288,6 +314,59 @@ fclose(outf); } +void log(int amount, int flags, int monst) +{ + char logmessage[160], ltemp[80]; + char *killer; + + if (waswizard) + return; +#ifdef LOGFILE + sprintf(logmessage, "%d %d %.20s ", time(NULL), amount, whoami); + if (flags == 0) /* died */ + { + strcat(logmessage, "killed by a"); + killer = killname(monst); + if (*killer == 'a' || *killer == 'e' || *killer == 'i' || + *killer == 'o' || *killer == 'u') + strcat(logmessage, "n "); + else + strcat(logmessage, " "); + strcat(logmessage, killer); + if (max_level > level) + sprintf(ltemp, " on level %d [max %d]\n", level, max_level); + else + sprintf(ltemp, " on level %d\n", level); + strcat(logmessage, ltemp); + } + else if (flags == 1) /* quit */ + { + if (max_level > level) + sprintf(ltemp, "quit on level %d [max %d]\n", level, max_level); + else + sprintf(ltemp, "quit on level %d\n", level); + strcat(logmessage, ltemp); + } + else if (flags == 2) /* won */ + { + sprintf(ltemp, "escaped with the Amulet found on level %d\n", max_level); + strcat(logmessage, ltemp); + } + else + return; + + logf = fopen(LOGFILE, "a"); /* permissions? */ + if (logf == NULL) + return; + /* and write it */ + md_lockfile(logf); + fprintf(logf, "%s", logmessage); + md_unlockfile(logf); + fclose(logf); +#endif + return; +} + void total_winner() { @@ -394,6 +473,7 @@ } mvprintw(c - 'a' + 1, 0," %5d Gold Peices ", oldpurse); refresh(); + log(purse, 2, 0); score(purse, 2, 0); exit(0); } diff -r 7ef854484e08 -r a731f515575e rogue3/rogue.h --- a/rogue3/rogue.h Sat Oct 31 15:18:51 2009 +0000 +++ b/rogue3/rogue.h Tue Nov 10 22:38:46 2009 +0000 @@ -443,6 +443,7 @@ extern int jump; /* Show running as series of jumps */ extern int lastscore; /* Score before this turn */ extern int level; /* What level rogue is on */ +extern FILE * logf; extern char lvl_mons[27]; extern struct linked_list * lvl_obj; /* List of objects on this level */ extern int max_hp; /* Player's max hit points */ @@ -597,6 +598,7 @@ char * killname(int monst); void lengthen(void (*func)(), int xtime); void light(coord *cp); +void log(int amount, int flags, int monst); void look(int wakeup); void miss(char *er, char *ee); void missile(int ydelta, int xdelta);