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