]> granicus.if.org Git - nethack/commitdiff
!GOLDOBJ gold in inventory (trunk only)
authornethack.rankin <nethack.rankin>
Sat, 6 Jan 2007 04:53:56 +0000 (04:53 +0000)
committernethack.rankin <nethack.rankin>
Sat, 6 Jan 2007 04:53:56 +0000 (04:53 +0000)
     Simplify the insertion into and removal from of gold in inventory for
the !GOLDOBJ configuration.  If GOLDOBJ ever becomes unconditional this
will be superfluous, but in the mean time it unclutters the container and
drop code.  Also, tweak a recent getobj() hack so that its purpose might
be a bit clearer.

include/extern.h
src/do.c
src/invent.c
src/pickup.c

index 3c8a8ec408098dabad9d9ef244af1c12fe4f8029..f9749eeaa456827e01b53b703ae5d45ea2e32f02 100644 (file)
@@ -1,4 +1,4 @@
-/*     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. */
 
@@ -878,7 +878,11 @@ E boolean FDECL(obj_here, (struct obj *,int,int));
 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 *));
index ee75ca29f47fa25cefca7bccd32d2a8255af5d62..83800be53c536ecc01f8b4295e6fa8ff24748381 100644 (file)
--- a/src/do.c
+++ b/src/do.c
@@ -648,17 +648,8 @@ int retry;
     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);
@@ -728,15 +719,8 @@ int retry;
 
  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;
 }
index 5d32f5df9cc9a3eaba9c4b4f2828b268f7a7a822..9218b9495b5de893a2b0c469f6581fd538109f75 100644 (file)
@@ -694,7 +694,44 @@ register long q;
        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)
@@ -799,13 +836,6 @@ register const char *let,*word;
 #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
@@ -837,7 +867,15 @@ register const char *let,*word;
 
        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;
index 1f7387a094d5511a3249f3087b8f586dfd03c3c0..4de12e82706a413f8fbf72678c2cced1fac7075b 100644 (file)
@@ -2258,19 +2258,9 @@ int held;
        }
 
 #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))) {
@@ -2308,14 +2298,8 @@ int held;
        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 */
@@ -2334,11 +2318,14 @@ int held;
        }
 
  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 */