From: PatR <rankin@nethack.org>
Date: Sat, 26 Mar 2016 23:42:24 +0000 (-0700)
Subject: zeromonst
X-Git-Tag: NetHack-3.6.1_RC01~854
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d6fa06f8e878cba10f5b26d6c4693b6a918c6efa;p=nethack

zeromonst

Make 'zeromonst' global instead of local to makemon.c.  Its address
isn't used as a special value like &zeroobj, but it is useful to
have available for initializing various pseudo-monsters.

modified:
  include/decl.h
  src/decl.c, makemon.c, mkobj.c, mplayer.c, teleport.c
---

diff --git a/include/decl.h b/include/decl.h
index 52145808e..7898d17ce 100644
--- a/include/decl.h
+++ b/include/decl.h
@@ -243,7 +243,8 @@ E NEARDATA struct obj *migrating_objs;
 E NEARDATA struct obj *billobjs;
 E NEARDATA struct obj *current_wand, *thrownobj, *kickedobj;
 
-E NEARDATA struct obj zeroobj; /* init'd and defined in decl.c */
+E NEARDATA struct obj zeroobj; /* for init; &zeroobj used as special value */
+
 E NEARDATA anything zeroany;   /* init'd and defined in decl.c */
 
 #include "you.h"
@@ -256,7 +257,8 @@ E NEARDATA struct u_realtime urealtime;
 #include "pm.h"
 #endif
 
-E NEARDATA struct monst youmonst; /* init'd and defined in decl.c */
+E NEARDATA struct monst zeromonst; /* for init of new or temp monsters */
+E NEARDATA struct monst youmonst; /* monster details when hero is poly'd */
 E NEARDATA struct monst *mydogs, *migrating_mons;
 
 E NEARDATA struct mvitals {
diff --git a/src/decl.c b/src/decl.c
index 944dbe368..479c075aa 100644
--- a/src/decl.c
+++ b/src/decl.c
@@ -194,8 +194,9 @@ NEARDATA struct obj *migrating_objs = (struct obj *) 0;
 /* objects not yet paid for */
 NEARDATA struct obj *billobjs = (struct obj *) 0;
 
-/* used to zero all elements of a struct obj */
+/* used to zero all elements of a struct obj and a struct monst */
 NEARDATA struct obj zeroobj = DUMMY;
+NEARDATA struct monst zeromonst = DUMMY;
 /* used to zero out union any; initializer deliberately omitted */
 NEARDATA anything zeroany;
 
diff --git a/src/makemon.c b/src/makemon.c
index 9e2d5b9a6..61de5af0e 100644
--- a/src/makemon.c
+++ b/src/makemon.c
@@ -6,8 +6,6 @@
 
 #include <ctype.h>
 
-STATIC_VAR NEARDATA struct monst zeromonst;
-
 /* this assumes that a human quest leader or nemesis is an archetype
    of the corresponding role; that isn't so for some roles (tourist
    for instance) but is for the priests and monks we use it for... */
@@ -23,7 +21,8 @@ STATIC_DCL void FDECL(m_initgrp, (struct monst *, int, int, int));
 STATIC_DCL void FDECL(m_initthrow, (struct monst *, int, int));
 STATIC_DCL void FDECL(m_initweap, (struct monst *));
 STATIC_DCL void FDECL(m_initinv, (struct monst *));
-STATIC_DCL boolean FDECL(makemon_rnd_goodpos, (struct monst *, unsigned, coord *));
+STATIC_DCL boolean FDECL(makemon_rnd_goodpos, (struct monst *,
+                                               unsigned, coord *));
 
 extern const int monstr[];
 
diff --git a/src/mkobj.c b/src/mkobj.c
index 6cb87e40b..3574eaece 100644
--- a/src/mkobj.c
+++ b/src/mkobj.c
@@ -107,13 +107,11 @@ struct obj *otmp;
 {
     if (!otmp->oextra)
         otmp->oextra = newoextra();
+
     if (!OMONST(otmp)) {
         struct monst *m = newmonst();
 
-        /* newmonst() allocates memory but doesn't initialize anything */
-        (void) memset((genericptr_t) m, 0, sizeof (struct monst));
-        m->mextra = (struct mextra *) 0;
-        m->nmon = (struct monst *) 0;
+        *m = zeromonst;
         OMONST(otmp) = m;
     }
 }
diff --git a/src/mplayer.c b/src/mplayer.c
index c2178b07f..de5a2d680 100644
--- a/src/mplayer.c
+++ b/src/mplayer.c
@@ -331,12 +331,13 @@ boolean special;
     int pm, x, y;
     struct monst fakemon;
 
+    fakemon = zeromonst;
     while (num) {
         int tryct = 0;
 
         /* roll for character class */
         pm = PM_ARCHEOLOGIST + rn2(PM_WIZARD - PM_ARCHEOLOGIST + 1);
-        fakemon.data = &mons[pm];
+        set_mon_data(&fakemon, &mons[pm], -1);
 
         /* roll for an available location */
         do {
diff --git a/src/teleport.c b/src/teleport.c
index 1c9b38872..289d6a351 100644
--- a/src/teleport.c
+++ b/src/teleport.c
@@ -128,7 +128,9 @@ unsigned entflags;
         /* default to player's original monster type */
         mdat = &mons[u.umonster];
     }
-    fakemon.data = mdat; /* set up for goodpos */
+    fakemon = zeromonst;
+    set_mon_data(&fakemon, mdat, -1); /* set up for goodpos */
+
     good_ptr = good;
     range = 1;
     /*