]> granicus.if.org Git - nethack/commitdiff
more set_corpsenm (trunk only)
authornethack.allison <nethack.allison>
Sun, 30 Jul 2006 20:08:57 +0000 (20:08 +0000)
committernethack.allison <nethack.allison>
Sun, 30 Jul 2006 20:08:57 +0000 (20:08 +0000)
Use set_corpsenm() in a few more places.

include/extern.h
src/bones.c
src/mkobj.c
src/objnam.c
src/sit.c
src/sp_lev.c
src/timeout.c
src/zap.c

index a30970ebff27ad27248e2dbfeefdf901b2d0f57d..40fd60b95218977fa57437b60d560f45078a6c7d 100644 (file)
@@ -2115,7 +2115,7 @@ E void FDECL(substitute_tiles, (d_level *));
 E void NDECL(burn_away_slime);
 E void NDECL(nh_timeout);
 E void FDECL(fall_asleep, (int, BOOLEAN_P));
-E void FDECL(attach_egg_hatch_timeout, (struct obj *));
+E void FDECL(attach_egg_hatch_timeout, (struct obj *, long));
 E void FDECL(attach_fig_transform_timeout, (struct obj *));
 E void FDECL(kill_egg, (struct obj *));
 E void FDECL(hatch_egg, (ANY_P *, long));
index df182e6ee833f7b709e0dc9569c84435e6be11b3..69ebf1da9c4d5020793b02331c0e346df19a7915 100644 (file)
@@ -137,7 +137,7 @@ boolean restore;
                                   would behave as if it remains unique */
                                if (mnum == PM_DOPPELGANGER &&
                                        otmp->otyp == CORPSE)
-                                   otmp->corpsenm = mnum;
+                                   set_corpsenm(otmp, mnum);
                            }
                        } else if (otmp->otyp == AMULET_OF_YENDOR) {
                            /* no longer the real Amulet */
index d3cb373d99bd9d0009d013fd2aaec7622dd3180b..d7f487a2eabc1abe676334d0adb5f9ff4b134d6b 100644 (file)
@@ -648,10 +648,10 @@ boolean artif;
                    mndx = can_be_hatched(rndmonnum());
                    if (mndx != NON_PM && !dead_species(mndx, TRUE)) {
                        otmp->corpsenm = mndx;          /* typed egg */
-                       attach_egg_hatch_timeout(otmp);
                        break;
                    }
                }
+               /* timer set below */
                break;
            case TIN:
                otmp->corpsenm = NON_PM;        /* empty (so far) */
@@ -846,7 +846,9 @@ boolean artif;
        /* Some things must get done (timers) even if init = 0 */
        switch (otmp->otyp) {
            case CORPSE:
-               start_corpse_timeout(otmp);
+           case EGG:
+           case FIGURINE:
+               set_corpsenm(otmp, otmp->corpsenm);
                break;
        }
 
@@ -871,27 +873,49 @@ boolean artif;
  *     - 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
+ * Re-calculates the weight of figurines and corpses to suit the
  * new species.
  *
