From bd3b2e4e53d1b4c8aaa05206693a60e10e571c56 Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Tue, 10 Nov 2009 22:38:46 +0000 Subject: [PATCH] rogue3: add the option of logging all games to a text file --- rogue3/Makefile | 3 +- rogue3/command.c | 1 + rogue3/main.c | 1 + rogue3/rip.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ rogue3/rogue.h | 2 ++ 5 files changed, 86 insertions(+), 1 deletion(-) diff --git a/rogue3/Makefile b/rogue3/Makefile index f980a28..d5df3c1 100644 --- a/rogue3/Makefile +++ b/rogue3/Makefile @@ -40,7 +40,8 @@ CC = gcc 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 --git a/rogue3/command.c b/rogue3/command.c index 9fd3e8e..e6825eb 100644 --- a/rogue3/command.c +++ b/rogue3/command.c @@ -338,6 +338,7 @@ quit(int p) move(LINES-1, 0); draw(stdscr); endwin(); + log(purse, 1, 0); score(purse, 1, 0); exit(0); } diff --git a/rogue3/main.c b/rogue3/main.c index 7cf623b..4a78f84 100644 --- a/rogue3/main.c +++ b/rogue3/main.c @@ -23,6 +23,7 @@ WINDOW *cw; /* Window that the player sees */ 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 --git a/rogue3/rip.c b/rogue3/rip.c index 6dbf52a..67a6339 100644 --- a/rogue3/rip.c +++ b/rogue3/rip.c @@ -77,6 +77,7 @@ death(int monst) 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 @@ open_score(void) #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 @@ score(int amount, int flags, int monst) 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 @@ total_winner() } mvprintw(c - 'a' + 1, 0," %5d Gold Peices ", oldpurse); refresh(); + log(purse, 2, 0); score(purse, 2, 0); exit(0); } diff --git a/rogue3/rogue.h b/rogue3/rogue.h index d88db82..341ed60 100644 --- a/rogue3/rogue.h +++ b/rogue3/rogue.h @@ -443,6 +443,7 @@ extern int inpack; /* Number of things in pack */ 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 @@ void killed(struct linked_list *item, int pr); 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);