comparison srogue/rip.c @ 36:2128c7dc8a40

Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 25 Nov 2010 12:21:41 +0000
parents
children 5ea4a4d8f961
comparison
equal deleted inserted replaced
35:05018c63a721 36:2128c7dc8a40
1 /*
2 * File for the fun, ends in death or a total win
3 *
4 * @(#)rip.c 9.0 (rdk) 7/17/84
5 *
6 * Super-Rogue
7 * Copyright (C) 1984 Robert D. Kindelberger
8 * All rights reserved.
9 *
10 * Based on "Rogue: Exploring the Dungeons of Doom"
11 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
12 * All rights reserved.
13 *
14 * See the file LICENSE.TXT for full copyright and licensing information.
15 */
16
17 #include <signal.h>
18 #include <ctype.h>
19 #include <sys/types.h>
20 #include <pwd.h>
21 #include <fcntl.h>
22 #include "rogue.h"
23 #include "rogue.ext"
24
25 static char scoreline[100];
26
27 static char *rip[] = {
28 " ____________________",
29 " / \\",
30 " / Bob Kindelberger's \\",
31 " / Graveyard \\",
32 " / \\",
33 " / REST IN PEACE \\",
34 " / \\",
35 " | |",
36 " | |",
37 " | Destroyed by a |",
38 " | |",
39 " | |",
40 " | |",
41 " | |",
42 " | |",
43 " | |",
44 " | |",
45 " *| * * * * |*",
46 " ________)\\\\//\\//\\)/\\//\\)/\\//\\)/\\//\\)/\\//\\//(________",
47 };
48
49 #define RIP_LINES (sizeof rip / (sizeof (char *)))
50
51 char *killname();
52
53 /*
54 * death:
55 * Do something really fun when he dies
56 */
57
58 #include <time.h>
59 death(monst)
60 char monst;
61 {
62 reg char dp, *killer;
63 struct tm *lt;
64 time_t date;
65 char buf[LINLEN];
66 struct tm *localtime();
67
68 time(&date);
69 lt = localtime(&date);
70 clear();
71 move(3, 0);
72 for (dp = 0; dp < RIP_LINES; dp++)
73 printw("%s\n", rip[dp]);
74 mvaddstr(10, 36 - ((strlen(whoami) + 1) / 2), whoami);
75 killer = killname(monst);
76 mvaddstr(12, 43, vowelstr(killer));
77 mvaddstr(14, 36 - ((strlen(killer) + 1) / 2), killer);
78 purse -= purse/10;
79 sprintf(buf, "%d Gold Pieces", purse);
80 mvaddstr(16, 36 - ((strlen(buf) + 1) / 2), buf);
81 sprintf(prbuf, "%d/%d/%d", lt->tm_mon + 1, lt->tm_mday, 1900+lt->tm_year);
82 mvaddstr(18, 32, prbuf);
83 move(LINES-1, 0);
84 refresh();
85 score(purse, KILLED, monst);
86 byebye(0);
87 }
88
89 /*
90 * top ten entry structure
91 */
92 static struct sc_ent {
93 int sc_score; /* gold */
94 char sc_name[LINLEN]; /* players name */
95 int sc_flags; /* reason for being here */
96 int sc_level; /* dungeon level */
97 int sc_uid; /* user ID */
98 unsigned char sc_monster; /* killer */
99 int sc_explvl; /* experience level */
100 long int sc_exppts; /* experience points */
101 time_t sc_date; /* time this score was posted */
102 } top_ten[10];
103
104 char *reason[] = {
105 "Killed",
106 "Chickened out",
107 "A Total Winner"
108 };
109 int oldpurse;
110
111 /*
112 * score:
113 * Figure score and post it.
114 */
115 score(amount, aflag, monst)
116 char monst;
117 int amount, aflag;
118 {
119 reg struct sc_ent *scp, *sc2;
120 reg int i, fd, prflags = 0;
121 reg FILE *outf;
122 char *packend;
123
124 signal(SIGINT, byebye);
125 signal(SIGQUIT, byebye);
126 if (aflag != WINNER) {
127 if (aflag == CHICKEN)
128 packend = "when you chickened out";
129 else
130 packend = "at your untimely demise";
131 mvaddstr(LINES - 1, 0, retstr);
132 refresh();
133 wgetnstr(stdscr,prbuf,80);
134 oldpurse = purse;
135 showpack(FALSE, packend);
136 }
137 /*
138 * Open file and read list
139 */
140 if ((fd = open(scorefile, O_RDWR | O_CREAT, 0666)) < 0)
141 return;
142 outf = (FILE *) fdopen(fd, "w");
143 for (scp = top_ten; scp <= &top_ten[9]; scp++) {
144 scp->sc_score = 0;
145 for (i = 0; i < 80; i++)
146 scp->sc_name[i] = rnd(255);
147 scp->sc_flags = rnd(255);
148 scp->sc_level = rnd(255);
149 scp->sc_monster = rnd(255);
150 scp->sc_uid = rnd(255);
151 scp->sc_date = rnd(255);
152 }
153 mvaddstr(LINES - 1, 0, retstr);
154 refresh();
155 wgetnstr(stdscr,prbuf,80);
156 if (author() || wizard)
157 if (strcmp(prbuf, "names") == 0)
158 prflags = 1;
159 for(i = 0; i < 10; i++)
160 {
161 unsigned int mon;
162
163 encread((char *) &top_ten[i].sc_name, LINLEN, fd);
164 encread((char *) scoreline, 100, fd);
165 sscanf(scoreline, " %d %d %d %d %u %d %ld %lx \n",
166 &top_ten[i].sc_score, &top_ten[i].sc_flags,
167 &top_ten[i].sc_level, &top_ten[i].sc_uid,
168 &mon, &top_ten[i].sc_explvl,
169 &top_ten[i].sc_exppts, &top_ten[i].sc_date);
170 top_ten[i].sc_monster = mon;
171 }
172 /*
173 * Insert it in list if need be
174 */
175 if (!waswizard) {
176 for (scp = top_ten; scp <= &top_ten[9]; scp++)
177 if (amount > scp->sc_score)
178 break;
179 if (scp <= &top_ten[9]) {
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 = aflag;
185 if (aflag == WINNER)
186 scp->sc_level = max_level;
187 else
188 scp->sc_level = level;
189 scp->sc_monster = monst;
190 scp->sc_uid = playuid;
191 scp->sc_explvl = him->s_lvl;
192 scp->sc_exppts = him->s_exp;
193 time(&scp->sc_date);
194 }
195 }
196 ignore();
197 fseek(outf, 0L, 0);
198 for(i = 0; i < 10; i++)
199 {
200 memset(scoreline,0,100);
201 encwrite((char *) top_ten[i].sc_name, LINLEN, outf);
202 sprintf(scoreline, " %d %d %d %d %u %d %ld %lx \n",
203 top_ten[i].sc_score, top_ten[i].sc_flags,
204 top_ten[i].sc_level, top_ten[i].sc_uid,
205 top_ten[i].sc_monster, top_ten[i].sc_explvl,
206 top_ten[i].sc_exppts, top_ten[i].sc_date);
207 encwrite((char *) scoreline, 100, outf);
208 }
209 fclose(outf);
210 signal(SIGINT, byebye);
211 signal(SIGQUIT, byebye);
212 clear();
213 refresh();
214 endwin();
215 showtop(prflags); /* print top ten list */
216 }
217
218 /*
219 * showtop:
220 * Display the top ten on the screen
221 */
222 showtop(showname)
223 int showname;
224 {
225 reg int fd, i;
226 char *killer;
227 struct sc_ent *scp;
228
229 if ((fd = open(scorefile, O_RDONLY)) < 0)
230 return FALSE;
231
232 for(i = 0; i < 10; i++)
233 {
234 unsigned int mon;
235 encread((char *) &top_ten[i].sc_name, LINLEN, fd);
236 encread((char *) scoreline, 100, fd);
237 sscanf(scoreline, " %d %d %d %d %u %d %ld %lx \n",
238 &top_ten[i].sc_score, &top_ten[i].sc_flags,
239 &top_ten[i].sc_level, &top_ten[i].sc_uid,
240 &mon, &top_ten[i].sc_explvl,
241 &top_ten[i].sc_exppts, &top_ten[i].sc_date);
242 top_ten[i].sc_monster = mon;
243 }
244 close(fd);
245 printf("Top Ten Adventurers:\nRank\tScore\tName\n");
246 for (scp = top_ten; scp <= &top_ten[9]; scp++) {
247 if (scp->sc_score > 0) {
248 printf("%d\t%d\t%s: %s\t\t--> %s on level %d",
249 scp - top_ten + 1, scp->sc_score, scp->sc_name,
250 ctime(&scp->sc_date), reason[scp->sc_flags],
251 scp->sc_level);
252 if (scp->sc_flags == KILLED) {
253 killer = killname(scp->sc_monster);
254 printf(" by a%s %s",vowelstr(killer), killer);
255 }
256 printf(" [Exp: %d/%ld]",scp->sc_explvl,scp->sc_exppts);
257 if (showname) {
258 struct passwd *pp, *getpwuid();
259
260 if ((pp = getpwuid(scp->sc_uid)) == NULL)
261 printf(" (%d)\n", scp->sc_uid);
262 else
263 printf(" (%s)\n", pp->pw_name);
264 }
265 else
266 printf("\n");
267 }
268 }
269 return TRUE;
270 }
271
272 /*
273 * total_winner:
274 * The hero made it back out alive
275 */
276 total_winner()
277 {
278 clear();
279 addstr(" \n");
280 addstr(" @ @ @ @ @ @@@ @ @ \n");
281 addstr(" @ @ @@ @@ @ @ @ @ \n");
282 addstr(" @ @ @@@ @ @ @ @ @ @@@ @@@@ @@@ @ @@@ @ \n");
283 addstr(" @@@@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ \n");
284 addstr(" @ @ @ @ @ @ @ @@@@ @ @ @@@@@ @ @ @ \n");
285 addstr(" @ @ @ @ @ @@ @ @ @ @ @ @ @ @ @ @ \n");
286 addstr(" @@@ @@@ @@ @ @ @ @@@@ @@@@ @@@ @@@ @@ @ \n");
287 addstr(" \n");
288 addstr(" Congratulations, you have made it to the light of day! \n");
289 addstr("\nYou have joined the elite ranks of those who have escaped the\n");
290 addstr("Dungeons of Doom alive. You journey home and sell all your loot at\n");
291 addstr("a great profit and are admitted to the fighters guild.\n");
292
293 mvaddstr(LINES - 1, 0,spacemsg);
294 refresh();
295 wait_for(stdscr, ' ');
296 clear();
297 oldpurse = purse;
298 showpack(TRUE, NULL);
299 score(purse, WINNER, 0);
300 byebye(0);
301 }
302
303 /*
304 * showpack:
305 * Display the contents of the hero's pack
306 */
307 showpack(winner, howso)
308 bool winner;
309 char *howso;
310 {
311 reg char *iname;
312 reg int cnt, worth, ch;
313 reg struct linked_list *item;
314 reg struct object *obj;
315
316 idenpack();
317 cnt = 1;
318 clear();
319 if (winner)
320 mvaddstr(0, 0, " Worth Item");
321 else
322 mvprintw(0, 0, "Contents of your pack %s:\n",howso);
323 ch = 'a';
324 for (item = pack; item != NULL; item = next(item)) {
325 obj = OBJPTR(item);
326 iname = inv_name(obj, FALSE);
327 if (winner) {
328 worth = get_worth(obj);
329 worth *= obj->o_count;
330 mvprintw(cnt, 0, " %6d %s",worth,iname);
331 purse += worth;
332 }
333 else {
334 mvprintw(cnt, 0, "%c) %s\n",ch,iname);
335 ch = npch(ch);
336 }
337 if (++cnt >= LINES - 2 && next(item) != NULL) {
338 cnt = 1;
339 mvaddstr(LINES - 1, 0, morestr);
340 refresh();
341 wait_for(stdscr, ' ');
342 clear();
343 }
344 }
345 mvprintw(cnt + 1,0,"--- %d Gold Pieces ---",oldpurse);
346 refresh();
347 }
348
349 /*
350 * killname:
351 * Returns what the hero was killed by.
352 */
353 char *
354 killname(monst)
355 unsigned char monst;
356 {
357 if (monst < MAXMONS + 1)
358 return monsters[monst].m_name;
359 else /* things other than monsters */
360 switch (monst) {
361 case K_ARROW: return "crooked arrow";
362 case K_DART: return "sharp dart";
363 case K_BOLT: return "jagged bolt";
364 case K_POOL: return "magic pool";
365 case K_ROD: return "exploding rod";
366 case K_SCROLL: return "burning scroll";
367 case K_STONE: return "transmogrification to stone";
368 case K_STARVE: return "starvation";
369 }
370 return "Bob Kindelberger";
371 }