wornarm_destroyed() vs destroy_arm()

Refine the fix #K3888 by moving multiple instances of the check for
cancel_don() from destroy_arm() to one instance in wornarm_destroyed().
Should be no change in behavior.
This commit is contained in:
PatR
2023-03-20 22:59:16 -07:00
parent 3ce02acbc5
commit a77aef09d7
+35 -38
View File
@@ -1529,11 +1529,17 @@ cancel_don(void)
{ {
/* the piece of armor we were donning/doffing has vanished, so stop /* the piece of armor we were donning/doffing has vanished, so stop
* wasting time on it (and don't dereference it when donning would * wasting time on it (and don't dereference it when donning would
* otherwise finish) * otherwise finish); afternmv never has some of these values because
* every item of the corresponding armor category takes 1 turn to wear,
* but check all of them anyway
*/ */
gc.context.takeoff.cancelled_don = gc.context.takeoff.cancelled_don = (ga.afternmv == Cloak_on
(ga.afternmv == Boots_on || ga.afternmv == Helmet_on || ga.afternmv == Armor_on
|| ga.afternmv == Gloves_on || ga.afternmv == Armor_on); || ga.afternmv == Shirt_on
|| ga.afternmv == Helmet_on
|| ga.afternmv == Gloves_on
|| ga.afternmv == Boots_on
|| ga.afternmv == Shield_on);
ga.afternmv = (int (*)(void)) 0; ga.afternmv = (int (*)(void)) 0;
gn.nomovemsg = (char *) 0; gn.nomovemsg = (char *) 0;
gm.multi = 0; gm.multi = 0;
@@ -2947,6 +2953,12 @@ wornarm_destroyed(struct obj *wornarm)
struct obj *invobj; struct obj *invobj;
unsigned wornoid = wornarm->o_id; unsigned wornoid = wornarm->o_id;
/* cancel_don() resets 'afternmv' when appropriate but doesn't reset
uarmc/uarm/&c so doing this now won't interfere with the tests in
'if (wornarm==uarmc) ... else if (wornarm==uarm) ... else ...' */
if (donning(wornarm))
cancel_don();
if (wornarm == uarmc) if (wornarm == uarmc)
(void) Cloak_off(); (void) Cloak_off();
else if (wornarm == uarm) else if (wornarm == uarm)
@@ -2979,6 +2991,7 @@ int
destroy_arm(struct obj *atmp) destroy_arm(struct obj *atmp)
{ {
struct obj *otmp; struct obj *otmp;
boolean losing_gloves = FALSE;
/* /*
* Note: if there were any artifact cloaks, the 90% chance of * Note: if there were any artifact cloaks, the 90% chance of
* resistance here means that the cloak could survive and then * resistance here means that the cloak could survive and then
@@ -2986,24 +2999,17 @@ destroy_arm(struct obj *atmp)
* artifact suit over a shirt. That would be a bug. Since there * artifact suit over a shirt. That would be a bug. Since there
* aren't any, we'll just look the other way. * aren't any, we'll just look the other way.
*/ */
#define DESTROY_ARM(o) \ #define DESTROY_ARM(o) \
(((otmp = (o)) != 0 && (!atmp || atmp == otmp) \ (((otmp = (o)) != 0 && (!atmp || atmp == otmp) \
&& (!obj_resists(otmp, 0, 90))) \ && !obj_resists(otmp, 0, 90)) ? (otmp->in_use = 1) : 0)
? (otmp->in_use = TRUE) \
: FALSE)
if (DESTROY_ARM(uarmc)) { if (DESTROY_ARM(uarmc)) {
if (donning(otmp))
cancel_don();
urgent_pline("Your %s crumbles and turns to dust!", urgent_pline("Your %s crumbles and turns to dust!",
/* cloak/robe/apron/smock (ID'd apron)/wrapping */ /* cloak/robe/apron/smock (ID'd apron)/wrapping */
cloak_simple_name(uarmc)); cloak_simple_name(otmp));
wornarm_destroyed(uarmc);
} else if (DESTROY_ARM(uarm)) { } else if (DESTROY_ARM(uarm)) {
const char *suit = suit_simple_name(uarm); const char *suit = suit_simple_name(otmp);
if (donning(otmp))
cancel_don();
/* for gold DSM, we don't want Armor_gone() to report that it /* for gold DSM, we don't want Armor_gone() to report that it
stops shining _after_ we've been told that it is destroyed */ stops shining _after_ we've been told that it is destroyed */
if (otmp->lamplit) if (otmp->lamplit)
@@ -3012,40 +3018,31 @@ destroy_arm(struct obj *atmp)
/* suit might be "dragon scales" so vtense() is needed */ /* suit might be "dragon scales" so vtense() is needed */
suit, vtense(suit, "turn"), vtense(suit, "fall"), suit, vtense(suit, "turn"), vtense(suit, "fall"),
surface(u.ux, u.uy)); surface(u.ux, u.uy));
wornarm_destroyed(uarm);
} else if (DESTROY_ARM(uarmu)) { } else if (DESTROY_ARM(uarmu)) {
if (donning(otmp))
cancel_don();
urgent_pline("Your %s crumbles into tiny threads and falls apart!", urgent_pline("Your %s crumbles into tiny threads and falls apart!",
shirt_simple_name(uarmu)); /* always "shirt" */ shirt_simple_name(otmp)); /* always "shirt" */
wornarm_destroyed(uarmu);
} else if (DESTROY_ARM(uarmh)) { } else if (DESTROY_ARM(uarmh)) {
if (donning(otmp))
cancel_don();
urgent_pline("Your %s turns to dust and is blown away!", urgent_pline("Your %s turns to dust and is blown away!",
helm_simple_name(uarmh)); /* "helm" or "hat" */ helm_simple_name(otmp)); /* "helm" or "hat" */
wornarm_destroyed(uarmh);
} else if (DESTROY_ARM(uarmg)) { } else if (DESTROY_ARM(uarmg)) {
if (donning(otmp)) urgent_pline("Your %s vanish!", gloves_simple_name(otmp));
cancel_don(); losing_gloves = TRUE;
urgent_pline("Your %s vanish!", gloves_simple_name(uarmg));
wornarm_destroyed(uarmg);
selftouch("You");
} else if (DESTROY_ARM(uarmf)) { } else if (DESTROY_ARM(uarmf)) {
if (donning(otmp)) urgent_pline("Your %s disintegrate!", boots_simple_name(otmp));
cancel_don();
urgent_pline("Your %s disintegrate!", boots_simple_name(uarmf));
wornarm_destroyed(uarmf);
} else if (DESTROY_ARM(uarms)) { } else if (DESTROY_ARM(uarms)) {
if (donning(otmp)) urgent_pline("Your %s crumbles away!", shield_simple_name(otmp));
cancel_don();
urgent_pline("Your %s crumbles away!", shield_simple_name(uarms));
wornarm_destroyed(uarms);
} else { } else {
return 0; /* could not destroy anything */ return 0; /* could not destroy anything */
} }
#undef DESTROY_ARM #undef DESTROY_ARM
/* cancel_don() if applicable, Cloak_off()/Armor_off()/&c, and useup() */
wornarm_destroyed(otmp);
/* glove loss means wielded weapon will be touched */
if (losing_gloves)
selftouch("You");
stop_occupation(); stop_occupation();
return 1; return 1;
} }