+ * Existing timeout value for egg hatch is preserved.
+ *
  */
 void
 set_corpsenm(obj, id)
 struct obj *obj;
 int id;
 {
-       
-       if (obj->timed) obj_stop_timers(obj);   /* corpse or figurine */
+       long when = 0L;
+
+       if (obj->timed) {
+           if (obj->otyp == EGG)
+               when = stop_timer(HATCH_EGG, obj_to_any(obj));
+           else {
+               when = 0L;
+               obj_stop_timers(obj);   /* corpse or figurine */
+           }
+       }
        obj->corpsenm = id;
-       if (obj->otyp == CORPSE) {
+       switch(obj->otyp) {
+           case CORPSE:
                start_corpse_timeout(obj);
-       } else if (obj->otyp == FIGURINE) {
+               obj->owt = weight(obj);
+               break;
+           case FIGURINE:
                if (obj->corpsenm != NON_PM
                    && !dead_species(obj->corpsenm,TRUE)
                    && (carried(obj) || mcarried(obj)))
                        attach_fig_transform_timeout(obj);
+               obj->owt = weight(obj);
+               break;
+           case EGG:
+               if (obj->corpsenm != NON_PM
+                   && !dead_species(obj->corpsenm,TRUE))
+                       attach_egg_hatch_timeout(obj, when);
+               break;
+           default:    /* tin, etc. */
+               obj->owt = weight(obj);
+               break;
        }
-       obj->owt = weight(obj);
 }
 
 /*
@@ -1469,7 +1493,6 @@ int force;        /* 0 = no force so do checks, <0 = force off, >0 force on */
        if (tleft != 0L) {
            long age;
            
-           tleft = tleft - monstermoves;
            /* mark the corpse as being on ice */
            otmp->on_ice = 1;
 #ifdef DEBUG_EFFECTS
@@ -1495,7 +1518,6 @@ int force;        /* 0 = no force so do checks, <0 = force off, >0 force on */
        if (tleft != 0L) {
                long age;
 
-               tleft = tleft - monstermoves;
                otmp->on_ice = 0;
 #ifdef DEBUG_EFFECTS
                pline("%s is no longer on ice at %d,%d.", The(xname(otmp)),x,y);
index b017c0535988ef7b96cc64b4dffe117dc81c2c95..623057ad2f362f1777af134a58e9ad6cc23f4674 100644 (file)
@@ -2787,14 +2787,9 @@ typfnd:
                case CORPSE:
                        if (!(mons[mntmp].geno & G_UNIQ) &&
                                   !(mvitals[mntmp].mvflags & G_NOCORPSE)) {
-                           /* beware of random troll or lizard corpse,
-                              or of ordinary one being forced to such */
-                           if (otmp->timed) obj_stop_timers(otmp);
                            if (mons[mntmp].msound == MS_GUARDIAN)
-                               otmp->corpsenm = genus(mntmp,1);
-                           else
-                               otmp->corpsenm = mntmp;
-                           start_corpse_timeout(otmp);
+                               mntmp = genus(mntmp,1);
+                           set_corpsenm(otmp, mntmp);
                        }
                        break;
                case FIGURINE:
@@ -2808,13 +2803,8 @@ typfnd:
                        break;
                case EGG:
                        mntmp = can_be_hatched(mntmp);
-                       if (mntmp != NON_PM) {
-                           otmp->corpsenm = mntmp;
-                           if (!dead_species(mntmp, TRUE))
-                               attach_egg_hatch_timeout(otmp);
-                           else
-                               kill_egg(otmp);
-                       }
+                       /* this also sets hatch timer if appropriate */
+                       set_corpsenm(otmp, mntmp);
                        break;
                case STATUE: otmp->corpsenm = mntmp;
                        if (Has_contents(otmp) && verysmall(&mons[mntmp]))
index 1eea68bb5a4815f131869135db48f93f2254ef6b..572b0c4ddf895ec7f6853a06d9cdf933028f1b09 100644 (file)
--- a/src/sit.c
+++ b/src/sit.c
@@ -303,9 +303,9 @@ dosit()
                uegg->spe = 1;
                uegg->quan = 1L;
                uegg->owt = weight(uegg);
-               uegg->corpsenm = egg_type_from_parent(u.umonnum, FALSE);
+               /* this sets hatch timers if appropriate */
+               set_corpsenm(uegg, egg_type_from_parent(u.umonnum, FALSE));
                uegg->known = uegg->dknown = 1;
-               attach_egg_hatch_timeout(uegg);
                You("lay an egg.");
                dropy(uegg);
                stackobj(uegg);
index 04034e852679486f9eae3ba12cc3231c748b59a6..2194b384f271c46826f0aca14096db36dde6748f 100644 (file)
@@ -983,17 +983,9 @@ struct mkroom      *croom;
        if (o->corpsenm != NON_PM) {
            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
-          hatchable */
-       if (otmp->otyp == EGG && otmp->corpsenm != NON_PM) {
-           if (dead_species(otmp->otyp, TRUE))
-               kill_egg(otmp); /* make sure nothing hatches */
-           else
-               attach_egg_hatch_timeout(otmp); /* attach new hatch timeout */
+           else set_corpsenm(otmp, o->corpsenm); 
        }
+       /* set_corpsenm() took care of egg hatch and corpse timers */
 
        if (named)
            otmp = oname(otmp, o->name.str);
index cac960036008d28afdea472c1653ad5eee32a147..0a73ad20422844f6dfb553ac621735f8473bb8bb 100644 (file)
@@ -397,10 +397,14 @@ boolean wakeup_msg;
        nomovemsg = wakeup_msg ? "You wake up." : You_can_move_again;
 }
 
-/* Attach an egg hatch timeout to the given egg. */
+/* Attach an egg hatch timeout to the given egg.
+ *     when = Time to hatch, usually only passed if re-creating an
+ *            existing hatch timer. Pass 0L for random hatch time.
+ */
 void
-attach_egg_hatch_timeout(egg)
+attach_egg_hatch_timeout(egg, when)
 struct obj *egg;
+long when;
 {
        int i;
 
@@ -413,13 +417,18 @@ struct obj *egg;
         * a number x, 1<=x<=age, where x>150.  This yields a chance of
         * hatching > 99.9993%.  Mimic that here.
         */
-       for (i = (MAX_EGG_HATCH_TIME-50)+1; i <= MAX_EGG_HATCH_TIME; i++)
-           if (rnd(i) > 150) {
-               /* egg will hatch */
-               (void) start_timer((long)i, TIMER_OBJECT,
-                                               HATCH_EGG, obj_to_any(egg));
-               break;
-           }
+       if (!when) {
+           for (i = (MAX_EGG_HATCH_TIME-50)+1; i <= MAX_EGG_HATCH_TIME; i++)
+               if (rnd(i) > 150) {
+                       /* egg will hatch */
+                       when = (long)i;
+                       break;
+               }
+       }
+       if (when) {
+           (void) start_timer(when, TIMER_OBJECT,
+                               HATCH_EGG, obj_to_any(egg));
+       }
 }
 
 /* prevent an egg from ever hatching */
@@ -584,13 +593,8 @@ long timeout;
 
            if (egg->quan > 0) {
                /* still some eggs left */
-               attach_egg_hatch_timeout(egg);
-               if (egg->timed) {
-                   /* replace ordinary egg timeout with a short one */
-                   (void) stop_timer(HATCH_EGG, obj_to_any(egg));
-                   (void) start_timer((long)rnd(12), TIMER_OBJECT,
-                                       HATCH_EGG, obj_to_any(egg));
-               }
+               /* Instead of ordinary egg timeout use a short one */
+               attach_egg_hatch_timeout(egg, (long)rnd(12));
            } else if (carried(egg)) {
                useup(egg);
            } else {
@@ -1492,7 +1496,7 @@ anything *arg;
 
 /*
  * Remove the timer from the current list and free it up.  Return the time
- * it would have gone off, 0 if not found.
+ * remaining until it would have gone off, 0 if not found.
  */
 long
 stop_timer(func_index, arg)
@@ -1511,7 +1515,7 @@ anything *arg;
        if (timeout_funcs[doomed->func_index].cleanup)
            (*timeout_funcs[doomed->func_index].cleanup)(arg, timeout);
        free((genericptr_t) doomed);
-       return timeout;
+       return (timeout - monstermoves);
     }
     return 0L;
 }
index b4843b7aca9a75e79712bad47a57fe31fefcc9d5..d187e01cb7626f1a267e76a9e2c3c77e1a60c9cf 100644 (file)
--- a/src/zap.c
+++ b/src/zap.c
@@ -820,7 +820,7 @@ struct obj *obj;
         */
        if (obj->otyp != EGG) return;
        if (obj->corpsenm != NON_PM && !dead_species(obj->corpsenm, TRUE))
-           attach_egg_hatch_timeout(obj);
+           attach_egg_hatch_timeout(obj, 0L);
 }
 
 /* try to revive all corpses and eggs carried by `mon' */
@@ -1323,8 +1323,7 @@ poly_obj(obj, id)
                    mnum = can_be_hatched(random_monster());
                    if (mnum != NON_PM && !dead_species(mnum, TRUE)) {
                        otmp->spe = 1;  /* layed by hero */
-                       otmp->corpsenm = mnum;
-                       attach_egg_hatch_timeout(otmp);
+                       set_corpsenm(otmp, mnum);       /* also sets hatch timer */
                        break;
                    }
                }