simplify unpunish()

unpunish() duplicated much of delobj() in order to use dealloc_obj().
Switch to delobj().  That required a fix to feel_location() when it
was called by savebones() after vision is turned disabled.
This commit is contained in:
PatR
2022-06-11 00:11:48 -07:00
parent 01fb6a703f
commit 7c732e64a0
2 changed files with 23 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 display.c $NHDT-Date: 1652391730 2022/05/12 21:42:10 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.183 $ */
/* NetHack 3.7 display.c $NHDT-Date: 1654931503 2022/06/11 07:11:43 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.184 $ */
/* Copyright (c) Dean Luick, with acknowledgements to Kevin Darcy */
/* and Dave Cohrs, 1990. */
/* NetHack may be freely redistributed. See license for details. */
@@ -769,19 +769,25 @@ feel_location(xchar x, xchar y)
* something has been dropped on the ball/chain. If the bit is
* not cleared, then when the ball/chain is moved it will drop
* the wrong glyph.
*
* Note: during unpunish() we can be called by delobj() when
* destroying uchain while uball hasn't been cleared yet (so
* Punished will still yield True but uchain might not be part
* of the floor list anymore).
*/
if (uchain->ox == x && uchain->oy == y) {
if (g.level.objects[x][y] == uchain)
u.bc_felt |= BC_CHAIN;
else
u.bc_felt &= ~BC_CHAIN; /* do not feel the chain */
}
if (!carried(uball) && uball->ox == x && uball->oy == y) {
if (g.level.objects[x][y] == uball)
u.bc_felt |= BC_BALL;
else
u.bc_felt &= ~BC_BALL; /* do not feel the ball */
}
if (uchain && uchain->where == OBJ_FLOOR
&& uchain->ox == x && uchain->oy == y
&& g.level.objects[x][y] == uchain)
u.bc_felt |= BC_CHAIN;
else
u.bc_felt &= ~BC_CHAIN; /* do not feel the chain */
if (uball && uball->where == OBJ_FLOOR
&& uball->ox == x && uball->oy == y
&& g.level.objects[x][y] == uball)
u.bc_felt |= BC_BALL;
else
u.bc_felt &= ~BC_BALL; /* do not feel the ball */
}
/* Floor spaces are dark if unlit. Corridors are dark if unlit. */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 read.c $NHDT-Date: 1637992351 2021/11/27 05:52:31 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.229 $ */
/* NetHack 3.7 read.c $NHDT-Date: 1654931501 2022/06/11 07:11:41 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.257 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
@@ -2833,11 +2833,10 @@ unpunish(void)
struct obj *savechain = uchain;
/* chain goes away */
obj_extract_self(uchain);
maybe_unhide_at(uchain->ox, uchain->oy);
newsym(uchain->ox, uchain->oy);
setworn((struct obj *) 0, W_CHAIN); /* sets 'uchain' to Null */
dealloc_obj(savechain);
/* for floor, unhides monster hidden under chain, calls newsym() */
delobj(savechain);
/* the chain is gone but the no longer attached ball persists */
setworn((struct obj *) 0, W_BALL); /* sets 'uball' to Null */
}