comparison rogue3/rip.c @ 0:527e2150eaf0

Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
author edwarj4
date Tue, 13 Oct 2009 13:33:34 +0000
parents
children d388234c4ce9
comparison
equal deleted inserted replaced
-1:000000000000 0:527e2150eaf0
1 /*
2 * File for the fun ends
3 * Death or a total win
4 *
5 * @(#)rip.c 3.13 (Berkeley) 6/16/81
6 *
7 * Rogue: Exploring the Dungeons of Doom
8 * Copyright (C) 1980, 1981 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 <stdlib.h>
15 #include <errno.h>
16 #include <time.h>
17 #include <signal.h>
18 #include <ctype.h>
19 #include <sys/types.h>
20 #include <fcntl.h>
21 #include <string.h>
22 #include "curses.h"
23 #include "machdep.h"
24 #include "rogue.h"
25
26 static char *rip[] = {
27 " __________",
28 " / \\",
29 " / REST \\",
30 " / IN \\",
31 " / PEACE \\",
32 " / \\",
33 " | |",
34 " | |",
35 " | killed by a |",
36 " | |",
37 " | 1980 |",
38 " *| * * * | *",
39 " ________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______",
40 0
41 };
42
43 char *killname();
44
45 /*
46 * death:
47 * Do something really fun when he dies
48 */
49
50 void
51 death(int monst)
52 {
53 char **dp = rip, *killer;
54 struct tm *lt;
55 time_t date;
56 char buf[80];
57
58 time(&date);
59 lt = localtime(&date);
60 clear();
61 move(8, 0);
62 while (*dp)
63 printw("%s\n", *dp++);
64 mvaddstr(14, 28-(((int)strlen(whoami)+1)/2), whoami);
65 purse -= purse/10;
66 sprintf(buf, "%d Au", purse);
67 mvaddstr(15, 28-(((int)strlen(buf)+1)/2), buf);
68 killer = killname(monst);
69 mvaddstr(17, 28-(((int)strlen(killer)+1)/2), killer);
70 mvaddstr(16, 33, vowelstr(killer));
71 sprintf(prbuf, "%4d", 1900+lt->tm_year);
72 mvaddstr(18, 26, prbuf);
73 move(LINES-1, 0);
74 draw(stdscr);
75 score(purse, 0, monst);
76 exit(0);
77 }
78
79 /*
80 * score -- figure score and post it.
81 */
82
83 void
84 open_score(void)
85 {
86 #ifdef SCOREFILE
87 char *scorefile = SCOREFILE;
88
89 if (scoreboard != NULL) {
90 rewind(scoreboard);
91 return;
92 }
93
94 scoreboard = fopen(scorefile, "r+");
95
96 if ((scoreboard == NULL) && (errno == ENOENT))
97 {
98 scoreboard = fopen(scorefile, "w+");
99 md_chmod(scorefile,0664);
100 }
101
102 if (scoreboard == NULL) {
103 fprintf(stderr, "Could not open %s for writing: %s\n", scorefile, strerror(errno));
104 fflush(stderr);
105 }
106 #else
107 scoreboard = NULL;
108 #endif
109 }
110
111 /* VARARGS2 */
112 void
113 score(int amount, int flags, int monst)
114 {
115 static struct sc_ent {
116 int sc_score;
117 char sc_name[80];
118 int sc_flags;
119 int sc_level;
120 char sc_login[8];
121 int sc_monster;
122 } top_ten[10];
123 struct sc_ent *scp;
124 int i;
125 struct sc_ent *sc2;
126 FILE *outf;
127 char *killer;
128 int prflags = 0;
129 static char *reason[] = {
130 "killed",
131 "quit",
132 "A total winner",
133 };
134 char scoreline[100];
135 int rogue_ver = 0, scorefile_ver = 0;
136
137 /*
138 * Open file and read list
139 */
140
141 if (scoreboard == NULL)
142 return;
143
144 outf = scoreboard;
145
146 for (scp = top_ten; scp <= &top_ten[9]; scp++)
147 {
148 scp->sc_score = 0;
149 for (i = 0; i < 80; i++)
150 scp->sc_name[i] = rnd(255);
151 scp->sc_flags = RN;
152 scp->sc_level = RN;
153 scp->sc_monster = RN;
154 scp->sc_login[0] = '\0';
155 }
156
157 signal(SIGINT, SIG_DFL);
158 if ((flags != -1) && (flags != 1))
159 {
160 mvaddstr(LINES-1, 0, "[Press return to continue]");
161 draw(stdscr);
162 prbuf[0] = 0;
163 get_str(prbuf, stdscr);
164 endwin();
165 }
166 if (wizard)
167 if (strcmp(prbuf, "names") == 0)
168 prflags = 1;
169 else if (strcmp(prbuf, "edit") == 0)
170 prflags = 2;
171
172 md_lockfile(outf);
173
174 encread(scoreline, 100, outf);
175 (void) sscanf(scoreline, "R%d %d\n", &rogue_ver, &scorefile_ver);
176
177 if ((rogue_ver == 36) && (scorefile_ver == 2))
178 for(i = 0; i < 10; i++)
179 {
180 encread(&top_ten[i].sc_name, 80, outf);
181 encread(&top_ten[i].sc_login, 8, outf);
182 encread(scoreline, 100, outf);
183 (void) sscanf(scoreline, " %d %d %d %d \n",
184 &top_ten[i].sc_score, &top_ten[i].sc_flags,
185 &top_ten[i].sc_level, &top_ten[i].sc_monster);
186 }
187
188 /*
189 * Insert her in list if need be
190 */
191 if (!waswizard)
192 {
193 for (scp = top_ten; scp <= &top_ten[9]; scp++)
194 if (amount > scp->sc_score)
195 break;
196 if (scp <= &top_ten[9])
197 {
198 for (sc2 = &top_ten[9]; sc2 > scp; sc2--)
199 *sc2 = *(sc2-1);
200 scp->sc_score = amount;
201 strcpy(scp->sc_name, whoami);
202 scp->sc_flags = flags;
203 if (flags == 2)
204 scp->sc_level = max_level;
205 else
206 scp->sc_level = level;
207 scp->sc_monster = monst;
208 strncpy(scp->sc_login, md_getusername(), 8);
209 }
210 }
211 /*
212 * Print the list
213 */
214 if (flags != -1)
215 printf("\n\n\n");
216 printf("Top Ten Adventurers:\nRank\tScore\tName\n");
217 for (scp = top_ten; scp <= &top_ten[9]; scp++) {
218 if (scp->sc_score) {
219 printf("%d\t%d\t%s: %s on level %d", scp - top_ten + 1,
220 scp->sc_score, scp->sc_name, reason[scp->sc_flags],
221 scp->sc_level);
222 if (scp->sc_flags == 0) {
223 printf(" by a");
224 killer = killname(scp->sc_monster);
225 if (*killer == 'a' || *killer == 'e' || *killer == 'i' ||
226 *killer == 'o' || *killer == 'u')
227 putchar('n');
228 printf(" %s", killer);
229 }
230 if (prflags == 1)
231 {
232 printf(" (%s)", scp->sc_login);
233 putchar('\n');
234 }
235 else if (prflags == 2)
236 {
237 fflush(stdout);
238 fgets(prbuf,80,stdin);
239 if (prbuf[0] == 'd')
240 {
241 for (sc2 = scp; sc2 < &top_ten[9]; sc2++)
242 *sc2 = *(sc2 + 1);
243 top_ten[9].sc_score = 0;
244 for (i = 0; i < 80; i++)
245 top_ten[9].sc_name[i] = rnd(255);
246 top_ten[9].sc_flags = RN;
247 top_ten[9].sc_level = RN;
248 top_ten[9].sc_monster = RN;
249 scp--;
250 }
251 }
252 else
253 printf(".\n");
254 }
255 }
256
257 /*
258 * Update the list file
259 */
260
261 rewind(outf);
262
263 strcpy(scoreline, "R36 2\n");
264 encwrite(scoreline, 100, outf);
265
266 for(i = 0; i < 10; i++)
267 {
268 encwrite(&top_ten[i].sc_name, 80, outf);
269 encwrite(&top_ten[i].sc_login, 8, outf);
270 sprintf(scoreline, " %d %d %d %d \n",
271 top_ten[i].sc_score, top_ten[i].sc_flags,
272 top_ten[i].sc_level, top_ten[i].sc_monster);
273 encwrite(scoreline, 100, outf);
274 }
275
276 md_unlockfile(outf);
277
278 fclose(outf);
279 }
280
281 void
282 total_winner()
283 {
284 struct linked_list *item;
285 struct object *obj;
286 int worth = 0;
287 int c;
288 int oldpurse;
289
290 clear();
291 standout();
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(" \n");
301 addstr(" Congratulations, you have made it to the light of day! \n");
302 standend();
303 addstr("\nYou have joined the elite ranks of those who have escaped the\n");
304 addstr("Dungeons of Doom alive. You journey home and sell all your loot at\n");
305 addstr("a great profit and are admitted to the fighters guild.\n");
306 mvaddstr(LINES - 1, 0, "--Press space to continue--");
307 refresh();
308 wait_for(stdscr, ' ');
309 clear();
310 mvaddstr(0, 0, " Worth Item");
311 oldpurse = purse;
312 for (c = 'a', item = pack; item != NULL; c++, item = next(item))
313 {
314 obj = (struct object *) ldata(item);
315 switch (obj->o_type)
316 {
317 case FOOD:
318 worth = 2 * obj->o_count;
319 when WEAPON:
320 switch (obj->o_which)
321 {
322 case MACE: worth = 8;
323 when SWORD: worth = 15;
324 when BOW: worth = 75;
325 when ARROW: worth = 1;
326 when DAGGER: worth = 2;
327 when ROCK: worth = 1;
328 when TWOSWORD: worth = 30;
329 when SLING: worth = 1;
330 when DART: worth = 1;
331 when CROSSBOW: worth = 15;
332 when BOLT: worth = 1;
333 when SPEAR: worth = 2;
334 otherwise: worth = 0;
335 }
336 worth *= (1 + (10 * obj->o_hplus + 10 * obj->o_dplus));
337 worth *= obj->o_count;
338 obj->o_flags |= ISKNOW;
339 when ARMOR:
340 switch (obj->o_which)
341 {
342 case LEATHER: worth = 5;
343 when RING_MAIL: worth = 30;
344 when STUDDED_LEATHER: worth = 15;
345 when SCALE_MAIL: worth = 3;
346 when CHAIN_MAIL: worth = 75;
347 when SPLINT_MAIL: worth = 80;
348 when BANDED_MAIL: worth = 90;
349 when PLATE_MAIL: worth = 400;
350 otherwise: worth = 0;
351 }
352 if (obj->o_which >= MAXARMORS)
353 break;
354 worth *= (1 + (10 * (a_class[obj->o_which] - obj->o_ac)));
355 obj->o_flags |= ISKNOW;
356 when SCROLL:
357 s_know[obj->o_which] = TRUE;
358 worth = s_magic[obj->o_which].mi_worth;
359 worth *= obj->o_count;
360 when POTION:
361 p_know[obj->o_which] = TRUE;
362 worth = p_magic[obj->o_which].mi_worth;
363 worth *= obj->o_count;
364 when RING:
365 obj->o_flags |= ISKNOW;
366 r_know[obj->o_which] = TRUE;
367 worth = r_magic[obj->o_which].mi_worth;
368 if (obj->o_which == R_ADDSTR || obj->o_which == R_ADDDAM ||
369 obj->o_which == R_PROTECT || obj->o_which == R_ADDHIT)
370 if (obj->o_ac > 0)
371 worth += obj->o_ac * 20;
372 else