more wormgone

When wormgone() takes a long worm off the map, clear its stale mx,my
coordinates.  None of its callers need those anymore.

Also a bit of potential long worm clean up that occurred to me when
I looked at object bypass handling.  Expected to be a no-op here.
This commit is contained in:
PatR
2022-05-14 18:10:42 -07:00
parent ef08773f2b
commit 3a0a92764a
3 changed files with 29 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 dog.c $NHDT-Date: 1652524227 2022/05/14 10:30:27 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.119 $ */
/* NetHack 3.7 dog.c $NHDT-Date: 1652577033 2022/05/15 01:10:33 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.120 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2011. */
/* NetHack may be freely redistributed. See license for details. */
@@ -609,9 +609,7 @@ mon_leave(struct monst *mtmp)
more segments than can fit in that field gets truncated */
num_segs = min(cnt, MAX_NUM_WORMS - 1);
wormgone(mtmp); /* discard tail segments, take head off map */
/* this used to be place_monster() but relmon() doesn't
need that as long as coordinates reflect actual state */
mtmp->mx = mtmp->my = 0; /* off normal map */
/* mtmp->mx,mtmp->my is now 0,0 */
}
return num_segs;
@@ -722,14 +720,13 @@ migrate_to_level(
xchar xyflags, mx = mtmp->mx, my = mtmp->my; /* <mx,my> needed below */
int num_segs; /* count of worm segments */
/* prepare to take mtmp off the map */
num_segs = mon_leave(mtmp);
if (mtmp->mleashed) {
mtmp->mtame--;
m_unleash(mtmp, TRUE);
}
/* prepare to take mtmp off the map */
num_segs = mon_leave(mtmp);
/* take off map and move mtmp from fmon list to migrating_mons */
relmon(mtmp, &g.migrating_mons); /* mtmp->mx,my get changed to 0,0 */
mtmp->mstate |= MON_MIGRATING;

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 worm.c $NHDT-Date: 1608236444 2020/12/17 20:20:44 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.49 $ */
/* NetHack 3.7 worm.c $NHDT-Date: 1652577033 2022/05/15 01:10:33 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.55 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2009. */
/* NetHack may be freely redistributed. See license for details. */
@@ -297,23 +297,38 @@ worm_nomove(struct monst *worm)
/*
* wormgone()
*
* Check for mon->wormno before calling this function!
* Kill a worm tail. Also takes the head off the map. Caller needs to
* keep track of what its coordinates were if planning to put it back.
*
* Kill a worm tail.
* Should only be called when mon->wormno is non-zero.
*/
void
wormgone(struct monst *worm)
{
int wnum = worm->wormno;
worm->wormno = 0;
/* This will also remove the real monster (ie 'w') from the its
* position in level.monsters[][].
if (!wnum) /* note: continuing with wnum==0 runs to completion */
impossible("wormgone: wormno is 0");
worm->wormno = 0; /* still a long worm but doesn't grow/shrink anymore */
/*
* This will also remove the real monster (ie 'w') from the its
* position in level.monsters[][]. (That happens when removing
* the hidden tail segment which is co-located with the head.)
*/
toss_wsegs(wtails[wnum], TRUE);
worm->mx = worm->my = 0; /* 'worm' is no longer on map but has not
* been killed off; caller might put it back */
wheads[wnum] = wtails[wnum] = (struct wseg *) 0;
wgrowtime[wnum] = 0L;
/* we don't expect to encounter this here but check for it anyway;
when a long worm gets created by a polymorph zap, it gets flagged
with MCORPSENM()==PM_LONG_WORM so that the same zap won't trigger
another polymorph if it hits the new tail */
if (worm->data == &mons[PM_LONG_WORM] && has_mcorpsenm(worm))
MCORPSENM(worm) = NON_PM; /* not polymorph-proof */
}
/*

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 worn.c $NHDT-Date: 1649529637 2022/04/09 18:40:37 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.82 $ */
/* NetHack 3.7 worn.c $NHDT-Date: 1652577035 2022/05/15 01:10:35 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.84 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2013. */
/* NetHack may be freely redistributed. See license for details. */
@@ -860,8 +860,9 @@ bypass_obj(struct obj *obj)
/* set or clear the bypass bit in a list of objects */
void
bypass_objlist(struct obj *objchain,
boolean on) /* TRUE => set, FALSE => clear */
bypass_objlist(
struct obj *objchain,
boolean on) /* TRUE => set, FALSE => clear */
{
if (on && objchain)
g.context.bypasses = TRUE;