]> granicus.if.org Git - nethack/commitdiff
restore.c globals moved to instance_globals.
authorBart House <bart@barthouse.com>
Fri, 23 Nov 2018 18:36:45 +0000 (10:36 -0800)
committerBart House <bart@barthouse.com>
Fri, 23 Nov 2018 23:22:54 +0000 (15:22 -0800)
include/decl.h
src/artifact.c
src/decl.c
src/objnam.c
src/restore.c
win/tty/wintty.c

index f13efca214398a75deab4df7a80308ba429c99e1..18d30daeacbbbe3f6f650079d385f2e0c2ee03d9 100644 (file)
@@ -454,12 +454,23 @@ struct instance_globals {
                               messages in artifact_hit() */
     /* botl.c */
     int mrank_sz; /* loaded by max_rank_sz */
+
     /* dog.c */
     int petname_used; /* user preferred pet name has been used */
+
     /* muse.c */
     boolean m_using; /* kludge to use mondided instead of killed */
+
     /* pickup.c */
     int oldcap; /* last encumberance */
+
+    /* restore.c */
+    int n_ids_mapped;
+    struct bucket *id_map;
+    boolean restoring;
+    struct fruit *oldfruit;
+    long omoves;
+
     /* rumors.c */
     long true_rumor_size; /* rumor size variables are signed so that value -1
                             can be used as a flag */
@@ -473,6 +484,7 @@ struct instance_globals {
     int oracle_flg; /* -1=>don't use, 0=>need init, 1=>init done */
     unsigned oracle_cnt; /* oracles are handled differently from rumors... */
     unsigned long *oracle_loc;
+
     /* save.c */
     boolean havestate;
     unsigned ustuck_id; /* need to preserve during save */
index 455856601f7b740b5913376fdefec8360188bf91..698913edef6e6f409ec21da1051c8839675ecfee 100644 (file)
@@ -536,7 +536,7 @@ long wp_mask;
          * that can print a message--need to guard against being printed
          * when restoring a game
          */
-        (void) make_hallucinated((long) !on, restoring ? FALSE : TRUE,
+        (void) make_hallucinated((long) !on, g.restoring ? FALSE : TRUE,
                                  wp_mask);
     }
     if (spfx & SPFX_ESP) {
index 3214faab106ef607fbdca9c6f3d2a2350e84aa24..c006cc71588db112cd40a00d67d3e17aa25aef88 100644 (file)
@@ -332,16 +332,29 @@ const struct instance_globals g_init = {
     0,  /* jumping_is_magic */
     -1, /* polearm_range_min */
     -1, /* polearm_range_max  */
+
     /* artifact.c */
     0,  /* spec_dbon_applies */
+
     /* botl.c */
     0,  /* mrank_sz */
+
     /* dog.c */
     0,  /* petname_used */
+
     /* mused.c */
     FALSE, /* m_using */
+
     /* pickup.c */
     0,  /* oldcap */
+
+    /* restore.c */
+    0, /* n_ids_mapped */
+    0, /* id_map */
+    FALSE, /* restoring */
+    UNDEFINED_PTR, /* oldfruit */
+    UNDEFINED_VALUE, /* omoves */
+
     /* rumors.c */
     0, /* true_rumor_size */
     0, /* false_rumor_size */
@@ -352,21 +365,27 @@ const struct instance_globals g_init = {
     0, /* oracle_flag */
     0, /* oracle_cnt */
     NULL, /* oracle_loc */
+
     /* save.c */
     TRUE, /* havestate*/
     0, /* ustuck_id */
     0, /* usteed_id */
+
     /* trap.c */
     0, /* force_mintrap */
+
     /* u_init.c */
     STRANGE_OBJECT, /* nocreate */
     STRANGE_OBJECT, /* nocreate2 */
     STRANGE_OBJECT, /* nocreate3 */
     STRANGE_OBJECT, /* nocreate4 */
+
     /* uhitm.c */
     UNDEFINED_VALUE, /* override_confirmation */
+
     /* weapon.c */
     UNDEFINED_PTR, /* propellor */
+
     /* zap.c */
     UNDEFINED_VALUE, /* poly_zap */
     UNDEFINED_VALUE,  /* obj_zapped */
index 3fc3e01d2b3689fac07d7d8536fec487cb4cae93..66e09d74684426aa4a530765e86c908d317f3950 100644 (file)
@@ -1200,7 +1200,7 @@ unsigned doname_flags;
     }
     /* treat 'restoring' like suppress_price because shopkeeper and
        bill might not be available yet while restore is in progress */
-    if (!iflags.suppress_price && !restoring && is_unpaid(obj)) {
+    if (!iflags.suppress_price && !g.restoring && is_unpaid(obj)) {
         long quotedprice = unpaid_cost(obj, TRUE);
 
         Sprintf(eos(bp), " (%s, %ld %s)",
index 99b74d36d70c17d1497933ea4f3a2259fac64649..ff14135f0cc673958cdd6472a53ab6d4e9f46859 100644 (file)
@@ -58,7 +58,7 @@ static struct restore_procs {
 
 /*
  * Save a mapping of IDs from ghost levels to the current level.  This
- * map is used by the timer routines when restoring ghost levels.
+ * map is used by the timer routines when g.restoring ghost levels.
  */
 #define N_PER_BUCKET 64
 struct bucket {
@@ -72,9 +72,6 @@ struct bucket {
 STATIC_DCL void NDECL(clear_id_mapping);
 STATIC_DCL void FDECL(add_id_mapping, (unsigned, unsigned));
 
-static int n_ids_mapped = 0;
-static struct bucket *id_map = 0;
-
 #ifdef AMII_GRAPHICS
 void FDECL(amii_setpens, (int)); /* use colors from save file */
 extern int amii_numcolors;
@@ -82,10 +79,6 @@ extern int amii_numcolors;
 
 #include "display.h"
 
-boolean restoring = FALSE;
-static NEARDATA struct fruit *oldfruit;
-static NEARDATA long omoves;
-
 #define Is_IceBox(o) ((o)->otyp == ICE_BOX ? TRUE : FALSE)
 
 /* Recalculate level.objects[x][y], since this info was not saved. */
@@ -179,11 +172,11 @@ boolean ghostly;
 
         mread(fd, (genericptr_t) tmp_dam, sizeof(*tmp_dam));
         if (ghostly)
-            tmp_dam->when += (monstermoves - omoves);
+            tmp_dam->when += (monstermoves - g.omoves);
         Strcpy(damaged_shops,
                in_rooms(tmp_dam->place.x, tmp_dam->place.y, SHOPBASE));
         if (u.uz.dlevel) {
-            /* when restoring, there are two passes over the current
+            /* when g.restoring, there are two passes over the current
              * level.  the first time, u.uz isn't set, so neither is
              * shop_keeper().  just wait and process the damage on
              * the second pass.
@@ -216,7 +209,7 @@ struct obj *otmp;
     mread(fd, (genericptr_t) otmp, sizeof(struct obj));
 
     /* next object pointers are invalid; otmp->cobj needs to be left
-       as is--being non-null is key to restoring container contents */
+       as is--being non-null is key to g.restoring container contents */
     otmp->nobj = otmp->nexthere = (struct obj *) 0;
     /* non-null oextra needs to be reconstructed */
     if (otmp->oextra) {
@@ -293,7 +286,7 @@ boolean ghostly, frozen;
          * immediately after old player died.
          */
         if (ghostly && !frozen && !age_is_relative(otmp))
-            otmp->age = monstermoves - omoves + otmp->age;
+            otmp->age = monstermoves - g.omoves + otmp->age;
 
         /* get contents of a container or statue */
         if (Has_contents(otmp)) {
@@ -513,7 +506,7 @@ register struct obj *otmp;
 {
     register struct fruit *oldf;
 
-    for (oldf = oldfruit; oldf; oldf = oldf->nextf)
+    for (oldf = g.oldfruit; oldf; oldf = oldf->nextf)
         if (oldf->fid == otmp->spe)
             break;
 
@@ -797,7 +790,7 @@ register int fd;
     int rtmp;
     struct obj *otmp;
 
-    restoring = TRUE;
+    g.restoring = TRUE;
     get_plname_from_file(fd, plname);
     getlev(fd, 0, (xchar) 0, FALSE);
     if (!restgamestate(fd, &stuckid, &steedid)) {
@@ -805,7 +798,7 @@ register int fd;
         savelev(-1, 0, FREE_SAVE); /* discard current level */
         (void) nhclose(fd);
         (void) delete_savefile();
-        restoring = FALSE;
+        g.restoring = FALSE;
         return 0;
     }
     restlevelstate(stuckid, steedid);
@@ -921,7 +914,7 @@ register int fd;
 
     run_timers(); /* expire all timers that have gone off while away */
     docrt();
-    restoring = FALSE;
+    g.restoring = FALSE;
     clear_nhwindow(WIN_MESSAGE);
 
     /* Success! */
@@ -1025,10 +1018,10 @@ boolean ghostly;
     setmode(fd, O_BINARY);
 #endif
     /* Load the old fruit info.  We have to do it first, so the
-     * information is available when restoring the objects.
+     * information is available when g.restoring the objects.
      */
     if (ghostly)
-        oldfruit = loadfruitchn(fd);
+        g.oldfruit = loadfruitchn(fd);
 
     /* First some sanity checks */
     mread(fd, (genericptr_t) &hpid, sizeof(hpid));
@@ -1055,8 +1048,8 @@ boolean ghostly;
     rest_levl(fd,
               (boolean) ((sfrestinfo.sfi1 & SFI1_RLECOMP) == SFI1_RLECOMP));
     mread(fd, (genericptr_t) lastseentyp, sizeof(lastseentyp));
-    mread(fd, (genericptr_t) &omoves, sizeof(omoves));
-    elapsed = monstermoves - omoves;
+    mread(fd, (genericptr_t) &g.omoves, sizeof(g.omoves));
+    elapsed = monstermoves - g.omoves;
     mread(fd, (genericptr_t) &upstair, sizeof(stairway));
     mread(fd, (genericptr_t) &dnstair, sizeof(stairway));
     mread(fd, (genericptr_t) &upladder, sizeof(stairway));
@@ -1132,7 +1125,7 @@ boolean ghostly;
     rest_regions(fd, ghostly);
     if (ghostly) {
         /* Now get rid of all the temp fruits... */
-        freefruitchn(oldfruit), oldfruit = 0;
+        freefruitchn(g.oldfruit), g.oldfruit = 0;
 
         if (lev > ledger_no(&medusa_level)
             && lev < ledger_no(&stronghold_level) && xdnstair == 0) {
@@ -1229,11 +1222,11 @@ clear_id_mapping()
 {
     struct bucket *curr;
 
-    while ((curr = id_map) != 0) {
-        id_map = curr->next;
+    while ((curr = g.id_map) != 0) {
+        g.id_map = curr->next;
         free((genericptr_t) curr);
     }
-    n_ids_mapped = 0;
+    g.n_ids_mapped = 0;
 }
 
 /* Add a mapping to the ID map. */
@@ -1243,18 +1236,18 @@ unsigned gid, nid;
 {
     int idx;
 
-    idx = n_ids_mapped % N_PER_BUCKET;
+    idx = g.n_ids_mapped % N_PER_BUCKET;
     /* idx is zero on first time through, as well as when a new bucket is */
     /* needed */
     if (idx == 0) {
         struct bucket *gnu = (struct bucket *) alloc(sizeof(struct bucket));
-        gnu->next = id_map;
-        id_map = gnu;
+        gnu->next = g.id_map;
+        g.id_map = gnu;
     }
 
-    id_map->map[idx].gid = gid;
-    id_map->map[idx].nid = nid;
-    n_ids_mapped++;
+    g.id_map->map[idx].gid = gid;
+    g.id_map->map[idx].nid = nid;
+    g.n_ids_mapped++;
 }
 
 /*
@@ -1269,11 +1262,11 @@ unsigned gid, *nidp;
     int i;
     struct bucket *curr;
 
-    if (n_ids_mapped)
-        for (curr = id_map; curr; curr = curr->next) {
+    if (g.n_ids_mapped)
+        for (curr = g.id_map; curr; curr = curr->next) {
             /* first bucket might not be totally full */
-            if (curr == id_map) {
-                i = n_ids_mapped % N_PER_BUCKET;
+            if (curr == g.id_map) {
+                i = g.n_ids_mapped % N_PER_BUCKET;
                 if (i == 0)
                     i = N_PER_BUCKET;
             } else
@@ -1623,10 +1616,10 @@ register unsigned int len;
             return;
         } else {
             pline("Read %d instead of %u bytes.", rlen, len);
-            if (restoring) {
+            if (g.restoring) {
                 (void) nhclose(fd);
                 (void) delete_savefile();
-                error("Error restoring old game.");
+                error("Error g.restoring old game.");
             }
             panic("Error reading level file.");
         }
index d5cac96c387b4a5a5aa651f52e88b9f4440bba3d..523b731ee595e6461cb72a9046cd016eedf7fab1 100644 (file)
@@ -3171,7 +3171,6 @@ void
 tty_cliparound(x, y)
 int x, y;
 {
-    extern boolean restoring;
     int oldx = clipx, oldy = clipy;
 
     if (!clipping)
@@ -3191,7 +3190,7 @@ int x, y;
         clipy = clipymax - (LI - 3);
     }
     if (clipx != oldx || clipy != oldy) {
-        if (on_level(&u.uz0, &u.uz) && !restoring)
+        if (on_level(&u.uz0, &u.uz) && !g.restoring)
             (void) doredraw();
     }
 }