2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
41 static const char rcsid[] =
48 * This source herein may be modified and/or distributed by anybody who
49 * so desires, with the following restrictions:
50 * 1.) No portion of this notice shall be removed.
51 * 2.) Credit shall not be taken for the creation of this source.
52 * 3.) This code is not to be traded, sold, or used for personal
59 #include "pathnames.h"
61 extern char login_name[];
62 extern char *m_names[];
63 extern short max_level;
64 extern boolean score_only, no_skull, msg_cleared;
65 extern char *byebye_string, *nick_name;
67 killed_by(monster, other)
68 const object *monster;
76 rogue.gold = ((rogue.gold * 9) / 10);
82 (void) strcpy(buf, "died of hypothermia");
85 (void) strcpy(buf, "died of starvation");
88 (void) strcpy(buf, "killed by a dart");
91 (void) strcpy(buf, "quit");
94 (void) strcpy(buf, "killed by fire");
98 (void) strcpy(buf, "Killed by ");
99 if (is_vowel(m_names[monster->m_char - 'A'][0])) {
100 (void) strcat(buf, "an ");
102 (void) strcat(buf, "a ");
104 (void) strcat(buf, m_names[monster->m_char - 'A']);
106 (void) strcat(buf, " with ");
107 sprintf(buf+strlen(buf), "%ld gold", rogue.gold);
108 if ((!other) && (!no_skull)) {
110 mvaddstr(4, 32, "__---------__");
111 mvaddstr(5, 30, "_~ ~_");
112 mvaddstr(6, 29, "/ \\");
113 mvaddstr(7, 28, "~ ~");
114 mvaddstr(8, 27, "/ \\");
115 mvaddstr(9, 27, "| XXXX XXXX |");
116 mvaddstr(10, 27, "| XXXX XXXX |");
117 mvaddstr(11, 27, "| XXX XXX |");
118 mvaddstr(12, 28, "\\ @ /");
119 mvaddstr(13, 29, "--\\ @@@ /--");
120 mvaddstr(14, 30, "| | @@@ | |");
121 mvaddstr(15, 30, "| | | |");
122 mvaddstr(16, 30, "| vvVvvvvvvvVvv |");
123 mvaddstr(17, 30, "| ^^^^^^^^^^^ |");
124 mvaddstr(18, 31, "\\_ _/");
125 mvaddstr(19, 33, "~---------~");
126 center(21, nick_name);
132 put_scores(monster, other);
137 unwield(rogue.weapon); /* disarm and relax */
139 un_put_on(rogue.left_ring);
140 un_put_on(rogue.right_ring);
143 mvaddstr(10, 11, "@ @ @@@ @ @ @ @ @ @@@ @ @ @");
144 mvaddstr(11, 11, " @ @ @ @ @ @ @ @ @ @ @ @@ @ @");
145 mvaddstr(12, 11, " @ @ @ @ @ @ @ @ @ @ @ @ @ @");
146 mvaddstr(13, 11, " @ @ @ @ @ @ @ @ @ @ @ @@");
147 mvaddstr(14, 11, " @ @@@ @@@ @@ @@ @@@ @ @ @");
148 mvaddstr(17, 11, "Congratulations, you have been admitted to the");
149 mvaddstr(18, 11, "Fighters' Guild. You return home, sell all your");
150 mvaddstr(19, 11, "treasures at great profit and retire into comfort.");
155 put_scores((object *) 0, WIN);
173 for (i = 0; i < DCOLS; i++) {
174 buf[i] = mvinch(0, i);
178 message("really quit?", 1);
179 if (rgetchar() != 'y') {
183 for (i = 0; i < DCOLS; i++) {
184 mvaddch(0, i, buf[i]);
193 clean_up(byebye_string);
196 killed_by((object *) 0, QUIT);
199 put_scores(monster, other)
200 const object *monster;
203 short i, n, rank = 10, x, ne = 0, found_player = -1;
205 char n_names[10][30];
209 boolean pause = score_only;
213 if ((fp = fopen(_PATH_SCOREFILE, "r+")) == NULL &&
214 (fp = fopen(_PATH_SCOREFILE, "w+")) == NULL) {
215 message("cannot read/write/create score file", 0);
221 for (i = 0; i < 10; i++) {
222 if (((n = fread(scores[i], sizeof(char), 80, fp)) < 80) && (n != 0)) {
226 if ((n = fread(n_names[i], sizeof(char), 30, fp)) < 30) {
229 xxxx(n_names[i], 30);
234 if ((!score_only) && (found_player == -1)) {
235 if (!name_cmp(scores[i]+15, login_name)) {
237 while (scores[i][x] == ' ') {
240 s = lget_number(scores[i] + x);
241 if (rogue.gold < s) {
249 if (found_player != -1) {
251 for (i = found_player; i < ne; i++) {
252 (void) strcpy(scores[i], scores[i+1]);
253 (void) strcpy(n_names[i], n_names[i+1]);
257 for (i = 0; i < ne; i++) {
259 while (scores[i][x] == ' ') {
262 s = lget_number(scores[i] + x);
264 if (rogue.gold >= s) {
271 } else if ((ne < 10) && (rank == 10)) {
275 insert_score(scores, n_names, nick_name, rank, ne, monster,
285 mvaddstr(3, 30, "Top Ten Rogueists");
286 mvaddstr(8, 0, "Rank Score Name");
292 for (i = 0; i < ne; i++) {
301 scores[i][1] = i + '1';
303 nickize(buf, scores[i], n_names[i]);
304 mvaddstr(i+10, 0, buf);
307 fwrite(scores[i], sizeof(char), 80, fp);
308 xxxx(n_names[i], 30);
309 fwrite(n_names[i], sizeof(char), 30, fp);
325 insert_score(scores, n_names, n_name, rank, n, monster, other)
330 const object *monster;
336 for (i = n; i > rank; i--) {
337 if ((i < 10) && (i > 0)) {
338 (void) strcpy(scores[i], scores[i-1]);
339 (void) strcpy(n_names[i], n_names[i-1]);
343 sprintf(buf, "%2d %6ld %s: ", rank+1, rogue.gold, login_name);
348 (void) strcat(buf, "died of hypothermia");
351 (void) strcat(buf, "died of starvation");
354 (void) strcat(buf, "killed by a dart");
357 (void) strcat(buf, "quit");
360 (void) strcat(buf, "a total winner");
363 (void) strcat(buf, "killed by fire");
367 (void) strcat(buf, "killed by ");
368 if (is_vowel(m_names[monster->m_char - 'A'][0])) {
369 (void) strcat(buf, "an ");
371 (void) strcat(buf, "a ");
373 (void) strcat(buf, m_names[monster->m_char - 'A']);
375 sprintf(buf+strlen(buf), " on level %d ", max_level);
376 if ((other != WIN) && has_amulet()) {
377 (void) strcat(buf, "with amulet");
379 for (i = strlen(buf); i < 79; i++) {
383 (void) strcpy(scores[rank], buf);
384 (void) strcpy(n_names[rank], n_name);
390 return( (ch == 'a') ||
403 obj = rogue.pack.next_object;
406 mvaddstr(1, 0, "Value Item");
409 if (obj->what_is != FOOD) {
411 val = get_value(obj);
415 sprintf(buf, "%5d ", val);
416 get_desc(obj, buf+11);
417 mvaddstr(row++, 0, buf);
420 obj = obj->next_object;
423 if (rogue.gold > MAX_GOLD) {
424 rogue.gold = MAX_GOLD;
435 wc = obj->which_kind;
437 switch(obj->what_is) {
439 val = id_weapons[wc].value;
440 if ((wc == ARROW) || (wc == DAGGER) || (wc == SHURIKEN) ||
442 val *= obj->quantity;
444 val += (obj->d_enchant * 85);
445 val += (obj->hit_enchant * 85);
448 val = id_armors[wc].value;
449 val += (obj->d_enchant * 75);
450 if (obj->is_protected) {
455 val = id_wands[wc].value * (obj->class + 1);
458 val = id_scrolls[wc].value * obj->quantity;
461 val = id_potions[wc].value * obj->quantity;
467 val = id_rings[wc].value * (obj->class + 1);
480 for (i = 0; i < SCROLS; i++) {
481 id_scrolls[i].id_status = IDENTIFIED;
483 for (i = 0; i < WEAPONS; i++) {
484 id_weapons[i].id_status = IDENTIFIED;
486 for (i = 0; i < ARMORS; i++) {
487 id_armors[i].id_status = IDENTIFIED;
489 for (i = 0; i < WANDS; i++) {
490 id_wands[i].id_status = IDENTIFIED;
492 for (i = 0; i < POTIONS; i++) {
493 id_potions[i].id_status = IDENTIFIED;
504 while(s1[i] != ':') {
520 for (i = 0; i < n; i++) {
522 /* It does not matter if accuracy is lost during this assignment */
523 c = (unsigned char) xxx(0);
541 r = ((f * s) + 9337) % 8887;
547 nickize(buf, score, n_name)
549 const char *score, *n_name;
554 (void) strcpy(buf, score);
556 (void) strncpy(buf, score, 16);
558 while (score[i] != ':') {
562 (void) strcpy(buf+15, n_name);
566 buf[j++] = score[i++];
579 margin = ((DCOLS - strlen(buf)) / 2);
580 mvaddstr(row, margin, buf);
587 clean_up("sorry, score file is out of order");