rogue4: add logging all games
This commit is contained in:
parent
f9c589b480
commit
4bc7038945
6 changed files with 75 additions and 2 deletions
|
|
@ -26,7 +26,8 @@ CFILES= vers.c extern.c armor.c chase.c command.c daemon.c daemons.c \
|
||||||
MISC= Makefile LICENSE.TXT rogue.6 rogue.me
|
MISC= Makefile LICENSE.TXT rogue.6 rogue.me
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS= -O3 -DSAVEDIR=\"/usr/local/games/roguelike/rogue4save/\"
|
CFLAGS= -O3 -DSAVEDIR=\"/usr/local/games/roguelike/rogue4save/\" \
|
||||||
|
-DLOGFILE=\"/usr/local/games/roguelike/rogue4.log\"
|
||||||
CRLIB = -lcurses
|
CRLIB = -lcurses
|
||||||
RM = rm -f
|
RM = rm -f
|
||||||
TAR = tar
|
TAR = tar
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,7 @@ int food_left; /* Amount of food in hero's stomach */
|
||||||
int group = 2; /* Current group number */
|
int group = 2; /* Current group number */
|
||||||
int hungry_state = 0; /* How hungry is he */
|
int hungry_state = 0; /* How hungry is he */
|
||||||
int fd; /* File descriptor for score file */
|
int fd; /* File descriptor for score file */
|
||||||
|
int lfd; /* File descriptor for log file */
|
||||||
int a_chances[MAXARMORS] = { /* Chance for each armor type */
|
int a_chances[MAXARMORS] = { /* Chance for each armor type */
|
||||||
20,
|
20,
|
||||||
35,
|
35,
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ extern char _flags[], _level[], file_name[], fruit[],
|
||||||
|
|
||||||
extern int a_chances[], a_class[], count, dnum, food_left,
|
extern int a_chances[], a_class[], count, dnum, food_left,
|
||||||
fung_hit, fd, group, hungry_state, inpack, lastscore,
|
fung_hit, fd, group, hungry_state, inpack, lastscore,
|
||||||
level, max_level, mpos, no_command, no_food, no_move,
|
level, lfd, max_level, mpos, no_command, no_food, no_move,
|
||||||
ntraps, purse, quiet, total;
|
ntraps, purse, quiet, total;
|
||||||
|
|
||||||
extern long seed;
|
extern long seed;
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,16 @@ open_score()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void open_log(void)
|
||||||
|
{
|
||||||
|
#ifdef LOGFILE
|
||||||
|
lfd = open(LOGFILE, O_WRONLY | O_APPEND | O_CREAT, 0666);
|
||||||
|
#else
|
||||||
|
lfd = -1;
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* setup:
|
* setup:
|
||||||
* Get starting setup for all games
|
* Get starting setup for all games
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@ char **envp;
|
||||||
/*
|
/*
|
||||||
* check for print-score option
|
* check for print-score option
|
||||||
*/
|
*/
|
||||||
|
open_log(); /* do first, open_score might drop needed permissions */
|
||||||
open_score();
|
open_score();
|
||||||
if (argc == 2 && strcmp(argv[1], "-s") == 0)
|
if (argc == 2 && strcmp(argv[1], "-s") == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -349,6 +350,7 @@ quit(int a)
|
||||||
mvprintw(LINES - 2, 0, "You quit with %d gold pieces", purse);
|
mvprintw(LINES - 2, 0, "You quit with %d gold pieces", purse);
|
||||||
move(LINES - 1, 0);
|
move(LINES - 1, 0);
|
||||||
refresh();
|
refresh();
|
||||||
|
writelog(purse, 1, 0);
|
||||||
score(purse, 1);
|
score(purse, 1);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
59
rogue4/rip.c
59
rogue4/rip.c
|
|
@ -236,6 +236,63 @@ char monst;
|
||||||
fclose(outf);
|
fclose(outf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writelog(int amount, int flags, char monst)
|
||||||
|
{
|
||||||
|
FILE *logfi;
|
||||||
|
char logmessage[160], ltemp[80];
|
||||||
|
char *killer;
|
||||||
|
if (waswizard)
|
||||||
|
return;
|
||||||
|
#ifdef LOGFILE
|
||||||
|
if (lfd >= 0)
|
||||||
|
logfi = fdopen(lfd, "a");
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
if (logfi == NULL)
|
||||||
|
return;
|
||||||
|
/* otherwise writing should work */
|
||||||
|
sprintf(logmessage, "%d %d %.20s %d ", time(NULL), amount, whoami,
|
||||||
|
pstats.s_lvl);
|
||||||
|
if (flags == 0) /* died */
|
||||||
|
{
|
||||||
|
strcat(logmessage, "killed by ");
|
||||||
|
killer = killname(monst, TRUE);
|
||||||
|
strcat(logmessage, killer);
|
||||||
|
if (amulet)
|
||||||
|
sprintf(ltemp, " on level %d [max %d] with the Amulet\n",
|
||||||
|
level, max_level);
|
||||||
|
else
|
||||||
|
sprintf(ltemp, " on level %d\n", level);
|
||||||
|
strcat(logmessage, ltemp);
|
||||||
|
}
|
||||||
|
else if (flags == 1) /* quit */
|
||||||
|
{
|
||||||
|
if (amulet)
|
||||||
|
sprintf(ltemp, "quit on level %d [max %d] with the Amulet\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 [deepest level :%d]\n",
|
||||||
|
max_level);
|
||||||
|
strcat(logmessage, ltemp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fclose(logfi);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* then write */
|
||||||
|
fprintf(logfi, "%s", logmessage);
|
||||||
|
fclose(logfi);
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* death:
|
* death:
|
||||||
* Do something really fun when he dies
|
* Do something really fun when he dies
|
||||||
|
|
@ -271,6 +328,7 @@ register char monst;
|
||||||
mvaddstr(18, 26, prbuf);
|
mvaddstr(18, 26, prbuf);
|
||||||
move(LINES-1, 0);
|
move(LINES-1, 0);
|
||||||
refresh();
|
refresh();
|
||||||
|
writelog(purse, 0, monst);
|
||||||
score(purse, 0, monst);
|
score(purse, 0, monst);
|
||||||
/* Make sure the output gets through */
|
/* Make sure the output gets through */
|
||||||
printf("[Press return to exit]\n");
|
printf("[Press return to exit]\n");
|
||||||
|
|
@ -390,6 +448,7 @@ total_winner()
|
||||||
}
|
}
|
||||||
mvprintw(c - 'a' + 1, 0," %5d Gold Pieces ", oldpurse);
|
mvprintw(c - 'a' + 1, 0," %5d Gold Pieces ", oldpurse);
|
||||||
refresh();
|
refresh();
|
||||||
|
writelog(purse, 2, 0);
|
||||||
score(purse, 2, 0);
|
score(purse, 2, 0);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue