!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.
This commit is contained in:
+4
-4
@@ -880,7 +880,7 @@ 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
|
#ifndef GOLDOBJ
|
||||||
E struct obj *FDECL(mkgoldobj, (long));
|
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);
|
E void NDECL(remove_gold_from_invent);
|
||||||
#endif
|
#endif
|
||||||
E struct obj *FDECL(getobj, (const char *,const char *));
|
E struct obj *FDECL(getobj, (const char *,const char *));
|
||||||
@@ -1870,13 +1870,13 @@ E int FDECL(restore_menu, (winid));
|
|||||||
E void NDECL(minit);
|
E void NDECL(minit);
|
||||||
E boolean FDECL(lookup_id_mapping, (unsigned, unsigned *));
|
E boolean FDECL(lookup_id_mapping, (unsigned, unsigned *));
|
||||||
E void FDECL(mread, (int,genericptr_t,unsigned int));
|
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 int FDECL(validate, (int,const char *));
|
||||||
E void NDECL(reset_restpref);
|
E void NDECL(reset_restpref);
|
||||||
E void FDECL(set_restpref, (const char *));
|
E void FDECL(set_restpref, (const char *));
|
||||||
E void FDECL(set_savepref, (const char *));
|
E void FDECL(set_savepref, (const char *));
|
||||||
|
#ifndef GOLDOBJ
|
||||||
|
E void FDECL(put_gold_back, (struct monst *));
|
||||||
|
#endif
|
||||||
|
|
||||||
/* ### rip.c ### */
|
/* ### rip.c ### */
|
||||||
|
|
||||||
|
|||||||
@@ -649,7 +649,7 @@ int retry;
|
|||||||
|
|
||||||
#ifndef GOLDOBJ
|
#ifndef GOLDOBJ
|
||||||
/* put gold where inventory traversal will see it */
|
/* 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
|
#endif
|
||||||
if (retry) {
|
if (retry) {
|
||||||
all_categories = (retry == -2);
|
all_categories = (retry == -2);
|
||||||
|
|||||||
+11
-10
@@ -697,14 +697,17 @@ register long q;
|
|||||||
|
|
||||||
/* used for container apply/#loot and multi-item Drop */
|
/* used for container apply/#loot and multi-item Drop */
|
||||||
struct obj *
|
struct obj *
|
||||||
insert_gold_into_invent()
|
insert_gold_into_invent(keep_on_status_line)
|
||||||
|
boolean keep_on_status_line;
|
||||||
{
|
{
|
||||||
struct obj *u_gold = 0;
|
struct obj *u_gold = 0;
|
||||||
|
|
||||||
if (u.ugold) {
|
if (u.ugold) {
|
||||||
u_gold = mkgoldobj(u.ugold);
|
u_gold = mkgoldobj(u.ugold);
|
||||||
u_gold->in_use = 1;
|
if (keep_on_status_line) {
|
||||||
u.ugold = u_gold->quan; /* put the gold back 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 '$' */
|
assigninvlet(u_gold); /* should yield '$' */
|
||||||
u_gold->where = OBJ_INVENT;
|
u_gold->where = OBJ_INVENT;
|
||||||
u_gold->nobj = invent;
|
u_gold->nobj = invent;
|
||||||
@@ -719,15 +722,13 @@ remove_gold_from_invent()
|
|||||||
{
|
{
|
||||||
struct obj *u_gold = invent; /* we expect gold to be first */
|
struct obj *u_gold = invent; /* we expect gold to be first */
|
||||||
|
|
||||||
if (u_gold && u_gold->otyp == GOLD_PIECE) {
|
if (u_gold && u_gold->otyp != GOLD_PIECE)
|
||||||
invent = u_gold->nobj;
|
u_gold = carrying(GOLD_PIECE);
|
||||||
u_gold->where = OBJ_FREE;
|
|
||||||
dealloc_obj(u_gold);
|
if (u_gold) {
|
||||||
#if 0
|
|
||||||
} else if ((u_gold = carrying(GOLD_PIECE)) != 0) {
|
|
||||||
extract_nobj(u_gold, &invent);
|
extract_nobj(u_gold, &invent);
|
||||||
|
if (!u_gold->in_use) u.ugold += u_gold->quan;
|
||||||
dealloc_obj(u_gold);
|
dealloc_obj(u_gold);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* !GOLDOBJ */
|
#endif /* !GOLDOBJ */
|
||||||
|
|||||||
+1
-1
@@ -2260,7 +2260,7 @@ int held;
|
|||||||
#ifndef GOLDOBJ
|
#ifndef GOLDOBJ
|
||||||
/* if putting in, place gold where inventory traversal will see it */
|
/* if putting in, place gold where inventory traversal will see it */
|
||||||
if ((loot_in || stash_one) && u.ugold)
|
if ((loot_in || stash_one) && u.ugold)
|
||||||
u_gold = insert_gold_into_invent();
|
u_gold = insert_gold_into_invent(TRUE);
|
||||||
#endif
|
#endif
|
||||||
if ((loot_in || stash_one) &&
|
if ((loot_in || stash_one) &&
|
||||||
(!invent || (invent == current_container && !invent->nobj))) {
|
(!invent || (invent == current_container && !invent->nobj))) {
|
||||||
|
|||||||
+22
-35
@@ -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. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* 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_DCL int FDECL(restlevelfile, (int,XCHAR_P));
|
||||||
STATIC_OVL void FDECL(restore_msghistory, (int));
|
STATIC_OVL void FDECL(restore_msghistory, (int));
|
||||||
STATIC_DCL void FDECL(reset_oattached_mids, (BOOLEAN_P));
|
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_DCL void FDECL(rest_levl, (int,BOOLEAN_P));
|
||||||
|
|
||||||
static struct restore_procs {
|
static struct restore_procs {
|
||||||
@@ -443,8 +440,8 @@ boolean ghostly;
|
|||||||
/* restore monster back pointer */
|
/* restore monster back pointer */
|
||||||
for (obj = mtmp->minvent; obj; obj = obj->nobj)
|
for (obj = mtmp->minvent; obj; obj = obj->nobj)
|
||||||
obj->ocarry = mtmp;
|
obj->ocarry = mtmp;
|
||||||
#ifndef GOLDOBJ
|
#ifndef GOLDOBJ /* GOLDOBJ-compatibility */
|
||||||
put_gold_back(&mtmp->minvent, &mtmp->mgold);
|
put_gold_back(mtmp);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (mtmp->mw) {
|
if (mtmp->mw) {
|
||||||
@@ -571,8 +568,8 @@ unsigned int *stuckid, *steedid; /* STEED */
|
|||||||
restore_timers(fd, RANGE_GLOBAL, FALSE, 0L);
|
restore_timers(fd, RANGE_GLOBAL, FALSE, 0L);
|
||||||
restore_light_sources(fd);
|
restore_light_sources(fd);
|
||||||
invent = restobjchn(fd, FALSE, FALSE);
|
invent = restobjchn(fd, FALSE, FALSE);
|
||||||
#ifndef GOLDOBJ
|
#ifndef GOLDOBJ /* GOLDOBJ-compatibility */
|
||||||
put_gold_back(&invent, &u.ugold);
|
put_gold_back(&youmonst);
|
||||||
#endif
|
#endif
|
||||||
/* tmp_bc only gets set here if the ball & chain were orphaned
|
/* tmp_bc only gets set here if the ball & chain were orphaned
|
||||||
because you were swallowed; otherwise they will be on the floor
|
because you were swallowed; otherwise they will be on the floor
|
||||||
@@ -1534,38 +1531,28 @@ register unsigned int len;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef GOLDOBJ
|
#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
|
takes all of the gold objects out of the invent or mtmp->minvent
|
||||||
* mtmp->minvent chain and puts it into either
|
chain and puts it into either u.ugold or mtmp->mgold */
|
||||||
* u.ugold or mtmp->mgold.
|
|
||||||
*/
|
|
||||||
void
|
void
|
||||||
put_gold_back(head_ptr, goldptr)
|
put_gold_back(mon)
|
||||||
struct obj **head_ptr;
|
struct monst *mon;
|
||||||
long *goldptr;
|
|
||||||
{
|
{
|
||||||
struct obj *goldobj;
|
struct obj *goldobj;
|
||||||
long gld = 0L;
|
boolean is_hero = (mon == &youmonst);
|
||||||
|
|
||||||
while ((goldobj = gold_in(*head_ptr))) {
|
/* there could be two gold objects in invent if a hangup save was
|
||||||
gld += goldobj->quan;
|
performed while gold was in invent for Drop or container access */
|
||||||
extract_nobj(goldobj, head_ptr);
|
while ((goldobj = (is_hero ? carrying(GOLD_PIECE) :
|
||||||
dealloc_obj(goldobj);
|
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*/
|
#endif /*GOLDOBJ*/
|
||||||
|
|
||||||
|
|||||||
+9
-20
@@ -334,15 +334,8 @@ register int fd, mode;
|
|||||||
#ifdef SYSFLAGS
|
#ifdef SYSFLAGS
|
||||||
bwrite(fd, (genericptr_t) &sysflags, sizeof(struct sysflag));
|
bwrite(fd, (genericptr_t) &sysflags, sizeof(struct sysflag));
|
||||||
#endif
|
#endif
|
||||||
#ifndef GOLDOBJ
|
#ifndef GOLDOBJ /* GOLDOBJ-compatibility */
|
||||||
if (u.ugold) {
|
if (u.ugold) (void)insert_gold_into_invent(FALSE);
|
||||||
struct obj *goldobj = mksobj(GOLD_PIECE, FALSE, FALSE);
|
|
||||||
goldobj->quan = u.ugold;
|
|
||||||
goldobj->where = OBJ_INVENT;
|
|
||||||
u.ugold = 0L;
|
|
||||||
goldobj->nobj = invent;
|
|
||||||
invent = goldobj;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
bwrite(fd, (genericptr_t) &u, sizeof(struct you));
|
bwrite(fd, (genericptr_t) &u, sizeof(struct you));
|
||||||
save_killers(fd, mode);
|
save_killers(fd, mode);
|
||||||
@@ -352,9 +345,8 @@ register int fd, mode;
|
|||||||
save_light_sources(fd, mode, RANGE_GLOBAL);
|
save_light_sources(fd, mode, RANGE_GLOBAL);
|
||||||
|
|
||||||
saveobjchn(fd, invent, mode);
|
saveobjchn(fd, invent, mode);
|
||||||
#ifndef GOLDOBJ
|
#ifndef GOLDOBJ /* GOLDOBJ-compatibility */
|
||||||
if (!release_data(mode))
|
if (!release_data(mode)) remove_gold_from_invent();
|
||||||
put_gold_back(&invent, &u.ugold);
|
|
||||||
#endif
|
#endif
|
||||||
if (BALL_IN_MON) {
|
if (BALL_IN_MON) {
|
||||||
/* prevent loss of ball & chain when swallowed */
|
/* prevent loss of ball & chain when swallowed */
|
||||||
@@ -1141,24 +1133,21 @@ register struct monst *mtmp;
|
|||||||
if (perform_bwrite(mode)) {
|
if (perform_bwrite(mode)) {
|
||||||
mtmp->mnum = monsndx(mtmp->data);
|
mtmp->mnum = monsndx(mtmp->data);
|
||||||
if (mtmp->ispriest) forget_temple_entry(mtmp); /* EPRI() */
|
if (mtmp->ispriest) forget_temple_entry(mtmp); /* EPRI() */
|
||||||
#ifndef GOLDOBJ
|
#ifndef GOLDOBJ /* GOLDOBJ-compatibility */
|
||||||
if (mtmp->mgold) {
|
if (mtmp->mgold) {
|
||||||
struct obj *goldobj = mksobj(GOLD_PIECE, FALSE, FALSE);
|
struct obj *goldobj = mksobj(GOLD_PIECE, FALSE, FALSE);
|
||||||
|
|
||||||
goldobj->quan = mtmp->mgold;
|
goldobj->quan = mtmp->mgold;
|
||||||
goldobj->ocarry = mtmp;
|
|
||||||
goldobj->where = OBJ_MINVENT;
|
|
||||||
mtmp->mgold = 0L;
|
mtmp->mgold = 0L;
|
||||||
goldobj->nobj = mtmp->minvent;
|
add_to_minv(mtmp, goldobj);
|
||||||
mtmp->minvent = goldobj;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
savemon(fd, mtmp);
|
savemon(fd, mtmp);
|
||||||
}
|
}
|
||||||
if (mtmp->minvent)
|
if (mtmp->minvent)
|
||||||
saveobjchn(fd,mtmp->minvent,mode);
|
saveobjchn(fd,mtmp->minvent,mode);
|
||||||
#ifndef GOLDOBJ
|
#ifndef GOLDOBJ /* GOLDOBJ-compatibility */
|
||||||
if (!release_data(mode))
|
if (!release_data(mode)) put_gold_back(mtmp);
|
||||||
put_gold_back(&mtmp->minvent, &mtmp->mgold);
|
|
||||||
#endif
|
#endif
|
||||||
if (release_data(mode))
|
if (release_data(mode))
|
||||||
dealloc_monst(mtmp);
|
dealloc_monst(mtmp);
|
||||||
|
|||||||
Reference in New Issue
Block a user