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

@@ -1672,6 +1672,9 @@ E int FDECL(mread, (int,genericptr_t,unsigned int));
#else
E void FDECL(mread, (int,genericptr_t,unsigned int));
#endif
#ifndef GOLDOBJ
E void FDECL(put_gold_back, (struct obj **,long *));
#endif
/* ### rip.c ### */

View File

@@ -130,8 +130,9 @@ struct monst {
long mtrapseen; /* bitmap of traps we've been trapped in */
long mlstmv; /* for catching up with lost time */
long mspare1;
#ifndef GOLDOBJ
long mgold;
#define mgold mspare1
#endif
struct obj *minvent;

View File

@@ -13,7 +13,7 @@
* Incrementing EDITLEVEL can be used to force invalidation of old bones
* and save files.
*/
#define EDITLEVEL 0
#define EDITLEVEL 1
#define COPYRIGHT_BANNER_A \
"NetHack, Copyright 1985-2003"

View File

@@ -337,10 +337,11 @@ struct you {
int ugangr; /* if the gods are angry at you */
int ugifts; /* number of artifacts bestowed */
int ublessed, ublesscnt; /* blessing/duration from #pray */
#ifndef GOLDOBJ
long ugold, ugold0;
#else
long umoney0;
long uspare1;
#ifndef GOLDOBJ
#define ugold uspare1
#define ugold0 umoney0
#endif
long uexp, urexp;
long ucleansed; /* to record moves when player was cleansed */

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;

View File

@@ -409,7 +409,9 @@ do_rumors()
/*
* Use this to explicitly mask out features during version checks.
*/
#define IGNORED_FEATURES ( 0L )
#define IGNORED_FEATURES ( 0L \
| (1L << 12) /* GOLDOBJ */ \
)
static void
make_version()