Use set_corpsenm() in a few more places.
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));
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 */
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) */
/* 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;
}
* - 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);
}
/*
if (tleft != 0L) {
long age;
- tleft = tleft - monstermoves;
/* mark the corpse as being on ice */
otmp->on_ice = 1;
#ifdef DEBUG_EFFECTS
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);
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:
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]))
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);
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);
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;
* 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 */
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 {
/*
* 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)
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;
}
*/
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' */
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;
}
}