comparison rogue4/rip.c @ 12:9535a08ddc39

Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
author edwarj4
date Sat, 24 Oct 2009 16:52:52 +0000
parents
children 4967c46f1320
comparison
equal deleted inserted replaced
11:949d558c2162 12:9535a08ddc39
1 /*
2 * File for the fun ends
3 * Death or a total win
4 *
5 * @(#)rip.c 4.28 (Berkeley) 4/12/82
6 *
7 * Rogue: Exploring the Dungeons of Doom
8 * Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman
9 * All rights reserved.
10 *
11 * See the file LICENSE.TXT for full copyright and licensing information.
12 */
13
14 #include <curses.h>
15 #include <time.h>
16 #include <signal.h>
17 #include <sys/types.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include "rogue.h"
21
22 static char *rip[] = {
23 " __________",
24 " / \\",
25 " / REST \\",
26 " / IN \\",
27 " / PEACE \\",
28 " / \\",
29 " | |",
30 " | |",
31 " | killed by a |",
32 " | |",
33 " | 1980 |",
34 " *| * * * | *",
35 " ________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______",
36 0
37 };
38
39 /*
40 * score:
41 * Figure score and post it.
42 */
43 /* VARARGS2 */
44 score(amount, flags, monst)
45 int amount, flags;
46 char monst;
47 {
48 register struct sc_ent *scp;
49 register int i;
50 register struct sc_ent *sc2;
51 register FILE *outf;
52 register int prflags = 0;
53 register void (*fp)(int);
54 register int uid;
55 char scoreline[MAXSTR + 100];
56
57 static struct sc_ent {
58 char sc_name[MAXSTR];
59 unsigned int sc_flags;
60 unsigned int sc_uid;
61 unsigned short sc_monster;
62 unsigned short sc_score;
63 unsigned short sc_level;
64 } top_ten[10];
65 static char *reason[] = {
66 "killed",
67 "quit",
68 "A total winner",
69 };
70 void endit();
71
72 start_score();
73
74 if (fd >= 0)
75 outf = md_fdopen(fd, "wb");
76 else
77 return;
78
79 for (scp = top_ten; scp <= &top_ten[9]; scp++)
80 {
81 scp->sc_score = 0;
82 for (i = 0; i < MAXSTR; i++)
83 scp->sc_name[i] = rnd(255);
84 scp->sc_flags = RN;
85 scp->sc_level = RN;
86 scp->sc_monster = RN;
87 scp->sc_uid = RN;
88 }
89
90 signal(SIGINT, SIG_DFL);
91 if (flags != -1
92 #ifdef WIZARD
93 || wizard
94 #endif
95 )
96 {
97 mvaddstr(LINES - 1, 0 , "[Press return to continue]");
98 refresh();
99 wgetnstr(stdscr,prbuf,80);
100 move(LINES - 1, 0);
101 clrtoeol();
102 refresh();
103 endwin();
104 }
105 #ifdef WIZARD
106 if (wizard)
107 if (strcmp(prbuf, "names") == 0)
108 prflags = 1;
109 else if (strcmp(prbuf, "edit") == 0)
110 prflags = 2;
111 #endif
112 for(i=0; i<10; i++)
113 {
114 encread((char *) &top_ten[i].sc_name, MAXSTR, fd);
115 scoreline[0] = '\0';
116 encread((char *) scoreline, 100, fd);
117 sscanf(scoreline, "%d %d %hd %hd %hd", &top_ten[i].sc_flags,
118 &top_ten[i].sc_uid, &top_ten[i].sc_monster, &top_ten[i].sc_score,
119 &top_ten[i].sc_level);
120 }
121 /*
122 * Insert her in list if need be
123 */
124 sc2 = NULL;
125 if (!noscore)
126 {
127 uid = md_getuid();
128
129 for (scp = top_ten; scp <= &top_ten[9]; scp++)
130 if (amount > scp->sc_score)
131 break;
132 #ifdef LIMIT_TOPTEN
133 else if (flags != 2 && scp->sc_uid == uid && scp->sc_flags != 2)
134 scp = &top_ten[9] + 1; /* only one score per nowin uid */
135 #endif
136 if (scp <= &top_ten[9])
137 {
138 #ifdef LIMIT_TOPTEN
139 if (flags != 2)
140 for (sc2 = scp; sc2 <= &top_ten[9]; sc2++)
141 {
142 if (sc2->sc_uid == uid && sc2->sc_flags != 2)
143 break;
144 }
145 else
146 #endif
147 sc2 = &top_ten[9];
148 while (sc2 > scp)
149 {
150 *sc2 = sc2[-1];
151 sc2--;
152 }
153 scp->sc_score = amount;
154 strncpy(scp->sc_name, whoami, MAXSTR);
155 scp->sc_flags = flags;
156 if (flags == 2)
157 scp->sc_level = max_level;
158 else
159 scp->sc_level = level;
160 scp->sc_monster = monst;
161 scp->sc_uid = uid;
162 sc2 = scp;
163 }
164 }
165 /*
166 * Print the list
167 */
168 printf("Top Ten Rogueists:\nRank\tScore\tName\n");
169 for (scp = top_ten; scp <= &top_ten[9]; scp++)
170 {
171 if (scp->sc_score) {
172 printf("%d\t%d\t%s: %s on level %d", scp - top_ten + 1,
173 scp->sc_score, scp->sc_name, reason[scp->sc_flags],
174 scp->sc_level);
175 if (scp->sc_flags == 0)
176 printf(" by %s", killname((char) scp->sc_monster, TRUE));
177 if (prflags == 1)
178 {
179 char *name;
180 name = md_getusername(scp->sc_uid);
181
182 if (name == NULL)
183 printf(" (%d)", scp->sc_uid);
184 else
185 printf(" (%s)", name);
186 putchar('\n');
187 }
188 else if (prflags == 2)
189 {
190 fflush(stdout);
191 fgets(prbuf,80,stdin);
192 if (prbuf[0] == 'd')
193 {
194 for (sc2 = scp; sc2 < &top_ten[9]; sc2++)
195 *sc2 = *(sc2 + 1);
196 top_ten[9].sc_score = 0;
197 for (i = 0; i < MAXSTR; i++)
198 top_ten[9].sc_name[i] = rnd(255);
199 top_ten[9].sc_flags = RN;
200 top_ten[9].sc_level = RN;
201 top_ten[9].sc_monster = RN;
202 scp--;
203 }
204 }
205 else
206 printf(".\n");
207 }
208 else
209 break;
210 }
211 fseek(outf, 0L, 0);
212 /*
213 * Update the list file
214 */
215 if (sc2 != NULL)
216 {
217 if (lock_sc())
218 {
219 int i;
220
221 fp = signal(SIGINT, SIG_IGN);
222
223 for(i=0; i<10; i++)
224 {
225 encwrite((char *) &top_ten[i].sc_name, MAXSTR, outf);
226 sprintf(scoreline," %d %d %hd %hd %hd \n",
227 top_ten[i].sc_flags, top_ten[i].sc_uid,
228 top_ten[i].sc_monster, top_ten[i].sc_score,
229 top_ten[i].sc_level);
230 encwrite((char *) scoreline, 100, outf);
231 }
232 unlock_sc();
233 signal(SIGINT, fp);
234 }
235 }
236 fclose(outf);
237 }
238
239 /*
240 * death:
241 * Do something really fun when he dies
242 */
243 death(monst)
244 register char monst;
245 {
246 register char **dp = rip, *killer;
247 register struct tm *lt;
248 time_t date;
249 char buf[MAXSTR];
250 struct tm *localtime();
251
252 signal(SIGINT, SIG_IGN);
253 purse -= purse / 10;
254 signal(SIGINT, leave);
255 time(&date);
256 lt = localtime(&date);
257 clear();
258 move(8, 0);
259 while (*dp)
260 printw("%s\n", *dp++);
261 mvaddstr(14, 28-((strlen(whoami)+1)/2), whoami);
262 sprintf(buf, "%d Au", purse);
263 mvaddstr(15, 28-((strlen(buf)+1)/2), buf);
264 killer = killname(monst, FALSE);
265 mvaddstr(17, 28-((strlen(killer)+1)/2), killer);
266 if (monst == 's')
267 mvaddch(16, 32, ' ');
268 else
269 mvaddstr(16, 33, vowelstr(killer));
270 sprintf(prbuf, "%2d", 1900+lt->tm_year);
271 mvaddstr(18, 26, prbuf);
272 move(LINES-1, 0);
273 refresh();
274 score(purse, 0, monst);
275 exit(0);
276 }
277
278 /*
279 * total_winner:
280 * Code for a winner
281 */
282 total_winner()
283 {
284 register THING *obj;
285 register int worth = 0;
286 register char c;
287 register int oldpurse;
288
289 clear();
290 standout();
291 addstr(" \n");
292 addstr(" @ @ @ @ @ @@@ @ @ \n");
293 addstr(" @ @ @@ @@ @ @ @ @ \n");
294 addstr(" @ @ @@@ @ @ @ @ @ @@@ @@@@ @@@ @ @@@ @ \n");
295 addstr(" @@@@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ \n");
296 addstr(" @ @ @ @ @ @ @ @@@@ @ @ @@@@@ @ @ @ \n");
297 addstr(" @ @ @ @ @ @@ @ @ @ @ @ @ @ @ @ @ \n");
298 addstr(" @@@ @@@ @@ @ @ @ @@@@ @@@@ @@@ @@@ @@ @ \n");
299 addstr(" \n");
300 addstr(" Congratulations, you have made it to the light of day! \n");
301 standend();
302 addstr("\nYou have joined the elite ranks of those who have escaped the\n");
303 addstr("Dungeons of Doom alive. You journey home and sell all your loot at\n");
304 addstr("a great profit and are admitted to the fighters guild.\n");
305 mvaddstr(LINES - 1, 0, "--Press space to continue--");
306 refresh();
307 wait_for(' ');
308 clear();
309 mvaddstr(0, 0, " Worth Item");
310 oldpurse = purse;
311 for (c = 'a', obj = pack; obj != NULL; c++, obj = next(obj))
312 {
313 switch (obj->o_type)
314 {
315 case FOOD:
316 worth = 2 * obj->o_count;
317 when WEAPON:
318 switch (obj->o_which)
319 {
320 case MACE: worth = 8;
321 when SWORD: worth = 15;
322 when CROSSBOW: worth = 30;
323 when ARROW: worth = 1;
324 when DAGGER: worth = 2;
325 when TWOSWORD: worth = 75;
326 when DART: worth = 1;
327 when BOW: worth = 15;
328 when BOLT: worth = 1;
329 when SPEAR: worth = 5;
330 }
331 worth *= 3 * (obj->o_hplus + obj->o_dplus) + obj->o_count;
332 obj->o_flags |= ISKNOW;
333 when ARMOR:
334 switch (obj->o_which)
335 {
336 case LEATHER: worth = 20;
337 when RING_MAIL: worth = 25;
338 when STUDDED_LEATHER: worth = 20;
339 when SCALE_MAIL: worth = 30;
340 when CHAIN_MAIL: worth = 75;
341 when SPLINT_MAIL: worth = 80;
342 when BANDED_MAIL: worth = 90;
343 when PLATE_MAIL: worth = 150;
344 }
345 worth += (9 - obj->o_ac) * 100;
346 worth += (10 * (a_class[obj->o_which] - obj->o_ac));
347 obj->o_flags |= ISKNOW;
348 when SCROLL:
349 worth = s_magic[obj->o_which].mi_worth;
350 worth *= obj->o_count;
351 if (!s_know[obj->o_which])
352 worth /= 2;
353 s_know[obj->o_which] = TRUE;
354 when POTION:
355 worth = p_magic[obj->o_which].mi_worth;
356 worth *= obj->o_count;
357 if (!p_know[obj->o_which])
358 worth /= 2;
359 p_know[obj->o_which] = TRUE;
360 when RING:
361 worth = r_magic[obj->o_which].mi_worth;
362 if (obj->o_which == R_ADDSTR || obj->o_which == R_ADDDAM ||
363 obj->o_which == R_PROTECT || obj->o_which == R_ADDHIT)
364 if (obj->o_ac > 0)
365 worth += obj->o_ac * 100;
366 else
367 worth = 10;
368 if (!(obj->o_flags & ISKNOW))
369 worth /= 2;
370 obj->o_flags |= ISKNOW;
371 r_know[obj->o_which] = TRUE;
372 when STICK:
373 worth = ws_magic[obj->o_which].mi_worth;
374 worth += 20 * obj->o_charges;
375 if (!(obj->o_flags & ISKNOW))
376 worth /= 2;
377 obj->o_flags |= ISKNOW;
378 ws_know[obj->o_which] = TRUE;
379 when AMULET:
380 worth = 1000;
381 }
382 if (worth < 0)
383 worth = 0;
384 mvprintw(c - 'a' + 1, 0, "%c) %5d %s", c, worth, inv_name(obj, FALSE));
385 purse += worth;
386 }
387 mvprintw(c - 'a' + 1, 0," %5d Gold Pieces ", oldpurse);
388 refresh();
389 score(purse, 2, 0);
390 exit(0);
391 }
392
393 /*
394 * killname:
395 * Convert a code to a monster name
396 */
397 char *
398 killname(monst, doart)
399 register char monst;
400 bool doart;
401 {
402 register const char *sp;
403 register bool article;
404
405 sp = prbuf;
406 article = TRUE;
407 switch (monst)
408 {
409 case 'a':
410 sp = "arrow";
411 when 'b':
412 sp = "bolt";
413 when 'd':
414 sp = "dart";
415 when 's':
416 sp = "starvation";
417 article = FALSE;
418 otherwise:
419 if (monst >= 'A' && monst <= 'Z')
420 sp = monsters[monst-'A'].m_name;
421 else
422 {
423 sp = "God";
424 article = FALSE;
425 }
426 }
427 if (doart && article)
428 sprintf(prbuf, "a%s ", vowelstr(sp));
429 else
430 prbuf[0] = '\0';
431 strcat(prbuf, sp);
432 return prbuf;
433 }