/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* hack.invent.c - version 1.0.3 */
extern struct obj
*splitobj();
extern struct obj zeroobj
;
extern struct wseg
*wsegs
[32];
static int lastinvnr
= 51; /* 0 ... 51 */
register struct obj
*otmp
;
register struct obj
*obj
;
for(i
= 0; i
< 52; i
++) inuse
[i
] = FALSE
;
for(obj
= invent
; obj
; obj
= obj
->nobj
) if(obj
!= otmp
) {
if('a' <= i
&& i
<= 'z') inuse
[i
- 'a'] = TRUE
; else
if('A' <= i
&& i
<= 'Z') inuse
[i
- 'A' + 26] = TRUE
;
if(i
== otmp
->invlet
) otmp
->invlet
= 0;
(('a' <= i
&& i
<= 'z') || ('A' <= i
&& i
<= 'Z')))
for(i
= lastinvnr
+1; i
!= lastinvnr
; i
++) {
if(i
== 52) { i
= -1; continue; }
otmp
->invlet
= (inuse
[i
] ? NOINVSYM
:
(i
< 26) ? ('a'+i
) : ('A'+i
-26));
register struct obj
*obj
;
register struct obj
*otmp
;
/* merge or attach to end of chain */
for(otmp
= invent
; /* otmp */; otmp
= otmp
->nobj
) {
if(flags
.invlet_constant
) {
* The ordering of the chain is nowhere significant
* so in case you prefer some other order than the
* historical one, change the code below.
if(otmp
) { /* find proper place in chain */
if((invent
->invlet
^ 040) > (obj
->invlet
^ 040)) {
for(otmp
= invent
; ; otmp
= otmp
->nobj
) {
(otmp
->nobj
->invlet
^ 040) > (obj
->invlet
^ 040)){
register struct obj
*obj
;
obfree(obj
, (struct obj
*) 0);
register struct obj
*obj
;
register struct obj
*otmp
;
for(otmp
= invent
; otmp
->nobj
!= obj
; otmp
= otmp
->nobj
)
if(!otmp
->nobj
) panic("freeinv");
/* destroy object in fobj chain (if unpaid, it remains on the bill) */
delobj(obj
) register struct obj
*obj
; {
obfree(obj
, (struct obj
*) 0);
/* unlink obj from chain starting with fobj */
freeobj(obj
) register struct obj
*obj
; {
register struct obj
*otmp
;
if(obj
== fobj
) fobj
= fobj
->nobj
;
for(otmp
= fobj
; otmp
->nobj
!= obj
; otmp
= otmp
->nobj
)
if(!otmp
) panic("error in freeobj");
/* Note: freegold throws away its argument! */
freegold(gold
) register struct gold
*gold
; {
register struct gold
*gtmp
;
if(gold
== fgold
) fgold
= gold
->ngold
;
for(gtmp
= fgold
; gtmp
->ngold
!= gold
; gtmp
= gtmp
->ngold
)
if(!gtmp
) panic("error in freegold");
gtmp
->ngold
= gold
->ngold
;
register struct trap
*trap
;
register struct trap
*ttmp
;
for(ttmp
= ftrap
; ttmp
->ntrap
!= trap
; ttmp
= ttmp
->ntrap
) ;
ttmp
->ntrap
= trap
->ntrap
;
register struct monst
*mtmp
;
register struct wseg
*wtmp
;
for(mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
){
if(mtmp
->mx
== x
&& mtmp
->my
== y
)
for(wtmp
= wsegs
[mtmp
->wormno
]; wtmp
; wtmp
= wtmp
->nseg
)
if(wtmp
->wx
== x
&& wtmp
->wy
== y
){
register struct obj
*otmp
;
for(otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
if(otmp
->ox
== x
&& otmp
->oy
== y
) return(otmp
);
register struct obj
*otmp
;
for(otmp
= fobj
; otmp
; otmp
= otmp
->nobj
)
if(otmp
->ox
== x
&& otmp
->oy
== y
&& otmp
->otyp
== n
)
carried(obj
) register struct obj
*obj
; {
register struct obj
*otmp
;
for(otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
if(otmp
== obj
) return(1);
register struct obj
*otmp
;
for(otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
o_on(id
, objchn
) unsigned int id
; register struct obj
*objchn
; {
if(objchn
->o_id
== id
) return(objchn
);
return((struct obj
*) 0);
register struct trap
*trap
= ftrap
;
if(trap
->tx
== x
&& trap
->ty
== y
) return(trap
);
register struct gold
*gold
= fgold
;
if(gold
->gx
== x
&& gold
->gy
== y
) return(gold
);
/* make dummy object structure containing gold - for temporary use only */
register struct obj
*otmp
;
/* should set o_id etc. but otmp will be freed soon */
* struct obj *xxx: object to do something with.
* (struct obj *) 0 error return: no object.
* &zeroobj explicitly no object (as in w-).
register char *let
,*word
;
register struct obj
*otmp
;
register char ilet
,ilet1
,ilet2
;
register int foo
= 0, foo2
;
xchar allowcnt
= 0; /* 0, 1 or 2 */
boolean allowgold
= FALSE
;
boolean allowall
= FALSE
;
boolean allownone
= FALSE
;
if(*let
== '0') let
++, allowcnt
= 1;
if(*let
== '$') let
++, allowgold
= TRUE
;
if(*let
== '#') let
++, allowall
= TRUE
;
if(*let
== '-') let
++, allownone
= TRUE
;
if(allownone
) *bp
++ = '-';
if(allowgold
) *bp
++ = '$';
if(bp
> buf
&& bp
[-1] == '-') *bp
++ = ' ';
for(otmp
= invent
; otmp
; otmp
= otmp
->nobj
){
if(!*let
|| index(let
, otmp
->olet
)) {
bp
[foo
++] = flags
.invlet_constant
? otmp
->invlet
: ilet
;
/* ugly check: remove inappropriate things */
if((!strcmp(word
, "take off") &&
!(otmp
->owornmask
& (W_ARMOR
- W_ARM2
)))
|| (!strcmp(word
, "wear") &&
(otmp
->owornmask
& (W_ARMOR
| W_RING
)))
|| (!strcmp(word
, "wield") &&
(otmp
->owornmask
& W_WEP
))) {
if(ilet
== 'z') ilet
= 'A'; else ilet
++;
if(foo
== 0 && bp
> buf
&& bp
[-1] == ' ') *--bp
= 0;
(void) strcpy(lets
, bp
); /* necessary since we destroy buf */
if(foo
> 5) { /* compactify string */
while(ilet
= bp
[++foo2
] = bp
[++foo
]){
bp
[foo2
- 1] = ilet1
= '-';
if(!foo
&& !allowall
&& !allowgold
&& !allownone
) {
pline("You don't have anything %sto %s.",
foox
? "else " : "", word
);
pline("What do you want to %s [*]? ", word
);
pline("What do you want to %s [%s or ?*]? ",
while(digit(ilet
) && allowcnt
) {
cnt
= 10*cnt
+ (ilet
- '0');
allowcnt
= 2; /* signal presence of cnt */
pline("No count allowed with this command.");
if(index(quitchars
,ilet
))
return(allownone
? &zeroobj
: (struct obj
*) 0);
pline("You cannot %s gold.", word
);
if(!(allowcnt
== 2 && cnt
< u
.ugold
))
if(!(ilet
= morc
)) continue;
/* he typed a letter (not a space) to more() */
if(!(ilet
= morc
)) continue;
if(flags
.invlet_constant
) {
for(otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
if(otmp
->invlet
== ilet
) break;
if(ilet
>= 'A' && ilet
<= 'Z') ilet
+= 'z'-'A'+1;
for(otmp
= invent
; otmp
&& ilet
;
ilet
--, otmp
= otmp
->nobj
) ;
pline("You don't have that object.");
if(cnt
< 0 || otmp
->quan
< cnt
) {
pline("You don't have that many! [You have %u]"
if(!allowall
&& let
&& !index(let
,otmp
->olet
)) {
pline("That is a silly thing to %s.",word
);
if(allowcnt
== 2) { /* cnt given */
register struct obj
*obj
;
obj
= splitobj(otmp
, (int) cnt
);
if(otmp
== uwep
) setuwep(obj
);
ckunpaid(otmp
) register struct obj
*otmp
; {
/* interactive version of getobj - used for Drop and Identify */
/* return the number of times fn was called successfully */
register int oletct
= 0, iletct
= 0;
register boolean allflag
= FALSE
;
char olets
[20], ilets
[20];
int (*ckfn
)() = (int (*)()) 0;
xchar allowgold
= (u
.ugold
&& !strcmp(word
, "drop")) ? 1 : 0; /* BAH */
if(!invent
&& !allowgold
){
pline("You have nothing to %s.", word
);
register struct obj
*otmp
= invent
;
if(allowgold
) ilets
[iletct
++] = '$';
if(!index(ilets
, otmp
->olet
)){
ilets
[iletct
++] = otmp
->olet
;
if(otmp
->unpaid
) uflg
= 1;
if(uflg
) ilets
[iletct
++] = 'u';
if(invent
) ilets
[iletct
++] = 'a';
pline("What kinds of thing do you want to %s? [%s] ",
(*fn
)(mkgoldobj(u
.ugold
));
pline("You have no gold.");
if(sym
== 'a' || sym
== 'A') allflag
= TRUE
; else
if(sym
== 'u' || sym
== 'U') ckfn
= ckunpaid
; else
if(index("!%?[()=*/\"0", sym
)){
else pline("You don't have any %c's.", sym
);
if(allowgold
== 2 && !oletct
)
return(1); /* he dropped gold (or at least tried to) */
return(askchain(invent
, olets
, allflag
, fn
, ckfn
, max
));
* Walk through the chain starting at objchn and ask for all objects
* with olet in olets (if nonNULL) and satisfying ckfn (if nonNULL)
* whether the action in question (i.e., fn) has to be performed.
* If allflag then no questions are asked. Max gives the max nr of
* objects to be treated. Return the number of objects treated.
askchain(objchn
, olets
, allflag
, fn
, ckfn
, max
)
register struct obj
*otmp
, *otmp2
;
for(otmp
= objchn
; otmp
; otmp
= otmp2
){
if(ilet
== 'z') ilet
= 'A'; else ilet
++;
if(olets
&& *olets
&& !index(olets
, otmp
->olet
)) continue;
if(ckfn
&& !(*ckfn
)(otmp
)) continue;
pline(xprname(otmp
, ilet
));
pline(cnt
? "That was all." : "No applicable objects.");
obj_to_let(obj
) /* should of course only be called for things in invent */
register struct obj
*obj
;
register struct obj
*otmp
;
if(flags
.invlet_constant
)
for(otmp
= invent
; otmp
&& otmp
!= obj
; otmp
= otmp
->nobj
)
if(++ilet
> 'z') ilet
= 'A';
return(otmp
? ilet
: NOINVSYM
);
register struct obj
*obj
;
pline(xprname(obj
, obj_to_let(obj
)));
register struct obj
*obj
;
(void) sprintf(li
, "%c - %s.",
flags
.invlet_constant
? obj
->invlet
: let
,
/* called with 0 or "": all objects in inventory */
/* otherwise: all objects with (serial) letter in lets */
register struct obj
*otmp
;
morc
= 0; /* just to be sure */
pline("Not carrying anything.");
for(otmp
= invent
; otmp
; otmp
= otmp
->nobj
) {
if(flags
.invlet_constant
) ilet
= otmp
->invlet
;
if(!lets
|| !*lets
|| index(lets
, ilet
)) {
cornline(1, xprname(otmp
, ilet
));
if(!flags
.invlet_constant
) if(++ilet
> 'z') ilet
= 'A';
dotypeinv () /* free after Robert Viduya */
/* Changed to one type only, so he doesnt have to type cr */
register struct obj
*otmp
;
boolean billx
= inshop() && doinvbill(0);
if (!invent
&& !u
.ugold
&& !billx
) {
pline ("You aren't carrying anything.");
if(u
.ugold
) stuff
[stct
++] = '$';
for(otmp
= invent
; otmp
; otmp
= otmp
->nobj
) {
if (!index (stuff
, otmp
->olet
)) {
stuff
[stct
++] = otmp
->olet
;
if(unpd
) stuff
[stct
++] = 'u';
if(billx
) stuff
[stct
++] = 'x';
pline ("What type of object [%s] do you want an inventory of? ",
if(index(quitchars
,c
)) return(0);
if(c
== 'x' || c
== 'X') {
pline("No used-up objects on the shopping bill.");
if((c
== 'u' || c
== 'U') && !unpd
) {
pline("You are not carrying any unpaid objects.");
for (otmp
= invent
; otmp
; otmp
= otmp
-> nobj
) {
if(flags
.invlet_constant
) ilet
= otmp
->invlet
;
if (c
== otmp
-> olet
|| (c
== 'u' && otmp
-> unpaid
))
if(!flags
.invlet_constant
) if(++ilet
> 'z') ilet
= 'A';
pline("You have no such objects.");
/* look at what is here */
register struct obj
*otmp
, *otmp0
;
register struct gold
*gold
;
char *verb
= Blind
? "feel" : "see";
pline("You try to feel what is lying here on the floor.");
if(Levitation
) { /* ab@unido */
pline("You cannot reach the floor!");
otmp0
= o_at(u
.ux
, u
.uy
);
if(u
.uswallow
|| (!otmp0
&& !gold
)) {
pline("You %s no objects here.", verb
);
cornline(0, "Things that are here:");
for(otmp
= otmp0
; otmp
; otmp
= otmp
->nobj
) {
if(otmp
->ox
== u
.ux
&& otmp
->oy
== u
.uy
) {
cornline(1, doname(otmp
));
if(Blind
&& otmp
->otyp
== DEAD_COCKATRICE
&& !uarmg
) {
pline("Touching the dead cockatrice is a fatal mistake ...");
killer
= "dead cockatrice";
(void) sprintf(gbuf
, "%ld gold piece%s",
gold
->amount
, plur(gold
->amount
));
pline("You %s here %s.", verb
, gbuf
);
pline("You %s here %s.", verb
, doname(otmp0
));
stackobj(obj
) register struct obj
*obj
; {
register struct obj
*otmp
= fobj
;
for(otmp
= fobj
; otmp
; otmp
= otmp
->nobj
) if(otmp
!= obj
)
if(otmp
->ox
== obj
->ox
&& otmp
->oy
== obj
->oy
&&
/* merge obj with otmp and delete obj if types agree */
merged(otmp
,obj
,lose
) register struct obj
*otmp
, *obj
; {
if(obj
->otyp
== otmp
->otyp
&&
obj
->unpaid
== otmp
->unpaid
&&
obj
->dknown
== otmp
->dknown
&&
obj
->cursed
== otmp
->cursed
&&
(index("%*?!", obj
->olet
) ||
(obj
->known
== otmp
->known
&&
(obj
->olet
== WEAPON_SYM
&& obj
->otyp
< BOOMERANG
)))) {
obfree(obj
,otmp
); /* free(obj), bill->otmp */
* Gold is no longer displayed; in fact, when you have a lot of money,
* it may take a while before you have counted it all.
* [Bug: d$ and pickup still tell you how much it was.]
extern int (*occupation
)();
if((goldcounted
+= 100*(u
.ulevel
+ 1)) >= u
.ugold
) {
if(!rn2(2)) eps
= rnd((int) (u
.ugold
/100 + 1));
pline("You probably have about %ld gold pieces.",
return(1); /* continue */
pline("You do not carry any gold.");
pline("You are carrying %ld gold pieces.", u
.ugold
);
pline("You sit down in order to count your gold pieces.");
occtxt
= "counting your gold";
/* --- end of gold counting section --- */
if(!uwep
) pline("You are empty handed.");
if(!uarm
&& !uarmg
&& !uarms
&& !uarmh
)
pline("You are not wearing any armor.");
if(uarm
) lets
[ct
++] = obj_to_let(uarm
);
if(uarm2
) lets
[ct
++] = obj_to_let(uarm2
);
if(uarmh
) lets
[ct
++] = obj_to_let(uarmh
);
if(uarms
) lets
[ct
++] = obj_to_let(uarms
);
if(uarmg
) lets
[ct
++] = obj_to_let(uarmg
);
pline("You are not wearing any rings.");
if(uleft
) lets
[ct
++] = obj_to_let(uleft
);
if(uright
) lets
[ct
++] = obj_to_let(uright
);
return(c
>= '0' && c
<= '9');