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