From 94837b78d4182c890b2b71320bf1ebef652913c3 Mon Sep 17 00:00:00 2001 From: cohrs Date: Tue, 21 May 2002 05:04:09 +0000 Subject: [PATCH] hangups with temp gold in inventory - Implement Michael's suggestion of marking temp gold put in inventory so it can be cleaned up during restore. --- doc/fixes34.1 | 1 + src/do.c | 2 ++ src/invent.c | 1 + src/pickup.c | 2 ++ src/restore.c | 11 ++++++ src/trap.c | 94 +++++++++++++++++++++++++-------------------------- 6 files changed, 64 insertions(+), 47 deletions(-) diff --git a/doc/fixes34.1 b/doc/fixes34.1 index fe15ecbf7..c41a31ded 100644 --- a/doc/fixes34.1 +++ b/doc/fixes34.1 @@ -109,6 +109,7 @@ when polymorphed, player killing a paper or straw golem via fire damage would kill the golem twice, resulting in an impossible error usually stop mimicing if you polymorph while using #monster mimic capability under !GOLDOBJ, gold shouldn't disappear if you try to throw it at yourself +under !GOLDOBJ, remove temp gold from inventory during restore Platform- and/or Interface-Specific Fixes diff --git a/src/do.c b/src/do.c index 63f4a1b90..cb14c4456 100644 --- a/src/do.c +++ b/src/do.c @@ -614,6 +614,7 @@ int retry; /* Hack: gold is not in the inventory, so make a gold object and put it at the head of the inventory list. */ u_gold = mkgoldobj(u.ugold); /* removes from u.ugold */ + u_gold->in_use = TRUE; u.ugold = u_gold->quan; /* put the gold back */ assigninvlet(u_gold); /* might end up as NOINVSYM */ u_gold->nobj = invent; @@ -686,6 +687,7 @@ int retry; /* didn't drop [all of] it */ u_gold = invent; invent = u_gold->nobj; + u_gold->in_use = FALSE; dealloc_obj(u_gold); update_inventory(); } diff --git a/src/invent.c b/src/invent.c index d4006c446..66d1c720b 100644 --- a/src/invent.c +++ b/src/invent.c @@ -480,6 +480,7 @@ struct obj *obj; if (obj->oclass == GOLD_CLASS) { #ifndef GOLDOBJ u.ugold -= obj->quan; + obj->in_use = FALSE; #endif flags.botl = 1; return; diff --git a/src/pickup.c b/src/pickup.c index 4d6c6b614..0dfa6fa7f 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -2084,6 +2084,7 @@ ask_again2: * and put it at the head of the inventory list. */ u_gold = mkgoldobj(u.ugold); /* removes from u.ugold */ + u_gold->in_use = TRUE; u.ugold = u_gold->quan; /* put the gold back */ assigninvlet(u_gold); /* might end up as NOINVSYM */ u_gold->nobj = invent; @@ -2118,6 +2119,7 @@ ask_again2: /* didn't stash [all of] it */ u_gold = invent; invent = u_gold->nobj; + u_gold->in_use = FALSE; dealloc_obj(u_gold); } #endif diff --git a/src/restore.c b/src/restore.c index 6c9edb31f..5522aa042 100644 --- a/src/restore.c +++ b/src/restore.c @@ -106,6 +106,17 @@ boolean quietly; for (otmp = invent; otmp; otmp = otmp2) { otmp2 = otmp->nobj; +#ifndef GOLDOBJ + if (otmp->oclass == GOLD_CLASS) { + /* in_use gold is created by some menu operations */ + if (!otmp->in_use) { + impossible("inven_inuse: !in_use gold in inventory"); + } + extract_nobj(otmp, &invent); + otmp->in_use = FALSE; + dealloc_obj(otmp); + } else +#endif /* GOLDOBJ */ if (otmp->in_use) { if (!quietly) pline("Finishing off %s...", xname(otmp)); useup(otmp); diff --git a/src/trap.c b/src/trap.c index 7ccbc1652..e7d229fb1 100644 --- a/src/trap.c +++ b/src/trap.c @@ -2494,64 +2494,64 @@ boolean *lostsome; { int invc = inv_cnt(); - while (near_capacity() > (Punished ? UNENCUMBERED : SLT_ENCUMBER)) { - register struct obj *obj, *otmp = (struct obj *)0; - register int i; + register struct obj *obj, *otmp = (struct obj *)0; + register int i; - /* Pick a random object */ - if (invc > 0) { - i = rn2(invc); + /* Pick a random object */ + if (invc > 0) { + i = rn2(invc); for (obj = invent; obj; obj = obj->nobj) { - /* - * Undroppables are: body armor, boots, gloves, - * amulets, and rings because of the time and effort - * in removing them + loadstone and other cursed stuff - * for obvious reasons. - */ - if (!((obj->otyp == LOADSTONE && obj->cursed) || - obj == uamul || obj == uleft || obj == uright || - obj == ublindf || obj == uarm || obj == uarmc || - obj == uarmg || obj == uarmf || + /* + * Undroppables are: body armor, boots, gloves, + * amulets, and rings because of the time and effort + * in removing them + loadstone and other cursed stuff + * for obvious reasons. + */ + if (!((obj->otyp == LOADSTONE && obj->cursed) || + obj == uamul || obj == uleft || obj == uright || + obj == ublindf || obj == uarm || obj == uarmc || + obj == uarmg || obj == uarmf || #ifdef TOURIST - obj == uarmu || + obj == uarmu || #endif - (obj->cursed && (obj == uarmh || obj == uarms)) || - welded(obj))) - otmp = obj; - /* reached the mark and found some stuff to drop? */ - if (--i < 0 && otmp) break; + (obj->cursed && (obj == uarmh || obj == uarms)) || + welded(obj))) + otmp = obj; + /* reached the mark and found some stuff to drop? */ + if (--i < 0 && otmp) break; - /* else continue */ - } + /* else continue */ } + } #ifndef GOLDOBJ - if (!otmp) { - /* Nothing available left to drop; try gold */ - if (u.ugold) { - pline("In desperation, you drop your purse."); - /* Hack: gold is not in the inventory, so make a gold object - * and put it at the head of the inventory list. - */ - obj = mkgoldobj(u.ugold); /* removes from u.ugold */ - u.ugold = obj->quan; /* put the gold back */ - assigninvlet(obj); /* might end up as NOINVSYM */ - obj->nobj = invent; - invent = obj; - *lostsome = TRUE; - dropx(obj); - continue; /* Try again */ - } - /* We can't even drop gold! */ - return (FALSE); + if (!otmp) { + /* Nothing available left to drop; try gold */ + if (u.ugold) { + pline("In desperation, you drop your purse."); + /* Hack: gold is not in the inventory, so make a gold object + * and put it at the head of the inventory list. + */ + obj = mkgoldobj(u.ugold); /* removes from u.ugold */ + obj->in_use = TRUE; + u.ugold = obj->quan; /* put the gold back */ + assigninvlet(obj); /* might end up as NOINVSYM */ + obj->nobj = invent; + invent = obj; + *lostsome = TRUE; + dropx(obj); + continue; /* Try again */ } + /* We can't even drop gold! */ + return (FALSE); + } #else - if (!otmp) return (FALSE); /* nothing to drop! */ + if (!otmp) return (FALSE); /* nothing to drop! */ #endif - if (otmp->owornmask) remove_worn_item(otmp, FALSE); - *lostsome = TRUE; - dropx(otmp); - invc--; + if (otmp->owornmask) remove_worn_item(otmp, FALSE); + *lostsome = TRUE; + dropx(otmp); + invc--; } return(TRUE); } -- 2.40.0