Annotation of early-roguelike/srogue/rip.c, Revision 1.1.1.1
1.1 rubenllo 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 <ctype.h>
18: #include <string.h>
19: #include <sys/types.h>
20: #include <fcntl.h>
21: #include <time.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: extern FILE *scoreboard;
52: extern FILE *logfile;
53:
54: char *killname(unsigned char monst);
55: void showpack(bool winner, char *howso);
56:
57: /*
58: * death:
59: * Do something really fun when he dies
60: */
61:
62: #include <time.h>
63: void
64: death(char monst)
65: {
66: reg char *killer;
67: int dp;
68: struct tm *lt;
69: time_t date;
70: char buf[LINLEN];
71: struct tm *localtime();
72:
73: time(&date);
74: lt = localtime(&date);
75: clear();
76: move(3, 0);
77: for (dp = 0; dp < RIP_LINES; dp++)
78: printw("%s\n", rip[dp]);
79: mvaddstr(10, 36 - ((strlen(whoami) + 1) / 2), whoami);
80: killer = killname(monst);
81: mvaddstr(12, 43, vowelstr(killer));
82: mvaddstr(14, 36 - ((strlen(killer) + 1) / 2), killer);
83: purse -= purse/10;
84: sprintf(buf, "%d Gold Pieces", purse);
85: mvaddstr(16, 36 - ((strlen(buf) + 1) / 2), buf);
86: sprintf(prbuf, "%d/%d/%d", lt->tm_mon + 1, lt->tm_mday, 1900+lt->tm_year);
87: mvaddstr(18, 32, prbuf);
88: move(LINES-1, 0);
89: refresh();
90: writelog(purse, KILLED, monst);
91: score(purse, KILLED, monst);
92: printf("[Press return to exit]\n");
93: fflush(NULL);
94: getchar();
95: byebye(0);
96: }
97:
98: /*
99: * top ten entry structure
100: */
101: static struct sc_ent {
102: int sc_score; /* gold */
103: char sc_name[LINLEN]; /* players name */
104: int sc_flags; /* reason for being here */
105: int sc_level; /* dungeon level */
106: int sc_uid; /* user ID */
107: unsigned char sc_monster; /* killer */
108: int sc_explvl; /* experience level */
109: long int sc_exppts; /* experience points */
110: time_t sc_date; /* time this score was posted */
111: } top_ten[10];
112:
113: char *reason[] = {
114: "Killed",
115: "Chickened out",
116: "A Total Winner"
117: };
118: int oldpurse;
119:
120: /*
121: * score:
122: * Figure score and post it.
123: */
124: void
125: score(int amount, int aflag, char monst)
126: {
127: reg struct sc_ent *scp, *sc2;
128: reg int i, prflags = 0;
129: char *packend;
130:
131: md_onsignal_exit();
132: if (aflag != WINNER) {
133: if (aflag == CHICKEN)
134: packend = "when you chickened out";
135: else
136: packend = "at your untimely demise";
137: mvaddstr(LINES - 1, 0, retstr);
138: refresh();
139: wgetnstr(stdscr,prbuf,80);
140: oldpurse = purse;
141: showpack(FALSE, packend);
142: }
143: /*
144: * Open file and read list
145: */
146: if (scoreboard == NULL)
147: return;
148: for (scp = top_ten; scp <= &top_ten[9]; scp++) {
149: scp->sc_score = 0;
150: for (i = 0; i < 80; i++)
151: scp->sc_name[i] = rnd(255);
152: scp->sc_flags = rnd(255);
153: scp->sc_level = rnd(255);
154: scp->sc_monster = rnd(255);
155: scp->sc_uid = rnd(255);
156: scp->sc_date = rnd(255);
157: }
158: mvaddstr(LINES - 1, 0, retstr);
159: refresh();
160: wgetnstr(stdscr,prbuf,80);
161: if (author() || wizard)
162: if (strcmp(prbuf, "names") == 0)
163: prflags = 1;
164: for(i = 0; i < 10; i++)
165: {
166: unsigned int mon;
167:
168: encread((char *) &top_ten[i].sc_name, LINLEN, scoreboard);
169: encread((char *) scoreline, 100, scoreboard);
170: sscanf(scoreline, " %d %d %d %d %u %d %ld %lx \n",
171: &top_ten[i].sc_score, &top_ten[i].sc_flags,
172: &top_ten[i].sc_level, &top_ten[i].sc_uid,
173: &mon, &top_ten[i].sc_explvl,
174: &top_ten[i].sc_exppts, &top_ten[i].sc_date);
175: top_ten[i].sc_monster = mon;
176: }
177: /*
178: * Insert it in list if need be
179: */
180: if (!waswizard) {
181: for (scp = top_ten; scp <= &top_ten[9]; scp++)
182: if (amount > scp->sc_score)
183: break;
184: if (scp <= &top_ten[9]) {
185: for (sc2 = &top_ten[9]; sc2 > scp; sc2--)
186: *sc2 = *(sc2-1);
187: scp->sc_score = amount;
188: strcpy(scp->sc_name, whoami);
189: scp->sc_flags = aflag;
190: if (aflag == WINNER)
191: scp->sc_level = max_level;
192: else
193: scp->sc_level = level;
194: scp->sc_monster = monst;
195: scp->sc_uid = playuid;
196: scp->sc_explvl = him->s_lvl;
197: scp->sc_exppts = him->s_exp;
198: time(&scp->sc_date);
199: }
200: }
201: ignore();
202: fseek(scoreboard, 0L, 0);
203: for(i = 0; i < 10; i++)
204: {
205: memset(scoreline,0,100);
206: encwrite((char *) top_ten[i].sc_name, LINLEN, scoreboard);
207: sprintf(scoreline, " %d %d %d %d %u %d %ld %lx \n",
208: top_ten[i].sc_score, top_ten[i].sc_flags,
209: top_ten[i].sc_level, top_ten[i].sc_uid,
210: top_ten[i].sc_monster, top_ten[i].sc_explvl,
211: top_ten[i].sc_exppts, top_ten[i].sc_date);
212: encwrite((char *) scoreline, 100, scoreboard);
213: }
214: fclose(scoreboard);
215: md_onsignal_exit();
216: clear();
217: refresh();
218: endwin();
219: showtop(prflags); /* print top ten list */
220: }
221:
222: void writelog(int amount, int aflag, char monst)
223: {
224: char logmessage[220], ltemp[80], mlev[40];
225: char *killer;
226:
227: if (waswizard)
228: return;
229: #ifdef LOGFILE
230: if (logfile == NULL)
231: return;
232: sprintf(logmessage, "%ld %d %s %d ", time(NULL), amount, whoami,
233: him->s_lvl);
234: if (amulet)
235: sprintf(mlev, " [max %d] with the Amulet", max_level);
236: else
237: mlev[0] = '\0';
238: if (aflag == KILLED) {
239: killer = killname(monst);
240: sprintf(ltemp, "killed by a%s %s on level %d%s\n",
241: vowelstr(killer), killer, level, mlev);
242: }
243: else if (aflag == CHICKEN) {
244: sprintf(ltemp, "quit on level %d%s\n", level, mlev);
245: }
246: else if (aflag == WINNER) {
247: sprintf(ltemp, "escaped with the Amulet [deepest level: %d]\n",
248: max_level);
249: }
250: else
251: return;
252: strcat(logmessage, ltemp);
253: fprintf(logfile, "%s", logmessage);
254: fclose(logfile);
255: #endif
256: return;
257: }
258:
259: /*
260: * showtop:
261: * Display the top ten on the screen
262: */
263: bool
264: showtop(int showname)
265: {
266: reg int i;
267: char *killer;
268: struct sc_ent *scp;
269: FILE *score_rdonly;
270:
271: if ((score_rdonly = fopen(scorefile, "r")) == NULL)
272: return FALSE;
273:
274: for(i = 0; i < 10; i++)
275: {
276: unsigned int mon;
277: encread((char *) &top_ten[i].sc_name, LINLEN, score_rdonly);
278: encread((char *) scoreline, 100, score_rdonly);
279: sscanf(scoreline, " %d %d %d %d %u %d %ld %lx \n",
280: &top_ten[i].sc_score, &top_ten[i].sc_flags,
281: &top_ten[i].sc_level, &top_ten[i].sc_uid,
282: &mon, &top_ten[i].sc_explvl,
283: &top_ten[i].sc_exppts, &top_ten[i].sc_date);
284: top_ten[i].sc_monster = mon;
285: }
286: fclose(score_rdonly);
287: printf("Top Ten Adventurers:\nRank\tScore\tName\n");
288: for (scp = top_ten; scp <= &top_ten[9]; scp++) {
289: if (scp->sc_score > 0) {
290: printf("%d\t%d\t%s: %s\t\t--> %s on level %d",
291: scp - top_ten + 1, scp->sc_score, scp->sc_name,
292: ctime(&scp->sc_date), reason[scp->sc_flags],
293: scp->sc_level);
294: if (scp->sc_flags == KILLED) {
295: killer = killname(scp->sc_monster);
296: printf(" by a%s %s",vowelstr(killer), killer);
297: }
298: printf(" [Exp: %d/%ld]",scp->sc_explvl,scp->sc_exppts);
299: if (showname) {
300: printf(" (%s)\n", md_getrealname(scp->sc_uid));
301: }
302: else
303: printf("\n");
304: }
305: }
306: return TRUE;
307: }
308:
309: /*
310: * total_winner:
311: * The hero made it back out alive
312: */
313: void
314: total_winner(void)
315: {
316: clear();
317: addstr(" \n");
318: addstr(" @ @ @ @ @ @@@ @ @ \n");
319: addstr(" @ @ @@ @@ @ @ @ @ \n");
320: addstr(" @ @ @@@ @ @ @ @ @ @@@ @@@@ @@@ @ @@@ @ \n");
321: addstr(" @@@@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ \n");
322: addstr(" @ @ @ @ @ @ @ @@@@ @ @ @@@@@ @ @ @ \n");
323: addstr(" @ @ @ @ @ @@ @ @ @ @ @ @ @ @ @ @ \n");
324: addstr(" @@@ @@@ @@ @ @ @ @@@@ @@@@ @@@ @@@ @@ @ \n");
325: addstr(" \n");
326: addstr(" Congratulations, you have made it to the light of day! \n");
327: addstr("\nYou have joined the elite ranks of those who have escaped the\n");
328: addstr("Dungeons of Doom alive. You journey home and sell all your loot at\n");
329: addstr("a great profit and are admitted to the fighters guild.\n");
330:
331: mvaddstr(LINES - 1, 0,spacemsg);
332: refresh();
333: wait_for(stdscr, ' ');
334: clear();
335: oldpurse = purse;
336: showpack(TRUE, NULL);
337: writelog(purse, WINNER, 0);
338: score(purse, WINNER, 0);
339: printf("[Press return to exit]\n");
340: fflush(NULL);
341: getchar();
342: byebye(0);
343: }
344:
345: /*
346: * showpack:
347: * Display the contents of the hero's pack
348: */
349: void
350: showpack(bool winner, char *howso)
351: {
352: reg char *iname;
353: reg int cnt, worth, ch;
354: reg struct linked_list *item;
355: reg struct object *obj;
356:
357: idenpack();
358: cnt = 1;
359: clear();
360: if (winner)
361: mvaddstr(0, 0, " Worth Item");
362: else
363: mvprintw(0, 0, "Contents of your pack %s:\n",howso);
364: ch = 'a';
365: for (item = pack; item != NULL; item = next(item)) {
366: obj = OBJPTR(item);
367: iname = inv_name(obj, FALSE);
368: if (winner) {
369: worth = get_worth(obj);
370: worth *= obj->o_count;
371: mvprintw(cnt, 0, " %6d %s",worth,iname);
372: purse += worth;
373: }
374: else {
375: mvprintw(cnt, 0, "%c) %s\n",ch,iname);
376: ch = npch(ch);
377: }
378: if (++cnt >= LINES - 2 && next(item) != NULL) {
379: cnt = 1;
380: mvaddstr(LINES - 1, 0, morestr);
381: refresh();
382: wait_for(stdscr, ' ');
383: clear();
384: }
385: }
386: mvprintw(cnt + 1,0,"--- %d Gold Pieces ---",oldpurse);
387: refresh();
388: }
389:
390: /*
391: * killname:
392: * Returns what the hero was killed by.
393: */
394: char *
395: killname(unsigned char monst)
396: {
397: if (monst < MAXMONS + 1)
398: return monsters[monst].m_name;
399: else /* things other than monsters */
400: switch (monst) {
401: case K_ARROW: return "crooked arrow";
402: case K_DART: return "sharp dart";
403: case K_BOLT: return "jagged bolt";
404: case K_POOL: return "magic pool";
405: case K_ROD: return "exploding rod";
406: case K_SCROLL: return "burning scroll";
407: case K_STONE: return "transmogrification to stone";
408: case K_STARVE: return "starvation";
409: }
410: return "Bob Kindelberger";
411: }
CVSweb