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