controlling u.ustuck

Setting or clearing u.ustuck now requires that context.botl be set,
so make a new routine to take care of both instead of manipulating
that pointer directly.
This commit is contained in:
PatR
2020-02-16 13:04:12 -08:00
parent c7ec28f4c7
commit 3981e3e6e5
15 changed files with 71 additions and 57 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 apply.c $NHDT-Date: 1580476196 2020/01/31 13:09:56 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.316 $ */
/* NetHack 3.6 apply.c $NHDT-Date: 1581886857 2020/02/16 21:00:57 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.317 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1721,8 +1721,10 @@ int magic; /* 0=Physical, otherwise skill level */
return 0;
} else if (u.ustuck) {
if (u.ustuck->mtame && !Conflict && !u.ustuck->mconf) {
You("pull free from %s.", mon_nam(u.ustuck));
u.ustuck = 0;
struct monst *mtmp = u.ustuck;
set_ustuck((struct monst *) 0);
You("pull free from %s.", mon_nam(mtmp));
return 1;
}
if (magic) {

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 artifact.c $NHDT-Date: 1577662239 2019/12/29 23:30:39 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.152 $ */
/* NetHack 3.6 artifact.c $NHDT-Date: 1581886858 2020/02/16 21:00:58 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.153 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2013. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1061,7 +1061,7 @@ char *hittee; /* target's name: "you" or mon_nam(mdef) */
g.multi_reason = "being scared stiff";
g.nomovemsg = "";
if (magr && magr == u.ustuck && sticks(g.youmonst.data)) {
u.ustuck = (struct monst *) 0;
set_ustuck((struct monst *) 0);
You("release %s!", mon_nam(magr));
}
}

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 cmd.c $NHDT-Date: 1581322659 2020/02/10 08:17:39 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.398 $ */
/* NetHack 3.6 cmd.c $NHDT-Date: 1581886858 2020/02/16 21:00:58 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.400 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2013. */
/* NetHack may be freely redistributed. See license for details. */
@@ -824,7 +824,7 @@ boolean pre, wiztower;
reset_utrap(FALSE);
check_special_room(TRUE); /* room exit */
u.ustuck = (struct monst *) 0;
u.uswallow = 0;
u.uswallow = u.uswldtim = 0;
u.uinwater = 0;
u.uundetected = 0; /* not hidden, even if means are available */
dmonsfree(); /* purge dead monsters from 'fmon' */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 do.c $NHDT-Date: 1581810044 2020/02/15 23:40:44 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.226 $ */
/* NetHack 3.6 do.c $NHDT-Date: 1581886859 2020/02/16 21:00:59 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.227 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1373,12 +1373,11 @@ boolean at_stairs, falling, portal;
unplacebc();
reset_utrap(FALSE); /* needed in level_tele */
fill_pit(u.ux, u.uy);
u.ustuck = 0; /* idem */
set_ustuck((struct monst *) 0); /* idem */
u.uswallow = u.uswldtim = 0;
u.uinwater = 0;
u.uundetected = 0; /* not hidden, even if means are available */
keepdogs(FALSE);
if (u.uswallow) /* idem */
u.uswldtim = u.uswallow = 0;
recalc_mapseen(); /* recalculate map overview before we leave the level */
/*
* We no longer see anything on the level. Make sure that this

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 hack.c $NHDT-Date: 1581810065 2020/02/15 23:41:05 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.247 $ */
/* NetHack 3.6 hack.c $NHDT-Date: 1581886860 2020/02/16 21:01:00 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.248 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1537,13 +1537,14 @@ domove_core()
if (u.ustuck && (x != u.ustuck->mx || y != u.ustuck->my)) {
if (distu(u.ustuck->mx, u.ustuck->my) > 2) {
/* perhaps it fled (or was teleported or ... ) */
u.ustuck = 0;
set_ustuck((struct monst *) 0);
} else if (sticks(g.youmonst.data)) {
/* When polymorphed into a sticking monster,
* u.ustuck means it's stuck to you, not you to it.
*/
You("release %s.", mon_nam(u.ustuck));
u.ustuck = 0;
mtmp = u.ustuck;
set_ustuck((struct monst *) 0);
You("release %s.", mon_nam(mtmp));
} else {
/* If holder is asleep or paralyzed:
* 37.5% chance of getting away,
@@ -1559,8 +1560,9 @@ domove_core()
case 1:
case 2:
pull_free:
You("pull free from %s.", mon_nam(u.ustuck));
u.ustuck = 0;
mtmp = u.ustuck;
set_ustuck((struct monst *) 0);
You("pull free from %s.", mon_nam(mtmp));
break;
case 3:
if (!u.ustuck->mcanmove) {

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 mhitm.c $NHDT-Date: 1573773926 2019/11/14 23:25:26 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.118 $ */
/* NetHack 3.6 mhitm.c $NHDT-Date: 1581886861 2020/02/16 21:01:01 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.130 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2011. */
/* NetHack may be freely redistributed. See license for details. */
@@ -146,8 +146,8 @@ register struct monst *mtmp;
if (monnear(mtmp, mon->mx, mon->my)) {
if (!u.uswallow && (mtmp == u.ustuck)) {
if (!rn2(4)) {
set_ustuck((struct monst *) 0);
pline("%s releases you!", Monnam(mtmp));
u.ustuck = 0;
} else
break;
}

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 mhitu.c $NHDT-Date: 1581810070 2020/02/15 23:41:10 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.182 $ */
/* NetHack 3.6 mhitu.c $NHDT-Date: 1581886862 2020/02/16 21:01:02 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.183 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
@@ -534,7 +534,7 @@ register struct monst *mtmp;
pline("Wait, %s! That's a %s named %s!", m_monnam(mtmp),
g.youmonst.data->mname, g.plname);
if (sticky)
u.ustuck = mtmp;
set_ustuck(mtmp);
g.youmonst.m_ap_type = M_AP_NOTHING;
g.youmonst.mappearance = 0;
newsym(u.ux, u.uy);
@@ -973,7 +973,7 @@ register struct attack *mattk;
if (u_slip_free(mtmp, mattk)) {
dmg = 0;
} else {
u.ustuck = mtmp;
set_ustuck(mtmp);
pline("%s grabs you!", Monnam(mtmp));
}
} else if (u.ustuck == mtmp) {
@@ -1269,8 +1269,7 @@ register struct attack *mattk;
case AD_STCK:
hitmsg(mtmp, mattk);
if (uncancelled && !u.ustuck && !sticks(g.youmonst.data)) {
g.context.botl = 1;
u.ustuck = mtmp;
set_ustuck(mtmp);
}
break;
case AD_WRAP:
@@ -1279,9 +1278,8 @@ register struct attack *mattk;
if (u_slip_free(mtmp, mattk)) {
dmg = 0;
} else {
g.context.botl = 1;
set_ustuck(mtmp); /* before message, for botl update */
pline("%s swings itself around you!", Monnam(mtmp));
u.ustuck = mtmp;
}
} else if (u.ustuck == mtmp) {
if (is_pool(mtmp->mx, mtmp->my) && !Swimming && !Amphibious) {
@@ -1296,8 +1294,9 @@ register struct attack *mattk;
moat ? "moat" : "pool of water",
an(mtmp->data->mname));
done(DROWNING);
} else if (mattk->aatyp == AT_HUGS)
} else if (mattk->aatyp == AT_HUGS) {
You("are being crushed.");
}
} else {
dmg = 0;
if (flags.verbose)
@@ -1801,7 +1800,7 @@ struct attack *mattk;
remove_monster(omx, omy);
mtmp->mtrapped = 0; /* no longer on old trap */
place_monster(mtmp, u.ux, u.uy);
u.ustuck = mtmp;
set_ustuck(mtmp);
newsym(mtmp->mx, mtmp->my);
if (is_animal(mtmp->data) && u.usteed) {
char buf[BUFSZ];
@@ -1814,8 +1813,9 @@ struct attack *mattk;
pline("%s lunges forward and plucks you off %s!", Monnam(mtmp),
buf);
dismount_steed(DISMOUNT_ENGULFED);
} else
} else {
pline("%s engulfs you!", Monnam(mtmp));
}
stop_occupation();
reset_occupations(); /* behave as if you had moved */
@@ -1843,7 +1843,7 @@ struct attack *mattk;
fully swallowed yet so that won't work here */
if (Punished)
placebc();
u.ustuck = 0;
set_ustuck((struct monst *) 0);
return (!DEADMONSTER(mtmp)) ? 0 : 2;
}
@@ -1869,7 +1869,7 @@ struct attack *mattk;
}
/* u.uswldtim always set > 1 */
u.uswldtim = (unsigned) ((tim_tmp < 2) ? 2 : tim_tmp);
swallowed(1);
swallowed(1); /* update the map display, shows hero swallowed */
for (otmp2 = g.invent; otmp2; otmp2 = otmp2->nobj)
(void) snuff_lit(otmp2);
}

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 mon.c $NHDT-Date: 1581810072 2020/02/15 23:41:12 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.323 $ */
/* NetHack 3.6 mon.c $NHDT-Date: 1581886863 2020/02/16 21:01:03 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.324 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1683,7 +1683,7 @@ struct monst *mtmp, *mtmp2;
mtmp2->nmon = fmon;
fmon = mtmp2;
if (u.ustuck == mtmp)
u.ustuck = mtmp2;
set_ustuck(mtmp2);
if (u.usteed == mtmp)
u.usteed = mtmp2;
if (mtmp2->isshk)
@@ -2314,15 +2314,23 @@ int how;
mondied(mdef);
}
void
set_ustuck(mtmp)
struct monst *mtmp;
{
g.context.botl = 1;
u.ustuck = mtmp;
}
void
unstuck(mtmp)
struct monst *mtmp;
{
if (u.ustuck == mtmp) {
g.context.botl = 1;
/* do this first so that docrt()'s botl update is accurate;
safe to do as long as u.uswallow is also cleared before docrt() */
u.ustuck = (struct monst *) 0;
set_ustuck((struct monst *) 0);
if (u.uswallow) {
u.ux = mtmp->mx;
u.uy = mtmp->my;

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 polyself.c $NHDT-Date: 1579660157 2020/01/22 02:29:17 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.149 $ */
/* NetHack 3.6 polyself.c $NHDT-Date: 1581886864 2020/02/16 21:01:04 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.150 $ */
/* Copyright (C) 1987, 1988, 1989 by Ken Arromdee */
/* NetHack may be freely redistributed. See license for details. */
@@ -767,7 +767,7 @@ int mntmp;
grabber to engulfer or vice versa because engulfing by poly'd hero
always ends immediately so won't be in effect during a polymorph] */
if (!sticky && !u.uswallow && u.ustuck && sticks(g.youmonst.data))
u.ustuck = 0;
set_ustuck((struct monst *) 0);
else if (sticky && !sticks(g.youmonst.data))
uunstick();
@@ -1622,12 +1622,14 @@ domindblast()
void
uunstick()
{
if (!u.ustuck) {
struct monst *mtmp = u.ustuck;
if (!mtmp) {
impossible("uunstick: no ustuck?");
return;
}
pline("%s is no longer in your clutches.", Monnam(u.ustuck));
u.ustuck = 0;
set_ustuck((struct monst *) 0); /* before pline() */
pline("%s is no longer in your clutches.", Monnam(mtmp));
}
void

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 restore.c $NHDT-Date: 1575245087 2019/12/02 00:04:47 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.136 $ */
/* NetHack 3.7 restore.c $NHDT-Date: 1581886865 2020/02/16 21:01:05 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.163 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2009. */
/* NetHack may be freely redistributed. See license for details. */
@@ -775,7 +775,7 @@ unsigned int stuckid, steedid;
break;
if (!mtmp)
panic("Cannot find the monster ustuck.");
u.ustuck = mtmp;
set_ustuck(mtmp);
}
if (steedid) {
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 save.c $NHDT-Date: 1559994625 2019/06/08 11:50:25 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.121 $ */
/* NetHack 3.6 save.c $NHDT-Date: 1581886866 2020/02/16 21:01:06 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.153 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2009. */
/* NetHack may be freely redistributed. See license for details. */
@@ -216,7 +216,7 @@ dosave0()
/* these pointers are no longer valid, and at least u.usteed
* may mislead place_monster() on other levels
*/
u.ustuck = (struct monst *) 0;
set_ustuck((struct monst *) 0);
u.usteed = (struct monst *) 0;
for (ltmp = (xchar) 1; ltmp <= maxledgerno(); ltmp++) {

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 teleport.c $NHDT-Date: 1581210886 2020/02/09 01:14:46 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.112 $ */
/* NetHack 3.6 teleport.c $NHDT-Date: 1581886867 2020/02/16 21:01:07 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.113 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2011. */
/* NetHack may be freely redistributed. See license for details. */
@@ -323,7 +323,7 @@ int teleds_flags;
}
}
reset_utrap(FALSE);
u.ustuck = 0;
set_ustuck((struct monst *) 0);
u.ux0 = u.ux;
u.uy0 = u.uy;

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 trap.c $NHDT-Date: 1578624299 2020/01/10 02:44:59 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.349 $ */
/* NetHack 3.6 trap.c $NHDT-Date: 1581886868 2020/02/16 21:01:08 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.351 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2013. */
/* NetHack may be freely redistributed. See license for details. */
@@ -2987,7 +2987,7 @@ long hmask, emask; /* might cancel timeout */
else
pline("Startled, %s can no longer hold you!",
mon_nam(u.ustuck));
u.ustuck = 0;
set_ustuck((struct monst *) 0);
}
/* kludge alert:
* drown() and lava_effects() print various messages almost

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 uhitm.c $NHDT-Date: 1573764936 2019/11/14 20:55:36 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.215 $ */
/* NetHack 3.6 uhitm.c $NHDT-Date: 1581886869 2020/02/16 21:01:09 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.227 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
@@ -145,7 +145,7 @@ struct obj *wep; /* uwep for attack(), null for kick_monster() */
/* applied pole-arm attack is too far to get stuck */
&& distu(mtmp->mx, mtmp->my) <= 2) {
if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK))
u.ustuck = mtmp;
set_ustuck(mtmp);
}
/* #H7329 - if hero is on engraved "Elbereth", this will end up
* assessing an alignment penalty and removing the engraving
@@ -495,7 +495,7 @@ int dieroll;
monflee(mon, !rn2(3) ? rnd(100) : 0, FALSE, TRUE);
if (u.ustuck == mon && !u.uswallow && !sticks(g.youmonst.data))
u.ustuck = 0;
set_ustuck((struct monst *) 0);
}
/* Vorpal Blade hit converted to miss */
/* could be headless monster or worm tail */
@@ -1933,7 +1933,7 @@ int specialdmg; /* blessed and/or silver bonus against various things */
tmp = 0;
} else {
You("swing yourself around %s!", mon_nam(mdef));
u.ustuck = mdef;
set_ustuck(mdef);
}
} else if (u.ustuck == mdef) {
/* Monsters don't wear amulets of magical breathing */
@@ -2631,7 +2631,7 @@ register struct monst *mon;
if (u.ustuck && u.ustuck != mon)
uunstick();
You("grab %s!", mon_nam(mon));
u.ustuck = mon;
set_ustuck(mon);
if (silverhit && flags.verbose)
silver_sears(&g.youmonst, mon, silverhit);
sum[i] = damageum(mon, mattk, specialdmg);
@@ -3042,7 +3042,7 @@ struct monst *mtmp;
const char *fmt = "Wait! That's %s!", *generic = "a monster", *what = 0;
if (!u.ustuck && !mtmp->mflee && dmgtype(mtmp->data, AD_STCK))
u.ustuck = mtmp;
set_ustuck(mtmp);
if (Blind) {
if (!Blind_telepat)