games: Massive style(9) cleanup commit. Reduces differences to NetBSD.
[dragonfly.git] / games / hack / hack.invent.c
blobc16f2e84b143cd7b60415cfb1430591ecc77d480
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 /* $DragonFly: src/games/hack/hack.invent.c,v 1.5 2006/08/21 19:45:32 pavalos Exp $ */
6 #include "hack.h"
7 extern struct obj zeroobj;
8 extern char quitchars[];
10 static void assigninvlet(struct obj *);
11 static struct obj *mkgoldobj(long);
12 static bool ckunpaid(struct obj *);
13 static char obj_to_let(struct obj *);
14 static char *xprname(struct obj *, char);
15 static void doinv(char *);
16 static bool merged(struct obj *, struct obj *, bool);
17 static bool countgold(void);
19 #ifndef NOWORM
20 extern struct wseg *wsegs[32];
21 #endif /* NOWORM */
23 #define NOINVSYM '#'
25 static int lastinvnr = 51; /* 0 ... 51 */
27 static void
28 assigninvlet(struct obj *otmp)
30 boolean inuse[52];
31 int i;
32 struct obj *obj;
34 for (i = 0; i < 52; i++)
35 inuse[i] = FALSE;
36 for (obj = invent; obj; obj = obj->nobj)
37 if (obj != otmp) {
38 i = obj->invlet;
39 if ('a' <= i && i <= 'z')
40 inuse[i - 'a'] = TRUE;
41 else if ('A' <= i && i <= 'Z')
42 inuse[i - 'A' + 26] = TRUE;
43 if (i == otmp->invlet)
44 otmp->invlet = 0;
46 if ((i = otmp->invlet) &&
47 (('a' <= i && i <= 'z') || ('A' <= i && i <= 'Z')))
48 return;
49 for (i = lastinvnr + 1; i != lastinvnr; i++) {
50 if (i == 52) {
51 i = -1;
52 continue;
54 if (!inuse[i])
55 break;
57 otmp->invlet = (inuse[i] ? NOINVSYM :
58 (i < 26) ? ('a' + i) : ('A' + i - 26));
59 lastinvnr = i;
62 struct obj *
63 addinv(struct obj *obj)
65 struct obj *otmp;
67 /* merge or attach to end of chain */
68 if (!invent) {
69 invent = obj;
70 otmp = 0;
71 } else
72 for (otmp = invent; /* otmp */; otmp = otmp->nobj) {
73 if (merged(otmp, obj, 0))
74 return (otmp);
75 if (!otmp->nobj) {
76 otmp->nobj = obj;
77 break;
80 obj->nobj = 0;
82 if (flags.invlet_constant) {
83 assigninvlet(obj);
85 * The ordering of the chain is nowhere significant
86 * so in case you prefer some other order than the
87 * historical one, change the code below.
89 if (otmp) { /* find proper place in chain */
90 otmp->nobj = 0;
91 if ((invent->invlet ^ 040) > (obj->invlet ^ 040)) {
92 obj->nobj = invent;
93 invent = obj;
94 } else
95 for (otmp = invent;; otmp = otmp->nobj) {
96 if (!otmp->nobj ||
97 (otmp->nobj->invlet ^ 040) >
98 (obj->invlet ^ 040)) {
99 obj->nobj = otmp->nobj;
100 otmp->nobj = obj;
101 break;
107 return (obj);
110 void
111 useup(struct obj *obj)
113 if (obj->quan > 1) {
114 obj->quan--;
115 obj->owt = weight(obj);
116 } else {
117 setnotworn(obj);
118 freeinv(obj);
119 obfree(obj, NULL);
123 void
124 freeinv(struct obj *obj)
126 struct obj *otmp;
128 if (obj == invent)
129 invent = invent->nobj;
130 else {
131 for (otmp = invent; otmp->nobj != obj; otmp = otmp->nobj)
132 if (!otmp->nobj)
133 panic("freeinv");
134 otmp->nobj = obj->nobj;
138 /* destroy object in fobj chain (if unpaid, it remains on the bill) */
139 void
140 delobj(struct obj *obj)
142 freeobj(obj);
143 unpobj(obj);
144 obfree(obj, NULL);
147 /* unlink obj from chain starting with fobj */
148 void
149 freeobj(struct obj *obj)
151 struct obj *otmp;
153 if (obj == fobj)
154 fobj = fobj->nobj;
155 else {
156 for (otmp = fobj; otmp->nobj != obj; otmp = otmp->nobj)
157 if (!otmp)
158 panic("error in freeobj");
159 otmp->nobj = obj->nobj;
163 /* Note: freegold throws away its argument! */
164 void
165 freegold(struct gold *gold)
167 struct gold *gtmp;
169 if (gold == fgold)
170 fgold = gold->ngold;
171 else {
172 for (gtmp = fgold; gtmp->ngold != gold; gtmp = gtmp->ngold)
173 if (!gtmp)
174 panic("error in freegold");
175 gtmp->ngold = gold->ngold;
177 free(gold);
180 void
181 deltrap(struct trap *trap)
183 struct trap *ttmp;
185 if (trap == ftrap)
186 ftrap = ftrap->ntrap;
187 else {
188 for (ttmp = ftrap; ttmp->ntrap != trap; ttmp = ttmp->ntrap)
189 ; /* nothing */
190 ttmp->ntrap = trap->ntrap;
192 free(trap);
195 struct wseg *m_atseg;
197 struct monst *
198 m_at(int x, int y)
200 struct monst *mtmp;
201 #ifndef NOWORM
202 struct wseg *wtmp;
203 #endif /* NOWORM */
205 m_atseg = 0;
206 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
207 if (mtmp->mx == x && mtmp->my == y)
208 return (mtmp);
209 #ifndef NOWORM
210 if (mtmp->wormno) {
211 for (wtmp = wsegs[mtmp->wormno]; wtmp; wtmp = wtmp->nseg)
212 if (wtmp->wx == x && wtmp->wy == y) {
213 m_atseg = wtmp;
214 return (mtmp);
218 #endif /* NOWORM */
220 return (0);
223 struct obj *
224 o_at(int x, int y)
226 struct obj *otmp;
228 for (otmp = fobj; otmp; otmp = otmp->nobj)
229 if (otmp->ox == x && otmp->oy == y)
230 return (otmp);
231 return (0);
234 struct obj *
235 sobj_at(int n, int x, int y)
237 struct obj *otmp;
239 for (otmp = fobj; otmp; otmp = otmp->nobj)
240 if (otmp->ox == x && otmp->oy == y && otmp->otyp == n)
241 return (otmp);
242 return (0);
245 bool
246 carried(struct obj *obj)
248 struct obj *otmp;
250 for (otmp = invent; otmp; otmp = otmp->nobj)
251 if (otmp == obj)
252 return (1);
253 return (0);
256 bool
257 carrying(int type)
259 struct obj *otmp;
261 for (otmp = invent; otmp; otmp = otmp->nobj)
262 if (otmp->otyp == type)
263 return (TRUE);
264 return (FALSE);
267 struct obj *
268 o_on(unsigned int id, struct obj *objchn)
270 while (objchn) {
271 if (objchn->o_id == id)
272 return (objchn);
273 objchn = objchn->nobj;
275 return (NULL);
278 struct trap *
279 t_at(int x, int y)
281 struct trap *trap = ftrap;
283 while (trap) {
284 if (trap->tx == x && trap->ty == y)
285 return (trap);
286 trap = trap->ntrap;
288 return (0);
291 struct gold *
292 g_at(int x, int y)
294 struct gold *gold = fgold;
296 while (gold) {
297 if (gold->gx == x && gold->gy == y)
298 return (gold);
299 gold = gold->ngold;
301 return (0);
304 /* make dummy object structure containing gold - for temporary use only */
305 static struct obj *
306 mkgoldobj(long q)
308 struct obj *otmp;
310 otmp = newobj(0);
311 /* should set o_id etc. but otmp will be freed soon */
312 otmp->olet = '$';
313 u.ugold -= q;
314 OGOLD(otmp) = q;
315 flags.botl = 1;
316 return (otmp);
320 * getobj returns:
321 * struct obj *xxx: object to do something with.
322 * NULL error return: no object.
323 * &zeroobj explicitly no object (as in w-).
325 struct obj *
326 getobj(const char *let, const char *word)
328 struct obj *otmp;
329 char ilet, ilet1, ilet2;
330 char buf[BUFSZ];
331 char lets[BUFSZ];
332 int foo = 0, foo2;
333 char *bp = buf;
334 xchar allowcnt = 0; /* 0, 1 or 2 */
335 boolean allowgold = FALSE;
336 boolean allowall = FALSE;
337 boolean allownone = FALSE;
338 xchar foox = 0;
339 long cnt;
341 if (*let == '0')
342 let++, allowcnt = 1;
343 if (*let == '$')
344 let++, allowgold = TRUE;
345 if (*let == '#')
346 let++, allowall = TRUE;
347 if (*let == '-')
348 let++, allownone = TRUE;
349 if (allownone)
350 *bp++ = '-';
351 if (allowgold)
352 *bp++ = '$';
353 if (bp > buf && bp[-1] == '-')
354 *bp++ = ' ';
356 ilet = 'a';
357 for (otmp = invent; otmp; otmp = otmp->nobj) {
358 if (!*let || strchr(let, otmp->olet)) {
359 bp[foo++] = flags.invlet_constant ? otmp->invlet : ilet;
361 /* ugly check: remove inappropriate things */
362 if ((!strcmp(word, "take off") &&
363 !(otmp->owornmask & (W_ARMOR - W_ARM2)))
364 || (!strcmp(word, "wear") &&
365 (otmp->owornmask & (W_ARMOR | W_RING)))
366 || (!strcmp(word, "wield") &&
367 (otmp->owornmask & W_WEP))) {
368 foo--;
369 foox++;
372 if (ilet == 'z')
373 ilet = 'A';
374 else
375 ilet++;
377 bp[foo] = 0;
378 if (foo == 0 && bp > buf && bp[-1] == ' ')
379 *--bp = 0;
380 strcpy(lets, bp); /* necessary since we destroy buf */
381 if (foo > 5) { /* compactify string */
382 foo = foo2 = 1;
383 ilet2 = bp[0];
384 ilet1 = bp[1];
385 while ((ilet = bp[++foo2] = bp[++foo])) {
386 if (ilet == ilet1 + 1) {
387 if (ilet1 == ilet2 + 1)
388 bp[foo2 - 1] = ilet1 = '-';
389 else if (ilet2 == '-') {
390 bp[--foo2] = ++ilet1;
391 continue;
394 ilet2 = ilet1;
395 ilet1 = ilet;
398 if (!foo && !allowall && !allowgold && !allownone) {
399 pline("You don't have anything %sto %s.",
400 foox ? "else " : "", word);
401 return (0);
403 for (;;) {
404 if (!buf[0])
405 pline("What do you want to %s [*]? ", word);
406 else
407 pline("What do you want to %s [%s or ?*]? ",
408 word, buf);
410 cnt = 0;
411 ilet = readchar();
412 while (digit(ilet) && allowcnt) {
413 if (cnt < 100000000)
414 cnt = 10 * cnt + (ilet - '0');
415 else
416 cnt = 999999999;
417 allowcnt = 2; /* signal presence of cnt */
418 ilet = readchar();
420 if (digit(ilet)) {
421 pline("No count allowed with this command.");
422 continue;
424 if (strchr(quitchars, ilet))
425 return (NULL);
426 if (ilet == '-')
427 return (allownone ? &zeroobj : NULL);
428 if (ilet == '$') {
429 if (!allowgold) {
430 pline("You cannot %s gold.", word);
431 continue;
433 if (!(allowcnt == 2 && cnt < u.ugold))
434 cnt = u.ugold;
435 return (mkgoldobj(cnt));
437 if (ilet == '?') {
438 doinv(lets);
439 if (!(ilet = morc))
440 continue;
441 /* he typed a letter (not a space) to more() */
442 } else if (ilet == '*') {
443 doinv(NULL);
444 if (!(ilet = morc))
445 continue;
446 /* ... */
448 if (flags.invlet_constant) {
449 for (otmp = invent; otmp; otmp = otmp->nobj)
450 if (otmp->invlet == ilet)
451 break;
452 } else {
453 if (ilet >= 'A' && ilet <= 'Z')
454 ilet += 'z' - 'A' + 1;
455 ilet -= 'a';
456 for (otmp = invent; otmp && ilet;
457 ilet--, otmp = otmp->nobj)
458 ; /* nothing */
460 if (!otmp) {
461 pline("You don't have that object.");
462 continue;
464 if (cnt < 0 || otmp->quan < cnt) {
465 pline("You don't have that many! [You have %u]" ,
466 otmp->quan);
467 continue;
469 break;
471 if (!allowall && let && !strchr(let, otmp->olet)) {
472 pline("That is a silly thing to %s.", word);
473 return (0);
475 if (allowcnt == 2) { /* cnt given */
476 if (cnt == 0)
477 return (0);
478 if (cnt != otmp->quan) {
479 struct obj *obj;
480 obj = splitobj(otmp, (int)cnt);
481 if (otmp == uwep)
482 setuwep(obj);
485 return (otmp);
488 static bool
489 ckunpaid(struct obj *otmp)
491 return (otmp->unpaid);
494 /* interactive version of getobj - used for Drop and Identify */
495 /* return the number of times fn was called successfully */
497 ggetobj(const char *word, int (*fn)(struct obj *), int max)
499 char buf[BUFSZ];
500 char *ip;
501 char sym;
502 int oletct = 0, iletct = 0;
503 boolean allflag = FALSE;
504 char olets[20], ilets[20];
505 bool (*ckfn)(struct obj *) = (bool (*)()) 0;
506 xchar allowgold = (u.ugold && !strcmp(word, "drop")) ? 1 : 0; /* BAH */
508 if (!invent && !allowgold) {
509 pline("You have nothing to %s.", word);
510 return (0);
511 } else {
512 struct obj *otmp = invent;
513 int uflg = 0;
515 if (allowgold)
516 ilets[iletct++] = '$';
517 ilets[iletct] = 0;
518 while (otmp) {
519 if (!strchr(ilets, otmp->olet)) {
520 ilets[iletct++] = otmp->olet;
521 ilets[iletct] = 0;
523 if (otmp->unpaid)
524 uflg = 1;
525 otmp = otmp->nobj;
527 ilets[iletct++] = ' ';
528 if (uflg)
529 ilets[iletct++] = 'u';
530 if (invent)
531 ilets[iletct++] = 'a';
532 ilets[iletct] = 0;
534 pline("What kinds of thing do you want to %s? [%s] ",
535 word, ilets);
536 getlin(buf);
537 if (buf[0] == '\033') {
538 clrlin();
539 return (0);
541 ip = buf;
542 olets[0] = 0;
543 while ((sym = *ip++)) {
544 if (sym == ' ')
545 continue;
546 if (sym == '$') {
547 if (allowgold == 1)
548 (*fn)(mkgoldobj(u.ugold));
549 else if (!u.ugold)
550 pline("You have no gold.");
551 allowgold = 2;
552 } else if (sym == 'a' || sym == 'A')
553 allflag = TRUE;
554 else if (sym == 'u' || sym == 'U')
555 ckfn = ckunpaid;
556 else if (strchr("!%?[()=*/\"0", sym)) {
557 if (!strchr(olets, sym)) {
558 olets[oletct++] = sym;
559 olets[oletct] = 0;
561 } else
562 pline("You don't have any %c's.", sym);
564 if (allowgold == 2 && !oletct)
565 return (1); /* he dropped gold (or at least tried to) */
566 else
567 return (askchain(invent, olets, allflag, fn, ckfn, max));
571 * Walk through the chain starting at objchn and ask for all objects
572 * with olet in olets (if nonNULL) and satisfying ckfn (if nonNULL)
573 * whether the action in question (i.e., fn) has to be performed.
574 * If allflag then no questions are asked. Max gives the max nr of
575 * objects to be treated. Return the number of objects treated.
578 askchain(struct obj *objchn, char *olets, int allflag,
579 int (*fn)(struct obj *), bool (*ckfn)(struct obj *), int max)
581 struct obj *otmp, *otmp2;
582 char sym, ilet;
583 int cnt = 0;
585 ilet = 'a' - 1;
586 for (otmp = objchn; otmp; otmp = otmp2) {
587 if (ilet == 'z')
588 ilet = 'A';
589 else
590 ilet++;
591 otmp2 = otmp->nobj;
592 if (olets && *olets && !strchr(olets, otmp->olet))
593 continue;
594 if (ckfn && !(*ckfn)(otmp))
595 continue;
596 if (!allflag) {
597 pline(xprname(otmp, ilet));
598 addtopl(" [nyaq]? ");
599 sym = readchar();
600 } else
601 sym = 'y';
603 switch (sym) {
604 case 'a':
605 allflag = 1;
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;
617 pline(cnt ? "That was all." : "No applicable objects.");
618 ret:
619 return (cnt);
622 /* should of course only be called for things in invent */
623 static char
624 obj_to_let(struct obj *obj)
626 struct obj *otmp;
627 char ilet;
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);
638 void
639 prinv(struct obj *obj)
641 pline(xprname(obj, obj_to_let(obj)));
644 static char *
645 xprname(struct obj *obj, char let)
647 static char li[BUFSZ];
649 sprintf(li, "%c - %s.",
650 flags.invlet_constant ? obj->invlet : let,
651 doname(obj));
652 return (li);
656 ddoinv(void)
658 doinv(NULL);
659 return (0);
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)
667 struct obj *otmp;
668 char ilet;
669 int ct = 0;
670 char any[BUFSZ];
672 morc = 0; /* just to be sure */
673 if (!invent) {
674 pline("Not carrying anything.");
675 return;
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;
687 if (!flags.invlet_constant)
688 if (++ilet > 'z')
689 ilet = 'A';
691 any[ct] = 0;
692 cornline(2, any);
696 dotypeinv(void) /* free after Robert Viduya */
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;
706 if (!invent && !u.ugold && !billx) {
707 pline("You aren't carrying anything.");
708 return (0);
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;
720 if (otmp->unpaid)
721 unpd = TRUE;
723 if (unpd)
724 stuff[stct++] = 'u';
725 if (billx)
726 stuff[stct++] = 'x';
727 stuff[stct] = 0;
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];
738 if (c == '$')
739 return (doprgold());
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);
749 if ((c == 'u' || c == 'U') && !unpd) {
750 pline("You are not carrying any unpaid objects.");
751 return (0);
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';
765 stuff[stct] = '\0';
766 if (stct == 0)
767 pline("You have no such objects.");
768 else
769 doinv(stuff);
771 return (0);
774 /* look at what is here */
776 dolook(void)
778 struct obj *otmp, *otmp0 = NULL;
779 struct gold *gold = NULL;
780 const char *verb = Blind ? "feel" : "see";
781 int ct = 0;
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);
791 otmp0 = o_at(u.ux, u.uy);
792 gold = g_at(u.ux, u.uy);
795 if (u.uswallow || (!otmp0 && !gold)) {
796 pline("You %s no objects here.", verb);
797 return (!!Blind);
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");
814 if (gold) {
815 char gbuf[30];
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);
825 if (ct == 1 && !gold) {
826 pline("You %s here %s.", verb, doname(otmp0));
827 cornline(3, NULL);
829 if (ct > 1)
830 cornline(2, NULL);
831 return (!!Blind);
834 void
835 stackobj(struct obj *obj)
837 struct obj *otmp = fobj;
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;
846 /* merge obj with otmp and delete obj if types agree */
847 static bool
848 merged(struct obj *otmp, struct obj *obj, bool lose)
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);
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.]
873 static long goldcounted;
875 static bool
876 countgold(void)
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 */
886 return (1); /* continue */
890 doprgold(void)
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";
902 return (1);
905 /* --- end of gold counting section --- */
908 doprwep(void)
910 if (!uwep)
911 pline("You are empty handed.");
912 else
913 prinv(uwep);
914 return (0);
918 doprarm(void)
920 if (!uarm && !uarmg && !uarms && !uarmh)
921 pline("You are not wearing any armor.");
922 else {
923 char lets[6];
924 int ct = 0;
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);
939 return (0);
943 doprring(void)
945 if (!uleft && !uright)
946 pline("You are not wearing any rings.");
947 else {
948 char lets[3];
949 int ct = 0;
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);
958 return (0);
961 bool
962 digit(char c)
964 return (c >= '0' && c <= '9');