Mercurial > hg > early-roguelike
comparison arogue7/rip.c @ 125:adfa37e67084
Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
author | John "Elwin" Edwards |
---|---|
date | Fri, 08 May 2015 15:24:40 -0400 |
parents | |
children | b786053d2f37 |
comparison
equal
deleted
inserted
replaced
124:d10fc4a065ac | 125:adfa37e67084 |
---|---|
1 /* | |
2 * rip.c - File for the fun ends Death or a total win | |
3 * | |
4 * Advanced Rogue | |
5 * Copyright (C) 1984, 1985, 1986 Michael Morgan, Ken Dalka and AT&T | |
6 * All rights reserved. | |
7 * | |
8 * Based on "Rogue: Exploring the Dungeons of Doom" | |
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
10 * All rights reserved. | |
11 * | |
12 * See the file LICENSE.TXT for full copyright and licensing information. | |
13 */ | |
14 | |
15 /* Print flags for scoring */ | |
16 #define REALLIFE 1 /* Print out machine and logname */ | |
17 #define EDITSCORE 2 /* Edit the current score file */ | |
18 #define ADDSCORE 3 /* Add a new score */ | |
19 | |
20 #define NAMELEN 80 | |
21 | |
22 /* | |
23 * File for the fun ends | |
24 * Death or a total win | |
25 * | |
26 */ | |
27 | |
28 #include "curses.h" | |
29 #ifdef BSD | |
30 #include <sys/time.h> | |
31 #else | |
32 #include <time.h> | |
33 #endif | |
34 #include <signal.h> | |
35 #include <ctype.h> | |
36 #include <sys/types.h> | |
37 #include <fcntl.h> | |
38 #include "mach_dep.h" | |
39 #include "network.h" | |
40 #include "rogue.h" | |
41 #ifdef PC7300 | |
42 #include "sys/window.h" | |
43 extern struct uwdata wdata, oldwin; | |
44 extern char oldtext[WTXTNUM][WTXTLEN]; | |
45 #endif | |
46 | |
47 #ifdef NUMNET | |
48 /* Network machines (for mutual score keeping) */ | |
49 static struct network Network[NUMNET] = { | |
50 { "ihwpt", "/t1/michael/bin/rg" }, | |
51 }; | |
52 #endif | |
53 | |
54 /* | |
55 * If you change this structure, change the compatibility routines | |
56 * scoreout() and scorein() to reflect the change. Also update SCORELEN. | |
57 */ | |
58 struct sc_ent { | |
59 unsigned long sc_score; | |
60 char sc_name[NAMELEN]; | |
61 char sc_system[SYSLEN]; | |
62 char sc_login[LOGLEN]; | |
63 short sc_flags; | |
64 short sc_level; | |
65 short sc_ctype; | |
66 short sc_monster; | |
67 short sc_quest; | |
68 }; | |
69 #define SCORELEN \ | |
70 (sizeof(unsigned long) + NAMELEN + SYSLEN + LOGLEN + 5*sizeof(short)) | |
71 | |
72 static char *rip[] = { | |
73 " __________", | |
74 " / \\", | |
75 " / REST \\", | |
76 " / IN \\", | |
77 " / PEACE \\", | |
78 " / \\", | |
79 " | |", | |
80 " | |", | |
81 " | killed by |", | |
82 " | |", | |
83 " | 1984 |", | |
84 " *| * * * | *", | |
85 " ________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______", | |
86 0 | |
87 }; | |
88 | |
89 char *killname(); | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 void | |
96 byebye(sig) | |
97 int sig; | |
98 { | |
99 if (!isendwin()) { | |
100 clear(); | |
101 endwin(); | |
102 } | |
103 #ifdef PC7300 | |
104 endhardwin(); | |
105 #endif | |
106 printf("\n"); | |
107 exit(0); | |
108 } | |
109 | |
110 | |
111 /* | |
112 * death: | |
113 * Do something really fun when he dies | |
114 */ | |
115 | |
116 death(monst) | |
117 register short monst; | |
118 { | |
119 register char **dp = rip, *killer; | |
120 register struct tm *lt; | |
121 time_t date; | |
122 char buf[LINELEN]; | |
123 struct tm *localtime(); | |
124 | |
125 time(&date); | |
126 lt = localtime(&date); | |
127 clear(); | |
128 move(8, 0); | |
129 while (*dp) | |
130 printw("%s\n", *dp++); | |
131 mvaddstr(14, 28-((strlen(whoami)+1)/2), whoami); | |
132 sprintf(buf, "%lu Points", pstats.s_exp ); | |
133 mvaddstr(15, 28-((strlen(buf)+1)/2), buf); | |
134 killer = killname(monst); | |
135 mvaddstr(17, 28-((strlen(killer)+1)/2), killer); | |
136 mvaddstr(18, 26, (sprintf(prbuf, "%4d", 1900+lt->tm_year), prbuf)); | |
137 move(lines-1, 0); | |
138 refresh(); | |
139 score(pstats.s_exp, KILLED, monst); | |
140 endwin(); | |
141 #ifdef PC7300 | |
142 endhardwin(); | |
143 #endif | |
144 exit(0); | |
145 } | |
146 | |
147 #ifdef PC7300 | |
148 /* | |
149 * Restore window characteristics on a hard window terminal (PC7300). | |
150 */ | |
151 endhardwin() | |
152 { | |
153 register int i; | |
154 struct utdata labelbuf; | |
155 | |
156 /* Restore the old window size */ | |
157 if (oldwin.uw_width) ioctl(1, WIOCSETD, &oldwin); | |
158 | |
159 /* Restore the old window text */ | |
160 for (i=0; i<WTXTNUM; i++) { | |
161 labelbuf.ut_num = i; | |
162 strcpy(labelbuf.ut_text, oldtext[i]); | |
163 ioctl(1, WIOCSETTEXT, &labelbuf); | |
164 } | |
165 } | |
166 #endif | |
167 | |
168 char * | |
169 killname(monst) | |
170 register short monst; | |
171 { | |
172 static char mons_name[LINELEN]; | |
173 int i; | |
174 | |
175 if (monst > NUMMONST) return("a strange monster"); | |
176 | |
177 if (monst >= 0) { | |
178 switch (monsters[monst].m_name[0]) { | |
179 case 'a': | |
180 case 'e': | |
181 case 'i': | |
182 case 'o': | |
183 case 'u': | |
184 sprintf(mons_name, "an %s", monsters[monst].m_name); | |
185 break; | |
186 default: | |
187 sprintf(mons_name, "a %s", monsters[monst].m_name); | |
188 } | |
189 return(mons_name); | |
190 } | |
191 for (i = 0; i< DEATHNUM; i++) { | |
192 if (deaths[i].reason == monst) | |
193 break; | |
194 } | |
195 if (i >= DEATHNUM) | |
196 return ("strange death"); | |
197 return (deaths[i].name); | |
198 } | |
199 | |
200 | |
201 /* | |
202 * score -- figure score and post it. | |
203 */ | |
204 | |
205 /* VARARGS2 */ | |
206 score(amount, flags, monst) | |
207 unsigned long amount; | |
208 short monst; | |
209 { | |
210 static struct sc_ent top_ten[NUMSCORE]; | |
211 register struct sc_ent *scp; | |
212 register int i; | |
213 register struct sc_ent *sc2; | |
214 register int outfd; | |
215 register char *killer; | |
216 register int prflags = 0; | |
217 register int fd; | |
218 short upquest, wintype, uplevel, uptype; /* For network updating */ | |
219 char upsystem[SYSLEN], uplogin[LOGLEN]; | |
220 char *thissys; /* Holds the name of this system */ | |
221 char *compatstr=NULL; /* Holds scores for writing compatible score files */ | |
222 char scoreline[100]; | |
223 #define REASONLEN 3 | |
224 static char *reason[] = { | |
225 "killed", | |
226 "quit", | |
227 "A total winner", | |
228 "somehow left", | |
229 }; | |
230 char *packend; | |
231 | |
232 signal(SIGINT, byebye); | |
233 if (flags != WINNER && flags != SCOREIT && flags != UPDATE) { | |
234 if (flags == CHICKEN) | |
235 packend = "when you quit"; | |
236 else | |
237 { | |
238 packend = "at your untimely demise"; | |
239 mvaddstr(lines - 1, 0, retstr); | |
240 refresh(); | |
241 getstr(prbuf); | |
242 } | |
243 showpack(packend); | |
244 } | |
245 purse = 0; /* Steal all the gold */ | |
246 | |
247 /* | |
248 * Open file and read list | |
249 */ | |
250 | |
251 if ((fd = open(score_file, O_RDWR | O_CREAT, 0666)) < 0) return; | |
252 outfd = fd; | |
253 | |
254 #ifndef SYSTEM | |
255 thissys = md_gethostname(); | |
256 #else | |
257 thissys = SYSTEM; | |
258 #endif | |
259 | |
260 for (scp = top_ten; scp <= &top_ten[NUMSCORE-1]; scp++) | |
261 { | |
262 scp->sc_score = 0L; | |
263 for (i = 0; i < NAMELEN; i++) | |
264 scp->sc_name[i] = rnd(255); | |
265 scp->sc_quest= RN; | |
266 scp->sc_flags = RN; | |
267 scp->sc_level = RN; | |
268 scp->sc_monster = RN; | |
269 scp->sc_ctype = 0; | |
270 strncpy(scp->sc_system, thissys, SYSLEN); | |
271 scp->sc_login[0] = '\0'; | |
272 } | |
273 | |
274 /* | |
275 * If this is a SCOREIT optin (rogue -s), don't call byebye. The | |
276 * endwin() call in byebye() will result in a core dump. | |
277 */ | |
278 if (flags == SCOREIT) signal(SIGINT, SIG_DFL); | |
279 else signal(SIGINT, byebye); | |
280 | |
281 if (flags != SCOREIT && flags != UPDATE) | |
282 { | |
283 mvaddstr(lines - 1, 0, retstr); | |
284 refresh(); | |
285 fflush(stdout); | |
286 getstr(prbuf); | |
287 } | |
288 | |
289 /* Check for special options */ | |
290 if (strcmp(prbuf, "names") == 0) | |
291 prflags = REALLIFE; | |
292 #ifdef WIZARD | |
293 else if (wizard) { | |
294 if (strcmp(prbuf, "edit") == 0) prflags = EDITSCORE; | |
295 else if (strcmp(prbuf, "add") == 0) { | |
296 prflags = ADDSCORE; | |
297 waswizard = FALSE; /* We want the new score recorded */ | |
298 } | |
299 } | |
300 #endif | |
301 | |
302 /* Read the score and convert it to a compatible format */ | |
303 for(i = 0; i < NUMSCORE; i++) | |
304 { | |
305 encread(top_ten[i].sc_name, NAMELEN, fd); | |
306 encread(top_ten[i].sc_system, SYSLEN, fd); | |
307 encread(top_ten[i].sc_login, LOGLEN, fd); | |
308 encread(scoreline, 100, fd); | |
309 sscanf(scoreline, " %lu %hd %hd %hd %hd %hd \n", | |
310 &top_ten[i].sc_score, &top_ten[i].sc_flags, | |
311 &top_ten[i].sc_level, &top_ten[i].sc_ctype, | |
312 &top_ten[i].sc_monster, &top_ten[i].sc_quest | |
313 ); | |
314 } | |
315 | |
316 /* Get some values if this is an update */ | |
317 if (flags == UPDATE) { | |
318 unsigned long netread(); | |
319 int errcheck, errors = 0; | |
320 | |
321 upquest = (short) netread(&errcheck, sizeof(short), stdin); | |
322 if (errcheck) errors++; | |
323 | |
324 if (fread(whoami, 1, NAMELEN, stdin) != NAMELEN) errors++; | |
325 | |
326 wintype = (short) netread(&errcheck, sizeof(short), stdin); | |
327 if (errcheck) errors++; | |
328 | |
329 uplevel = (short) netread(&errcheck, sizeof(short), stdin); | |
330 if (errcheck) errors++; | |
331 | |
332 uptype = (short) netread(&errcheck, sizeof(short), stdin); | |
333 if (errcheck) errors++; | |
334 | |
335 if (fread(upsystem, 1, SYSLEN, stdin) != SYSLEN) | |
336 errors++; | |
337 if (fread(uplogin, 1, LOGLEN, stdin) != LOGLEN) | |
338 errors++; | |
339 | |
340 if (errors) { | |
341 close(outfd); | |
342 free(compatstr); | |
343 return; | |
344 } | |
345 } | |
346 | |
347 /* | |
348 * Insert player in list if need be | |
349 */ | |
350 if (!waswizard) { | |
351 char *login; | |
352 | |
353 if (flags != UPDATE) { | |
354 login = md_getusername(); | |
355 } | |
356 | |
357 if (flags == UPDATE) | |
358 (void) update(top_ten, amount, upquest, whoami, wintype, | |
359 uplevel, monst, uptype, upsystem, uplogin); | |
360 else { | |
361 #ifdef WIZARD | |
362 if (prflags == ADDSCORE) { /* Overlay characteristic by new ones */ | |
363 char buffer[LINELEN]; | |
364 | |
365 clear(); | |
366 mvaddstr(1, 0, "Score: "); | |
367 mvaddstr(2, 0, "Quest (number): "); | |
368 mvaddstr(3, 0, "Name: "); | |
369 mvaddstr(4, 0, "System: "); | |
370 mvaddstr(5, 0, "Login: "); | |
371 mvaddstr(6, 0, "Level: "); | |
372 mvaddstr(7, 0, "Char type: "); | |
373 mvaddstr(8, 0, "Result: "); | |
374 | |
375 /* Get the score */ | |
376 move(1, 7); | |
377 get_str(buffer, stdscr); | |
378 amount = atol(buffer); | |
379 | |
380 /* Get the character's quest -- must be a number */ |