GOLDOBJ compat (main trunk only)

This patch gives game and savefile compatibility
whether GOLDOBJ is defined or not.

You can build with GOLDOBJ defined or not, and
still load your saved games. Rebuild with the
opposite, and load the same game.

That way GOLDOBJ can be experimented with
more easily.

1. Leave the "you" struct and the "monst"
   struct the same under the hood between
   GOLDOBJ and !GOLDOBJ.

2. Always write out gold as an
   object on the player and monster
   inventory chains.

On a restore of the savefile with GOLDOBJ
not defined,  take the gold objects out of
the inventory chains and put it into u.ugold
or mtmp->mgold as appropriate.

On a restore of the savefile with GOLDOBJ
defined, nothing special is done.
This commit is contained in:
nethack.allison
2003-04-11 22:32:08 +00:00
parent b39599719e
commit e1aa6d5148
7 changed files with 83 additions and 6 deletions

View File

@@ -30,6 +30,7 @@ STATIC_DCL boolean FDECL(restgamestate, (int, unsigned int *, unsigned int *));
STATIC_DCL void FDECL(restlevelstate, (unsigned int, unsigned int));
STATIC_DCL int FDECL(restlevelfile, (int,XCHAR_P));
STATIC_DCL void FDECL(reset_oattached_mids, (BOOLEAN_P));
STATIC_DCL struct obj *FDECL(gold_in, (struct obj *));
/*
* Save a mapping of IDs from ghost levels to the current level. This
@@ -269,6 +270,9 @@ 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);
#endif
}
if (mtmp->mw) {
struct obj *obj;
@@ -388,6 +392,9 @@ 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);
#endif
migrating_objs = restobjchn(fd, FALSE, FALSE);
migrating_mons = restmonchn(fd, FALSE);
mread(fd, (genericptr_t) mvitals, sizeof(mvitals));
@@ -1073,5 +1080,39 @@ register unsigned int len;
}
}
#endif /* ZEROCOMP */
#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.
*/
void
put_gold_back(head_ptr, goldptr)
struct obj **head_ptr;
long *goldptr;
{
struct obj *goldobj;
long gld = 0L;
while ((goldobj = gold_in(*head_ptr))) {
gld += goldobj->quan;
extract_nobj(goldobj, head_ptr);
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*/
/*restore.c*/

View File

@@ -280,6 +280,16 @@ register int fd, mode;
uid = getuid();
bwrite(fd, (genericptr_t) &uid, sizeof uid);
bwrite(fd, (genericptr_t) &flags, sizeof(struct flag));
#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;
}
#endif
bwrite(fd, (genericptr_t) &u, sizeof(struct you));
/* must come before migrating_objs and migrating_mons are freed */
@@ -287,6 +297,10 @@ 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);
#endif
saveobjchn(fd, migrating_objs, mode);
savemonchn(fd, migrating_mons, mode);
if (release_data(mode)) {
@@ -881,10 +895,25 @@ register struct monst *mtmp;
mtmp->mnum = monsndx(mtmp->data);
xl = mtmp->mxlth + mtmp->mnamelth;
bwrite(fd, (genericptr_t) &xl, sizeof(int));
#ifndef GOLDOBJ
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;
}
#endif
bwrite(fd, (genericptr_t) mtmp, xl + sizeof(struct monst));
}
if (mtmp->minvent)
saveobjchn(fd,mtmp->minvent,mode);
#ifndef GOLDOBJ
if (!release_data(mode))
put_gold_back(&mtmp->minvent, &mtmp->mgold);
#endif
if (release_data(mode))
dealloc_monst(mtmp);
mtmp = mtmp2;