From b6778e36cfdb1f02f2d638d321c56b63047625ac Mon Sep 17 00:00:00 2001 From: "nethack.rankin" Date: Fri, 12 Jan 2007 04:18:40 +0000 Subject: [PATCH] !GOLDOBJ gold in inventory during save/restore (trunk only) Simplify the save/restore handling the !GOLDOBJ config does for gold to maintain save/bones file compatibility with the GOLDOBJ config. --- include/extern.h | 8 +++---- src/do.c | 2 +- src/invent.c | 21 +++++++++--------- src/pickup.c | 2 +- src/restore.c | 57 +++++++++++++++++++----------------------------- src/save.c | 29 ++++++++---------------- 6 files changed, 48 insertions(+), 71 deletions(-) diff --git a/include/extern.h b/include/extern.h index 48b816863..6ceeba1d7 100644 --- a/include/extern.h +++ b/include/extern.h @@ -880,7 +880,7 @@ 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 struct obj *FDECL(insert_gold_into_invent, (BOOLEAN_P)); E void NDECL(remove_gold_from_invent); #endif E struct obj *FDECL(getobj, (const char *,const char *)); @@ -1870,13 +1870,13 @@ E int FDECL(restore_menu, (winid)); E void NDECL(minit); E boolean FDECL(lookup_id_mapping, (unsigned, unsigned *)); E void FDECL(mread, (int,genericptr_t,unsigned int)); -#ifndef GOLDOBJ -E void FDECL(put_gold_back, (struct obj **,long *)); -#endif E int FDECL(validate, (int,const char *)); E void NDECL(reset_restpref); E void FDECL(set_restpref, (const char *)); E void FDECL(set_savepref, (const char *)); +#ifndef GOLDOBJ +E void FDECL(put_gold_back, (struct monst *)); +#endif /* ### rip.c ### */ diff --git a/src/do.c b/src/do.c index 83800be53..8adbfd5cc 100644 --- a/src/do.c +++ b/src/do.c @@ -649,7 +649,7 @@ int retry; #ifndef GOLDOBJ /* put gold where inventory traversal will see it */ - if (u.ugold) u_gold = insert_gold_into_invent(); + if (u.ugold) u_gold = insert_gold_into_invent(TRUE); #endif if (retry) { all_categories = (retry == -2); diff --git a/src/invent.c b/src/invent.c index af2bb101c..e2eb553b6 100644 --- a/src/invent.c +++ b/src/invent.c @@ -697,14 +697,17 @@ register long q; /* used for container apply/#loot and multi-item Drop */ struct obj * -insert_gold_into_invent() +insert_gold_into_invent(keep_on_status_line) +boolean keep_on_status_line; { 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 */ + if (keep_on_status_line) { + u_gold->in_use = 1; /* in case of panic/hangup save */ + u.ugold = u_gold->quan; /* put back on status line */ + } /* else mkgoldobj() left status $:0 */ assigninvlet(u_gold); /* should yield '$' */ u_gold->where = OBJ_INVENT; u_gold->nobj = invent; @@ -719,15 +722,13 @@ 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) { + if (u_gold && u_gold->otyp != GOLD_PIECE) + u_gold = carrying(GOLD_PIECE); + + if (u_gold) { extract_nobj(u_gold, &invent); + if (!u_gold->in_use) u.ugold += u_gold->quan; dealloc_obj(u_gold); -#endif } } #endif /* !GOLDOBJ */ diff --git a/src/pickup.c b/src/pickup.c index 4de12e827..4f795500c 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -2260,7 +2260,7 @@ int held; #ifndef GOLDOBJ /* if putting in, place gold where inventory traversal will see it */ if ((loot_in || stash_one) && u.ugold) - u_gold = insert_gold_into_invent(); + u_gold = insert_gold_into_invent(TRUE); #endif if ((loot_in || stash_one) && (!invent || (invent == current_container && !invent->nobj))) { diff --git a/src/restore.c b/src/restore.c index 607aafdb8..e5ec5e2bd 100644 --- a/src/restore.c +++ b/src/restore.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)restore.c 3.5 2006/12/11 */ +/* SCCS Id: @(#)restore.c 3.5 2007/01/11 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -39,9 +39,6 @@ STATIC_DCL void FDECL(restlevelstate, (unsigned int, unsigned int)); STATIC_DCL int FDECL(restlevelfile, (int,XCHAR_P)); STATIC_OVL void FDECL(restore_msghistory, (int)); STATIC_DCL void FDECL(reset_oattached_mids, (BOOLEAN_P)); -#ifndef GOLDOBJ -STATIC_DCL struct obj *FDECL(gold_in, (struct obj *)); -#endif STATIC_DCL void FDECL(rest_levl, (int,BOOLEAN_P)); static struct restore_procs { @@ -443,8 +440,8 @@ boolean ghostly; /* restore monster back pointer */ for (obj = mtmp->minvent; obj; obj = obj->nobj) obj->ocarry = mtmp; -#ifndef GOLDOBJ - put_gold_back(&mtmp->minvent, &mtmp->mgold); +#ifndef GOLDOBJ /* GOLDOBJ-compatibility */ + put_gold_back(mtmp); #endif } if (mtmp->mw) { @@ -571,8 +568,8 @@ unsigned int *stuckid, *steedid; /* STEED */ restore_timers(fd, RANGE_GLOBAL, FALSE, 0L); restore_light_sources(fd); invent = restobjchn(fd, FALSE, FALSE); -#ifndef GOLDOBJ - put_gold_back(&invent, &u.ugold); +#ifndef GOLDOBJ /* GOLDOBJ-compatibility */ + put_gold_back(&youmonst); #endif /* tmp_bc only gets set here if the ball & chain were orphaned because you were swallowed; otherwise they will be on the floor @@ -1534,38 +1531,28 @@ register unsigned int len; } } -#ifndef GOLDOBJ -/* - * Takes all of the gold objects out of the invent or - * mtmp->minvent chain and puts it into either - * u.ugold or mtmp->mgold. - */ +#ifndef GOLDOBJ /* GOLDOBJ-compatibility */ +/* used to make save & bones files be compatible with GOLDOBJ config; + takes all of the gold objects out of the invent or mtmp->minvent + chain and puts it into either u.ugold or mtmp->mgold */ void -put_gold_back(head_ptr, goldptr) -struct obj **head_ptr; -long *goldptr; +put_gold_back(mon) +struct monst *mon; { struct obj *goldobj; - long gld = 0L; + boolean is_hero = (mon == &youmonst); - while ((goldobj = gold_in(*head_ptr))) { - gld += goldobj->quan; - extract_nobj(goldobj, head_ptr); - dealloc_obj(goldobj); + /* there could be two gold objects in invent if a hangup save was + performed while gold was in invent for Drop or container access */ + while ((goldobj = (is_hero ? carrying(GOLD_PIECE) : + m_carrying(mon, GOLD_PIECE))) != 0) { + extract_nobj(goldobj, is_hero ? &invent : &mon->minvent); + if (!goldobj->in_use) { + if (is_hero) u.ugold += goldobj->quan; + else mon->mgold += goldobj->quan; + } + dealloc_obj(goldobj); } - if (gld) *goldptr += gld; -} - -STATIC_OVL struct obj * -gold_in(chn) -struct obj *chn; -{ - struct obj *otmp; - - for(otmp = chn; otmp; otmp = otmp->nobj) - if(otmp->otyp == GOLD_PIECE) - return(otmp); - return((struct obj *) 0); } #endif /*GOLDOBJ*/ diff --git a/src/save.c b/src/save.c index 551428f1a..4db45bf26 100644 --- a/src/save.c +++ b/src/save.c @@ -334,15 +334,8 @@ register int fd, mode; #ifdef SYSFLAGS bwrite(fd, (genericptr_t) &sysflags, sizeof(struct sysflag)); #endif -#ifndef GOLDOBJ - if (u.ugold) { - struct obj *goldobj = mksobj(GOLD_PIECE, FALSE, FALSE); - goldobj->quan = u.ugold; - goldobj->where = OBJ_INVENT; - u.ugold = 0L; - goldobj->nobj = invent; - invent = goldobj; - } +#ifndef GOLDOBJ /* GOLDOBJ-compatibility */ + if (u.ugold) (void)insert_gold_into_invent(FALSE); #endif bwrite(fd, (genericptr_t) &u, sizeof(struct you)); save_killers(fd, mode); @@ -352,9 +345,8 @@ register int fd, mode; save_light_sources(fd, mode, RANGE_GLOBAL); saveobjchn(fd, invent, mode); -#ifndef GOLDOBJ - if (!release_data(mode)) - put_gold_back(&invent, &u.ugold); +#ifndef GOLDOBJ /* GOLDOBJ-compatibility */ + if (!release_data(mode)) remove_gold_from_invent(); #endif if (BALL_IN_MON) { /* prevent loss of ball & chain when swallowed */ @@ -1141,24 +1133,21 @@ register struct monst *mtmp; if (perform_bwrite(mode)) { mtmp->mnum = monsndx(mtmp->data); if (mtmp->ispriest) forget_temple_entry(mtmp); /* EPRI() */ -#ifndef GOLDOBJ +#ifndef GOLDOBJ /* GOLDOBJ-compatibility */ if (mtmp->mgold) { struct obj *goldobj = mksobj(GOLD_PIECE, FALSE, FALSE); + goldobj->quan = mtmp->mgold; - goldobj->ocarry = mtmp; - goldobj->where = OBJ_MINVENT; mtmp->mgold = 0L; - goldobj->nobj = mtmp->minvent; - mtmp->minvent = goldobj; + add_to_minv(mtmp, goldobj); } #endif savemon(fd, mtmp); } if (mtmp->minvent) saveobjchn(fd,mtmp->minvent,mode); -#ifndef GOLDOBJ - if (!release_data(mode)) - put_gold_back(&mtmp->minvent, &mtmp->mgold); +#ifndef GOLDOBJ /* GOLDOBJ-compatibility */ + if (!release_data(mode)) put_gold_back(mtmp); #endif if (release_data(mode)) dealloc_monst(mtmp);