]> granicus.if.org Git - nethack/commitdiff
zeromonst
authorPatR <rankin@nethack.org>
Sat, 26 Mar 2016 23:42:24 +0000 (16:42 -0700)
committerPatR <rankin@nethack.org>
Sat, 26 Mar 2016 23:42:24 +0000 (16:42 -0700)
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

include/decl.h
src/decl.c
src/makemon.c
src/mkobj.c
src/mplayer.c
src/teleport.c

index 52145808e6f45fd0e3419488c5ceea0781dffe7d..7898d17ceb2a796258b2384822014bc9583fffa5 100644 (file)
@@ -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 {
index 944dbe36876b139c974ca82ab0bdb35d39f1004e..479c075aae1031d433dbf541d9a852f511edb903 100644 (file)
@@ -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;
 
index 9e2d5b9a603e171b9e5aa568151a9811da9d54a3..61de5af0e0b56783f0a18473ba2f3975d571320c 100644 (file)
@@ -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[];
 
index 6cb87e40bc77543ee2c5ab3f5aff02ee4e39312d..3574eaece6ac88d437268506cb4348943734da91 100644 (file)
@@ -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;
     }
 }
index c2178b07ff3cd5d6f6ffc613cae2cf1e5f422c90..de5a2d680692b4f46ebf4b72c8d177123435ceca 100644 (file)
@@ -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 {
index 1c9b388724498043f1e34720372964cc8bae61a7..289d6a35113eaba273f81881d058e5c7967e0c2d 100644 (file)
@@ -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;
     /*