Mercurial > hg > early-roguelike
comparison srogue/rip.c @ 41:5ea4a4d8f961
srogue: add logging.
| author | elwin |
|---|---|
| date | Sat, 04 Dec 2010 14:45:38 +0000 |
| parents | 2128c7dc8a40 |
| children | 24e6beb9e7aa |
comparison
equal
deleted
inserted
replaced
| 40:984f7d5afb6f | 41:5ea4a4d8f961 |
|---|---|
| 19 #include <sys/types.h> | 19 #include <sys/types.h> |
| 20 #include <pwd.h> | 20 #include <pwd.h> |
| 21 #include <fcntl.h> | 21 #include <fcntl.h> |
| 22 #include "rogue.h" | 22 #include "rogue.h" |
| 23 #include "rogue.ext" | 23 #include "rogue.ext" |
| 24 | |
| 25 #define LOGFILE "/usr/local/games/roguelike/srogue.log" | |
| 24 | 26 |
| 25 static char scoreline[100]; | 27 static char scoreline[100]; |
| 26 | 28 |
| 27 static char *rip[] = { | 29 static char *rip[] = { |
| 28 " ____________________", | 30 " ____________________", |
| 80 mvaddstr(16, 36 - ((strlen(buf) + 1) / 2), buf); | 82 mvaddstr(16, 36 - ((strlen(buf) + 1) / 2), buf); |
| 81 sprintf(prbuf, "%d/%d/%d", lt->tm_mon + 1, lt->tm_mday, 1900+lt->tm_year); | 83 sprintf(prbuf, "%d/%d/%d", lt->tm_mon + 1, lt->tm_mday, 1900+lt->tm_year); |
| 82 mvaddstr(18, 32, prbuf); | 84 mvaddstr(18, 32, prbuf); |
| 83 move(LINES-1, 0); | 85 move(LINES-1, 0); |
| 84 refresh(); | 86 refresh(); |
| 87 writelog(purse, KILLED, monst); | |
| 85 score(purse, KILLED, monst); | 88 score(purse, KILLED, monst); |
| 86 byebye(0); | 89 byebye(0); |
| 87 } | 90 } |
| 88 | 91 |
| 89 /* | 92 /* |
| 213 refresh(); | 216 refresh(); |
| 214 endwin(); | 217 endwin(); |
| 215 showtop(prflags); /* print top ten list */ | 218 showtop(prflags); /* print top ten list */ |
| 216 } | 219 } |
| 217 | 220 |
| 221 void writelog(int amount, int aflag, char monst) | |
| 222 { | |
| 223 char logmessage[160], ltemp[80], mlev[40]; | |
| 224 char *killer; | |
| 225 FILE *logfi; | |
| 226 | |
| 227 if (waswizard) | |
| 228 return; | |
| 229 #ifdef LOGFILE | |
| 230 sprintf(logmessage, "%d %d %.20s %d ", time(NULL), amount, whoami, | |
| 231 him->s_lvl); | |
| 232 if (amulet) | |
| 233 sprintf(mlev, " [max %d] with the Amulet", max_level); | |
| 234 else | |
| 235 mlev[0] = '\0'; | |
| 236 if (aflag == KILLED) { | |
| 237 killer = killname(monst); | |
| 238 sprintf(ltemp, "killed by a%s %s on level %d%s\n", | |
| 239 vowelstr(killer), killer, level, mlev); | |
| 240 } | |
| 241 else if (aflag == CHICKEN) { | |
| 242 sprintf(ltemp, "quit on level %d%s\n", level, mlev); | |
| 243 } | |
| 244 else if (aflag == WINNER) { | |
| 245 sprintf(ltemp, "escaped with the Amulet [deepest level: %d]\n", | |
| 246 max_level); | |
| 247 } | |
| 248 else | |
| 249 return; | |
| 250 strcat(logmessage, ltemp); | |
| 251 logfi = fopen(LOGFILE, "a"); | |
| 252 if (logfi == NULL) | |
| 253 return; | |
| 254 fprintf(logfi, "%s", logmessage); | |
| 255 fclose(logfi); | |
| 256 #endif | |
| 257 return; | |
| 258 } | |
| 259 | |
| 218 /* | 260 /* |
| 219 * showtop: | 261 * showtop: |
| 220 * Display the top ten on the screen | 262 * Display the top ten on the screen |
| 221 */ | 263 */ |
| 222 showtop(showname) | 264 showtop(showname) |
| 294 refresh(); | 336 refresh(); |
| 295 wait_for(stdscr, ' '); | 337 wait_for(stdscr, ' '); |
| 296 clear(); | 338 clear(); |
| 297 oldpurse = purse; | 339 oldpurse = purse; |
| 298 showpack(TRUE, NULL); | 340 showpack(TRUE, NULL); |
| 341 writelog(purse, WINNER, 0); | |
| 299 score(purse, WINNER, 0); | 342 score(purse, WINNER, 0); |
| 300 byebye(0); | 343 byebye(0); |
| 301 } | 344 } |
| 302 | 345 |
| 303 /* | 346 /* |
