From e1aa6d5148e953e33c0609ab5a86e1a45385271e Mon Sep 17 00:00:00 2001 From: "nethack.allison" Date: Fri, 11 Apr 2003 22:32:08 +0000 Subject: [PATCH] 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. --- include/extern.h | 3 +++ include/monst.h | 3 ++- include/patchlevel.h | 2 +- include/you.h | 7 ++++--- src/restore.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/save.c | 29 +++++++++++++++++++++++++++++ util/makedefs.c | 4 +++- 7 files changed, 83 insertions(+), 6 deletions(-) diff --git a/include/extern.h b/include/extern.h index 2de637de3..1234aa7a0 100644 --- a/include/extern.h +++ b/include/extern.h @@ -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 ### */ diff --git a/include/monst.h b/include/monst.h index af2bb7806..335b6150a 100644 --- a/include/monst.h +++ b/include/monst.h @@ -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; diff --git a/include/patchlevel.h b/include/patchlevel.h index 0edf6ec9c..2d76a452a 100644 --- a/include/patchlevel.h +++ b/include/patchlevel.h @@ -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" diff --git a/include/you.h b/include/you.h index ed347a713..9460bb164 100644 --- a/include/you.h +++ b/include/you.h @@ -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 */ diff --git a/src/restore.c b/src/restore.c index 7c927e337..023adc1c9 100644 --- a/src/restore.c +++ b/src/restore.c @@ -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*/ diff --git a/src/save.c b/src/save.c index ea53b22bd..6230788fd 100644 --- a/src/save.c +++ b/src/save.c @@ -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; diff --git a/util/makedefs.c b/util/makedefs.c index af6fe1669..444608e39 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -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() -- 2.40.0