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