comparison rogue3/rip.c @ 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 78df7025783b
children d67cac79f0f1
comparison
equal deleted inserted replaced
15:7ef854484e08 16:a731f515575e
75 mvaddstr(16, 33, vowelstr(killer)); 75 mvaddstr(16, 33, vowelstr(killer));
76 sprintf(prbuf, "%4d", 1900+lt->tm_year); 76 sprintf(prbuf, "%4d", 1900+lt->tm_year);
77 mvaddstr(18, 26, prbuf); 77 mvaddstr(18, 26, prbuf);
78 move(LINES-1, 0); 78 move(LINES-1, 0);
79 draw(stdscr); 79 draw(stdscr);
80 log(purse, 0, monst);
80 score(purse, 0, monst); 81 score(purse, 0, monst);
81 /* Make sure all the output gets through ssh and 82 /* Make sure all the output gets through ssh and
82 anything else that might be in the way. */ 83 anything else that might be in the way. */
83 printf("[Press return to exit]\n"); 84 printf("[Press return to exit]\n");
84 fflush(NULL); 85 fflush(NULL);
115 } 116 }
116 #else 117 #else
117 scoreboard = NULL; 118 scoreboard = NULL;
118 #endif 119 #endif
119 } 120 }
121
122 #if 0 /* not necessary */
123 /* Same thing, but for the log file. Maybe combine them eventually. */
124 /* FIXME you don't know what this does */
125 void open_log(void)
126 {
127 #ifdef LOGFILE
128 if (logf != NULL) {
129 rewind(logf);
130 return;
131 }
132
133 logf = fopen(LOGFILE, "a");
134
135 if (logf == NULL)
136 {
137 fprintf(stderr, "Could not open %s for appending: %s\n", LOGFILE, strerror(errno));
138 fflush(stderr);
139 }
140 #else
141 logf == NULL;
142 #endif
143 return;
144 }
145 #endif
120 146
121 /* VARARGS2 */ 147 /* VARARGS2 */
122 void 148 void
123 score(int amount, int flags, int monst) 149 score(int amount, int flags, int monst)
124 { 150 {
284 } 310 }
285 311
286 md_unlockfile(outf); 312 md_unlockfile(outf);
287 313
288 fclose(outf); 314 fclose(outf);
315 }
316
317 void log(int amount, int flags, int monst)
318 {
319 char logmessage[160], ltemp[80];
320 char *killer;
321
322 if (waswizard)
323 return;
324 #ifdef LOGFILE
325 sprintf(logmessage, "%d %d %.20s ", time(NULL), amount, whoami);
326 if (flags == 0) /* died */
327 {
328 strcat(logmessage, "killed by a");
329 killer = killname(monst);
330 if (*killer == 'a' || *killer == 'e' || *killer == 'i' ||
331 *killer == 'o' || *killer == 'u')
332 strcat(logmessage, "n ");
333 else
334 strcat(logmessage, " ");
335 strcat(logmessage, killer);
336 if (max_level > level)
337 sprintf(ltemp, " on level %d [max %d]\n", level, max_level);
338 else
339 sprintf(ltemp, " on level %d\n", level);
340 strcat(logmessage, ltemp);
341 }
342 else if (flags == 1) /* quit */
343 {
344 if (max_level > level)
345 sprintf(ltemp, "quit on level %d [max %d]\n", level, max_level);
346 else
347 sprintf(ltemp, "quit on level %d\n", level);
348 strcat(logmessage, ltemp);
349 }
350 else if (flags == 2) /* won */
351 {
352 sprintf(ltemp, "escaped with the Amulet found on level %d\n", max_level);
353 strcat(logmessage, ltemp);
354 }
355 else
356 return;
357
358 logf = fopen(LOGFILE, "a"); /* permissions? */
359 if (logf == NULL)
360 return;
361 /* and write it */
362 md_lockfile(logf);
363 fprintf(logf, "%s", logmessage);
364 md_unlockfile(logf);
365 fclose(logf);
366 #endif
367 return;
289 } 368 }
290 369
291 void 370 void
292 total_winner() 371 total_winner()
293 { 372 {
392 mvprintw(c - 'a' + 1, 0, "%c) %5d %s", c, worth, inv_name(obj, FALSE)); 471 mvprintw(c - 'a' + 1, 0, "%c) %5d %s", c, worth, inv_name(obj, FALSE));
393 purse += worth; 472 purse += worth;
394 } 473 }
395 mvprintw(c - 'a' + 1, 0," %5d Gold Peices ", oldpurse); 474 mvprintw(c - 'a' + 1, 0," %5d Gold Peices ", oldpurse);
396 refresh(); 475 refresh();
476 log(purse, 2, 0);
397 score(purse, 2, 0); 477 score(purse, 2, 0);
398 exit(0); 478 exit(0);
399 } 479 }
400 480
401 char * 481 char *