Home | History | Annotate | Line # | Download | only in hack
hack.invent.c revision 1.10.4.2
      1  1.10.4.2       snj /*	$NetBSD: hack.invent.c,v 1.10.4.2 2009/06/29 23:55:23 snj Exp $	*/
      2       1.5  christos 
      3       1.3   mycroft /*
      4       1.8       jsm  * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
      5       1.8       jsm  * Amsterdam
      6       1.8       jsm  * All rights reserved.
      7       1.8       jsm  *
      8       1.8       jsm  * Redistribution and use in source and binary forms, with or without
      9       1.8       jsm  * modification, are permitted provided that the following conditions are
     10       1.8       jsm  * met:
     11       1.8       jsm  *
     12       1.8       jsm  * - Redistributions of source code must retain the above copyright notice,
     13       1.8       jsm  * this list of conditions and the following disclaimer.
     14       1.8       jsm  *
     15       1.8       jsm  * - Redistributions in binary form must reproduce the above copyright
     16       1.8       jsm  * notice, this list of conditions and the following disclaimer in the
     17       1.8       jsm  * documentation and/or other materials provided with the distribution.
     18       1.8       jsm  *
     19       1.8       jsm  * - Neither the name of the Stichting Centrum voor Wiskunde en
     20       1.8       jsm  * Informatica, nor the names of its contributors may be used to endorse or
     21       1.8       jsm  * promote products derived from this software without specific prior
     22       1.8       jsm  * written permission.
     23       1.8       jsm  *
     24       1.8       jsm  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     25       1.8       jsm  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26       1.8       jsm  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     27       1.8       jsm  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
     28       1.8       jsm  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     29       1.8       jsm  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     30       1.8       jsm  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     31       1.8       jsm  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     32       1.8       jsm  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     33       1.8       jsm  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     34       1.8       jsm  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35       1.8       jsm  */
     36       1.8       jsm 
     37       1.8       jsm /*
     38       1.8       jsm  * Copyright (c) 1982 Jay Fenlason <hack (at) gnu.org>
     39       1.8       jsm  * All rights reserved.
     40       1.8       jsm  *
     41       1.8       jsm  * Redistribution and use in source and binary forms, with or without
     42       1.8       jsm  * modification, are permitted provided that the following conditions
     43       1.8       jsm  * are met:
     44       1.8       jsm  * 1. Redistributions of source code must retain the above copyright
     45       1.8       jsm  *    notice, this list of conditions and the following disclaimer.
     46       1.8       jsm  * 2. Redistributions in binary form must reproduce the above copyright
     47       1.8       jsm  *    notice, this list of conditions and the following disclaimer in the
     48       1.8       jsm  *    documentation and/or other materials provided with the distribution.
     49       1.8       jsm  * 3. The name of the author may not be used to endorse or promote products
     50       1.8       jsm  *    derived from this software without specific prior written permission.
     51       1.8       jsm  *
     52       1.8       jsm  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     53       1.8       jsm  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
     54       1.8       jsm  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
     55       1.8       jsm  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     56       1.8       jsm  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     57       1.8       jsm  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     58       1.8       jsm  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     59       1.8       jsm  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     60       1.8       jsm  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     61       1.8       jsm  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     62       1.3   mycroft  */
     63       1.3   mycroft 
     64       1.5  christos #include <sys/cdefs.h>
     65       1.3   mycroft #ifndef lint
     66  1.10.4.2       snj __RCSID("$NetBSD: hack.invent.c,v 1.10.4.2 2009/06/29 23:55:23 snj Exp $");
     67       1.5  christos #endif				/* not lint */
     68       1.1       cgd 
     69  1.10.4.2       snj #include <assert.h>
     70       1.5  christos #include <stdlib.h>
     71       1.5  christos #include "hack.h"
     72       1.5  christos #include "extern.h"
     73       1.1       cgd 
     74       1.1       cgd #ifndef NOWORM
     75       1.1       cgd #include	"def.wseg.h"
     76       1.5  christos #endif	/* NOWORM */
     77       1.1       cgd 
     78       1.1       cgd #define	NOINVSYM	'#'
     79       1.1       cgd 
     80       1.5  christos static int      lastinvnr = 51;	/* 0 ... 51 */
     81       1.5  christos 
     82       1.9       jsm static void assigninvlet(struct obj *);
     83       1.9       jsm static char *xprname(struct obj *, char);
     84       1.5  christos 
     85       1.5  christos static void
     86       1.1       cgd assigninvlet(otmp)
     87       1.5  christos 	struct obj     *otmp;
     88       1.1       cgd {
     89       1.5  christos 	boolean         inuse[52];
     90       1.5  christos 	int             i;
     91       1.5  christos 	struct obj     *obj;
     92       1.5  christos 
     93       1.5  christos 	for (i = 0; i < 52; i++)
     94       1.5  christos 		inuse[i] = FALSE;
     95       1.5  christos 	for (obj = invent; obj; obj = obj->nobj)
     96       1.5  christos 		if (obj != otmp) {
     97       1.5  christos 			i = obj->invlet;
     98       1.5  christos 			if ('a' <= i && i <= 'z')
     99       1.5  christos 				inuse[i - 'a'] = TRUE;
    100       1.5  christos 			else if ('A' <= i && i <= 'Z')
    101       1.5  christos 				inuse[i - 'A' + 26] = TRUE;
    102       1.5  christos 			if (i == otmp->invlet)
    103       1.5  christos 				otmp->invlet = 0;
    104       1.5  christos 		}
    105       1.5  christos 	if ((i = otmp->invlet) &&
    106       1.1       cgd 	    (('a' <= i && i <= 'z') || ('A' <= i && i <= 'Z')))
    107       1.1       cgd 		return;
    108       1.5  christos 	for (i = lastinvnr + 1; i != lastinvnr; i++) {
    109       1.5  christos 		if (i == 52) {
    110       1.5  christos 			i = -1;
    111       1.5  christos 			continue;
    112       1.5  christos 		}
    113       1.5  christos 		if (!inuse[i])
    114       1.5  christos 			break;
    115       1.1       cgd 	}
    116       1.1       cgd 	otmp->invlet = (inuse[i] ? NOINVSYM :
    117       1.5  christos 			(i < 26) ? ('a' + i) : ('A' + i - 26));
    118       1.1       cgd 	lastinvnr = i;
    119       1.1       cgd }
    120       1.1       cgd 
    121       1.5  christos struct obj     *
    122       1.1       cgd addinv(obj)
    123       1.5  christos 	struct obj     *obj;
    124       1.1       cgd {
    125       1.5  christos 	struct obj     *otmp;
    126       1.1       cgd 
    127       1.1       cgd 	/* merge or attach to end of chain */
    128       1.5  christos 	if (!invent) {
    129       1.1       cgd 		invent = obj;
    130       1.1       cgd 		otmp = 0;
    131       1.1       cgd 	} else
    132       1.5  christos 		for (otmp = invent; /* otmp */ ; otmp = otmp->nobj) {
    133       1.5  christos 			if (merged(otmp, obj, 0))
    134       1.5  christos 				return (otmp);
    135       1.5  christos 			if (!otmp->nobj) {
    136       1.5  christos 				otmp->nobj = obj;
    137       1.5  christos 				break;
    138       1.5  christos 			}
    139       1.1       cgd 		}
    140       1.1       cgd 	obj->nobj = 0;
    141       1.1       cgd 
    142       1.5  christos 	if (flags.invlet_constant) {
    143       1.1       cgd 		assigninvlet(obj);
    144       1.1       cgd 		/*
    145       1.1       cgd 		 * The ordering of the chain is nowhere significant
    146       1.1       cgd 		 * so in case you prefer some other order than the
    147       1.1       cgd 		 * historical one, change the code below.
    148       1.1       cgd 		 */
    149       1.5  christos 		if (otmp) {	/* find proper place in chain */
    150       1.1       cgd 			otmp->nobj = 0;
    151       1.5  christos 			if ((invent->invlet ^ 040) > (obj->invlet ^ 040)) {
    152       1.1       cgd 				obj->nobj = invent;
    153       1.1       cgd 				invent = obj;
    154       1.1       cgd 			} else
    155       1.5  christos 				for (otmp = invent;; otmp = otmp->nobj) {
    156       1.5  christos 					if (!otmp->nobj ||
    157       1.5  christos 					    (otmp->nobj->invlet ^ 040) > (obj->invlet ^ 040)) {
    158       1.5  christos 						obj->nobj = otmp->nobj;
    159       1.5  christos 						otmp->nobj = obj;
    160       1.5  christos 						break;
    161       1.5  christos 					}
    162       1.5  christos 				}
    163       1.1       cgd 		}
    164       1.1       cgd 	}
    165       1.5  christos 	return (obj);
    166       1.1       cgd }
    167       1.1       cgd 
    168       1.5  christos void
    169       1.1       cgd useup(obj)
    170       1.5  christos 	struct obj     *obj;
    171       1.1       cgd {
    172       1.5  christos 	if (obj->quan > 1) {
    173       1.1       cgd 		obj->quan--;
    174       1.1       cgd 		obj->owt = weight(obj);
    175       1.1       cgd 	} else {
    176       1.1       cgd 		setnotworn(obj);
    177       1.1       cgd 		freeinv(obj);
    178       1.1       cgd 		obfree(obj, (struct obj *) 0);
    179       1.1       cgd 	}
    180       1.1       cgd }
    181       1.1       cgd 
    182       1.5  christos void
    183       1.1       cgd freeinv(obj)
    184       1.5  christos 	struct obj     *obj;
    185       1.1       cgd {
    186       1.5  christos 	struct obj     *otmp;
    187       1.1       cgd 
    188       1.5  christos 	if (obj == invent)
    189       1.1       cgd 		invent = invent->nobj;
    190       1.1       cgd 	else {
    191       1.5  christos 		for (otmp = invent; otmp->nobj != obj; otmp = otmp->nobj)
    192       1.5  christos 			if (!otmp->nobj)
    193       1.5  christos 				panic("freeinv");
    194       1.1       cgd 		otmp->nobj = obj->nobj;
    195       1.1       cgd 	}
    196       1.1       cgd }
    197       1.1       cgd 
    198       1.1       cgd /* destroy object in fobj chain (if unpaid, it remains on the bill) */
    199       1.5  christos void
    200       1.5  christos delobj(obj)
    201       1.5  christos 	struct obj     *obj;
    202       1.5  christos {
    203       1.1       cgd 	freeobj(obj);
    204       1.1       cgd 	unpobj(obj);
    205       1.1       cgd 	obfree(obj, (struct obj *) 0);
    206       1.1       cgd }
    207       1.1       cgd 
    208       1.1       cgd /* unlink obj from chain starting with fobj */
    209       1.5  christos void
    210       1.5  christos freeobj(obj)
    211       1.5  christos 	struct obj     *obj;
    212       1.5  christos {
    213       1.5  christos 	struct obj     *otmp;
    214       1.1       cgd 
    215       1.5  christos 	if (obj == fobj)
    216       1.5  christos 		fobj = fobj->nobj;
    217       1.1       cgd 	else {
    218      1.10   jnemeth 		otmp = fobj;
    219      1.10   jnemeth 		while (otmp->nobj != obj) {
    220      1.10   jnemeth 			if (otmp->nobj == NULL)
    221       1.5  christos 				panic("error in freeobj");
    222      1.10   jnemeth 			otmp = otmp->nobj;
    223      1.10   jnemeth 		}
    224       1.1       cgd 		otmp->nobj = obj->nobj;
    225       1.1       cgd 	}
    226       1.1       cgd }
    227       1.1       cgd 
    228       1.1       cgd /* Note: freegold throws away its argument! */
    229       1.5  christos void
    230       1.5  christos freegold(gold)
    231       1.5  christos 	struct gold    *gold;
    232       1.5  christos {
    233       1.5  christos 	struct gold    *gtmp;
    234       1.1       cgd 
    235       1.5  christos 	if (gold == fgold)
    236       1.5  christos 		fgold = gold->ngold;
    237       1.1       cgd 	else {
    238      1.10   jnemeth 		gtmp = fgold;
    239      1.10   jnemeth 		while (gtmp->ngold != gold) {
    240      1.10   jnemeth 			if (gtmp->ngold == NULL)
    241       1.5  christos 				panic("error in freegold");
    242      1.10   jnemeth 			gtmp = gtmp->ngold;
    243      1.10   jnemeth 		}
    244       1.1       cgd 		gtmp->ngold = gold->ngold;
    245       1.1       cgd 	}
    246       1.1       cgd 	free((char *) gold);
    247       1.1       cgd }
    248       1.1       cgd 
    249       1.5  christos void
    250       1.1       cgd deltrap(trap)
    251       1.5  christos 	struct trap    *trap;
    252       1.1       cgd {
    253       1.5  christos 	struct trap    *ttmp;
    254       1.1       cgd 
    255       1.5  christos 	if (trap == ftrap)
    256       1.1       cgd 		ftrap = ftrap->ntrap;
    257       1.1       cgd 	else {
    258       1.5  christos 		for (ttmp = ftrap; ttmp->ntrap != trap; ttmp = ttmp->ntrap);
    259       1.1       cgd 		ttmp->ntrap = trap->ntrap;
    260       1.1       cgd 	}
    261       1.1       cgd 	free((char *) trap);
    262       1.1       cgd }
    263       1.1       cgd 
    264       1.5  christos struct wseg    *m_atseg;
    265       1.1       cgd 
    266       1.5  christos struct monst   *
    267       1.5  christos m_at(x, y)
    268       1.5  christos 	int x, y;
    269       1.1       cgd {
    270       1.5  christos 	struct monst   *mtmp;
    271       1.1       cgd #ifndef NOWORM
    272       1.5  christos 	struct wseg    *wtmp;
    273       1.5  christos #endif	/* NOWORM */
    274       1.1       cgd 
    275       1.1       cgd 	m_atseg = 0;
    276       1.5  christos 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
    277       1.5  christos 		if (mtmp->mx == x && mtmp->my == y)
    278       1.5  christos 			return (mtmp);
    279       1.1       cgd #ifndef NOWORM
    280       1.5  christos 		if (mtmp->wormno) {
    281       1.5  christos 			for (wtmp = wsegs[mtmp->wormno]; wtmp; wtmp = wtmp->nseg)
    282       1.5  christos 				if (wtmp->wx == x && wtmp->wy == y) {
    283       1.5  christos 					m_atseg = wtmp;
    284       1.5  christos 					return (mtmp);
    285       1.5  christos 				}
    286       1.1       cgd 		}
    287       1.5  christos #endif	/* NOWORM */
    288       1.1       cgd 	}
    289       1.5  christos 	return (0);
    290       1.1       cgd }
    291       1.1       cgd 
    292       1.5  christos struct obj     *
    293       1.5  christos o_at(x, y)
    294       1.5  christos 	int x, y;
    295       1.1       cgd {
    296       1.5  christos 	struct obj     *otmp;
    297       1.1       cgd 
    298       1.5  christos 	for (otmp = fobj; otmp; otmp = otmp->nobj)
    299       1.5  christos 		if (otmp->ox == x && otmp->oy == y)
    300       1.5  christos 			return (otmp);
    301       1.5  christos 	return (0);
    302       1.1       cgd }
    303       1.1       cgd 
    304       1.5  christos struct obj     *
    305       1.5  christos sobj_at(n, x, y)
    306       1.5  christos 	int n, x, y;
    307       1.1       cgd {
    308       1.5  christos 	struct obj     *otmp;
    309       1.1       cgd 
    310       1.5  christos 	for (otmp = fobj; otmp; otmp = otmp->nobj)
    311       1.5  christos 		if (otmp->ox == x && otmp->oy == y && otmp->otyp == n)
    312       1.5  christos 			return (otmp);
    313       1.5  christos 	return (0);
    314       1.1       cgd }
    315       1.1       cgd 
    316       1.5  christos int
    317       1.5  christos carried(obj)
    318       1.5  christos 	struct obj     *obj;
    319       1.5  christos {
    320       1.5  christos 	struct obj     *otmp;
    321       1.5  christos 	for (otmp = invent; otmp; otmp = otmp->nobj)
    322       1.5  christos 		if (otmp == obj)
    323       1.5  christos 			return (1);
    324       1.5  christos 	return (0);
    325       1.1       cgd }
    326       1.1       cgd 
    327       1.5  christos int
    328       1.1       cgd carrying(type)
    329       1.5  christos 	int             type;
    330       1.1       cgd {
    331       1.5  christos 	struct obj     *otmp;
    332       1.1       cgd 
    333       1.5  christos 	for (otmp = invent; otmp; otmp = otmp->nobj)
    334       1.5  christos 		if (otmp->otyp == type)
    335       1.5  christos 			return (TRUE);
    336       1.5  christos 	return (FALSE);
    337       1.1       cgd }
    338       1.1       cgd 
    339       1.5  christos struct obj     *
    340       1.5  christos o_on(id, objchn)
    341       1.5  christos 	unsigned int    id;
    342       1.5  christos 	struct obj     *objchn;
    343       1.5  christos {
    344       1.5  christos 	while (objchn) {
    345       1.5  christos 		if (objchn->o_id == id)
    346       1.5  christos 			return (objchn);
    347       1.1       cgd 		objchn = objchn->nobj;
    348       1.1       cgd 	}
    349       1.5  christos 	return ((struct obj *) 0);
    350       1.1       cgd }
    351       1.1       cgd 
    352       1.5  christos struct trap    *
    353       1.5  christos t_at(x, y)
    354       1.5  christos 	int x, y;
    355       1.1       cgd {
    356       1.5  christos 	struct trap    *trap = ftrap;
    357       1.5  christos 	while (trap) {
    358       1.5  christos 		if (trap->tx == x && trap->ty == y)
    359       1.5  christos 			return (trap);
    360       1.1       cgd 		trap = trap->ntrap;
    361       1.1       cgd 	}
    362       1.5  christos 	return (0);
    363       1.1       cgd }
    364       1.1       cgd 
    365       1.5  christos struct gold    *
    366       1.5  christos g_at(x, y)
    367       1.5  christos 	int x, y;
    368       1.1       cgd {
    369       1.5  christos 	struct gold    *gold = fgold;
    370       1.5  christos 	while (gold) {
    371       1.5  christos 		if (gold->gx == x && gold->gy == y)
    372       1.5  christos 			return (gold);
    373       1.1       cgd 		gold = gold->ngold;
    374       1.1       cgd 	}
    375       1.5  christos 	return (0);
    376       1.1       cgd }
    377       1.1       cgd 
    378       1.1       cgd /* make dummy object structure containing gold - for temporary use only */
    379       1.5  christos struct obj     *
    380       1.1       cgd mkgoldobj(q)
    381       1.5  christos 	long            q;
    382       1.1       cgd {
    383       1.5  christos 	struct obj     *otmp;
    384       1.1       cgd 
    385       1.1       cgd 	otmp = newobj(0);
    386       1.1       cgd 	/* should set o_id etc. but otmp will be freed soon */
    387       1.1       cgd 	otmp->olet = '$';
    388       1.1       cgd 	u.ugold -= q;
    389       1.1       cgd 	OGOLD(otmp) = q;
    390       1.1       cgd 	flags.botl = 1;
    391       1.5  christos 	return (otmp);
    392       1.1       cgd }
    393       1.1       cgd 
    394       1.1       cgd /*
    395       1.1       cgd  * getobj returns:
    396       1.1       cgd  *	struct obj *xxx:	object to do something with.
    397       1.1       cgd  *	(struct obj *) 0	error return: no object.
    398       1.1       cgd  *	&zeroobj		explicitly no object (as in w-).
    399       1.1       cgd  */
    400       1.5  christos struct obj     *
    401       1.5  christos getobj(let, word)
    402       1.7       jsm 	const char           *let, *word;
    403       1.5  christos {
    404       1.5  christos 	struct obj     *otmp;
    405       1.5  christos 	char            ilet, ilet1, ilet2;
    406       1.5  christos 	char            buf[BUFSZ];
    407       1.5  christos 	char            lets[BUFSZ];
    408       1.5  christos 	int             foo = 0, foo2;
    409       1.5  christos 	char           *bp = buf;
    410       1.5  christos 	xchar           allowcnt = 0;	/* 0, 1 or 2 */
    411       1.5  christos 	boolean         allowgold = FALSE;
    412       1.5  christos 	boolean         allowall = FALSE;
    413       1.5  christos 	boolean         allownone = FALSE;
    414       1.5  christos 	xchar           foox = 0;
    415       1.5  christos 	long            cnt;
    416       1.5  christos 
    417       1.5  christos 	if (*let == '0')
    418       1.5  christos 		let++, allowcnt = 1;
    419       1.5  christos 	if (*let == '$')
    420       1.5  christos 		let++, allowgold = TRUE;
    421       1.5  christos 	if (*let == '#')
    422       1.5  christos 		let++, allowall = TRUE;
    423       1.5  christos 	if (*let == '-')
    424       1.5  christos 		let++, allownone = TRUE;
    425       1.5  christos 	if (allownone)
    426       1.5  christos 		*bp++ = '-';
    427       1.5  christos 	if (allowgold)
    428       1.5  christos 		*bp++ = '$';
    429       1.5  christos 	if (bp > buf && bp[-1] == '-')
    430       1.5  christos 		*bp++ = ' ';
    431       1.1       cgd 
    432       1.1       cgd 	ilet = 'a';
    433       1.5  christos 	for (otmp = invent; otmp; otmp = otmp->nobj) {
    434       1.5  christos 		if (!*let || strchr(let, otmp->olet)) {
    435       1.5  christos 			bp[foo++] = flags.invlet_constant ? otmp->invlet : ilet;
    436       1.5  christos 
    437       1.5  christos 			/* ugly check: remove inappropriate things */
    438       1.5  christos 			if ((!strcmp(word, "take off") &&
    439       1.5  christos 			     !(otmp->owornmask & (W_ARMOR - W_ARM2)))
    440       1.5  christos 			    || (!strcmp(word, "wear") &&
    441       1.5  christos 				(otmp->owornmask & (W_ARMOR | W_RING)))
    442       1.5  christos 			    || (!strcmp(word, "wield") &&
    443       1.5  christos 				(otmp->owornmask & W_WEP))) {
    444       1.5  christos 				foo--;
    445       1.5  christos 				foox++;
    446       1.5  christos 			}
    447       1.1       cgd 		}
    448       1.5  christos 		if (ilet == 'z')
    449       1.5  christos 			ilet = 'A';
    450       1.5  christos 		else
    451       1.5  christos 			ilet++;
    452       1.1       cgd 	}
    453       1.1       cgd 	bp[foo] = 0;
    454       1.5  christos 	if (foo == 0 && bp > buf && bp[-1] == ' ')
    455       1.5  christos 		*--bp = 0;
    456       1.5  christos 	(void) strcpy(lets, bp);/* necessary since we destroy buf */
    457       1.5  christos 	if (foo > 5) {		/* compactify string */
    458       1.1       cgd 		foo = foo2 = 1;
    459       1.1       cgd 		ilet2 = bp[0];
    460       1.1       cgd 		ilet1 = bp[1];
    461       1.5  christos 		while ((ilet = bp[++foo2] = bp[++foo]) != '\0') {
    462       1.5  christos 			if (ilet == ilet1 + 1) {
    463       1.5  christos 				if (ilet1 == ilet2 + 1)
    464       1.1       cgd 					bp[foo2 - 1] = ilet1 = '-';
    465       1.5  christos 				else if (ilet2 == '-') {
    466       1.1       cgd 					bp[--foo2] = ++ilet1;
    467       1.1       cgd 					continue;
    468       1.1       cgd 				}
    469       1.1       cgd 			}
    470       1.1       cgd 			ilet2 = ilet1;
    471       1.1       cgd 			ilet1 = ilet;
    472       1.1       cgd 		}
    473       1.1       cgd 	}
    474       1.5  christos 	if (!foo && !allowall && !allowgold && !allownone) {
    475       1.1       cgd 		pline("You don't have anything %sto %s.",
    476       1.5  christos 		      foox ? "else " : "", word);
    477       1.5  christos 		return (0);
    478       1.1       cgd 	}
    479       1.5  christos 	for (;;) {
    480       1.5  christos 		if (!buf[0])
    481       1.1       cgd 			pline("What do you want to %s [*]? ", word);
    482       1.1       cgd 		else
    483       1.1       cgd 			pline("What do you want to %s [%s or ?*]? ",
    484       1.5  christos 			      word, buf);
    485       1.1       cgd 
    486       1.1       cgd 		cnt = 0;
    487       1.1       cgd 		ilet = readchar();
    488       1.5  christos 		while (digit(ilet) && allowcnt) {
    489       1.1       cgd 			if (cnt < 100000000)
    490       1.5  christos 				cnt = 10 * cnt + (ilet - '0');
    491       1.1       cgd 			else
    492       1.5  christos 				cnt = 999999999;
    493       1.1       cgd 			allowcnt = 2;	/* signal presence of cnt */
    494       1.1       cgd 			ilet = readchar();
    495       1.1       cgd 		}
    496       1.5  christos 		if (digit(ilet)) {
    497       1.1       cgd 			pline("No count allowed with this command.");
    498       1.1       cgd 			continue;
    499       1.1       cgd 		}
    500       1.5  christos 		if (strchr(quitchars, ilet))
    501       1.5  christos 			return ((struct obj *) 0);
    502       1.5  christos 		if (ilet == '-') {
    503       1.5  christos 			return (allownone ? &zeroobj : (struct obj *) 0);
    504       1.1       cgd 		}
    505       1.5  christos 		if (ilet == '$') {
    506       1.5  christos 			if (!allowgold) {
    507       1.1       cgd 				pline("You cannot %s gold.", word);
    508       1.1       cgd 				continue;
    509       1.1       cgd 			}
    510       1.5  christos 			if (!(allowcnt == 2 && cnt < u.ugold))
    511       1.1       cgd 				cnt = u.ugold;
    512       1.5  christos 			return (mkgoldobj(cnt));
    513       1.1       cgd 		}
    514       1.5  christos 		if (ilet == '?') {
    515       1.1       cgd 			doinv(lets);
    516       1.5  christos 			if (!(ilet = morc))
    517       1.5  christos 				continue;
    518       1.1       cgd 			/* he typed a letter (not a space) to more() */
    519       1.5  christos 		} else if (ilet == '*') {
    520       1.1       cgd 			doinv((char *) 0);
    521       1.5  christos 			if (!(ilet = morc))
    522       1.5  christos 				continue;
    523       1.1       cgd 			/* ... */
    524       1.1       cgd 		}
    525       1.5  christos 		if (flags.invlet_constant) {
    526       1.5  christos 			for (otmp = invent; otmp; otmp = otmp->nobj)
    527       1.5  christos 				if (otmp->invlet == ilet)
    528       1.5  christos 					break;
    529       1.1       cgd 		} else {
    530       1.5  christos 			if (ilet >= 'A' && ilet <= 'Z')
    531       1.5  christos 				ilet += 'z' - 'A' + 1;
    532       1.1       cgd 			ilet -= 'a';
    533       1.5  christos 			for (otmp = invent; otmp && ilet;
    534       1.5  christos 			     ilet--, otmp = otmp->nobj);
    535       1.1       cgd 		}
    536       1.5  christos 		if (!otmp) {
    537       1.1       cgd 			pline("You don't have that object.");
    538       1.1       cgd 			continue;
    539       1.1       cgd 		}
    540       1.5  christos 		if (cnt < 0 || otmp->quan < cnt) {
    541       1.1       cgd 			pline("You don't have that many! [You have %u]"
    542       1.5  christos 			      ,otmp->quan);
    543       1.1       cgd 			continue;
    544       1.1       cgd 		}
    545       1.1       cgd 		break;
    546       1.1       cgd 	}
    547       1.5  christos 	if (!allowall && let && !strchr(let, otmp->olet)) {
    548       1.5  christos 		pline("That is a silly thing to %s.", word);
    549       1.5  christos 		return (0);
    550       1.5  christos 	}
    551       1.5  christos 	if (allowcnt == 2) {	/* cnt given */
    552       1.5  christos 		if (cnt == 0)
    553       1.5  christos 			return (0);
    554       1.5  christos 		if (cnt != otmp->quan) {
    555       1.5  christos 			struct obj     *obj;
    556       1.1       cgd 			obj = splitobj(otmp, (int) cnt);
    557       1.5  christos 			if (otmp == uwep)
    558       1.5  christos 				setuwep(obj);
    559       1.1       cgd 		}
    560       1.1       cgd 	}
    561       1.5  christos 	return (otmp);
    562       1.1       cgd }
    563       1.1       cgd 
    564       1.5  christos int
    565       1.5  christos ckunpaid(otmp)
    566       1.5  christos 	struct obj     *otmp;
    567       1.5  christos {
    568       1.5  christos 	return (otmp->unpaid);
    569       1.1       cgd }
    570       1.1       cgd 
    571       1.1       cgd /* interactive version of getobj - used for Drop and Identify */
    572       1.1       cgd /* return the number of times fn was called successfully */
    573       1.5  christos int
    574       1.1       cgd ggetobj(word, fn, max)
    575       1.7       jsm 	const char *word;
    576       1.9       jsm 	int (*fn)(struct obj *);
    577       1.5  christos 	int max;
    578       1.5  christos {
    579       1.5  christos 	char            buf[BUFSZ];
    580       1.5  christos 	char           *ip;
    581       1.5  christos 	char            sym;
    582  1.10.4.2       snj 	unsigned        oletct = 0, iletct = 0;
    583       1.5  christos 	boolean         allflag = FALSE;
    584       1.5  christos 	char            olets[20], ilets[20];
    585       1.9       jsm 	int           (*ckfn)(struct obj *) =
    586       1.9       jsm 	    (int (*)(struct obj *)) 0;
    587       1.5  christos 	xchar           allowgold = (u.ugold && !strcmp(word, "drop")) ? 1 : 0;	/* BAH */
    588       1.5  christos 	if (!invent && !allowgold) {
    589       1.1       cgd 		pline("You have nothing to %s.", word);
    590       1.5  christos 		return (0);
    591       1.1       cgd 	} else {
    592       1.5  christos 		struct obj     *otmp = invent;
    593       1.5  christos 		int             uflg = 0;
    594       1.1       cgd 
    595       1.5  christos 		if (allowgold)
    596       1.5  christos 			ilets[iletct++] = '$';
    597       1.1       cgd 		ilets[iletct] = 0;
    598       1.5  christos 		while (otmp) {
    599       1.5  christos 			if (!strchr(ilets, otmp->olet)) {
    600       1.1       cgd 				ilets[iletct++] = otmp->olet;
    601       1.1       cgd 				ilets[iletct] = 0;
    602       1.1       cgd 			}
    603       1.5  christos 			if (otmp->unpaid)
    604       1.5  christos 				uflg = 1;
    605       1.1       cgd 			otmp = otmp->nobj;
    606       1.1       cgd 		}
    607       1.1       cgd 		ilets[iletct++] = ' ';
    608       1.5  christos 		if (uflg)
    609       1.5  christos 			ilets[iletct++] = 'u';
    610       1.5  christos 		if (invent)
    611       1.5  christos 			ilets[iletct++] = 'a';
    612       1.1       cgd 		ilets[iletct] = 0;
    613  1.10.4.2       snj 		assert(iletct < sizeof(ilets));
    614       1.1       cgd 	}
    615       1.1       cgd 	pline("What kinds of thing do you want to %s? [%s] ",
    616       1.5  christos 	      word, ilets);
    617       1.1       cgd 	getlin(buf);
    618       1.5  christos 	if (buf[0] == '\033') {
    619       1.1       cgd 		clrlin();
    620       1.5  christos 		return (0);
    621       1.1       cgd 	}
    622       1.1       cgd 	ip = buf;
    623       1.1       cgd 	olets[0] = 0;
    624       1.5  christos 	while ((sym = *ip++) != '\0') {
    625       1.5  christos 		if (sym == ' ')
    626       1.5  christos 			continue;
    627       1.5  christos 		if (sym == '$') {
    628       1.5  christos 			if (allowgold == 1)
    629       1.5  christos 				(*fn) (mkgoldobj(u.ugold));
    630       1.5  christos 			else if (!u.ugold)
    631       1.1       cgd 				pline("You have no gold.");
    632       1.1       cgd 			allowgold = 2;
    633       1.5  christos 		} else if (sym == 'a' || sym == 'A')
    634       1.5  christos 			allflag = TRUE;
    635       1.5  christos 		else if (sym == 'u' || sym == 'U')
    636       1.5  christos 			ckfn = ckunpaid;
    637       1.5  christos 		else if (strchr("!%?[()=*/\"0", sym)) {
    638       1.5  christos 			if (!strchr(olets, sym)) {
    639       1.1       cgd 				olets[oletct++] = sym;
    640       1.1       cgd 				olets[oletct] = 0;
    641       1.1       cgd 			}
    642  1.10.4.2       snj 			assert(oletct < sizeof(olets));
    643       1.5  christos 		} else
    644       1.5  christos 			pline("You don't have any %c's.", sym);
    645       1.1       cgd 	}
    646       1.5  christos 	if (allowgold == 2 && !oletct)
    647       1.5  christos 		return (1);	/* he dropped gold (or at least tried to) */
    648       1.1       cgd 	else
    649       1.5  christos 		return (askchain(invent, olets, allflag, fn, ckfn, max));
    650       1.1       cgd }
    651       1.1       cgd 
    652       1.1       cgd /*
    653       1.1       cgd  * Walk through the chain starting at objchn and ask for all objects
    654       1.1       cgd  * with olet in olets (if nonNULL) and satisfying ckfn (if nonNULL)
    655       1.1       cgd  * whether the action in question (i.e., fn) has to be performed.
    656       1.1       cgd  * If allflag then no questions are asked. Max gives the max nr of
    657       1.1       cgd  * objects to be treated. Return the number of objects treated.
    658       1.1       cgd  */
    659       1.5  christos int
    660       1.1       cgd askchain(objchn, olets, allflag, fn, ckfn, max)
    661       1.5  christos 	struct obj     *objchn;
    662       1.5  christos 	char           *olets;
    663       1.5  christos 	int             allflag;
    664       1.9       jsm 	int           (*fn)(struct obj *);
    665       1.9       jsm 	int	      (*ckfn)(struct obj *);
    666       1.5  christos 	int             max;
    667       1.5  christos {
    668       1.5  christos 	struct obj     *otmp, *otmp2;
    669       1.5  christos 	char            sym, ilet;
    670       1.5  christos 	int             cnt = 0;
    671       1.5  christos 	ilet = 'a' - 1;
    672       1.5  christos 	for (otmp = objchn; otmp; otmp = otmp2) {
    673       1.5  christos 		if (ilet == 'z')
    674       1.5  christos 			ilet = 'A';
    675       1.5  christos 		else
    676       1.5  christos 			ilet++;
    677       1.1       cgd 		otmp2 = otmp->nobj;
    678       1.5  christos 		if (olets && *olets && !strchr(olets, otmp->olet))
    679       1.5  christos 			continue;
    680       1.5  christos 		if (ckfn && !(*ckfn) (otmp))
    681       1.5  christos 			continue;
    682       1.5  christos 		if (!allflag) {
    683       1.1       cgd 			pline(xprname(otmp, ilet));
    684       1.1       cgd 			addtopl(" [nyaq]? ");
    685       1.1       cgd 			sym = readchar();
    686       1.5  christos 		} else
    687       1.5  christos 			sym = 'y';
    688       1.1       cgd 
    689       1.5  christos 		switch (sym) {
    690       1.1       cgd 		case 'a':
    691       1.1       cgd 			allflag = 1;
    692       1.1       cgd 		case 'y':
    693       1.5  christos 			cnt += (*fn) (otmp);
    694       1.5  christos 			if (--max == 0)
    695       1.5  christos 				goto ret;
    696       1.1       cgd 		case 'n':
    697       1.1       cgd 		default:
    698       1.1       cgd 			break;
    699       1.1       cgd 		case 'q':
    700       1.1       cgd 			goto ret;
    701       1.1       cgd 		}
    702       1.1       cgd 	}
    703       1.1       cgd 	pline(cnt ? "That was all." : "No applicable objects.");
    704       1.1       cgd ret:
    705       1.5  christos 	return (cnt);
    706       1.1       cgd }
    707       1.1       cgd 
    708       1.5  christos char
    709       1.5  christos obj_to_let(obj)			/* should of course only be called for things
    710       1.5  christos 				 * in invent */
    711       1.5  christos 	struct obj     *obj;
    712       1.1       cgd {
    713       1.5  christos 	struct obj     *otmp;
    714       1.5  christos 	char            ilet;
    715       1.1       cgd 
    716       1.5  christos 	if (flags.invlet_constant)
    717       1.5  christos 		return (obj->invlet);
    718       1.1       cgd 	ilet = 'a';
    719       1.5  christos 	for (otmp = invent; otmp && otmp != obj; otmp = otmp->nobj)
    720       1.5  christos 		if (++ilet > 'z')
    721       1.5  christos 			ilet = 'A';
    722       1.5  christos 	return (otmp ? ilet : NOINVSYM);
    723       1.1       cgd }
    724       1.1       cgd 
    725       1.5  christos void
    726       1.1       cgd prinv(obj)
    727       1.5  christos 	struct obj     *obj;
    728       1.1       cgd {
    729       1.1       cgd 	pline(xprname(obj, obj_to_let(obj)));
    730       1.1       cgd }
    731       1.1       cgd 
    732       1.5  christos static char    *
    733       1.5  christos xprname(obj, let)
    734       1.5  christos 	struct obj     *obj;
    735       1.5  christos 	char            let;
    736       1.1       cgd {
    737       1.5  christos 	static char     li[BUFSZ];
    738       1.1       cgd 
    739  1.10.4.1       snj 	(void) snprintf(li, sizeof(li), "%c - %s.",
    740       1.5  christos 		       flags.invlet_constant ? obj->invlet : let,
    741       1.5  christos 		       doname(obj));
    742       1.5  christos 	return (li);
    743       1.1       cgd }
    744       1.1       cgd 
    745       1.5  christos int
    746       1.1       cgd ddoinv()
    747       1.1       cgd {
    748       1.1       cgd 	doinv((char *) 0);
    749       1.5  christos 	return (0);
    750       1.1       cgd }
    751       1.1       cgd 
    752       1.1       cgd /* called with 0 or "": all objects in inventory */
    753       1.1       cgd /* otherwise: all objects with (serial) letter in lets */
    754       1.5  christos void
    755       1.1       cgd doinv(lets)
    756       1.5  christos 	char           *lets;
    757       1.1       cgd {
    758       1.5  christos 	struct obj     *otmp;
    759       1.5  christos 	char            ilet;
    760  1.10.4.2       snj 	unsigned        ct = 0;
    761       1.5  christos 	char            any[BUFSZ];
    762       1.1       cgd 
    763       1.1       cgd 	morc = 0;		/* just to be sure */
    764       1.1       cgd 
    765       1.5  christos 	if (!invent) {
    766       1.1       cgd 		pline("Not carrying anything.");
    767       1.1       cgd 		return;
    768       1.1       cgd 	}
    769       1.1       cgd 	cornline(0, (char *) 0);
    770       1.1       cgd 	ilet = 'a';
    771       1.5  christos 	for (otmp = invent; otmp; otmp = otmp->nobj) {
    772       1.5  christos 		if (flags.invlet_constant)
    773       1.5  christos 			ilet = otmp->invlet;
    774       1.5  christos 		if (!lets || !*lets || strchr(lets, ilet)) {
    775       1.5  christos 			cornline(1, xprname(otmp, ilet));
    776       1.5  christos 			any[ct++] = ilet;
    777       1.5  christos 		}
    778       1.5  christos 		if (!flags.invlet_constant)
    779       1.5  christos 			if (++ilet > 'z')
    780       1.5  christos 				ilet = 'A';
    781       1.1       cgd 	}
    782       1.1       cgd 	any[ct] = 0;
    783  1.10.4.2       snj 	assert(ct < sizeof(any));
    784       1.1       cgd 	cornline(2, any);
    785       1.1       cgd }
    786       1.1       cgd 
    787       1.5  christos int
    788       1.5  christos dotypeinv()
    789       1.5  christos {				/* free after Robert Viduya */
    790       1.5  christos 	/* Changed to one type only, so he doesnt have to type cr */
    791       1.5  christos 	char            c, ilet;
    792       1.5  christos 	char            stuff[BUFSZ];
    793  1.10.4.2       snj 	unsigned        stct;
    794       1.5  christos 	struct obj     *otmp;
    795       1.5  christos 	boolean         billx = inshop() && doinvbill(0);
    796       1.5  christos 	boolean         unpd = FALSE;
    797       1.1       cgd 
    798       1.1       cgd 	if (!invent && !u.ugold && !billx) {
    799       1.5  christos 		pline("You aren't carrying anything.");
    800       1.5  christos 		return (0);
    801       1.1       cgd 	}
    802       1.1       cgd 	stct = 0;
    803       1.5  christos 	if (u.ugold)
    804       1.5  christos 		stuff[stct++] = '$';
    805       1.1       cgd 	stuff[stct] = 0;
    806       1.5  christos 	for (otmp = invent; otmp; otmp = otmp->nobj) {
    807       1.5  christos 		if (!strchr(stuff, otmp->olet)) {
    808       1.5  christos 			stuff[stct++] = otmp->olet;
    809       1.5  christos 			stuff[stct] = 0;
    810       1.5  christos 		}
    811       1.5  christos 		if (otmp->unpaid)
    812       1.5  christos 			unpd = TRUE;
    813       1.5  christos 	}
    814       1.5  christos 	if (unpd)
    815       1.5  christos 		stuff[stct++] = 'u';
    816       1.5  christos 	if (billx)
    817       1.5  christos 		stuff[stct++] = 'x';
    818       1.1       cgd 	stuff[stct] = 0;
    819  1.10.4.2       snj 	assert(stct < sizeof(stuff));
    820       1.1       cgd 
    821       1.5  christos 	if (stct > 1) {
    822       1.5  christos 		pline("What type of object [%s] do you want an inventory of? ",
    823       1.5  christos 		      stuff);
    824       1.5  christos 		c = readchar();
    825       1.5  christos 		if (strchr(quitchars, c))
    826       1.5  christos 			return (0);
    827       1.1       cgd 	} else
    828       1.5  christos 		c = stuff[0];
    829       1.1       cgd 
    830       1.5  christos 	if (c == '$')
    831       1.5  christos 		return (doprgold());
    832       1.1       cgd 
    833       1.5  christos 	if (c == 'x' || c == 'X') {
    834       1.5  christos 		if (billx)
    835       1.5  christos 			(void) doinvbill(1);
    836       1.5  christos 		else
    837       1.5  christos 			pline("No used-up objects on the shopping bill.");
    838       1.5  christos 		return (0);
    839       1.1       cgd 	}
    840       1.5  christos 	if ((c == 'u' || c == 'U') && !unpd) {
    841       1.1       cgd 		pline("You are not carrying any unpaid objects.");
    842       1.5  christos 		return (0);
    843       1.1       cgd 	}
    844       1.1       cgd 	stct = 0;
    845       1.1       cgd 	ilet = 'a';
    846       1.5  christos 	for (otmp = invent; otmp; otmp = otmp->nobj) {
    847       1.5  christos 		if (flags.invlet_constant)
    848       1.5  christos 			ilet = otmp->invlet;
    849       1.5  christos 		if (c == otmp->olet || (c == 'u' && otmp->unpaid))
    850       1.5  christos 			stuff[stct++] = ilet;
    851       1.5  christos 		if (!flags.invlet_constant)
    852       1.5  christos 			if (++ilet > 'z')
    853       1.5  christos 				ilet = 'A';
    854       1.1       cgd 	}
    855       1.1       cgd 	stuff[stct] = '\0';
    856  1.10.4.2       snj 	assert(stct < sizeof(stuff));
    857  1.10.4.2       snj 
    858       1.5  christos 	if (stct == 0)
    859       1.1       cgd 		pline("You have no such objects.");
    860       1.1       cgd 	else
    861       1.5  christos 		doinv(stuff);
    862       1.1       cgd 
    863       1.5  christos 	return (0);
    864       1.1       cgd }
    865       1.1       cgd 
    866       1.1       cgd /* look at what is here */
    867       1.5  christos int
    868       1.5  christos dolook()
    869       1.5  christos {
    870       1.6      fair 	struct obj     *otmp = NULL, *otmp0 = NULL;
    871       1.6      fair 	struct gold    *gold = NULL;
    872       1.7       jsm 	const char     *verb = Blind ? "feel" : "see";
    873       1.5  christos 	int             ct = 0;
    874       1.5  christos 
    875       1.5  christos 	if (!u.uswallow) {
    876       1.5  christos 		if (Blind) {
    877       1.5  christos 			pline("You try to feel what is lying here on the floor.");
    878       1.5  christos 			if (Levitation) {	/* ab@unido */
    879       1.5  christos 				pline("You cannot reach the floor!");
    880       1.5  christos 				return (1);
    881       1.5  christos 			}
    882       1.5  christos 		}
    883       1.5  christos 		otmp0 = o_at(u.ux, u.uy);
    884       1.5  christos 		gold = g_at(u.ux, u.uy);
    885       1.5  christos 	}
    886       1.5  christos 	if (u.uswallow || (!otmp0 && !gold)) {
    887       1.5  christos 		pline("You %s no objects here.", verb);
    888       1.5  christos 		return (!!Blind);
    889       1.5  christos 	}
    890       1.5  christos 	cornline(0, "Things that are here:");
    891       1.5  christos 	for (otmp = otmp0; otmp; otmp = otmp->nobj) {
    892       1.5  christos 		if (otmp->ox == u.ux && otmp->oy == u.uy) {
    893       1.5  christos 			ct++;
    894       1.5  christos 			cornline(1, doname(otmp));
    895       1.5  christos 			if (Blind && otmp->otyp == DEAD_COCKATRICE && !uarmg) {
    896       1.5  christos 				pline("Touching the dead cockatrice is a fatal mistake ...");
    897       1.5  christos 				pline("You die ...");
    898       1.5  christos 				killer = "dead cockatrice";
    899       1.5  christos 				done("died");
    900       1.5  christos 			}
    901       1.5  christos 		}
    902       1.5  christos 	}
    903       1.5  christos 
    904       1.5  christos 	if (gold) {
    905       1.5  christos 		char            gbuf[30];
    906       1.1       cgd 
    907  1.10.4.1       snj 		(void) snprintf(gbuf, sizeof(gbuf), "%ld gold piece%s",
    908       1.5  christos 			       gold->amount, plur(gold->amount));
    909       1.5  christos 		if (!ct++)
    910       1.5  christos 			pline("You %s here %s.", verb, gbuf);
    911       1.5  christos 		else
    912       1.5  christos 			cornline(1, gbuf);
    913       1.5  christos 	}
    914       1.5  christos 	if (ct == 1 && !gold) {
    915       1.5  christos 		pline("You %s here %s.", verb, doname(otmp0));
    916       1.5  christos 		cornline(3, (char *) 0);
    917       1.5  christos 	}
    918       1.5  christos 	if (ct > 1)
    919       1.5  christos 		cornline(2, (char *) 0);
    920       1.5  christos 	return (!!Blind);
    921       1.5  christos }
    922       1.5  christos 
    923       1.5  christos void
    924       1.5  christos stackobj(obj)
    925       1.5  christos 	struct obj     *obj;
    926       1.5  christos {
    927       1.5  christos 	struct obj     *otmp = fobj;
    928       1.5  christos 	for (otmp = fobj; otmp; otmp = otmp->nobj)
    929       1.5  christos 		if (otmp != obj)
    930       1.5  christos 			if (otmp->ox == obj->ox && otmp->oy == obj->oy &&
    931       1.5  christos 			    merged(obj, otmp, 1))
    932       1.5  christos 				return;
    933       1.1       cgd }
    934       1.1       cgd 
    935       1.1       cgd /* merge obj with otmp and delete obj if types agree */
    936       1.5  christos int
    937       1.5  christos merged(otmp, obj, lose)
    938       1.5  christos 	struct obj     *otmp, *obj;
    939       1.7       jsm 	int lose;
    940       1.5  christos {
    941       1.5  christos 	if (obj->otyp == otmp->otyp &&
    942       1.5  christos 	    obj->unpaid == otmp->unpaid &&
    943       1.5  christos 	    obj->spe == otmp->spe &&
    944       1.5  christos 	    obj->dknown == otmp->dknown &&
    945       1.5  christos 	    obj->cursed == otmp->cursed &&
    946       1.5  christos 	    (strchr("%*?!", obj->olet) ||
    947       1.5  christos 	     (obj->known == otmp->known &&
    948       1.5  christos 	      (obj->olet == WEAPON_SYM && obj->otyp < BOOMERANG)))) {
    949       1.1       cgd 		otmp->quan += obj->quan;
    950       1.1       cgd 		otmp->owt += obj->owt;
    951       1.5  christos 		if (lose)
    952       1.5  christos 			freeobj(obj);
    953       1.5  christos 		obfree(obj, otmp);	/* free(obj), bill->otmp */
    954       1.5  christos 		return (1);
    955       1.5  christos 	} else
    956       1.5  christos 		return (0);
    957       1.1       cgd }
    958       1.1       cgd 
    959       1.5  christos static long goldcounted;
    960       1.1       cgd /*
    961       1.1       cgd  * Gold is no longer displayed; in fact, when you have a lot of money,
    962       1.1       cgd  * it may take a while before you have counted it all.
    963       1.1       cgd  * [Bug: d$ and pickup still tell you how much it was.]
    964       1.1       cgd  */
    965       1.5  christos int
    966       1.5  christos countgold()
    967       1.5  christos {
    968       1.5  christos 	if ((goldcounted += 100 * (u.ulevel + 1)) >= u.ugold) {
    969       1.5  christos 		long            eps = 0;
    970       1.5  christos 		if (!rn2(2))
    971       1.5  christos 			eps = rnd((int) (u.ugold / 100 + 1));
    972       1.1       cgd 		pline("You probably have about %ld gold pieces.",
    973       1.5  christos 		      u.ugold + eps);
    974       1.5  christos 		return (0);	/* done */
    975       1.1       cgd 	}
    976       1.5  christos 	return (1);		/* continue */
    977       1.1       cgd }
    978       1.1       cgd 
    979       1.5  christos int
    980       1.5  christos doprgold()
    981       1.5  christos {
    982       1.5  christos 	if (!u.ugold)
    983       1.1       cgd 		pline("You do not carry any gold.");
    984       1.5  christos 	else if (u.ugold <= 500)
    985       1.1       cgd 		pline("You are carrying %ld gold pieces.", u.ugold);
    986       1.1       cgd 	else {
    987       1.1       cgd 		pline("You sit down in order to count your gold pieces.");
    988       1.1       cgd 		goldcounted = 500;
    989       1.1       cgd 		occupation = countgold;
    990       1.1       cgd 		occtxt = "counting your gold";
    991       1.1       cgd 	}
    992       1.5  christos 	return (1);
    993       1.1       cgd }
    994       1.1       cgd 
    995       1.1       cgd /* --- end of gold counting section --- */
    996       1.5  christos int
    997       1.5  christos doprwep()
    998       1.5  christos {
    999       1.5  christos 	if (!uwep)
   1000       1.5  christos 		pline("You are empty handed.");
   1001       1.5  christos 	else
   1002       1.5  christos 		prinv(uwep);
   1003       1.5  christos 	return (0);
   1004       1.1       cgd }
   1005       1.1       cgd 
   1006       1.5  christos int
   1007       1.5  christos doprarm()
   1008       1.5  christos {
   1009       1.5  christos 	if (!uarm && !uarmg && !uarms && !uarmh)
   1010       1.1       cgd 		pline("You are not wearing any armor.");
   1011       1.1       cgd 	else {
   1012       1.5  christos 		char            lets[6];
   1013       1.5  christos 		int             ct = 0;
   1014       1.1       cgd 
   1015       1.5  christos 		if (uarm)
   1016       1.5  christos 			lets[ct++] = obj_to_let(uarm);
   1017       1.5  christos 		if (uarm2)
   1018       1.5  christos 			lets[ct++] = obj_to_let(uarm2);
   1019       1.5  christos 		if (uarmh)
   1020       1.5  christos 			lets[ct++] = obj_to_let(uarmh);
   1021       1.5  christos 		if (uarms)
   1022       1.5  christos 			lets[ct++] = obj_to_let(uarms);
   1023       1.5  christos 		if (uarmg)
   1024       1.5  christos 			lets[ct++] = obj_to_let(uarmg);
   1025       1.1       cgd 		lets[ct] = 0;
   1026       1.1       cgd 		doinv(lets);
   1027       1.1       cgd 	}
   1028       1.5  christos 	return (0);
   1029       1.1       cgd }
   1030       1.1       cgd 
   1031       1.5  christos int
   1032       1.5  christos doprring()
   1033       1.5  christos {
   1034       1.5  christos 	if (!uleft && !uright)
   1035       1.1       cgd 		pline("You are not wearing any rings.");
   1036       1.1       cgd 	else {
   1037       1.5  christos 		char            lets[3];
   1038       1.5  christos 		int             ct = 0;
   1039       1.1       cgd 
   1040       1.5  christos 		if (uleft)
   1041       1.5  christos 			lets[ct++] = obj_to_let(uleft);
   1042       1.5  christos 		if (uright)
   1043       1.5  christos 			lets[ct++] = obj_to_let(uright);
   1044       1.1       cgd 		lets[ct] = 0;
   1045       1.1       cgd 		doinv(lets);
   1046       1.1       cgd 	}
   1047       1.5  christos 	return (0);
   1048       1.1       cgd }
   1049       1.1       cgd 
   1050       1.5  christos int
   1051       1.5  christos digit(c)
   1052       1.5  christos 	char            c;
   1053       1.5  christos {
   1054       1.5  christos 	return (c >= '0' && c <= '9');
   1055       1.1       cgd }
   1056