-/* SCCS Id: @(#)extern.h 3.5 2006/07/08 */
+/* SCCS Id: @(#)extern.h 3.5 2007/01/05 */
/* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */
E boolean NDECL(wearing_armor);
E boolean FDECL(is_worn, (struct obj *));
E struct obj *FDECL(g_at, (int,int));
+#ifndef GOLDOBJ
E struct obj *FDECL(mkgoldobj, (long));
+E struct obj *NDECL(insert_gold_into_invent);
+E void NDECL(remove_gold_from_invent);
+#endif
E struct obj *FDECL(getobj, (const char *,const char *));
E int FDECL(ggetobj, (const char *,int (*)(OBJ_P),int,BOOLEAN_P,unsigned *));
E void FDECL(fully_identify_obj, (struct obj *));
boolean drop_everything = FALSE;
#ifndef GOLDOBJ
- if (u.ugold) {
- /* 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;
- invent = u_gold;
- u_gold->where = OBJ_INVENT;
- }
+ /* put gold where inventory traversal will see it */
+ if (u.ugold) u_gold = insert_gold_into_invent();
#endif
if (retry) {
all_categories = (retry == -2);
drop_done:
#ifndef GOLDOBJ
- if (u_gold && invent && invent->oclass == COIN_CLASS) {
- /* didn't drop [all of] it */
- u_gold = invent;
- invent = u_gold->nobj;
- u_gold->in_use = FALSE;
- u_gold->where = OBJ_FREE;
- dealloc_obj(u_gold);
- update_inventory();
- }
+ /* if we put gold into inventory above, take it back out now */
+ if (u_gold) remove_gold_from_invent();
#endif
return n_dropped;
}
context.botl = 1;
return(otmp);
}
+
+/* used for container apply/#loot and multi-item Drop */
+struct obj *
+insert_gold_into_invent()
+{
+ struct obj *u_gold = 0;
+
+ if (u.ugold) {
+ u_gold = mkgoldobj(u.ugold);
+ u_gold->in_use = 1;
+ u.ugold = u_gold->quan; /* put the gold back on status line */
+ assigninvlet(u_gold); /* should yield '$' */
+ u_gold->where = OBJ_INVENT;
+ u_gold->nobj = invent;
+ invent = u_gold;
+ }
+ return u_gold;
+}
+
+/* undo insert_gold_into_invent; gold might have been used up though */
+void
+remove_gold_from_invent()
+{
+ struct obj *u_gold = invent; /* we expect gold to be first */
+
+ if (u_gold && u_gold->otyp == GOLD_PIECE) {
+ invent = u_gold->nobj;
+ u_gold->where = OBJ_FREE;
+ dealloc_obj(u_gold);
+#if 0
+ } else if ((u_gold = carrying(GOLD_PIECE)) != 0) {
+ u.ugold += u_gold->quan; /* freeinv will subtract it back out */
+ freeinv(u_gold);
+ dealloc_obj(u_gold);
#endif
+ }
+}
+#endif /* !GOLDOBJ */
STATIC_OVL void
compactify(buf)
#ifndef GOLDOBJ
if(*let == COIN_CLASS) let++,
usegold = TRUE, allowgold = (u.ugold ? TRUE : FALSE);
- if (firstobj && firstobj->oclass == COIN_CLASS) {
- /* gold has been inserted into inventory; skip it during
- inventory letter collection */
- u_gold = firstobj;
- firstobj = u_gold->nobj;
- allowgold = usegold;
- }
#else
if(*let == COIN_CLASS) let++, usegold = TRUE;
#endif
if(allownone) *bp++ = '-';
#ifndef GOLDOBJ
- if(allowgold) *bp++ = def_oc_syms[COIN_CLASS].sym;
+ if(allowgold) {
+ *bp++ = def_oc_syms[COIN_CLASS].sym;
+ if (firstobj && firstobj->otyp == GOLD_PIECE) {
+ /* gold has been inserted into inventory; skip it during
+ inventory letter collection */
+ u_gold = firstobj;
+ firstobj = u_gold->nobj;
+ }
+ }
#endif
if(bp > buf && bp[-1] == '-') *bp++ = ' ';
ap = altlets;
}
#ifndef GOLDOBJ
- if ((loot_in ||stash_one) && u.ugold) {
- /*
- * 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;
- invent = u_gold;
- u_gold->where = OBJ_INVENT;
- }
+ /* if putting in, place gold where inventory traversal will see it */
+ if ((loot_in || stash_one) && u.ugold)
+ u_gold = insert_gold_into_invent();
#endif
if ((loot_in || stash_one) &&
(!invent || (invent == current_container && !invent->nobj))) {
if (!current_container) loot_out = FALSE;
#ifndef GOLDOBJ
- if (u_gold && invent && invent->oclass == COIN_CLASS) {
- /* didn't stash [all of] it */
- u_gold = invent;
- invent = u_gold->nobj;
- u_gold->in_use = FALSE;
- u_gold->where = OBJ_FREE;
- dealloc_obj(u_gold);
- }
+ /* if we put gold into inventory above, take it back out now */
+ if (u_gold) remove_gold_from_invent();
#endif
/* out after in */
}
containerdone:
- /* Not completely correct; if we put something in without knowing
- whatever was already inside, now we suddenly do. That can't be
- helped unless we want to track things item by item and then deal
- with containers whose contents are "partly known". */
- if (used && current_container) current_container->cknown = 1;
+ if (used) {
+ /* Not completely correct; if we put something in without knowing
+ whatever was already inside, now we suddenly do. That can't
+ be helped unless we want to track things item by item and then
+ deal with containers whose contents are "partly known". */
+ if (current_container) current_container->cknown = 1;
+ update_inventory();
+ }
*objp = current_container; /* might have become null */
current_container = 0; /* avoid hanging on to stale pointer */