more set_corpsenm (trunk only)

Use set_corpsenm() in a few more places.
This commit is contained in:
nethack.allison
2006-07-30 20:08:57 +00:00
parent 557f94c83a
commit 7f826cd288
8 changed files with 66 additions and 59 deletions

View 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));

View 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 */

View 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);

View 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]))

View File

@@ -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);

View 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);

View 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;
}

View File

@@ -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;
}
}