comparison xrogue/rip.c @ 138:dd137c35c3b1

xrogue: record the result of each game in a logfile.
author John "Elwin" Edwards
date Tue, 05 May 2015 11:24:02 -0400
parents ce0cf824c192
children 7faf4568c295
comparison
equal deleted inserted replaced
137:443c8bd3e290 138:dd137c35c3b1
17 */ 17 */
18 18
19 #define REALLIFE 1 /* Print out machine and logname */ 19 #define REALLIFE 1 /* Print out machine and logname */
20 #define EDITSCORE 2 /* Edit the current score file */ 20 #define EDITSCORE 2 /* Edit the current score file */
21 #define ADDSCORE 3 /* Add a new score */ 21 #define ADDSCORE 3 /* Add a new score */
22
23 #define LOGFILE "xrogue.log"
22 24
23 #include <curses.h> 25 #include <curses.h>
24 #include <time.h> 26 #include <time.h>
25 #include <signal.h> 27 #include <signal.h>
26 #include <ctype.h> 28 #include <ctype.h>
78 register struct tm *lt; 80 register struct tm *lt;
79 time_t date; 81 time_t date;
80 char buf[LINELEN]; 82 char buf[LINELEN];
81 struct tm *localtime(); 83 struct tm *localtime();
82 84
85 writelog(pstats.s_exp, KILLED, monst);
83 time(&date); 86 time(&date);
84 lt = localtime(&date); 87 lt = localtime(&date);
85 clear(); 88 clear();
86 move(8, 0); 89 move(8, 0);
87 while (*dp) 90 while (*dp)
126 break; 129 break;
127 } 130 }
128 if (i >= DEATHNUM) 131 if (i >= DEATHNUM)
129 return ("strange death"); 132 return ("strange death");
130 return (deaths[i].name); 133 return (deaths[i].name);
134 }
135
136 /* Writes an entry in the log file */
137
138 void
139 writelog(unsigned long amount, int flags, short monst)
140 {
141 FILE *logwriter;
142 char had_quest = '0';
143 char fate[LINELEN];
144 struct linked_list *item;
145 struct object *obj;
146 #ifdef LOGFILE
147 if (waswizard)
148 return;
149 /* Adjustments to the score */
150 if (level == 0 && max_level == 0)
151 amount = 0;
152 if (flags == CHICKEN)
153 amount /= 100;
154 /* Check for quest item */
155 for (item = pack; item != NULL; item = next(item)) {
156 obj = OBJPTR(item);
157 if (obj->o_type == RELIC && obj->o_which == quest_item)
158 had_quest = '1';
159 }
160 /* Describe what happened */
161 if (flags == KILLED) {
162 snprintf(fate, LINELEN, "killed by %s", killname(monst));
163 }
164 else if (flags == CHICKEN) {
165 strcpy(fate, "quit");
166 }
167 else if (flags == WINNER) {
168 strcpy(fate, "escaped");
169 }
170 else
171 return;
172 /* Open and write */
173 logwriter = fopen(LOGFILE, "a");
174 if (logwriter == NULL)
175 return;
176 fprintf(logwriter, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount,
177 whoami, pstats.s_lvl, char_class[char_type].name, level, max_level,
178 quest_item, had_quest, fate);
179 fclose(logwriter);
180 #endif
181 return;
131 } 182 }
132 183
133 /* 184 /*
134 * score -- figure score and post it. 185 * score -- figure score and post it.
135 */ 186 */
597 mvprintw(c-'a'+1, 0, "%c) %6ld %s", c, worth, inv_name(obj, FALSE)); 648 mvprintw(c-'a'+1, 0, "%c) %6ld %s", c, worth, inv_name(obj, FALSE));
598 purse += worth; 649 purse += worth;
599 } 650 }
600 mvprintw(c - 'a' + 1, 0," %5ld Gold Pieces ", oldpurse); 651 mvprintw(c - 'a' + 1, 0," %5ld Gold Pieces ", oldpurse);
601 refresh(); 652 refresh();
653 writelog(pstats.s_exp + (long) purse, WINNER, '\0');
602 score(pstats.s_exp + (long) purse, WINNER, '\0'); 654 score(pstats.s_exp + (long) purse, WINNER, '\0');
603 exit_game(EXIT_ENDWIN); 655 exit_game(EXIT_ENDWIN);
604 } 656 }
605 657
606 658