]> granicus.if.org Git - nethack/commitdiff
GOLDOBJ compat (main trunk only)
authornethack.allison <nethack.allison>
Fri, 11 Apr 2003 22:32:08 +0000 (22:32 +0000)
committernethack.allison <nethack.allison>
Fri, 11 Apr 2003 22:32:08 +0000 (22:32 +0000)
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
include/monst.h
include/patchlevel.h
include/you.h
src/restore.c
src/save.c
util/makedefs.c

index 2de637de33ed5b7a073a37ac5b48b4b5dc22189c..1234aa7a019e3d801719a54b5d0f0268d4efd2ee 100644 (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 ### */
 
index af2bb780683d9c3f5ccb9673edd8353ea48990a2..335b6150a764669c8247e2970bd03fc0e485e1a1 100644 (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;
 
index 0edf6ec9cfdd02668735880faf4518508a5c457c..2d76a452aee51ddff13a3b2dc7ef0dd46bdeef5b 100644 (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"
index ed347a7136a36eba0f8dd34b13b8b75c750a837c..9460bb164b772e20858e01f29aa2bcb58362725b 100644 (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 */
index 7c927e337e802d6d7d0b46dace076e0b1fbe5bd6..023adc1c9b4c4b464b5aa03e796a77058458bc1d 100644 (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*/
index ea53b22bd701aeceab27cc846f4e02202b42eb0b..6230788fd20d338aea08c9f12961d591718aaa5a 100644 (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;
index af6fe1669a853bebb8d195c9217392197bc2aed0..444608e39ce1c320dc6a211d6509a872431bae09 100644 (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()