!GOLDOBJ gold in inventory (trunk only)

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.
This commit is contained in:
nethack.rankin
2007-01-06 04:53:56 +00:00
parent 15122d269c
commit 21caf64b86
4 changed files with 68 additions and 55 deletions
+5 -1
View 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. */ /* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */ /* 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 NDECL(wearing_armor);
E boolean FDECL(is_worn, (struct obj *)); E boolean FDECL(is_worn, (struct obj *));
E struct obj *FDECL(g_at, (int,int)); E struct obj *FDECL(g_at, (int,int));
#ifndef GOLDOBJ
E struct obj *FDECL(mkgoldobj, (long)); 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 struct obj *FDECL(getobj, (const char *,const char *));
E int FDECL(ggetobj, (const char *,int (*)(OBJ_P),int,BOOLEAN_P,unsigned *)); E int FDECL(ggetobj, (const char *,int (*)(OBJ_P),int,BOOLEAN_P,unsigned *));
E void FDECL(fully_identify_obj, (struct obj *)); E void FDECL(fully_identify_obj, (struct obj *));
+4 -20
View File
@@ -648,17 +648,8 @@ int retry;
boolean drop_everything = FALSE; boolean drop_everything = FALSE;
#ifndef GOLDOBJ #ifndef GOLDOBJ
if (u.ugold) { /* put gold where inventory traversal will see it */
/* Hack: gold is not in the inventory, so make a gold object if (u.ugold) u_gold = insert_gold_into_invent();
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;
}
#endif #endif
if (retry) { if (retry) {
all_categories = (retry == -2); all_categories = (retry == -2);
@@ -728,15 +719,8 @@ int retry;
drop_done: drop_done:
#ifndef GOLDOBJ #ifndef GOLDOBJ
if (u_gold && invent && invent->oclass == COIN_CLASS) { /* if we put gold into inventory above, take it back out now */
/* didn't drop [all of] it */ if (u_gold) remove_gold_from_invent();
u_gold = invent;
invent = u_gold->nobj;
u_gold->in_use = FALSE;
u_gold->where = OBJ_FREE;
dealloc_obj(u_gold);
update_inventory();
}
#endif #endif
return n_dropped; return n_dropped;
} }
+46 -8
View File
@@ -694,7 +694,44 @@ register long q;
context.botl = 1; context.botl = 1;
return(otmp); 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
}
}
#endif /* !GOLDOBJ */
STATIC_OVL void STATIC_OVL void
compactify(buf) compactify(buf)
@@ -799,13 +836,6 @@ register const char *let,*word;
#ifndef GOLDOBJ #ifndef GOLDOBJ
if(*let == COIN_CLASS) let++, if(*let == COIN_CLASS) let++,
usegold = TRUE, allowgold = (u.ugold ? TRUE : FALSE); 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 #else
if(*let == COIN_CLASS) let++, usegold = TRUE; if(*let == COIN_CLASS) let++, usegold = TRUE;
#endif #endif
@@ -837,7 +867,15 @@ register const char *let,*word;
if(allownone) *bp++ = '-'; if(allownone) *bp++ = '-';
#ifndef GOLDOBJ #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 #endif
if(bp > buf && bp[-1] == '-') *bp++ = ' '; if(bp > buf && bp[-1] == '-') *bp++ = ' ';
ap = altlets; ap = altlets;
+13 -26
View File
@@ -2258,19 +2258,9 @@ int held;
} }
#ifndef GOLDOBJ #ifndef GOLDOBJ
if ((loot_in ||stash_one) && u.ugold) { /* if putting in, place gold where inventory traversal will see it */
/* if ((loot_in || stash_one) && u.ugold)
* Hack: gold is not in the inventory, so make a gold object u_gold = insert_gold_into_invent();
* 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;
}
#endif #endif
if ((loot_in || stash_one) && if ((loot_in || stash_one) &&
(!invent || (invent == current_container && !invent->nobj))) { (!invent || (invent == current_container && !invent->nobj))) {
@@ -2308,14 +2298,8 @@ int held;
if (!current_container) loot_out = FALSE; if (!current_container) loot_out = FALSE;
#ifndef GOLDOBJ #ifndef GOLDOBJ
if (u_gold && invent && invent->oclass == COIN_CLASS) { /* if we put gold into inventory above, take it back out now */
/* didn't stash [all of] it */ if (u_gold) remove_gold_from_invent();
u_gold = invent;
invent = u_gold->nobj;
u_gold->in_use = FALSE;
u_gold->where = OBJ_FREE;
dealloc_obj(u_gold);
}
#endif #endif
/* out after in */ /* out after in */
@@ -2334,11 +2318,14 @@ int held;
} }
containerdone: containerdone:
/* Not completely correct; if we put something in without knowing if (used) {
whatever was already inside, now we suddenly do. That can't be /* Not completely correct; if we put something in without knowing
helped unless we want to track things item by item and then deal whatever was already inside, now we suddenly do. That can't
with containers whose contents are "partly known". */ be helped unless we want to track things item by item and then
if (used && current_container) current_container->cknown = 1; deal with containers whose contents are "partly known". */
if (current_container) current_container->cknown = 1;
update_inventory();
}
*objp = current_container; /* might have become null */ *objp = current_container; /* might have become null */
current_container = 0; /* avoid hanging on to stale pointer */ current_container = 0; /* avoid hanging on to stale pointer */