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
36 * @(#)score.c 8.1 (Berkeley) 5/31/93
37 * $FreeBSD: src/games/rogue/score.c,v 1.4 1999/11/30 03:49:27 billf Exp $
38 * $DragonFly: src/games/rogue/score.c,v 1.3 2003/08/26 23:52:50 drhodus Exp $
44 * This source herein may be modified and/or distributed by anybody who
45 * so desires, with the following restrictions:
46 * 1.) No portion of this notice shall be removed.
47 * 2.) Credit shall not be taken for the creation of this source.
48 * 3.) This code is not to be traded, sold, or used for personal
55 #include "pathnames.h"
57 extern char *m_names[];
58 extern short max_level;
59 extern boolean score_only, no_skull, msg_cleared;
60 extern char *byebye_string, *nick_name;
62 killed_by(monster, other)
63 const object *monster;
71 rogue.gold = ((rogue.gold * 9) / 10);
77 (void) strcpy(buf, "died of hypothermia");
80 (void) strcpy(buf, "died of starvation");
83 (void) strcpy(buf, "killed by a dart");
86 (void) strcpy(buf, "quit");
89 (void) strcpy(buf, "killed by fire");
93 (void) strcpy(buf, "Killed by ");
94 if (is_vowel(m_names[monster->m_char - 'A'][0])) {
95 (void) strcat(buf, "an ");
97 (void) strcat(buf, "a ");
99 (void) strcat(buf, m_names[monster->m_char - 'A']);
101 (void) strcat(buf, " with ");
102 sprintf(buf+strlen(buf), "%ld gold", rogue.gold);
103 if ((!other) && (!no_skull)) {
105 mvaddstr(4, 32, "__---------__");
106 mvaddstr(5, 30, "_~ ~_");
107 mvaddstr(6, 29, "/ \\");
108 mvaddstr(7, 28, "~ ~");
109 mvaddstr(8, 27, "/ \\");
110 mvaddstr(9, 27, "| XXXX XXXX |");
111 mvaddstr(10, 27, "| XXXX XXXX |");
112 mvaddstr(11, 27, "| XXX XXX |");
113 mvaddstr(12, 28, "\\ @ /");
114 mvaddstr(13, 29, "--\\ @@@ /--");
115 mvaddstr(14, 30, "| | @@@ | |");
116 mvaddstr(15, 30, "| | | |");
117 mvaddstr(16, 30, "| vvVvvvvvvvVvv |");
118 mvaddstr(17, 30, "| ^^^^^^^^^^^ |");
119 mvaddstr(18, 31, "\\_ _/");
120 mvaddstr(19, 33, "~---------~");
121 center(21, nick_name);
127 put_scores(monster, other);
132 unwield(rogue.weapon); /* disarm and relax */
134 un_put_on(rogue.left_ring);
135 un_put_on(rogue.right_ring);
138 mvaddstr(10, 11, "@ @ @@@ @ @ @ @ @ @@@ @ @ @");
139 mvaddstr(11, 11, " @ @ @ @ @ @ @ @ @ @ @ @@ @ @");
140 mvaddstr(12, 11, " @ @ @ @ @ @ @ @ @ @ @ @ @ @");
141 mvaddstr(13, 11, " @ @ @ @ @ @ @ @ @ @ @ @@");
142 mvaddstr(14, 11, " @ @@@ @@@ @@ @@ @@@ @ @ @");
143 mvaddstr(17, 11, "Congratulations, you have been admitted to the");
144 mvaddstr(18, 11, "Fighters' Guild. You return home, sell all your");
145 mvaddstr(19, 11, "treasures at great profit and retire into comfort.");
150 put_scores((object *) 0, WIN);
168 for (i = 0; i < DCOLS; i++) {
169 buf[i] = mvinch(0, i);
173 message("really quit?", 1);
174 if (rgetchar() != 'y') {
178 for (i = 0; i < DCOLS; i++) {
179 mvaddch(0, i, buf[i]);
188 clean_up(byebye_string);
191 killed_by((object *) 0, QUIT);
194 put_scores(monster, other)
195 const object *monster;
198 short i, n, rank = 10, x, ne = 0, found_player = -1;
200 char n_names[10][30];
204 boolean pause = score_only;
208 if ((fp = fopen(_PATH_SCOREFILE, "r+")) == NULL &&
209 (fp = fopen(_PATH_SCOREFILE, "w+")) == NULL) {
210 message("cannot read/write/create score file", 0);
216 for (i = 0; i < 10; i++) {
217 if (((n = fread(scores[i], sizeof(char), 80, fp)) < 80) && (n != 0)) {
221 if ((n = fread(n_names[i], sizeof(char), 30, fp)) < 30) {
224 xxxx(n_names[i], 30);
229 if ((!score_only) && (found_player == -1)) {
230 if (!name_cmp(scores[i]+15, login_name)) {
232 while (scores[i][x] == ' ') {
235 s = lget_number(scores[i] + x);
236 if (rogue.gold < s) {
244 if (found_player != -1) {
246 for (i = found_player; i < ne; i++) {
247 (void) strcpy(scores[i], scores[i+1]);
248 (void) strcpy(n_names[i], n_names[i+1]);
252 for (i = 0; i < ne; i++) {
254 while (scores[i][x] == ' ') {
257 s = lget_number(scores[i] + x);
259 if (rogue.gold >= s) {
266 } else if ((ne < 10) && (rank == 10)) {
270 insert_score(scores, n_names, nick_name, rank, ne, monster,
280 mvaddstr(3, 30, "Top Ten Rogueists");
281 mvaddstr(8, 0, "Rank Score Name");
287 for (i = 0; i < ne; i++) {
296 scores[i][1] = i + '1';
298 nickize(buf, scores[i], n_names[i]);
299 mvaddstr(i+10, 0, buf);
302 fwrite(scores[i], sizeof(char), 80, fp);
303 xxxx(n_names[i], 30);
304 fwrite(n_names[i], sizeof(char), 30, fp);
320 insert_score(scores, n_names, n_name, rank, n, monster, other)
325 const object *monster;
331 for (i = n; i > rank; i--) {
332 if ((i < 10) && (i > 0)) {
333 (void) strcpy(scores[i], scores[i-1]);
334 (void) strcpy(n_names[i], n_names[i-1]);
338 sprintf(buf, "%2d %6ld %s: ", rank+1, rogue.gold, login_name);
343 (void) strcat(buf, "died of hypothermia");
346 (void) strcat(buf, "died of starvation");
349 (void) strcat(buf, "killed by a dart");
352 (void) strcat(buf, "quit");
355 (void) strcat(buf, "a total winner");
358 (void) strcpy(buf, "killed by fire");
362 (void) strcat(buf, "killed by ");
363 if (is_vowel(m_names[monster->m_char - 'A'][0])) {
364 (void) strcat(buf, "an ");
366 (void) strcat(buf, "a ");
368 (void) strcat(buf, m_names[monster->m_char - 'A']);
370 sprintf(buf+strlen(buf), " on level %d ", max_level);
371 if ((other != WIN) && has_amulet()) {
372 (void) strcat(buf, "with amulet");
374 for (i = strlen(buf); i < 79; i++) {
378 (void) strcpy(scores[rank], buf);
379 (void) strcpy(n_names[rank], n_name);
385 return( (ch == 'a') ||
398 obj = rogue.pack.next_object;
401 mvaddstr(1, 0, "Value Item");
404 if (obj->what_is != FOOD) {
406 val = get_value(obj);
410 sprintf(buf, "%5d ", val);
411 get_desc(obj, buf+11);
412 mvaddstr(row++, 0, buf);
415 obj = obj->next_object;
418 if (rogue.gold > MAX_GOLD) {
419 rogue.gold = MAX_GOLD;
430 wc = obj->which_kind;
432 switch(obj->what_is) {
434 val = id_weapons[wc].value;
435 if ((wc == ARROW) || (wc == DAGGER) || (wc == SHURIKEN) ||
437 val *= obj->quantity;
439 val += (obj->d_enchant * 85);
440 val += (obj->hit_enchant * 85);
443 val = id_armors[wc].value;
444 val += (obj->d_enchant * 75);
445 if (obj->is_protected) {
450 val = id_wands[wc].value * (obj->class + 1);
453 val = id_scrolls[wc].value * obj->quantity;
456 val = id_potions[wc].value * obj->quantity;
462 val = id_rings[wc].value * (obj->class + 1);
475 for (i = 0; i < SCROLS; i++) {
476 id_scrolls[i].id_status = IDENTIFIED;
478 for (i = 0; i < WEAPONS; i++) {
479 id_weapons[i].id_status = IDENTIFIED;
481 for (i = 0; i < ARMORS; i++) {
482 id_armors[i].id_status = IDENTIFIED;
484 for (i = 0; i < WANDS; i++) {
485 id_wands[i].id_status = IDENTIFIED;
487 for (i = 0; i < POTIONS; i++) {
488 id_potions[i].id_status = IDENTIFIED;
499 while(s1[i] != ':') {
515 for (i = 0; i < n; i++) {
517 /* It does not matter if accuracy is lost during this assignment */
518 c = (unsigned char) xxx(0);
536 r = ((f * s) + 9337) % 8887;
542 nickize(buf, score, n_name)
544 const char *score, *n_name;
549 (void) strcpy(buf, score);
551 (void) strncpy(buf, score, 16);
553 while (score[i] != ':') {
557 (void) strcpy(buf+15, n_name);
561 buf[j++] = score[i++];
574 margin = ((DCOLS - strlen(buf)) / 2);
575 mvaddstr(row, margin, buf);
582 clean_up("sorry, score file is out of order");