]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.invent.c
1 /* $NetBSD: hack.invent.c,v 1.6 1997/10/23 07:05:55 fair Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.invent.c,v 1.6 1997/10/23 07:05:55 fair Exp $");
22 static int lastinvnr
= 51; /* 0 ... 51 */
24 static void assigninvlet
__P((struct obj
*));
25 static char *xprname
__P((struct obj
*, char));
35 for (i
= 0; i
< 52; i
++)
37 for (obj
= invent
; obj
; obj
= obj
->nobj
)
40 if ('a' <= i
&& i
<= 'z')
41 inuse
[i
- 'a'] = TRUE
;
42 else if ('A' <= i
&& i
<= 'Z')
43 inuse
[i
- 'A' + 26] = TRUE
;
44 if (i
== otmp
->invlet
)
47 if ((i
= otmp
->invlet
) &&
48 (('a' <= i
&& i
<= 'z') || ('A' <= i
&& i
<= 'Z')))
50 for (i
= lastinvnr
+ 1; i
!= lastinvnr
; i
++) {
58 otmp
->invlet
= (inuse
[i
] ? NOINVSYM
:
59 (i
< 26) ? ('a' + i
) : ('A' + i
- 26));
69 /* merge or attach to end of chain */
74 for (otmp
= invent
; /* otmp */ ; otmp
= otmp
->nobj
) {
75 if (merged(otmp
, obj
, 0))
84 if (flags
.invlet_constant
) {
87 * The ordering of the chain is nowhere significant
88 * so in case you prefer some other order than the
89 * historical one, change the code below.
91 if (otmp
) { /* find proper place in chain */
93 if ((invent
->invlet
^ 040) > (obj
->invlet
^ 040)) {
97 for (otmp
= invent
;; otmp
= otmp
->nobj
) {
99 (otmp
->nobj
->invlet
^ 040) > (obj
->invlet
^ 040)) {
100 obj
->nobj
= otmp
->nobj
;
116 obj
->owt
= weight(obj
);
120 obfree(obj
, (struct obj
*) 0);
131 invent
= invent
->nobj
;
133 for (otmp
= invent
; otmp
->nobj
!= obj
; otmp
= otmp
->nobj
)
136 otmp
->nobj
= obj
->nobj
;
140 /* destroy object in fobj chain (if unpaid, it remains on the bill) */
147 obfree(obj
, (struct obj
*) 0);
150 /* unlink obj from chain starting with fobj */
160 for (otmp
= fobj
; otmp
->nobj
!= obj
; otmp
= otmp
->nobj
)
162 panic("error in freeobj");
163 otmp
->nobj
= obj
->nobj
;
167 /* Note: freegold throws away its argument! */
177 for (gtmp
= fgold
; gtmp
->ngold
!= gold
; gtmp
= gtmp
->ngold
)
179 panic("error in freegold");
180 gtmp
->ngold
= gold
->ngold
;
192 ftrap
= ftrap
->ntrap
;
194 for (ttmp
= ftrap
; ttmp
->ntrap
!= trap
; ttmp
= ttmp
->ntrap
);
195 ttmp
->ntrap
= trap
->ntrap
;
200 struct wseg
*m_atseg
;
212 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) {
213 if (mtmp
->mx
== x
&& mtmp
->my
== y
)
217 for (wtmp
= wsegs
[mtmp
->wormno
]; wtmp
; wtmp
= wtmp
->nseg
)
218 if (wtmp
->wx
== x
&& wtmp
->wy
== y
) {
234 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
235 if (otmp
->ox
== x
&& otmp
->oy
== y
)
246 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
247 if (otmp
->ox
== x
&& otmp
->oy
== y
&& otmp
->otyp
== n
)
257 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
269 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
270 if (otmp
->otyp
== type
)
281 if (objchn
->o_id
== id
)
283 objchn
= objchn
->nobj
;
285 return ((struct obj
*) 0);
292 struct trap
*trap
= ftrap
;
294 if (trap
->tx
== x
&& trap
->ty
== y
)
305 struct gold
*gold
= fgold
;
307 if (gold
->gx
== x
&& gold
->gy
== y
)
314 /* make dummy object structure containing gold - for temporary use only */
322 /* should set o_id etc. but otmp will be freed soon */
332 * struct obj *xxx: object to do something with.
333 * (struct obj *) 0 error return: no object.
334 * &zeroobj explicitly no object (as in w-).
341 char ilet
, ilet1
, ilet2
;
346 xchar allowcnt
= 0; /* 0, 1 or 2 */
347 boolean allowgold
= FALSE
;
348 boolean allowall
= FALSE
;
349 boolean allownone
= FALSE
;
356 let
++, allowgold
= TRUE
;
358 let
++, allowall
= TRUE
;
360 let
++, allownone
= TRUE
;
365 if (bp
> buf
&& bp
[-1] == '-')
369 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
) {
370 if (!*let
|| strchr(let
, otmp
->olet
)) {
371 bp
[foo
++] = flags
.invlet_constant
? otmp
->invlet
: ilet
;
373 /* ugly check: remove inappropriate things */
374 if ((!strcmp(word
, "take off") &&
375 !(otmp
->owornmask
& (W_ARMOR
- W_ARM2
)))
376 || (!strcmp(word
, "wear") &&
377 (otmp
->owornmask
& (W_ARMOR
| W_RING
)))
378 || (!strcmp(word
, "wield") &&
379 (otmp
->owornmask
& W_WEP
))) {
390 if (foo
== 0 && bp
> buf
&& bp
[-1] == ' ')
392 (void) strcpy(lets
, bp
);/* necessary since we destroy buf */
393 if (foo
> 5) { /* compactify string */
397 while ((ilet
= bp
[++foo2
] = bp
[++foo
]) != '\0') {
398 if (ilet
== ilet1
+ 1) {
399 if (ilet1
== ilet2
+ 1)
400 bp
[foo2
- 1] = ilet1
= '-';
401 else if (ilet2
== '-') {
402 bp
[--foo2
] = ++ilet1
;
410 if (!foo
&& !allowall
&& !allowgold
&& !allownone
) {
411 pline("You don't have anything %sto %s.",
412 foox
? "else " : "", word
);
417 pline("What do you want to %s [*]? ", word
);
419 pline("What do you want to %s [%s or ?*]? ",
424 while (digit(ilet
) && allowcnt
) {
426 cnt
= 10 * cnt
+ (ilet
- '0');
429 allowcnt
= 2; /* signal presence of cnt */
433 pline("No count allowed with this command.");
436 if (strchr(quitchars
, ilet
))
437 return ((struct obj
*) 0);
439 return (allownone
? &zeroobj
: (struct obj
*) 0);
443 pline("You cannot %s gold.", word
);
446 if (!(allowcnt
== 2 && cnt
< u
.ugold
))
448 return (mkgoldobj(cnt
));
454 /* he typed a letter (not a space) to more() */
455 } else if (ilet
== '*') {
461 if (flags
.invlet_constant
) {
462 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
463 if (otmp
->invlet
== ilet
)
466 if (ilet
>= 'A' && ilet
<= 'Z')
467 ilet
+= 'z' - 'A' + 1;
469 for (otmp
= invent
; otmp
&& ilet
;
470 ilet
--, otmp
= otmp
->nobj
);
473 pline("You don't have that object.");
476 if (cnt
< 0 || otmp
->quan
< cnt
) {
477 pline("You don't have that many! [You have %u]"
483 if (!allowall
&& let
&& !strchr(let
, otmp
->olet
)) {
484 pline("That is a silly thing to %s.", word
);
487 if (allowcnt
== 2) { /* cnt given */
490 if (cnt
!= otmp
->quan
) {
492 obj
= splitobj(otmp
, (int) cnt
);
504 return (otmp
->unpaid
);
507 /* interactive version of getobj - used for Drop and Identify */
508 /* return the number of times fn was called successfully */
510 ggetobj(word
, fn
, max
)
512 int (*fn
) __P((struct obj
*));
518 int oletct
= 0, iletct
= 0;
519 boolean allflag
= FALSE
;
520 char olets
[20], ilets
[20];
521 int (*ckfn
) __P((struct obj
*)) =
522 (int (*) __P((struct obj
*))) 0;
523 xchar allowgold
= (u
.ugold
&& !strcmp(word
, "drop")) ? 1 : 0; /* BAH */
524 if (!invent
&& !allowgold
) {
525 pline("You have nothing to %s.", word
);
528 struct obj
*otmp
= invent
;
532 ilets
[iletct
++] = '$';
535 if (!strchr(ilets
, otmp
->olet
)) {
536 ilets
[iletct
++] = otmp
->olet
;
543 ilets
[iletct
++] = ' ';
545 ilets
[iletct
++] = 'u';
547 ilets
[iletct
++] = 'a';
550 pline("What kinds of thing do you want to %s? [%s] ",
553 if (buf
[0] == '\033') {
559 while ((sym
= *ip
++) != '\0') {
564 (*fn
) (mkgoldobj(u
.ugold
));
566 pline("You have no gold.");
568 } else if (sym
== 'a' || sym
== 'A')
570 else if (sym
== 'u' || sym
== 'U')
572 else if (strchr("!%?[()=*/\"0", sym
)) {
573 if (!strchr(olets
, sym
)) {
574 olets
[oletct
++] = sym
;
578 pline("You don't have any %c's.", sym
);
580 if (allowgold
== 2 && !oletct
)
581 return (1); /* he dropped gold (or at least tried to) */
583 return (askchain(invent
, olets
, allflag
, fn
, ckfn
, max
));
587 * Walk through the chain starting at objchn and ask for all objects
588 * with olet in olets (if nonNULL) and satisfying ckfn (if nonNULL)
589 * whether the action in question (i.e., fn) has to be performed.
590 * If allflag then no questions are asked. Max gives the max nr of
591 * objects to be treated. Return the number of objects treated.
594 askchain(objchn
, olets
, allflag
, fn
, ckfn
, max
)
598 int (*fn
) __P((struct obj
*));
599 int (*ckfn
) __P((struct obj
*));
602 struct obj
*otmp
, *otmp2
;
606 for (otmp
= objchn
; otmp
; otmp
= otmp2
) {
612 if (olets
&& *olets
&& !strchr(olets
, otmp
->olet
))
614 if (ckfn
&& !(*ckfn
) (otmp
))
617 pline(xprname(otmp
, ilet
));
618 addtopl(" [nyaq]? ");
637 pline(cnt
? "That was all." : "No applicable objects.");
643 obj_to_let(obj
) /* should of course only be called for things
650 if (flags
.invlet_constant
)
651 return (obj
->invlet
);
653 for (otmp
= invent
; otmp
&& otmp
!= obj
; otmp
= otmp
->nobj
)
656 return (otmp
? ilet
: NOINVSYM
);
663 pline(xprname(obj
, obj_to_let(obj
)));
671 static char li
[BUFSZ
];
673 (void) sprintf(li
, "%c - %s.",
674 flags
.invlet_constant
? obj
->invlet
: let
,
686 /* called with 0 or "": all objects in inventory */
687 /* otherwise: all objects with (serial) letter in lets */
697 morc
= 0; /* just to be sure */
700 pline("Not carrying anything.");
703 cornline(0, (char *) 0);
705 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
) {
706 if (flags
.invlet_constant
)
708 if (!lets
|| !*lets
|| strchr(lets
, ilet
)) {
709 cornline(1, xprname(otmp
, ilet
));
712 if (!flags
.invlet_constant
)
722 { /* free after Robert Viduya */
723 /* Changed to one type only, so he doesnt have to type cr */
728 boolean billx
= inshop() && doinvbill(0);
729 boolean unpd
= FALSE
;
731 if (!invent
&& !u
.ugold
&& !billx
) {
732 pline("You aren't carrying anything.");
739 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
) {
740 if (!strchr(stuff
, otmp
->olet
)) {
741 stuff
[stct
++] = otmp
->olet
;
754 pline("What type of object [%s] do you want an inventory of? ",
757 if (strchr(quitchars
, c
))
765 if (c
== 'x' || c
== 'X') {
769 pline("No used-up objects on the shopping bill.");
772 if ((c
== 'u' || c
== 'U') && !unpd
) {
773 pline("You are not carrying any unpaid objects.");
778 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
) {
779 if (flags
.invlet_constant
)
781 if (c
== otmp
->olet
|| (c
== 'u' && otmp
->unpaid
))
782 stuff
[stct
++] = ilet
;
783 if (!flags
.invlet_constant
)
789 pline("You have no such objects.");
796 /* look at what is here */
800 struct obj
*otmp
= NULL
, *otmp0
= NULL
;
801 struct gold
*gold
= NULL
;
802 char *verb
= Blind
? "feel" : "see";
807 pline("You try to feel what is lying here on the floor.");
808 if (Levitation
) { /* ab@unido */
809 pline("You cannot reach the floor!");
813 otmp0
= o_at(u
.ux
, u
.uy
);
814 gold
= g_at(u
.ux
, u
.uy
);
816 if (u
.uswallow
|| (!otmp0
&& !gold
)) {
817 pline("You %s no objects here.", verb
);
820 cornline(0, "Things that are here:");
821 for (otmp
= otmp0
; otmp
; otmp
= otmp
->nobj
) {
822 if (otmp
->ox
== u
.ux
&& otmp
->oy
== u
.uy
) {
824 cornline(1, doname(otmp
));
825 if (Blind
&& otmp
->otyp
== DEAD_COCKATRICE
&& !uarmg
) {
826 pline("Touching the dead cockatrice is a fatal mistake ...");
827 pline("You die ...");
828 killer
= "dead cockatrice";
837 (void) sprintf(gbuf
, "%ld gold piece%s",
838 gold
->amount
, plur(gold
->amount
));
840 pline("You %s here %s.", verb
, gbuf
);
844 if (ct
== 1 && !gold
) {
845 pline("You %s here %s.", verb
, doname(otmp0
));
846 cornline(3, (char *) 0);
849 cornline(2, (char *) 0);
857 struct obj
*otmp
= fobj
;
858 for (otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
860 if (otmp
->ox
== obj
->ox
&& otmp
->oy
== obj
->oy
&&
861 merged(obj
, otmp
, 1))
865 /* merge obj with otmp and delete obj if types agree */
867 merged(otmp
, obj
, lose
)
868 struct obj
*otmp
, *obj
;
870 if (obj
->otyp
== otmp
->otyp
&&
871 obj
->unpaid
== otmp
->unpaid
&&
872 obj
->spe
== otmp
->spe
&&
873 obj
->dknown
== otmp
->dknown
&&
874 obj
->cursed
== otmp
->cursed
&&
875 (strchr("%*?!", obj
->olet
) ||
876 (obj
->known
== otmp
->known
&&
877 (obj
->olet
== WEAPON_SYM
&& obj
->otyp
< BOOMERANG
)))) {
878 otmp
->quan
+= obj
->quan
;
879 otmp
->owt
+= obj
->owt
;
882 obfree(obj
, otmp
); /* free(obj), bill->otmp */
888 static long goldcounted
;
890 * Gold is no longer displayed; in fact, when you have a lot of money,
891 * it may take a while before you have counted it all.
892 * [Bug: d$ and pickup still tell you how much it was.]
897 if ((goldcounted
+= 100 * (u
.ulevel
+ 1)) >= u
.ugold
) {
900 eps
= rnd((int) (u
.ugold
/ 100 + 1));
901 pline("You probably have about %ld gold pieces.",
903 return (0); /* done */
905 return (1); /* continue */
912 pline("You do not carry any gold.");
913 else if (u
.ugold
<= 500)
914 pline("You are carrying %ld gold pieces.", u
.ugold
);
916 pline("You sit down in order to count your gold pieces.");
918 occupation
= countgold
;
919 occtxt
= "counting your gold";
924 /* --- end of gold counting section --- */
929 pline("You are empty handed.");
938 if (!uarm
&& !uarmg
&& !uarms
&& !uarmh
)
939 pline("You are not wearing any armor.");
945 lets
[ct
++] = obj_to_let(uarm
);
947 lets
[ct
++] = obj_to_let(uarm2
);
949 lets
[ct
++] = obj_to_let(uarmh
);
951 lets
[ct
++] = obj_to_let(uarms
);
953 lets
[ct
++] = obj_to_let(uarmg
);
963 if (!uleft
&& !uright
)
964 pline("You are not wearing any rings.");
970 lets
[ct
++] = obj_to_let(uleft
);
972 lets
[ct
++] = obj_to_let(uright
);
983 return (c
>= '0' && c
<= '9');