|
|
1.1 root 1: /*
2: * Copyright (c) 1988 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * This code is derived from software contributed to Berkeley by
6: * Timothy C. Stoehr.
7: *
8: * Redistribution and use in source and binary forms are permitted
9: * provided that: (1) source distributions retain this entire copyright
10: * notice and comment, and (2) distributions including binaries display
11: * the following acknowledgement: ``This product includes software
12: * developed by the University of California, Berkeley and its contributors''
13: * in the documentation or other materials provided with the distribution
14: * and in all advertising materials mentioning features or use of this
15: * software. Neither the name of the University nor the names of its
16: * contributors may be used to endorse or promote products derived
17: * from this software without specific prior written permission.
18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21: */
22:
23: #ifndef lint
24: static char sccsid[] = "@(#)score.c 5.5 (Berkeley) 6/1/90";
25: #endif /* not lint */
26:
27: /*
28: * score.c
29: *
30: * This source herein may be modified and/or distributed by anybody who
31: * so desires, with the following restrictions:
32: * 1.) No portion of this notice shall be removed.
33: * 2.) Credit shall not be taken for the creation of this source.
34: * 3.) This code is not to be traded, sold, or used for personal
35: * gain or profit.
36: *
37: */
38:
39: #include <stdio.h>
40: #include "rogue.h"
41: #include "pathnames.h"
42:
43: extern char login_name[];
44: extern char *m_names[];
45: extern short max_level;
46: extern boolean score_only, no_skull, msg_cleared;
47: extern char *byebye_string, *nick_name;
48:
49: killed_by(monster, other)
50: object *monster;
51: short other;
52: {
53: char buf[128];
54:
55: md_ignore_signals();
56:
57: if (other != QUIT) {
58: rogue.gold = ((rogue.gold * 9) / 10);
59: }
60:
61: if (other) {
62: switch(other) {
63: case HYPOTHERMIA:
64: (void) strcpy(buf, "died of hypothermia");
65: break;
66: case STARVATION:
67: (void) strcpy(buf, "died of starvation");
68: break;
69: case POISON_DART:
70: (void) strcpy(buf, "killed by a dart");
71: break;
72: case QUIT:
73: (void) strcpy(buf, "quit");
74: break;
75: case KFIRE:
76: (void) strcpy(buf, "killed by fire");
77: break;
78: }
79: } else {
80: (void) strcpy(buf, "Killed by ");
81: if (is_vowel(m_names[monster->m_char - 'A'][0])) {
82: (void) strcat(buf, "an ");
83: } else {
84: (void) strcat(buf, "a ");
85: }
86: (void) strcat(buf, m_names[monster->m_char - 'A']);
87: }
88: (void) strcat(buf, " with ");
89: sprintf(buf+strlen(buf), "%ld gold", rogue.gold);
90: if ((!other) && (!no_skull)) {
91: clear();
92: mvaddstr(4, 32, "__---------__");
93: mvaddstr(5, 30, "_~ ~_");
94: mvaddstr(6, 29, "/ \\");
95: mvaddstr(7, 28, "~ ~");
96: mvaddstr(8, 27, "/ \\");
97: mvaddstr(9, 27, "| XXXX XXXX |");
98: mvaddstr(10, 27, "| XXXX XXXX |");
99: mvaddstr(11, 27, "| XXX XXX |");
100: mvaddstr(12, 28, "\\ @ /");
101: mvaddstr(13, 29, "--\\ @@@ /--");
102: mvaddstr(14, 30, "| | @@@ | |");
103: mvaddstr(15, 30, "| | | |");
104: mvaddstr(16, 30, "| vvVvvvvvvvVvv |");
105: mvaddstr(17, 30, "| ^^^^^^^^^^^ |");
106: mvaddstr(18, 31, "\\_ _/");
107: mvaddstr(19, 33, "~---------~");
108: center(21, nick_name);
109: center(22, buf);
110: } else {
111: message(buf, 0);
112: }
113: message("", 0);
114: put_scores(monster, other);
115: }
116:
117: win()
118: {
119: unwield(rogue.weapon); /* disarm and relax */
120: unwear(rogue.armor);
121: un_put_on(rogue.left_ring);
122: un_put_on(rogue.right_ring);
123:
124: clear();
125: mvaddstr(10, 11, "@ @ @@@ @ @ @ @ @ @@@ @ @ @");
126: mvaddstr(11, 11, " @ @ @ @ @ @ @ @ @ @ @ @@ @ @");
127: mvaddstr(12, 11, " @ @ @ @ @ @ @ @ @ @ @ @ @ @");
128: mvaddstr(13, 11, " @ @ @ @ @ @ @ @ @ @ @ @@");
129: mvaddstr(14, 11, " @ @@@ @@@ @@ @@ @@@ @ @ @");
130: mvaddstr(17, 11, "Congratulations, you have been admitted to the");
131: mvaddstr(18, 11, "Fighters' Guild. You return home, sell all your");
132: mvaddstr(19, 11, "treasures at great profit and retire into comfort.");
133: message("", 0);
134: message("", 0);
135: id_all();
136: sell_pack();
137: put_scores((object *) 0, WIN);
138: }
139:
140: quit(from_intrpt)
141: boolean from_intrpt;
142: {
143: char buf[128];
144: short i, orow, ocol;
145: boolean mc;
146:
147: md_ignore_signals();
148:
149: if (from_intrpt) {
150: orow = rogue.row;
151: ocol = rogue.col;
152:
153: mc = msg_cleared;
154:
155: for (i = 0; i < DCOLS; i++) {
156: buf[i] = mvinch(0, i);
157: }
158: }
159: check_message();
160: message("really quit?", 1);
161: if (rgetchar() != 'y') {
162: md_heed_signals();
163: check_message();
164: if (from_intrpt) {
165: for (i = 0; i < DCOLS; i++) {
166: mvaddch(0, i, buf[i]);
167: }
168: msg_cleared = mc;
169: move(orow, ocol);
170: refresh();
171: }
172: return;
173: }
174: if (from_intrpt) {
175: clean_up(byebye_string);
176: }
177: check_message();
178: killed_by((object *) 0, QUIT);
179: }
180:
181: put_scores(monster, other)
182: object *monster;
183: short other;
184: {
185: short i, n, rank = 10, x, ne = 0, found_player = -1;
186: char scores[10][82];
187: char n_names[10][30];
188: char buf[128];
189: FILE *fp;
190: long s;
191: boolean pause = score_only;
192:
193: md_lock(1);
194:
195: if ((fp = fopen(_PATH_SCOREFILE, "a+")) == NULL) {
196: message("cannot read/write/create score file", 0);
197: sf_error();
198: }
199: rewind(fp);
200: (void) xxx(1);
201:
202: for (i = 0; i < 10; i++) {
203: if (((n = fread(scores[i], sizeof(char), 80, fp)) < 80) && (n != 0)) {
204: sf_error();
205: } else if (n != 0) {
206: xxxx(scores[i], 80);
207: if ((n = fread(n_names[i], sizeof(char), 30, fp)) < 30) {
208: sf_error();
209: }
210: xxxx(n_names[i], 30);
211: } else {
212: break;
213: }
214: ne++;
215: if ((!score_only) && (found_player == -1)) {
216: if (!name_cmp(scores[i]+15, login_name)) {
217: x = 5;
218: while (scores[i][x] == ' ') {
219: x++;
220: }
221: s = lget_number(scores[i] + x);
222: if (rogue.gold < s) {
223: score_only = 1;
224: } else {
225: found_player = i;
226: }
227: }
228: }
229: }
230: if (found_player != -1) {
231: ne--;
232: for (i = found_player; i < ne; i++) {
233: (void) strcpy(scores[i], scores[i+1]);
234: (void) strcpy(n_names[i], n_names[i+1]);
235: }
236: }
237: if (!score_only) {
238: for (i = 0; i < ne; i++) {
239: x = 5;
240: while (scores[i][x] == ' ') {
241: x++;
242: }
243: s = lget_number(scores[i] + x);
244:
245: if (rogue.gold >= s) {
246: rank = i;
247: break;
248: }
249: }
250: if (ne == 0) {
251: rank = 0;
252: } else if ((ne < 10) && (rank == 10)) {
253: rank = ne;
254: }
255: if (rank < 10) {
256: insert_score(scores, n_names, nick_name, rank, ne, monster,
257: other);
258: if (ne < 10) {
259: ne++;
260: }
261: }
262: rewind(fp);
263: }
264:
265: clear();
266: mvaddstr(3, 30, "Top Ten Rogueists");
267: mvaddstr(8, 0, "Rank Score Name");
268:
269: md_ignore_signals();
270:
271: (void) xxx(1);
272:
273: for (i = 0; i < ne; i++) {
274: if (i == rank) {
275: standout();
276: }
277: if (i == 9) {
278: scores[i][0] = '1';
279: scores[i][1] = '0';
280: } else {
281: scores[i][0] = ' ';
282: scores[i][1] = i + '1';
283: }
284: nickize(buf, scores[i], n_names[i]);
285: mvaddstr(i+10, 0, buf);
286: if (rank < 10) {
287: xxxx(scores[i], 80);
288: fwrite(scores[i], sizeof(char), 80, fp);
289: xxxx(n_names[i], 30);
290: fwrite(n_names[i], sizeof(char), 30, fp);
291: }
292: if (i == rank) {
293: standend();
294: }
295: }
296: md_lock(0);
297: refresh();
298: fclose(fp);
299: message("", 0);
300: if (pause) {
301: message("", 0);
302: }
303: clean_up("");
304: }
305:
306: insert_score(scores, n_names, n_name, rank, n, monster, other)
307: char scores[][82];
308: char n_names[][30];
309: char *n_name;
310: short rank, n;
311: object *monster;
312: {
313: short i;
314: char buf[128];
315:
316: if (n > 0) {
317: for (i = n; i > rank; i--) {
318: if ((i < 10) && (i > 0)) {
319: (void) strcpy(scores[i], scores[i-1]);
320: (void) strcpy(n_names[i], n_names[i-1]);
321: }
322: }
323: }
324: sprintf(buf, "%2d %6d %s: ", rank+1, rogue.gold, login_name);
325:
326: if (other) {
327: switch(other) {
328: case HYPOTHERMIA:
329: (void) strcat(buf, "died of hypothermia");
330: break;
331: case STARVATION:
332: (void) strcat(buf, "died of starvation");
333: break;
334: case POISON_DART:
335: (void) strcat(buf, "killed by a dart");
336: break;
337: case QUIT:
338: (void) strcat(buf, "quit");
339: break;
340: case WIN:
341: (void) strcat(buf, "a total winner");
342: break;
343: case KFIRE:
344: (void) strcpy(buf, "killed by fire");
345: break;
346: }
347: } else {
348: (void) strcat(buf, "killed by ");
349: if (is_vowel(m_names[monster->m_char - 'A'][0])) {
350: (void) strcat(buf, "an ");
351: } else {
352: (void) strcat(buf, "a ");
353: }
354: (void) strcat(buf, m_names[monster->m_char - 'A']);
355: }
356: sprintf(buf+strlen(buf), " on level %d ", max_level);
357: if ((other != WIN) && has_amulet()) {
358: (void) strcat(buf, "with amulet");
359: }
360: for (i = strlen(buf); i < 79; i++) {
361: buf[i] = ' ';
362: }
363: buf[79] = 0;
364: (void) strcpy(scores[rank], buf);
365: (void) strcpy(n_names[rank], n_name);
366: }
367:
368: is_vowel(ch)
369: short ch;
370: {
371: return( (ch == 'a') ||
372: (ch == 'e') ||
373: (ch == 'i') ||
374: (ch == 'o') ||
375: (ch == 'u') );
376: }
377:
378: sell_pack()
379: {
380: object *obj;
381: short row = 2, val;
382: char buf[DCOLS];
383:
384: obj = rogue.pack.next_object;
385:
386: clear();
387: mvaddstr(1, 0, "Value Item");
388:
389: while (obj) {
390: if (obj->what_is != FOOD) {
391: obj->identified = 1;
392: val = get_value(obj);
393: rogue.gold += val;
394:
395: if (row < DROWS) {
396: sprintf(buf, "%5d ", val);
397: get_desc(obj, buf+11);
398: mvaddstr(row++, 0, buf);
399: }
400: }
401: obj = obj->next_object;
402: }
403: refresh();
404: if (rogue.gold > MAX_GOLD) {
405: rogue.gold = MAX_GOLD;
406: }
407: message("", 0);
408: }
409:
410: get_value(obj)
411: object *obj;
412: {
413: short wc;
414: int val;
415:
416: wc = obj->which_kind;
417:
418: switch(obj->what_is) {
419: case WEAPON:
420: val = id_weapons[wc].value;
421: if ((wc == ARROW) || (wc == DAGGER) || (wc == SHURIKEN) ||
422: (wc == DART)) {
423: val *= obj->quantity;
424: }
425: val += (obj->d_enchant * 85);
426: val += (obj->hit_enchant * 85);
427: break;
428: case ARMOR:
429: val = id_armors[wc].value;
430: val += (obj->d_enchant * 75);
431: if (obj->is_protected) {
432: val += 200;
433: }
434: break;
435: case WAND:
436: val = id_wands[wc].value * (obj->class + 1);
437: break;
438: case SCROL:
439: val = id_scrolls[wc].value * obj->quantity;
440: break;
441: case POTION:
442: val = id_potions[wc].value * obj->quantity;
443: break;
444: case AMULET:
445: val = 5000;
446: break;
447: case RING:
448: val = id_rings[wc].value * (obj->class + 1);
449: break;
450: }
451: if (val <= 0) {
452: val = 10;
453: }
454: return(val);
455: }
456:
457: id_all()
458: {
459: short i;
460:
461: for (i = 0; i < SCROLS; i++) {
462: id_scrolls[i].id_status = IDENTIFIED;
463: }
464: for (i = 0; i < WEAPONS; i++) {
465: id_weapons[i].id_status = IDENTIFIED;
466: }
467: for (i = 0; i < ARMORS; i++) {
468: id_armors[i].id_status = IDENTIFIED;
469: }
470: for (i = 0; i < WANDS; i++) {
471: id_wands[i].id_status = IDENTIFIED;
472: }
473: for (i = 0; i < POTIONS; i++) {
474: id_potions[i].id_status = IDENTIFIED;
475: }
476: }
477:
478: name_cmp(s1, s2)
479: char *s1, *s2;
480: {
481: short i = 0;
482: int r;
483:
484: while(s1[i] != ':') {
485: i++;
486: }
487: s1[i] = 0;
488: r = strcmp(s1, s2);
489: s1[i] = ':';
490: return(r);
491: }
492:
493: xxxx(buf, n)
494: char *buf;
495: short n;
496: {
497: short i;
498: unsigned char c;
499:
500: for (i = 0; i < n; i++) {
501:
502: /* It does not matter if accuracy is lost during this assignment */
503: c = (unsigned char) xxx(0);
504:
505: buf[i] ^= c;
506: }
507: }
508:
509: long
510: xxx(st)
511: boolean st;
512: {
513: static long f, s;
514: long r;
515:
516: if (st) {
517: f = 37;
518: s = 7;
519: return(0L);
520: }
521: r = ((f * s) + 9337) % 8887;
522: f = s;
523: s = r;
524: return(r);
525: }
526:
527: nickize(buf, score, n_name)
528: char *buf, *score, *n_name;
529: {
530: short i = 15, j;
531:
532: if (!n_name[0]) {
533: (void) strcpy(buf, score);
534: } else {
535: (void) strncpy(buf, score, 16);
536:
537: while (score[i] != ':') {
538: i++;
539: }
540:
541: (void) strcpy(buf+15, n_name);
542: j = strlen(buf);
543:
544: while (score[i]) {
545: buf[j++] = score[i++];
546: }
547: buf[j] = 0;
548: buf[79] = 0;
549: }
550: }
551:
552: center(row, buf)
553: short row;
554: char *buf;
555: {
556: short margin;
557:
558: margin = ((DCOLS - strlen(buf)) / 2);
559: mvaddstr(row, margin, buf);
560: }
561:
562: sf_error()
563: {
564: md_lock(0);
565: message("", 1);
566: clean_up("sorry, score file is out of order");
567: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.