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