Mercurial > hg > early-roguelike
comparison xrogue/rip.c @ 142:6b5fbd7c3ece
Merge arogue7 and xrogue trees.
author | John "Elwin" Edwards |
---|---|
date | Tue, 12 May 2015 21:39:39 -0400 |
parents | dd137c35c3b1 |
children | 7faf4568c295 |
comparison
equal
deleted
inserted
replaced
132:66b0263af424 | 142:6b5fbd7c3ece |
---|---|
1 /* | |
2 rip.c - File for the fun ends Death or a total win | |
3 | |
4 XRogue: Expeditions into the Dungeons of Doom | |
5 Copyright (C) 1991 Robert Pietkivitch | |
6 All rights reserved. | |
7 | |
8 Based on "Advanced Rogue" | |
9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T | |
10 All rights reserved. | |
11 | |
12 Based on "Rogue: Exploring the Dungeons of Doom" | |
13 Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
14 All rights reserved. | |
15 | |
16 See the file LICENSE.TXT for full copyright and licensing information. | |
17 */ | |
18 | |
19 #define REALLIFE 1 /* Print out machine and logname */ | |
20 #define EDITSCORE 2 /* Edit the current score file */ | |
21 #define ADDSCORE 3 /* Add a new score */ | |
22 | |
23 #define LOGFILE "xrogue.log" | |
24 | |
25 #include <curses.h> | |
26 #include <time.h> | |
27 #include <signal.h> | |
28 #include <ctype.h> | |
29 #include <string.h> | |
30 #include <sys/types.h> | |
31 #include <fcntl.h> | |
32 #include "mach_dep.h" | |
33 #include "network.h" | |
34 #include "rogue.h" | |
35 | |
36 /* Network machines (for mutual score keeping) */ | |
37 struct network Network[] = { | |
38 { "", "" }, | |
39 }; | |
40 | |
41 static char *rip[] = { | |
42 " ___________", | |
43 " / \\", | |
44 " / \\", | |
45 " / R. I. P. \\", | |
46 " / \\", | |
47 " / \\", | |
48 " | |", | |
49 " | |", | |
50 " | killed by |", | |
51 " | |", | |
52 " | |", | |
53 " | |", | |
54 " *| * * * |*", | |
55 " _________)|//\\\\///\\///\\//\\//\\/|(_________", | |
56 NULL | |
57 }; | |
58 | |
59 char *killname(); | |
60 | |
61 /*UNUSED*/ | |
62 void | |
63 byebye(sig) | |
64 int sig; | |
65 { | |
66 NOOP(sig); | |
67 exit_game(EXIT_ENDWIN); | |
68 } | |
69 | |
70 | |
71 /* | |
72 * death: | |
73 * Do something really fun when he dies | |
74 */ | |
75 | |
76 death(monst) | |
77 register short monst; | |
78 { | |
79 register char **dp = rip, *killer; | |
80 register struct tm *lt; | |
81 time_t date; | |
82 char buf[LINELEN]; | |
83 struct tm *localtime(); | |
84 | |
85 writelog(pstats.s_exp, KILLED, monst); | |
86 time(&date); | |
87 lt = localtime(&date); | |
88 clear(); | |
89 move(8, 0); | |
90 while (*dp) | |
91 printw("%s\n", *dp++); | |
92 mvaddstr(14, 28-((strlen(whoami)+1)/2), whoami); | |
93 sprintf(buf, "%lu Points", pstats.s_exp ); | |
94 mvaddstr(15, 28-((strlen(buf)+1)/2), buf); | |
95 killer = killname(monst); | |
96 mvaddstr(17, 28-((strlen(killer)+1)/2), killer); | |
97 mvaddstr(18, 25, (sprintf(prbuf, "%4d", 1900+lt->tm_year), prbuf)); | |
98 move(lines-1, 0); | |
99 refresh(); | |
100 score(pstats.s_exp, KILLED, monst); | |
101 exit_game(EXIT_ENDWIN); | |
102 } | |
103 | |
104 char * | |
105 killname(monst) | |
106 register short monst; | |
107 { | |
108 static char mons_name[LINELEN/2]; | |
109 int i; | |
110 | |
111 if (monst > NUMMONST) return("a strange monster"); | |
112 | |
113 if (monst >= 0) { | |
114 switch (monsters[monst].m_name[0]) { | |
115 case 'a': | |
116 case 'e': | |
117 case 'i': | |
118 case 'o': | |
119 case 'u': | |
120 sprintf(mons_name, "an %s", monsters[monst].m_name); | |
121 break; | |
122 default: | |
123 sprintf(mons_name, "a %s", monsters[monst].m_name); | |
124 } | |
125 return(mons_name); | |
126 } | |
127 for (i = 0; i< DEATHNUM; i++) { | |
128 if (deaths[i].reason == monst) | |
129 break; | |
130 } | |
131 if (i >= DEATHNUM) | |
132 return ("strange death"); | |
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; | |
182 } | |
183 | |
184 /* | |
185 * score -- figure score and post it. | |
186 */ | |
187 | |
188 /* VARARGS2 */ | |
189 score(amount, flags, monst) | |
190 unsigned long amount; | |
191 int flags; | |
192 short monst; | |
193 { | |
194 struct sc_ent top_ten[NUMSCORE]; | |
195 register struct sc_ent *scp; | |
196 register int i; | |
197 register struct sc_ent *sc2; | |
198 register FILE *outf; | |
199 register char *killer; | |
200 register int prflags = 0; | |
201 short upquest=0, wintype=0, uplevel=0, uptype=0; /* For network updating */ | |
202 char upsystem[SYSLEN], uplogin[LOGLEN]; | |
203 char *thissys; /* Holds the name of this system */ | |
204 | |
205 #define REASONLEN 3 | |
206 static char *reason[] = { | |
207 "killed", | |
208 "quit", | |
209 "A total winner", | |
210 "somehow left", | |
211 }; | |
212 char *packend; | |
213 | |
214 memset(top_ten,0,sizeof(top_ten)); | |
215 | |
216 signal(SIGINT, byebye); | |
217 if (level == 0 && max_level == 0) | |
218 amount = 0; /*don't count if quit early */ | |
219 if (flags != WINNER && flags != SCOREIT && flags != UPDATE) { | |
220 if (flags == CHICKEN) { | |
221 packend = "when you quit"; | |
222 amount = amount / 100; | |
223 } | |
224 else | |
225 packend = "at your untimely demise"; | |
226 mvaddstr(lines - 1, 0, retstr); | |
227 refresh(); | |
228 getstr(prbuf); | |
229 showpack(packend); | |
230 } | |
231 purse = 0; /* Steal all the gold */ | |
232 | |
233 /* | |
234 * Open file and read list | |
235 */ | |
236 | |
237 if ((outf = fopen(score_file, "rb+")) == NULL) | |
238 { | |
239 if ((outf = fopen(score_file, "wb+")) == NULL) | |
240 { | |
241 mvprintw(lines - 1, 0, "Unable to open or create score file: %s",score_file); | |
242 refresh(); | |
243 return; | |
244 } | |
245 } | |
246 | |
247 thissys = md_gethostname(); | |
248 | |
249 /* | |
250 * If this is a SCOREIT optin (rogue -s), don't call byebye. The | |
251 * endwin() calls in byebye() will and this results in a core dump. | |
252 */ | |
253 if (flags == SCOREIT) signal(SIGINT, SIG_DFL); | |
254 else signal(SIGINT, byebye); | |
255 | |
256 if (flags != SCOREIT && flags != UPDATE) | |
257 { | |
258 mvaddstr(lines - 1, 0, retstr); | |
259 refresh(); | |
260 fflush(stdout); | |
261 getstr(prbuf); | |
262 } | |
263 | |
264 /* Check for special options */ | |
265 if (strcmp(prbuf, "names") == 0) | |
266 prflags = REALLIFE; | |
267 else if (wizard) { | |
268 if (strcmp(prbuf, "edit") == 0) prflags = EDITSCORE; | |
269 else if (strcmp(prbuf, "add") == 0) { | |
270 prflags = ADDSCORE; | |
271 waswizard = FALSE; /* We want the new score recorded */ | |
272 } | |
273 } | |
274 | |
275 /* Read the score and convert it to a compatible format */ | |
276 | |
277 fseek(outf, 0, SEEK_SET); | |
278 rs_read_scorefile(outf, top_ten, NUMSCORE); | |
279 | |
280 /* Get some values if this is an update */ | |
281 if (flags == UPDATE) { | |
282 int errcheck, errors = 0; | |
283 | |
284 upquest = (short) netread(&errcheck, sizeof(short), stdin); | |
285 if (errcheck) errors++; | |
286 | |
287 if (fread(whoami, 1, NAMELEN, stdin) != NAMELEN) errors++; | |
288 | |
289 wintype = (short) netread(&errcheck, sizeof(short), stdin); | |
290 if (errcheck) errors++; | |
291 | |
292 uplevel = (short) netread(&errcheck, sizeof(short), stdin); | |
293 if (errcheck) errors++; | |
294 | |
295 uptype = (short) netread(&errcheck, sizeof(short), stdin); | |
296 if (errcheck) errors++; | |
297 | |
298 if (fread(upsystem, 1, SYSLEN, stdin) != SYSLEN) | |
299 errors++; | |
300 if (fread(uplogin, 1, LOGLEN, stdin) != LOGLEN) | |
301 errors++; | |
302 | |
303 if (errors) { | |
304 fclose(outf); | |
305 return; | |
306 } | |
307 } | |
308 | |
309 /* | |
310 * Insert player in list if need be | |
311 */ | |
312 if (!waswizard) { | |
313 char *login= NULL; | |
314 | |
315 if (flags != UPDATE) { | |
316 login = md_getusername(); | |
317 | |
318 if ((login == NULL) || (*login == 0)) | |
319 login = "another rogue fiend"; | |
320 } | |
321 | |
322 if (flags == UPDATE) | |
323 (void) update(top_ten, amount, upquest, whoami, wintype, | |
324 uplevel, monst, uptype, upsystem, uplogin); | |
325 else { | |
326 if (prflags == ADDSCORE) { /* Overlay characteristic by new ones */ | |
327 char buffer[LINELEN]; | |
328 | |
329 clear(); | |
330 mvaddstr(1, 0, "Score: "); | |
331 mvaddstr(2, 0, "Quest (number): "); | |
332 mvaddstr(3, 0, "Name: "); | |
333 mvaddstr(4, 0, "System: "); | |
334 mvaddstr(5, 0, "Login: "); | |
335 mvaddstr(6, 0, "Level: "); | |
336 mvaddstr(7, 0, "Char type: "); | |
337 mvaddstr(8, 0, "Result: "); | |
338 | |
339 /* Get the score */ | |
340 move(1, 7); | |
341 get_str(buffer, stdscr); | |
342 amount = atol(buffer); | |
343 | |
344 /* Get the character's quest -- must be a number */ | |
345 move(2, 16); | |
346 get_str(buffer, stdscr); | |
347 quest_item = atoi(buffer); | |
348 | |
349 /* Get the character's name */ | |
350 move(3, 6); | |
351 get_str(buffer, stdscr); | |
352 strncpy(whoami, buffer, NAMELEN); | |
353 | |
354 /* Get the system */ | |
355 move(4, 8); | |
356 get_str(buffer, stdscr); | |
357 strncpy(thissys, buffer, SYSLEN); | |
358 | |
359 /* Get the login */ | |
360 move(5, 7); | |
361 get_str(buffer, stdscr); | |
362 strncpy(login, buffer, LOGLEN); | |
363 | |
364 /* Get the level */ | |
365 move(6, 7); | |
366 get_str(buffer, stdscr); | |
367 level = max_level = (short) atoi(buffer); | |
368 | |
369 /* Get the character type */ | |
370 move(7, 11); |