Home | History | Annotate | Line # | Download | only in rogue
score.c revision 1.13
      1  1.13  dholland /*	$NetBSD: score.c,v 1.13 2008/01/14 00:23:53 dholland 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.11       agc  * 3. Neither the name of the University nor the names of its contributors
     19   1.1       cgd  *    may be used to endorse or promote products derived from this software
     20   1.1       cgd  *    without specific prior written permission.
     21   1.1       cgd  *
     22   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.1       cgd  * SUCH DAMAGE.
     33   1.1       cgd  */
     34   1.1       cgd 
     35   1.6     lukem #include <sys/cdefs.h>
     36   1.1       cgd #ifndef lint
     37   1.5       cgd #if 0
     38   1.5       cgd static char sccsid[] = "@(#)score.c	8.1 (Berkeley) 5/31/93";
     39   1.5       cgd #else
     40  1.13  dholland __RCSID("$NetBSD: score.c,v 1.13 2008/01/14 00:23:53 dholland Exp $");
     41   1.5       cgd #endif
     42   1.1       cgd #endif /* not lint */
     43   1.1       cgd 
     44   1.1       cgd /*
     45   1.1       cgd  * score.c
     46   1.1       cgd  *
     47   1.1       cgd  * This source herein may be modified and/or distributed by anybody who
     48   1.1       cgd  * so desires, with the following restrictions:
     49   1.1       cgd  *    1.)  No portion of this notice shall be removed.
     50   1.1       cgd  *    2.)  Credit shall not be taken for the creation of this source.
     51   1.1       cgd  *    3.)  This code is not to be traded, sold, or used for personal
     52   1.1       cgd  *         gain or profit.
     53   1.1       cgd  *
     54   1.1       cgd  */
     55   1.1       cgd 
     56   1.1       cgd #include <stdio.h>
     57   1.1       cgd #include "rogue.h"
     58   1.1       cgd #include "pathnames.h"
     59   1.1       cgd 
     60   1.6     lukem void
     61   1.1       cgd killed_by(monster, other)
     62   1.7   hubertf 	const object *monster;
     63   1.6     lukem 	short other;
     64   1.1       cgd {
     65  1.12  dholland 	const char *mechanism = "killed by something unknown (?)";
     66  1.12  dholland 	char mechanism_buf[128];
     67  1.12  dholland 	const char *article;
     68  1.12  dholland 	char message_buf[128];
     69   1.1       cgd 
     70   1.1       cgd 	md_ignore_signals();
     71   1.1       cgd 
     72   1.1       cgd 	if (other != QUIT) {
     73   1.1       cgd 		rogue.gold = ((rogue.gold * 9) / 10);
     74   1.1       cgd 	}
     75   1.1       cgd 
     76   1.1       cgd 	if (other) {
     77   1.1       cgd 		switch(other) {
     78   1.1       cgd 		case HYPOTHERMIA:
     79  1.12  dholland 			mechanism = "died of hypothermia";
     80   1.1       cgd 			break;
     81   1.1       cgd 		case STARVATION:
     82  1.12  dholland 			mechanism = "died of starvation";
     83   1.1       cgd 			break;
     84   1.1       cgd 		case POISON_DART:
     85  1.12  dholland 			mechanism = "killed by a dart";
     86   1.1       cgd 			break;
     87   1.1       cgd 		case QUIT:
     88  1.12  dholland 			mechanism = "quit";
     89   1.1       cgd 			break;
     90   1.1       cgd 		case KFIRE:
     91  1.12  dholland 			mechanism = "killed by fire";
     92   1.1       cgd 			break;
     93   1.1       cgd 		}
     94   1.1       cgd 	} else {
     95   1.1       cgd 		if (is_vowel(m_names[monster->m_char - 'A'][0])) {
     96  1.12  dholland 			article = "an";
     97   1.1       cgd 		} else {
     98  1.12  dholland 			article = "a";
     99   1.1       cgd 		}
    100  1.12  dholland 		snprintf(mechanism_buf, sizeof(mechanism_buf),
    101  1.12  dholland 			"Killed by %s %s",
    102  1.12  dholland 			 article, m_names[monster->m_char - 'A']);
    103  1.12  dholland 		mechanism = mechanism_buf;
    104   1.1       cgd 	}
    105  1.12  dholland 	snprintf(message_buf, sizeof(message_buf),
    106  1.12  dholland 		 "%s with %ld gold", mechanism, rogue.gold);
    107  1.12  dholland 
    108   1.1       cgd 	if ((!other) && (!no_skull)) {
    109   1.1       cgd 		clear();
    110   1.1       cgd 		mvaddstr(4, 32, "__---------__");
    111   1.1       cgd 		mvaddstr(5, 30, "_~             ~_");
    112   1.1       cgd 		mvaddstr(6, 29, "/                 \\");
    113   1.1       cgd 		mvaddstr(7, 28, "~                   ~");
    114   1.1       cgd 		mvaddstr(8, 27, "/                     \\");
    115   1.1       cgd 		mvaddstr(9, 27, "|    XXXX     XXXX    |");
    116   1.1       cgd 		mvaddstr(10, 27, "|    XXXX     XXXX    |");
    117   1.1       cgd 		mvaddstr(11, 27, "|    XXX       XXX    |");
    118   1.1       cgd 		mvaddstr(12, 28, "\\         @         /");
    119   1.1       cgd 		mvaddstr(13, 29, "--\\     @@@     /--");
    120   1.1       cgd 		mvaddstr(14, 30, "| |    @@@    | |");
    121   1.1       cgd 		mvaddstr(15, 30, "| |           | |");
    122   1.1       cgd 		mvaddstr(16, 30, "| vvVvvvvvvvVvv |");
    123   1.1       cgd 		mvaddstr(17, 30, "|  ^^^^^^^^^^^  |");
    124   1.1       cgd 		mvaddstr(18, 31, "\\_           _/");
    125   1.1       cgd 		mvaddstr(19, 33, "~---------~");
    126   1.1       cgd 		center(21, nick_name);
    127  1.12  dholland 		center(22, message_buf);
    128   1.1       cgd 	} else {
    129  1.12  dholland 		messagef(0, "%s", message_buf);
    130   1.1       cgd 	}
    131  1.12  dholland 	messagef(0, "%s", "");		/* gcc objects to just "" */
    132   1.1       cgd 	put_scores(monster, other);
    133   1.1       cgd }
    134   1.1       cgd 
    135   1.6     lukem void
    136   1.1       cgd win()
    137   1.1       cgd {
    138   1.1       cgd 	unwield(rogue.weapon);		/* disarm and relax */
    139   1.1       cgd 	unwear(rogue.armor);
    140   1.1       cgd 	un_put_on(rogue.left_ring);
    141   1.1       cgd 	un_put_on(rogue.right_ring);
    142   1.1       cgd 
    143   1.1       cgd 	clear();
    144   1.1       cgd 	mvaddstr(10, 11, "@   @  @@@   @   @      @  @  @   @@@   @   @   @");
    145   1.1       cgd 	mvaddstr(11, 11, " @ @  @   @  @   @      @  @  @  @   @  @@  @   @");
    146   1.1       cgd 	mvaddstr(12, 11, "  @   @   @  @   @      @  @  @  @   @  @ @ @   @");
    147   1.1       cgd 	mvaddstr(13, 11, "  @   @   @  @   @      @  @  @  @   @  @  @@");
    148   1.1       cgd 	mvaddstr(14, 11, "  @    @@@    @@@        @@ @@    @@@   @   @   @");
    149   1.1       cgd 	mvaddstr(17, 11, "Congratulations,  you have  been admitted  to  the");
    150   1.1       cgd 	mvaddstr(18, 11, "Fighters' Guild.   You return home,  sell all your");
    151   1.1       cgd 	mvaddstr(19, 11, "treasures at great profit and retire into comfort.");
    152  1.12  dholland 	messagef(0, "%s", "");		/* gcc objects to just "" */
    153  1.12  dholland 	messagef(0, "%s", "");		/* gcc objects to just "" */
    154   1.1       cgd 	id_all();
    155   1.1       cgd 	sell_pack();
    156  1.13  dholland 	put_scores((object *)0, WIN);
    157   1.1       cgd }
    158   1.1       cgd 
    159   1.6     lukem void
    160   1.1       cgd quit(from_intrpt)
    161   1.6     lukem 	boolean from_intrpt;
    162   1.1       cgd {
    163  1.12  dholland 	char buf[DCOLS];
    164   1.1       cgd 	short i, orow, ocol;
    165   1.1       cgd 	boolean mc;
    166   1.1       cgd 
    167   1.6     lukem 	orow = ocol = 0;
    168   1.6     lukem 	mc = FALSE;
    169   1.1       cgd 	md_ignore_signals();
    170   1.1       cgd 
    171   1.1       cgd 	if (from_intrpt) {
    172   1.1       cgd 		orow = rogue.row;
    173   1.1       cgd 		ocol = rogue.col;
    174   1.1       cgd 
    175   1.1       cgd 		mc = msg_cleared;
    176   1.1       cgd 
    177   1.1       cgd 		for (i = 0; i < DCOLS; i++) {
    178   1.1       cgd 			buf[i] = mvinch(0, i);
    179   1.1       cgd 		}
    180   1.1       cgd 	}
    181   1.1       cgd 	check_message();
    182  1.12  dholland 	messagef(1, "really quit?");
    183   1.1       cgd 	if (rgetchar() != 'y') {
    184   1.1       cgd 		md_heed_signals();
    185   1.1       cgd 		check_message();
    186   1.1       cgd 		if (from_intrpt) {
    187   1.1       cgd 			for (i = 0; i < DCOLS; i++) {
    188   1.1       cgd 				mvaddch(0, i, buf[i]);
    189   1.1       cgd 			}
    190   1.1       cgd 			msg_cleared = mc;
    191   1.1       cgd 			move(orow, ocol);
    192   1.1       cgd 			refresh();
    193   1.1       cgd 		}
    194   1.1       cgd 		return;
    195   1.1       cgd 	}
    196   1.1       cgd 	if (from_intrpt) {
    197   1.1       cgd 		clean_up(byebye_string);
    198   1.1       cgd 	}
    199   1.1       cgd 	check_message();
    200  1.13  dholland 	killed_by((object *)0, QUIT);
    201   1.1       cgd }
    202   1.1       cgd 
    203  1.12  dholland /*
    204  1.12  dholland  * The score file on disk is up to ten entries of the form
    205  1.12  dholland  *      score block [80 bytes]
    206  1.12  dholland  *      nickname block [30 bytes]
    207  1.12  dholland  *
    208  1.12  dholland  * The score block is to be parsed as follows:
    209  1.12  dholland  *      bytes 0-1	Rank (" 1" to "10")
    210  1.12  dholland  *      bytes 2-4	space padding
    211  1.12  dholland  *      bytes 5-15	Score/gold
    212  1.12  dholland  *      byte 15 up to a ':'	Login name
    213  1.12  dholland  *      past the ':'    Death mechanism
    214  1.12  dholland  *
    215  1.12  dholland  * The nickname block is an alternate name to be printed in place of the
    216  1.12  dholland  * login name. Both blocks are supposed to contain a null-terminator.
    217  1.12  dholland  */
    218  1.12  dholland 
    219  1.12  dholland struct score_entry {
    220  1.12  dholland 	long gold;
    221  1.12  dholland 	char username[80];
    222  1.12  dholland 	char death[80];
    223  1.12  dholland 	char nickname[30];
    224  1.12  dholland };
    225  1.12  dholland 
    226  1.12  dholland #define NUM_SCORE_ENTRIES 10
    227  1.12  dholland 
    228  1.12  dholland static void pad_spaces __P((char *, size_t));
    229  1.12  dholland static void unpad_spaces(char *);
    230  1.12  dholland static int read_score_entry __P((struct score_entry *, FILE *));
    231  1.12  dholland static void write_score_entry __P((const struct score_entry *, int, FILE *));
    232  1.12  dholland static void make_score __P((struct score_entry *, const object *, int));
    233  1.12  dholland 
    234  1.12  dholland 
    235  1.12  dholland static
    236  1.12  dholland void
    237  1.12  dholland pad_spaces(str, len)
    238  1.12  dholland 	char *str;
    239  1.12  dholland 	size_t len;
    240  1.12  dholland {
    241  1.12  dholland 	size_t x;
    242  1.12  dholland 	for (x=strlen(str); x<len-1; x++) {
    243  1.12  dholland 		str[x] = ' ';
    244  1.12  dholland 	}
    245  1.12  dholland 	str[len-1] = 0;
    246  1.12  dholland }
    247  1.12  dholland 
    248  1.12  dholland static
    249  1.12  dholland void
    250  1.12  dholland unpad_spaces(str)
    251  1.12  dholland 	char *str;
    252  1.12  dholland {
    253  1.12  dholland 	size_t x;
    254  1.12  dholland 	for (x=strlen(str); x>0 && str[x-1]==' '; x--);
    255  1.12  dholland 	str[x] = 0;
    256  1.12  dholland }
    257  1.12  dholland 
    258  1.12  dholland static
    259  1.12  dholland int
    260  1.12  dholland read_score_entry(se, fp)
    261  1.12  dholland 	struct score_entry *se;
    262  1.12  dholland 	FILE *fp;
    263  1.12  dholland {
    264  1.12  dholland 	char score_block[80];
    265  1.12  dholland 	char nickname_block[30];
    266  1.12  dholland 	size_t n, x;
    267  1.12  dholland 
    268  1.12  dholland 	n = fread(score_block, 1, sizeof(score_block), fp);
    269  1.12  dholland 	if (n==0) {
    270  1.12  dholland 		/* EOF */
    271  1.12  dholland 		return 0;
    272  1.12  dholland 	}
    273  1.12  dholland 	if (n != sizeof(score_block)) {
    274  1.12  dholland 		sf_error();
    275  1.12  dholland 	}
    276  1.12  dholland 
    277  1.12  dholland 	n = fread(nickname_block, 1, sizeof(nickname_block), fp);
    278  1.12  dholland 	if (n != sizeof(nickname_block)) {
    279  1.12  dholland 		sf_error();
    280  1.12  dholland 	}
    281  1.12  dholland 
    282  1.12  dholland 	xxxx(score_block, sizeof(score_block));
    283  1.12  dholland 	xxxx(nickname_block, sizeof(nickname_block));
    284  1.12  dholland 
    285  1.12  dholland 	/* Ensure null termination */
    286  1.12  dholland 	score_block[sizeof(score_block)-1] = 0;
    287  1.12  dholland 	nickname_block[sizeof(nickname_block)-1] = 0;
    288  1.12  dholland 
    289  1.12  dholland 	/* If there are other nulls in the score block, file is corrupt */
    290  1.12  dholland 	if (strlen(score_block)!=sizeof(score_block)-1) {
    291  1.12  dholland 		sf_error();
    292  1.12  dholland 	}
    293  1.12  dholland 	/* but this is NOT true of the nickname block */
    294  1.12  dholland 
    295  1.12  dholland 	/* quash trailing spaces */
    296  1.12  dholland 	unpad_spaces(score_block);
    297  1.12  dholland 	unpad_spaces(nickname_block);
    298  1.12  dholland 
    299  1.12  dholland 	for (x=5; score_block[x] == ' '; x++);
    300  1.12  dholland 	se->gold = lget_number(score_block+x);
    301  1.12  dholland 
    302  1.12  dholland 	for (x=15; score_block[x] != 0 && score_block[x] != ':'; x++);
    303  1.12  dholland 	if (score_block[x] == 0) {
    304  1.12  dholland 		sf_error();
    305  1.12  dholland 	}
    306  1.12  dholland 	score_block[x++] = 0;
    307  1.12  dholland 	strlcpy(se->username, score_block+15, sizeof(se->username));
    308  1.12  dholland 
    309  1.12  dholland 	strlcpy(se->death, score_block+x, sizeof(se->death));
    310  1.12  dholland 	strlcpy(se->nickname, nickname_block, sizeof(se->nickname));
    311  1.12  dholland 
    312  1.12  dholland 	return 1;
    313  1.12  dholland }
    314  1.12  dholland 
    315  1.12  dholland static
    316  1.12  dholland void
    317  1.12  dholland write_score_entry(se, rank, fp)
    318  1.12  dholland 	const struct score_entry *se;
    319  1.12  dholland 	int rank;
    320  1.12  dholland 	FILE *fp;
    321  1.12  dholland {
    322  1.12  dholland 	char score_block[80];
    323  1.12  dholland 	char nickname_block[30];
    324  1.12  dholland 
    325  1.12  dholland 	/* avoid writing crap to score file */
    326  1.12  dholland 	memset(score_block, 0, sizeof(score_block));
    327  1.12  dholland 	memset(nickname_block, 0, sizeof(nickname_block));
    328  1.12  dholland 
    329  1.12  dholland 	snprintf(score_block, sizeof(score_block),
    330  1.12  dholland 		 "%2d    %6ld   %s: %s",
    331  1.12  dholland 		 rank+1, se->gold, se->username, se->death);
    332  1.12  dholland 	strlcpy(nickname_block, se->nickname, sizeof(nickname_block));
    333  1.12  dholland 
    334  1.12  dholland 	/* pad blocks out with spaces */
    335  1.12  dholland 	pad_spaces(score_block, sizeof(score_block));
    336  1.12  dholland 	/*pad_spaces(nickname_block, sizeof(nickname_block)); -- wrong! */
    337  1.12  dholland 
    338  1.12  dholland 	xxxx(score_block, sizeof(score_block));
    339  1.12  dholland 	xxxx(nickname_block, sizeof(nickname_block));
    340  1.12  dholland 
    341  1.12  dholland 	fwrite(score_block, 1, sizeof(score_block), fp);
    342  1.12  dholland 	fwrite(nickname_block, 1, sizeof(nickname_block), fp);
    343  1.12  dholland }
    344  1.12  dholland 
    345   1.6     lukem void
    346   1.1       cgd put_scores(monster, other)
    347   1.7   hubertf 	const object *monster;
    348   1.6     lukem 	short other;
    349   1.1       cgd {
    350  1.12  dholland 	short i, rank=-1, found_player = -1, numscores = 0;
    351  1.12  dholland 	struct score_entry scores[NUM_SCORE_ENTRIES];
    352  1.12  dholland 	const char *name;
    353   1.1       cgd 	FILE *fp;
    354  1.10      tron 	boolean dopause = score_only;
    355   1.1       cgd 
    356   1.1       cgd 	md_lock(1);
    357   1.1       cgd 
    358   1.8       jsm 	setegid(egid);
    359   1.4       cgd 	if ((fp = fopen(_PATH_SCOREFILE, "r+")) == NULL &&
    360   1.4       cgd 	    (fp = fopen(_PATH_SCOREFILE, "w+")) == NULL) {
    361   1.8       jsm 		setegid(gid);
    362  1.12  dholland 		messagef(0, "cannot read/write/create score file");
    363   1.1       cgd 		sf_error();
    364   1.1       cgd 	}
    365   1.8       jsm 	setegid(gid);
    366   1.1       cgd 	rewind(fp);
    367  1.13  dholland 	(void)xxx(1);
    368   1.1       cgd 
    369  1.12  dholland 	for (numscores = 0; numscores < NUM_SCORE_ENTRIES; numscores++) {
    370  1.12  dholland 		if (read_score_entry(&scores[numscores], fp) == 0) {
    371   1.1       cgd 			break;
    372   1.1       cgd 		}
    373  1.12  dholland 	}
    374  1.12  dholland 
    375  1.12  dholland 	/* Search the score list. */
    376  1.12  dholland 	for (i=0; i<numscores; i++) {
    377  1.12  dholland 		if (!strcmp(scores[i].username, login_name)) {
    378  1.12  dholland 			/* found our score */
    379  1.12  dholland 			if (rogue.gold < scores[i].gold) {
    380  1.12  dholland 				/* we didn't do as well as last time */
    381  1.12  dholland 				score_only = 1;
    382  1.12  dholland 			} else {
    383  1.12  dholland 				/* we did better; mark entry for removal */
    384  1.12  dholland 				found_player = i;
    385   1.1       cgd 			}
    386  1.12  dholland 			break;
    387   1.1       cgd 		}
    388   1.1       cgd 	}
    389  1.12  dholland 
    390  1.12  dholland 	/* Remove a superseded entry, if any. */
    391   1.1       cgd 	if (found_player != -1) {
    392  1.12  dholland 		numscores--;
    393  1.12  dholland 		for (i = found_player; i < numscores; i++) {
    394  1.12  dholland 			scores[i] = scores[i+1];
    395   1.1       cgd 		}
    396   1.1       cgd 	}
    397  1.12  dholland 
    398  1.12  dholland 	/* If we're going to insert ourselves, do it now */
    399   1.1       cgd 	if (!score_only) {
    400   1.1       cgd 
    401  1.12  dholland 		/* if we aren't better than anyone, add at end. */
    402  1.12  dholland 		rank = numscores;
    403  1.12  dholland 
    404  1.12  dholland 		/* Otherwise, find our slot. */
    405  1.12  dholland 		for (i = 0; i < numscores; i++) {
    406  1.12  dholland 			if (rogue.gold >= scores[i].gold) {
    407   1.1       cgd 				rank = i;
    408   1.1       cgd 				break;
    409   1.1       cgd 			}
    410   1.1       cgd 		}
    411  1.12  dholland 
    412  1.12  dholland 		if (rank < NUM_SCORE_ENTRIES) {
    413  1.12  dholland 			/* Open up a slot */
    414  1.12  dholland 			for (i = numscores; i > rank; i--) {
    415  1.12  dholland 				scores[i] = scores[i-1];
    416   1.1       cgd 			}
    417  1.12  dholland 			numscores++;
    418  1.12  dholland 
    419  1.12  dholland 			/* Put our info in the slot */
    420  1.12  dholland 			make_score(&scores[rank], monster, other);
    421   1.1       cgd 		}
    422  1.12  dholland 
    423  1.12  dholland 		/* Now rewrite the score file */
    424  1.12  dholland 
    425  1.12  dholland 		md_ignore_signals();
    426   1.1       cgd 		rewind(fp);
    427  1.13  dholland 		(void)xxx(1);
    428  1.12  dholland 
    429  1.12  dholland 		for (i = 0; i < numscores; i++) {
    430  1.12  dholland 			write_score_entry(&scores[i], i, fp);
    431  1.12  dholland 		}
    432   1.1       cgd 	}
    433  1.12  dholland 	md_lock(0);
    434  1.12  dholland 	fclose(fp);
    435  1.12  dholland 
    436  1.12  dholland 	/* Display the scores */
    437   1.1       cgd 
    438   1.1       cgd 	clear();
    439   1.1       cgd 	mvaddstr(3, 30, "Top  Ten  Rogueists");
    440   1.1       cgd 	mvaddstr(8, 0, "Rank   Score   Name");
    441   1.1       cgd 
    442  1.12  dholland 	for (i = 0; i < numscores; i++) {
    443   1.1       cgd 		if (i == rank) {
    444   1.1       cgd 			standout();
    445   1.1       cgd 		}
    446  1.12  dholland 
    447  1.12  dholland 		if (scores[i].nickname[0]) {
    448  1.12  dholland 			name = scores[i].nickname;
    449   1.1       cgd 		} else {
    450  1.12  dholland 			name = scores[i].username;
    451   1.1       cgd 		}
    452  1.12  dholland 
    453  1.12  dholland 		mvprintw(i+10, 0, "%2d    %6ld   %s: %s",
    454  1.12  dholland 			 i+1, scores[i].gold, name, scores[i].death);
    455  1.12  dholland 
    456   1.1       cgd 		if (i == rank) {
    457   1.1       cgd 			standend();
    458   1.1       cgd 		}
    459   1.1       cgd 	}
    460   1.1       cgd 	refresh();
    461  1.12  dholland 	messagef(0, "%s", "");		/* gcc objects to just "" */
    462  1.10      tron 	if (dopause) {
    463  1.12  dholland 		messagef(0, "%s", "");
    464   1.1       cgd 	}
    465   1.1       cgd 	clean_up("");
    466   1.1       cgd }
    467   1.1       cgd 
    468  1.12  dholland static
    469   1.6     lukem void
    470  1.12  dholland make_score(se, monster, other)
    471  1.12  dholland 	struct score_entry *se;
    472   1.7   hubertf 	const object *monster;
    473   1.6     lukem 	int other;
    474   1.1       cgd {
    475  1.12  dholland 	const char *death = "bolts from the blue (?)";
    476  1.12  dholland 	const char *hasamulet;
    477  1.12  dholland 	char deathbuf[80];
    478   1.1       cgd 
    479  1.12  dholland 	se->gold = rogue.gold;
    480  1.12  dholland 	strlcpy(se->username, login_name, sizeof(se->username));
    481   1.1       cgd 
    482   1.1       cgd 	if (other) {
    483   1.1       cgd 		switch(other) {
    484   1.1       cgd 		case HYPOTHERMIA:
    485  1.12  dholland 			death = "died of hypothermia";
    486   1.1       cgd 			break;
    487   1.1       cgd 		case STARVATION:
    488  1.12  dholland 			death = "died of starvation";
    489   1.1       cgd 			break;
    490   1.1       cgd 		case POISON_DART:
    491  1.12  dholland 			death = "killed by a dart";
    492   1.1       cgd 			break;
    493   1.1       cgd 		case QUIT:
    494  1.12  dholland 			death = "quit";
    495   1.1       cgd 			break;
    496   1.1       cgd 		case WIN:
    497  1.12  dholland 			death = "a total winner";
    498   1.1       cgd 			break;
    499   1.1       cgd 		case KFIRE:
    500  1.12  dholland 			death = "killed by fire";
    501   1.1       cgd 			break;
    502   1.1       cgd 		}
    503   1.1       cgd 	} else {
    504  1.12  dholland 		const char *mn, *article;
    505  1.12  dholland 
    506  1.12  dholland 		mn = m_names[monster->m_char - 'A'];
    507  1.12  dholland 		if (is_vowel(mn[0])) {
    508  1.12  dholland 			article = "an";
    509   1.1       cgd 		} else {
    510  1.12  dholland 			article = "a";
    511   1.1       cgd 		}
    512  1.13  dholland 
    513  1.12  dholland 		snprintf(deathbuf, sizeof(deathbuf),
    514  1.12  dholland 			 "killed by %s %s", article, mn);
    515  1.12  dholland 		death = deathbuf;
    516   1.1       cgd 	}
    517  1.12  dholland 
    518  1.12  dholland 	if (other != WIN && has_amulet()) {
    519  1.12  dholland 		hasamulet = " with amulet";
    520  1.12  dholland 	} else {
    521  1.12  dholland 		hasamulet = "";
    522   1.1       cgd 	}
    523  1.12  dholland 
    524  1.12  dholland 	snprintf(se->death, sizeof(se->death), "%s on level %d%s",
    525  1.12  dholland 		 death, max_level, hasamulet);
    526  1.12  dholland 
    527  1.12  dholland 	strlcpy(se->nickname, nick_name, sizeof(se->nickname));
    528   1.1       cgd }
    529   1.1       cgd 
    530   1.6     lukem boolean
    531   1.1       cgd is_vowel(ch)
    532   1.6     lukem 	short ch;
    533   1.1       cgd {
    534   1.1       cgd 	return( (ch == 'a') ||
    535   1.1       cgd 		(ch == 'e') ||
    536   1.1       cgd 		(ch == 'i') ||
    537   1.1       cgd 		(ch == 'o') ||
    538   1.1       cgd 		(ch == 'u') );
    539   1.1       cgd }
    540   1.1       cgd 
    541   1.6     lukem void
    542   1.1       cgd sell_pack()
    543   1.1       cgd {
    544   1.1       cgd 	object *obj;
    545   1.1       cgd 	short row = 2, val;
    546   1.1       cgd 	char buf[DCOLS];
    547   1.1       cgd 
    548   1.1       cgd 	obj = rogue.pack.next_object;
    549   1.1       cgd 
    550   1.1       cgd 	clear();
    551   1.1       cgd 	mvaddstr(1, 0, "Value      Item");
    552   1.1       cgd 
    553   1.1       cgd 	while (obj) {
    554   1.1       cgd 		if (obj->what_is != FOOD) {
    555   1.1       cgd 			obj->identified = 1;
    556   1.1       cgd 			val = get_value(obj);
    557   1.1       cgd 			rogue.gold += val;
    558   1.1       cgd 
    559   1.1       cgd 			if (row < DROWS) {
    560  1.12  dholland 				get_desc(obj, buf, sizeof(buf));
    561  1.12  dholland 				mvprintw(row++, 0, "%5d      %s", val, buf);
    562   1.1       cgd 			}
    563   1.1       cgd 		}
    564   1.1       cgd 		obj = obj->next_object;
    565   1.1       cgd 	}
    566   1.1       cgd 	refresh();
    567   1.1       cgd 	if (rogue.gold > MAX_GOLD) {
    568   1.1       cgd 		rogue.gold = MAX_GOLD;
    569   1.1       cgd 	}
    570  1.12  dholland 	messagef(0, "%s", "");		/* gcc objects to just "" */
    571   1.1       cgd }
    572   1.1       cgd 
    573   1.6     lukem int
    574   1.1       cgd get_value(obj)
    575   1.7   hubertf 	const object *obj;
    576   1.1       cgd {
    577   1.1       cgd 	short wc;
    578   1.1       cgd 	int val;
    579   1.1       cgd 
    580   1.6     lukem 	val = 0;
    581   1.1       cgd 	wc = obj->which_kind;
    582   1.1       cgd 
    583   1.1       cgd 	switch(obj->what_is) {
    584   1.1       cgd 	case WEAPON:
    585   1.1       cgd 		val = id_weapons[wc].value;
    586   1.1       cgd 		if ((wc == ARROW) || (wc == DAGGER) || (wc == SHURIKEN) ||
    587   1.1       cgd 			(wc == DART)) {
    588   1.1       cgd 			val *= obj->quantity;
    589   1.1       cgd 		}
    590   1.1       cgd 		val += (obj->d_enchant * 85);
    591   1.1       cgd 		val += (obj->hit_enchant * 85);
    592   1.1       cgd 		break;
    593   1.1       cgd 	case ARMOR:
    594   1.1       cgd 		val = id_armors[wc].value;
    595   1.1       cgd 		val += (obj->d_enchant * 75);
    596   1.1       cgd 		if (obj->is_protected) {
    597   1.1       cgd 			val += 200;
    598   1.1       cgd 		}
    599   1.1       cgd 		break;
    600   1.1       cgd 	case WAND:
    601   1.1       cgd 		val = id_wands[wc].value * (obj->class + 1);
    602   1.1       cgd 		break;
    603   1.1       cgd 	case SCROL:
    604   1.1       cgd 		val = id_scrolls[wc].value * obj->quantity;
    605   1.1       cgd 		break;
    606   1.1       cgd 	case POTION:
    607   1.1       cgd 		val = id_potions[wc].value * obj->quantity;
    608   1.1       cgd 		break;
    609   1.1       cgd 	case AMULET:
    610   1.1       cgd 		val = 5000;
    611   1.1       cgd 		break;
    612   1.1       cgd 	case RING:
    613   1.1       cgd 		val = id_rings[wc].value * (obj->class + 1);
    614   1.1       cgd 		break;
    615   1.1       cgd 	}
    616   1.1       cgd 	if (val <= 0) {
    617   1.1       cgd 		val = 10;
    618   1.1       cgd 	}
    619   1.1       cgd 	return(val);
    620   1.1       cgd }
    621   1.1       cgd 
    622   1.6     lukem void
    623   1.1       cgd id_all()
    624   1.1       cgd {
    625   1.1       cgd 	short i;
    626   1.1       cgd 
    627   1.1       cgd 	for (i = 0; i < SCROLS; i++) {
    628   1.1       cgd 		id_scrolls[i].id_status = IDENTIFIED;
    629   1.1       cgd 	}
    630   1.1       cgd 	for (i = 0; i < WEAPONS; i++) {
    631   1.1       cgd 		id_weapons[i].id_status = IDENTIFIED;
    632   1.1       cgd 	}
    633   1.1       cgd 	for (i = 0; i < ARMORS; i++) {
    634   1.1       cgd 		id_armors[i].id_status = IDENTIFIED;
    635   1.1       cgd 	}
    636   1.1       cgd 	for (i = 0; i < WANDS; i++) {
    637   1.1       cgd 		id_wands[i].id_status = IDENTIFIED;
    638   1.1       cgd 	}
    639   1.1       cgd 	for (i = 0; i < POTIONS; i++) {
    640   1.1       cgd 		id_potions[i].id_status = IDENTIFIED;
    641   1.1       cgd 	}
    642   1.1       cgd }
    643   1.1       cgd 
    644   1.6     lukem void
    645   1.1       cgd xxxx(buf, n)
    646   1.6     lukem 	char *buf;
    647   1.6     lukem 	short n;
    648   1.1       cgd {
    649   1.1       cgd 	short i;
    650   1.1       cgd 	unsigned char c;
    651   1.1       cgd 
    652   1.1       cgd 	for (i = 0; i < n; i++) {
    653   1.1       cgd 
    654   1.1       cgd 		/* It does not matter if accuracy is lost during this assignment */
    655  1.13  dholland 		c = (unsigned char)xxx(0);
    656   1.1       cgd 
    657   1.1       cgd 		buf[i] ^= c;
    658   1.1       cgd 	}
    659   1.1       cgd }
    660   1.1       cgd 
    661   1.1       cgd long
    662   1.1       cgd xxx(st)
    663   1.6     lukem 	boolean st;
    664   1.1       cgd {
    665   1.1       cgd 	static long f, s;
    666   1.1       cgd 	long r;
    667   1.1       cgd 
    668   1.1       cgd 	if (st) {
    669   1.1       cgd 		f = 37;
    670   1.1       cgd 		s = 7;
    671   1.1       cgd 		return(0L);
    672   1.1       cgd 	}
    673   1.1       cgd 	r = ((f * s) + 9337) % 8887;
    674   1.1       cgd 	f = s;
    675   1.1       cgd 	s = r;
    676   1.1       cgd 	return(r);
    677   1.1       cgd }
    678   1.1       cgd 
    679   1.6     lukem void
    680   1.1       cgd center(row, buf)
    681   1.6     lukem 	short row;
    682   1.7   hubertf 	const char *buf;
    683   1.1       cgd {
    684   1.1       cgd 	short margin;
    685   1.1       cgd 
    686   1.1       cgd 	margin = ((DCOLS - strlen(buf)) / 2);
    687   1.1       cgd 	mvaddstr(row, margin, buf);
    688   1.1       cgd }
    689   1.1       cgd 
    690   1.6     lukem void
    691   1.1       cgd sf_error()
    692   1.1       cgd {
    693   1.1       cgd 	md_lock(0);
    694  1.12  dholland 	messagef(1, "%s", "");		/* gcc objects to just "" */
    695   1.1       cgd 	clean_up("sorry, score file is out of order");
    696   1.1       cgd }
    697