Mercurial > hg > early-roguelike
changeset 16:a731f515575e
rogue3: add the option of logging all games to a text file
author | edwarj4 |
---|---|
date | Tue, 10 Nov 2009 22:38:46 +0000 |
parents | 7ef854484e08 |
children | d67cac79f0f1 |
files | rogue3/Makefile rogue3/command.c rogue3/main.c rogue3/rip.c rogue3/rogue.h |
diffstat | 5 files changed, 86 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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); }
--- 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;
--- 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); }
--- 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);