📄 hack.invent.c
字号:
if(otmp == uwep) setuwep(obj); } } return(otmp);}ckunpaid(otmp) register struct obj *otmp; { return( otmp->unpaid );}/* interactive version of getobj - used for Drop and Identify *//* return the number of times fn was called successfully */ggetobj(word, fn, max)char *word;int (*fn)(), max;{char buf[BUFSZ];register char *ip;register char sym;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); return(0); } else { register struct obj *otmp = invent; register int uflg = 0; if(allowgold) ilets[iletct++] = '$'; ilets[iletct] = 0; while(otmp) { if(!index(ilets, otmp->olet)){ ilets[iletct++] = otmp->olet; ilets[iletct] = 0; } if(otmp->unpaid) uflg = 1; otmp = otmp->nobj; } ilets[iletct++] = ' '; if(uflg) ilets[iletct++] = 'u'; if(invent) ilets[iletct++] = 'a'; ilets[iletct] = 0; } pline("What kinds of thing do you want to %s? [%s] ", word, ilets); getlin(buf); if(buf[0] == '\033') { clrlin(); return(0); } ip = buf; olets[0] = 0; while(sym = *ip++){ if(sym == ' ') continue; if(sym == '$') { if(allowgold == 1) (*fn)(mkgoldobj(u.ugold)); else if(!u.ugold) pline("You have no gold."); allowgold = 2; } else if(sym == 'a' || sym == 'A') allflag = TRUE; else if(sym == 'u' || sym == 'U') ckfn = ckunpaid; else if(index("!%?[()=*/\"0", sym)){ if(!index(olets, sym)){ olets[oletct++] = sym; olets[oletct] = 0; } } else pline("You don't have any %c's.", sym); } if(allowgold == 2 && !oletct) return(1); /* he dropped gold (or at least tried to) */ else 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)struct obj *objchn;register char *olets;int allflag;int (*fn)(), (*ckfn)();int max;{register struct obj *otmp, *otmp2;register char sym, ilet;register int cnt = 0; ilet = 'a'-1; for(otmp = objchn; otmp; otmp = otmp2){ if(ilet == 'z') ilet = 'A'; else ilet++; otmp2 = otmp->nobj; if(olets && *olets && !index(olets, otmp->olet)) continue; if(ckfn && !(*ckfn)(otmp)) continue; if(!allflag) { pline(xprname(otmp, ilet)); addtopl(" [nyaq]? "); sym = readchar(); } else sym = 'y'; switch(sym){ case 'a': allflag = 1; case 'y': cnt += (*fn)(otmp); if(--max == 0) goto ret; case 'n': default: break; case 'q': goto ret; } } pline(cnt ? "That was all." : "No applicable objects.");ret: return(cnt);}obj_to_let(obj) /* should of course only be called for things in invent */register struct obj *obj;{ register struct obj *otmp; register char ilet; if(flags.invlet_constant) return(obj->invlet); ilet = 'a'; for(otmp = invent; otmp && otmp != obj; otmp = otmp->nobj) if(++ilet > 'z') ilet = 'A'; return(otmp ? ilet : NOINVSYM);}prinv(obj)register struct obj *obj;{ pline(xprname(obj, obj_to_let(obj)));}static char *xprname(obj,let)register struct obj *obj;register char let;{ static char li[BUFSZ]; (void) sprintf(li, "%c - %s.", flags.invlet_constant ? obj->invlet : let, doname(obj)); return(li);}ddoinv(){ doinv((char *) 0); return(0);}/* called with 0 or "": all objects in inventory *//* otherwise: all objects with (serial) letter in lets */doinv(lets)register char *lets;{ register struct obj *otmp; register char ilet; int ct = 0; char any[BUFSZ]; morc = 0; /* just to be sure */ if(!invent){ pline("Not carrying anything."); return; } cornline(0, (char *) 0); ilet = 'a'; 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)); any[ct++] = ilet; } if(!flags.invlet_constant) if(++ilet > 'z') ilet = 'A'; } any[ct] = 0; cornline(2, any);}dotypeinv () /* free after Robert Viduya *//* Changed to one type only, so he doesnt have to type cr */{ char c, ilet; char stuff[BUFSZ]; register int stct; register struct obj *otmp; boolean billx = inshop() && doinvbill(0); boolean unpd = FALSE; if (!invent && !u.ugold && !billx) { pline ("You aren't carrying anything."); return(0); } stct = 0; if(u.ugold) stuff[stct++] = '$'; stuff[stct] = 0; for(otmp = invent; otmp; otmp = otmp->nobj) { if (!index (stuff, otmp->olet)) { stuff[stct++] = otmp->olet; stuff[stct] = 0; } if(otmp->unpaid) unpd = TRUE; } if(unpd) stuff[stct++] = 'u'; if(billx) stuff[stct++] = 'x'; stuff[stct] = 0; if(stct > 1) { pline ("What type of object [%s] do you want an inventory of? ", stuff); c = readchar(); if(index(quitchars,c)) return(0); } else c = stuff[0]; if(c == '$') return(doprgold()); if(c == 'x' || c == 'X') { if(billx) (void) doinvbill(1); else pline("No used-up objects on the shopping bill."); return(0); } if((c == 'u' || c == 'U') && !unpd) { pline("You are not carrying any unpaid objects."); return(0); } stct = 0; ilet = 'a'; for (otmp = invent; otmp; otmp = otmp -> nobj) { if(flags.invlet_constant) ilet = otmp->invlet; if (c == otmp -> olet || (c == 'u' && otmp -> unpaid)) stuff[stct++] = ilet; if(!flags.invlet_constant) if(++ilet > 'z') ilet = 'A'; } stuff[stct] = '\0'; if(stct == 0) pline("You have no such objects."); else doinv (stuff); return(0);}/* look at what is here */dolook() { register struct obj *otmp, *otmp0; register struct gold *gold; char *verb = Blind ? "feel" : "see"; int ct = 0; if(!u.uswallow) { if(Blind) { pline("You try to feel what is lying here on the floor."); if(Levitation) { /* ab@unido */ pline("You cannot reach the floor!"); return(1); } } otmp0 = o_at(u.ux, u.uy); gold = g_at(u.ux, u.uy); } if(u.uswallow || (!otmp0 && !gold)) { pline("You %s no objects here.", verb); return(!!Blind); } cornline(0, "Things that are here:"); for(otmp = otmp0; otmp; otmp = otmp->nobj) { if(otmp->ox == u.ux && otmp->oy == u.uy) { ct++; cornline(1, doname(otmp)); if(Blind && otmp->otyp == DEAD_COCKATRICE && !uarmg) { pline("Touching the dead cockatrice is a fatal mistake ..."); pline("You die ..."); killer = "dead cockatrice"; done("died"); } } } if(gold) { char gbuf[30]; (void) sprintf(gbuf, "%ld gold piece%s", gold->amount, plur(gold->amount)); if(!ct++) pline("You %s here %s.", verb, gbuf); else cornline(1, gbuf); } if(ct == 1 && !gold) { pline("You %s here %s.", verb, doname(otmp0)); cornline(3, (char *) 0); } if(ct > 1) cornline(2, (char *) 0); return(!!Blind);}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 && merged(obj,otmp,1)) return;}/* 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->spe == otmp->spe && obj->dknown == otmp->dknown && obj->cursed == otmp->cursed && (index("%*?!", obj->olet) || (obj->known == otmp->known && (obj->olet == WEAPON_SYM && obj->otyp < BOOMERANG)))) { otmp->quan += obj->quan; otmp->owt += obj->owt; if(lose) freeobj(obj); obfree(obj,otmp); /* free(obj), bill->otmp */ return(1); } else return(0);}/* * 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)();extern char *occtxt;static long goldcounted;countgold(){ if((goldcounted += 100*(u.ulevel + 1)) >= u.ugold) { long eps = 0; if(!rn2(2)) eps = rnd((int) (u.ugold/100 + 1)); pline("You probably have about %ld gold pieces.", u.ugold + eps); return(0); /* done */ } return(1); /* continue */}doprgold(){ if(!u.ugold) pline("You do not carry any gold."); else if(u.ugold <= 500) pline("You are carrying %ld gold pieces.", u.ugold); else { pline("You sit down in order to count your gold pieces."); goldcounted = 500; occupation = countgold; occtxt = "counting your gold"; } return(1);}/* --- end of gold counting section --- */doprwep(){ if(!uwep) pline("You are empty handed."); else prinv(uwep); return(0);}doprarm(){ if(!uarm && !uarmg && !uarms && !uarmh) pline("You are not wearing any armor."); else { char lets[6]; register int ct = 0; 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); lets[ct] = 0; doinv(lets); } return(0);}doprring(){ if(!uleft && !uright) pline("You are not wearing any rings."); else { char lets[3]; register int ct = 0; if(uleft) lets[ct++] = obj_to_let(uleft); if(uright) lets[ct++] = obj_to_let(uright); lets[ct] = 0; doinv(lets); } return(0);}digit(c) char c; { return(c >= '0' && c <= '9');}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -