]> granicus.if.org Git - nethack/commitdiff
set_corpsenm()
authornethack.allison <nethack.allison>
Tue, 9 May 2006 23:10:22 +0000 (23:10 +0000)
committernethack.allison <nethack.allison>
Tue, 9 May 2006 23:10:22 +0000 (23:10 +0000)
Provide a common routine that always does the right
thing with respect to timers and weight when altering
obj->corpsenm, and use it throughout the code.

include/extern.h
src/mhitm.c
src/mkmaze.c
src/mkobj.c
src/sp_lev.c
src/topten.c
src/zap.c

index 700bff0926d4e40ed73ac0ffa3594edb231a12f0..5e1bb238390c4bda5270714324773f14462950ec 100644 (file)
@@ -1146,6 +1146,7 @@ E struct obj *FDECL(mk_tt_object, (int,int,int));
 E struct obj *FDECL(mk_named_object,
                        (int,struct permonst *,int,int,const char *));
 E struct obj *FDECL(rnd_treefruit_at, (int, int));
+E void FDECL(set_corpsenm, (struct obj *, int));
 E void FDECL(start_corpse_timeout, (struct obj *));
 E void FDECL(bless, (struct obj *));
 E void FDECL(unbless, (struct obj *));
index eaf960866b130cdf57f984f226397bd8755a9646..9d0fcd16ca38169d79ebda6b1138b3839fc95af0 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)mhitm.c    3.5     2005/12/02      */
+/*     SCCS Id: @(#)mhitm.c    3.5     2006/05/09      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -761,8 +761,7 @@ mdamagem(magr, mdef, mattk)
                    struct obj *virtualcorpse = mksobj(CORPSE, FALSE, FALSE);
                    int nutrit;
 
-                   virtualcorpse->corpsenm = num;
-                   virtualcorpse->owt = weight(virtualcorpse);
+                   set_corpsenm(virtualcorpse, num);
                    nutrit = dog_nutrition(magr, virtualcorpse);
                    dealloc_obj(virtualcorpse);
 
index 1589e6abef640067d7608db60b3e1ef11050b86a..24497f3e3a69fb51baa755a7a65c59d3d7c71f6d 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)mkmaze.c   3.5     2002/04/04      */
+/*     SCCS Id: @(#)mkmaze.c   3.5     2006/05/09      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -421,8 +421,8 @@ fixup_special()
                otmp = mk_tt_object(STATUE, x, y);
                while (otmp && (poly_when_stoned(&mons[otmp->corpsenm]) ||
                                pm_resistance(&mons[otmp->corpsenm],MR_STONE))) {
-                   otmp->corpsenm = rndmonnum();
-                   otmp->owt = weight(otmp);
+                   /* set_corpsenm() handles weight too */
+                   set_corpsenm(otmp, rndmonnum());
                }
            }
        }
@@ -435,8 +435,8 @@ fixup_special()
        if (otmp) {
            while (pm_resistance(&mons[otmp->corpsenm],MR_STONE)
                   || poly_when_stoned(&mons[otmp->corpsenm])) {
-               otmp->corpsenm = rndmonnum();
-               otmp->owt = weight(otmp);
+               /* set_corpsenm() handles weight too */
+               set_corpsenm(otmp, rndmonnum());
            }
        }
     } else if(Is_wiz1_level(&u.uz)) {
index f7268e51e3f9cba6a472fdc97b841b10a3b521d8..1f0e22273a5081c2d26fd0e8a841923b77889ef8 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)mkobj.c    3.5     2006/04/14      */
+/*     SCCS Id: @(#)mkobj.c    3.5     2006/05/09      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -857,6 +857,43 @@ boolean artif;
        return(otmp);
 }
 
+/*
+ * Several areas of the code made direct reassignments
+ * to obj->corpsenm. Because some special handling is
+ * required in certain cases, place that handling here
+ * and call this routine in place of the direct assignment.
+ * 
+ * If the object was a lizard or lichen corpse:
+ *     - ensure that you don't end up with some
+ *       other corpse type which has no rot-away timer.
+ *
+ * If the object was a troll corpse:
+ *     - ensure that you don't end up with some other
+ *       corpse type which resurrects from the dead.
+ *
+ * Re-calculate the weight of the object to suit the
+ * new species.
+ *
+ */
+void
+set_corpsenm(obj, id)
+struct obj *obj;
+int id;
+{
+       
+       if (obj->timed) obj_stop_timers(obj);   /* corpse or figurine */
+       obj->corpsenm = id;
+       if (obj->otyp == CORPSE) {
+               start_corpse_timeout(obj);
+       } else if (obj->otyp == FIGURINE) {
+               if (obj->corpsenm != NON_PM
+                   && !dead_species(obj->corpsenm,TRUE)
+                   && (carried(obj) || mcarried(obj)))
+                       attach_fig_transform_timeout(obj);
+       }
+       obj->owt = weight(obj);
+}
+
 /*
  * Start a corpse decay or revive timer.
  * This takes the age of the corpse into consideration as of 3.4.0.
index 149c7118c4b3c94a5bd3e48902e0184c52c0f4b1..04034e852679486f9eae3ba12cc3231c748b59a6 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)sp_lev.c   3.5     2006/01/28      */
+/*     SCCS Id: @(#)sp_lev.c   3.5     2006/05/09      */
 /*     Copyright (c) 1989 by Jean-Christophe Collet */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -981,23 +981,9 @@ struct mkroom      *croom;
 
        /*      corpsenm is "empty" if -1, random if -2, otherwise specific */
        if (o->corpsenm != NON_PM) {
-
-           /* Corpse was already created above, so the timers are
-            * appropriate for otmp->corpsenm at the time of creation.
-            * Since the next section is about to alter the type of
-            * corpse directly, the timers must be removed, then re-added
-            * afterwards.
-            *
-            * Failure to do so leads to inappropriate corpse types
-            * behaving like a lizard or lichen corpse (no timer), or
-            * behaving like a troll (revive timer).
-            */
-
-           if (otmp->otyp == CORPSE && otmp->timed) obj_stop_timers(otmp);
-           if (o->corpsenm == NON_PM - 1) otmp->corpsenm = rndmonnum();
-           else otmp->corpsenm = o->corpsenm;
-           if (otmp->otyp == CORPSE) start_corpse_timeout(otmp);
-           otmp->owt = weight(otmp);
+           if (o->corpsenm == NON_PM - 1)
+               set_corpsenm(otmp, rndmonnum());
+           else set_corpsenm(otmp, o->corpsenm);
        }
 
        /* assume we wouldn't be given an egg corpsenm unless it was
@@ -1058,7 +1044,7 @@ struct mkroom     *croom;
                }
                mongone(was);
            }
-           otmp->corpsenm = wastyp;
+           set_corpsenm(otmp, wastyp);
            while(was->minvent) {
                obj = was->minvent;
                obj->owornmask = 0;
index fd15e24c241d42cb6264cbf08eeba27f2d186af8..562d5910f82e679092ea2115ca21119cf041568d 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)topten.c   3.5     2000/01/21      */
+/*     SCCS Id: @(#)topten.c   3.5     2006/05/09      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -943,12 +943,9 @@ pickentry:
                }
                otmp = (struct obj *) 0;
        } else {
-               /* reset timer in case corpse started out as lizard or troll */
-               if (otmp->otyp == CORPSE) obj_stop_timers(otmp);
-               otmp->corpsenm = classmon(tt->plrole, (tt->plgend[0] == 'F'));
-               otmp->owt = weight(otmp);
+               set_corpsenm(otmp,
+                       classmon(tt->plrole, (tt->plgend[0] == 'F')));
                otmp = oname(otmp, tt->name);
-               if (otmp->otyp == CORPSE) start_corpse_timeout(otmp);
        }
 
        (void) fclose(rfile);
index 67c25842e7802ba1474786d9c4d957b7f98eb4a4..b47cf7211a2f48c546139f1c9f82d1d416bca582 100644 (file)
--- a/src/zap.c
+++ b/src/zap.c
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)zap.c      3.5     2006/04/17      */
+/*     SCCS Id: @(#)zap.c      3.5     2006/05/09      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -1283,7 +1283,7 @@ poly_obj(obj, id)
        /* Actually more things use corpsenm but they polymorph differently */
 #define USES_CORPSENM(typ) ((typ)==CORPSE || (typ)==STATUE || (typ)==FIGURINE)
            if (USES_CORPSENM(obj->otyp) && USES_CORPSENM(id))
-               otmp->corpsenm = obj->corpsenm;
+               set_corpsenm(otmp, obj->corpsenm);
 #undef USES_CORPSENM
        }