From: nethack.rankin Date: Thu, 3 Apr 2003 09:28:28 +0000 (+0000) Subject: container groundwork X-Git-Tag: MOVE2GIT~2040 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ee9c9f8b352d8d46912c56b7132e453c94ee70e;p=nethack container groundwork Move a couple of instances of container contents manipulation into their own routines. Behavior for items disappearing from cursed bags of holding isn't quite identical but is effectively the same. I think its use of stolen_value (or simply the behavior of the latter) is buggy, but I haven't tried to fix that. (Cursed bag of holding destroying a player owned bag containing shopped owned items definitely doesn't work well.) --- diff --git a/include/extern.h b/include/extern.h index 8fef9bfa5..cfc172a67 100644 --- a/include/extern.h +++ b/include/extern.h @@ -933,6 +933,7 @@ E void FDECL(mimic_hit_msg, (struct monst *, SHORT_P)); #ifdef GOLDOBJ E void FDECL(mkmonmoney, (struct monst *, long)); #endif +E void FDECL(bagotricks, (struct obj *)); /* ### mapglyph.c ### */ diff --git a/src/apply.c b/src/apply.c index 1219da2e1..3b6b45bee 100644 --- a/src/apply.c +++ b/src/apply.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)apply.c 3.4 2003/02/13 */ +/* SCCS Id: @(#)apply.c 3.4 2003/03/29 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2780,18 +2780,7 @@ doapply() res = use_container(obj, 1); break; case BAG_OF_TRICKS: - if(obj->spe > 0) { - register int cnt = 1; - - check_unpaid(obj); - obj->spe--; - if(!rn2(23)) cnt += rn2(7) + 1; - while(cnt--) - (void) makemon((struct permonst *) 0, - u.ux, u.uy, NO_MM_FLAGS); - makeknown(BAG_OF_TRICKS); - } else - pline(nothing_happens); + bagotricks(obj); break; case CAN_OF_GREASE: use_grease(obj); diff --git a/src/makemon.c b/src/makemon.c index c2e197d49..48e70bc52 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)makemon.c 3.4 2002/02/07 */ +/* SCCS Id: @(#)makemon.c 3.4 2003/03/29 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1719,6 +1719,30 @@ assign_sym: mtmp->mappearance = appear; } +/* release a monster from a bag of tricks */ +void +bagotricks(bag) +struct obj *bag; +{ + if (!bag || bag->otyp != BAG_OF_TRICKS) { + impossible("bad bag o' tricks"); + } else if (bag->spe < 1) { + pline(nothing_happens); + } else { + boolean gotone = FALSE; + int cnt = 1; + + check_unpaid(bag); + bag->spe--; + if (!rn2(23)) cnt += rn1(7, 1); + while (cnt-- > 0) { + if (makemon((struct permonst *)0, u.ux, u.uy, NO_MM_FLAGS)) + gotone = TRUE; + } + if (gotone) makeknown(BAG_OF_TRICKS); + } +} + #endif /* OVLB */ /*makemon.c*/ diff --git a/src/pickup.c b/src/pickup.c index d76fd0404..5bf55a7a7 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)pickup.c 3.4 2003/03/23 */ +/* SCCS Id: @(#)pickup.c 3.4 2003/04/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -31,6 +31,7 @@ STATIC_DCL boolean FDECL(mbag_explodes, (struct obj *,int)); STATIC_PTR int FDECL(in_container,(struct obj *)); STATIC_PTR int FDECL(ck_bag,(struct obj *)); STATIC_PTR int FDECL(out_container,(struct obj *)); +STATIC_DCL long FDECL(mbag_item_gone, (int,struct obj *)); STATIC_DCL int FDECL(menu_loot, (int, struct obj *, BOOLEAN_P)); STATIC_DCL int FDECL(in_or_out_menu, (const char *,struct obj *, BOOLEAN_P, BOOLEAN_P)); STATIC_DCL int FDECL(container_at, (int, int, BOOLEAN_P)); @@ -1903,6 +1904,29 @@ register struct obj *obj; return 1; } +/* an object inside a cursed bag of holding is being destroyed */ +STATIC_OVL long +mbag_item_gone(held, item) +int held; +struct obj *item; +{ + struct monst *shkp; + long loss = 0L; + + if (item->dknown) + pline("%s %s vanished!", Doname2(item), otense(item, "have")); + else + You("%s %s disappear!", Blind ? "notice" : "see", doname(item)); + + if (*u.ushops && (shkp = shop_keeper(*u.ushops)) != 0) { + if (held ? (boolean) item->unpaid : costly_spot(u.ux, u.uy)) + loss = stolen_value(item, u.ux, u.uy, + (boolean)shkp->mpeaceful, TRUE); + } + obfree(item, (struct obj *) 0); + return loss; +} + #undef Icebox int @@ -1919,7 +1943,7 @@ register int held; char select[MAXOCLASSES+1]; char qbuf[BUFSZ], emptymsg[BUFSZ], pbuf[QBUFSZ]; long loss = 0L; - int cnt = 0, used = 0, lcnt = 0, + int cnt = 0, used = 0, menu_on_request; emptymsg[0] = '\0'; @@ -1985,39 +2009,20 @@ register int held; for (curr = obj->cobj; curr; curr = otmp) { otmp = curr->nobj; if (Is_mbag(obj) && obj->cursed && !rn2(13)) { - if (curr->dknown) - pline("%s to have vanished!", The(aobjnam(curr,"seem"))); - else - You("%s %s disappear.", Blind ? "notice" : "see", - doname(curr)); obj_extract_self(curr); - if (*u.ushops && (shkp = shop_keeper(*u.ushops)) != 0) { - if(held) { - if(curr->unpaid) - loss += stolen_value(curr, u.ux, u.uy, - (boolean)shkp->mpeaceful, TRUE); - lcnt++; - } else if(costly_spot(u.ux, u.uy)) { - loss += stolen_value(curr, u.ux, u.uy, - (boolean)shkp->mpeaceful, TRUE); - lcnt++; - } - } - /* obfree() will free all contained objects */ - obfree(curr, (struct obj *) 0); + loss += mbag_item_gone(held, curr); used = 1; } else { cnt++; } } - if (lcnt && loss) - You("owe %ld %s for lost item%s.", - loss, currency(loss), lcnt > 1 ? "s" : ""); - + if (loss) + You("owe %ld %s for lost merchandise.", loss, currency(loss)); obj->owt = weight(obj); - if (!cnt) Sprintf(emptymsg, "%s %s empty.", Yname2(obj), otense(obj, "are")); + if (!cnt) + Sprintf(emptymsg, "%s is empty.", Yname2(obj)); if (cnt || flags.menu_style == MENU_FULL) { Sprintf(qbuf, "Do you want to take %s out of %s?", something, yname(obj));