From c87a373b11d00b218b608198dda6b5d43edad9be Mon Sep 17 00:00:00 2001 From: nhmall Date: Sun, 10 Nov 2024 10:06:07 -0500 Subject: [PATCH] more follow-up related to #1320 --- include/hack.h | 8 ++++++++ src/do.c | 4 ++-- src/do_wear.c | 7 +++++-- src/invent.c | 2 +- src/pickup.c | 19 ++++++++++--------- src/zap.c | 2 +- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/include/hack.h b/include/hack.h index 088007784..0851da3ef 100644 --- a/include/hack.h +++ b/include/hack.h @@ -859,6 +859,14 @@ typedef struct strbuf { char buf[256]; } strbuf_t; +enum stoning_checks { + st_gloves = 0x1, /* wearing gloves? */ + st_corpse = 0x2, /* is it a corpse obj? */ + st_petrifies = 0x4, /* does the corpse petrify on touch? */ + st_resists = 0x8, /* do you have stoning resistance? */ + st_all = (st_gloves | st_corpse | st_petrifies | st_resists) +}; + struct trapinfo { struct obj *tobj; coordxy tx, ty; diff --git a/src/do.c b/src/do.c index 204643522..2fcf6bd40 100644 --- a/src/do.c +++ b/src/do.c @@ -941,10 +941,10 @@ better_not_try_to_drop_that(struct obj *otmp) { char buf[BUFSZ]; - /* u_safe_from_fatal_corpse() with 0xF checks for gloves and stoning + /* u_safe_from_fatal_corpse() with st_all checks for gloves and stoning * resistance before bothering to prompt you. */ - if (otmp->otyp == CORPSE && !u_safe_from_fatal_corpse(otmp, 0xF)) { + if (otmp->otyp == CORPSE && !u_safe_from_fatal_corpse(otmp, st_all)) { Snprintf( buf, sizeof buf, "Drop the %s corpse without any protection while handling it?", diff --git a/src/do_wear.c b/src/do_wear.c index d6aac2a60..652c13868 100644 --- a/src/do_wear.c +++ b/src/do_wear.c @@ -2895,12 +2895,15 @@ better_not_take_that_off(struct obj *otmp) struct obj *corpse = carrying_stoning_corpse(); char buf[BUFSZ]; - /* u_safe_from_fatal_corpse() with 0x4e instead of 0x6 + /* u_safe_from_fatal_corpse() with + (st_corpse | st_petrifies | st_resists) instead of + (st_corpse | st_petrifies) would also check for no stoning resistance before bothering to prompt, but losing stoning resistance later, without the gloves on could prove dangerous, so we won't factor that in */ - if (corpse && !u_safe_from_fatal_corpse(corpse, 0x6)) { + if (corpse + && !u_safe_from_fatal_corpse(corpse, st_corpse | st_petrifies)) { Snprintf(buf, sizeof buf, "Take off your %s despite carrying a dead %s?", gloves_simple_name(otmp), obj_pmname(corpse)); diff --git a/src/invent.c b/src/invent.c index fb137aabf..cf5d7e378 100644 --- a/src/invent.c +++ b/src/invent.c @@ -1232,7 +1232,7 @@ hold_another_object( obj = addinv_core0(obj, (struct obj *) 0, FALSE); goto drop_it; } else if (obj->otyp == CORPSE - && !u_safe_from_fatal_corpse(obj, 0xF) + && !u_safe_from_fatal_corpse(obj, st_all) && obj->wishedfor) { obj->wishedfor = 0; obj = addinv_core0(obj, (struct obj *) 0, FALSE); diff --git a/src/pickup.c b/src/pickup.c index 48fe61c18..df8896fe4 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -263,18 +263,19 @@ query_classes( /* * tests: - * 1 = gloves - * 2 = is_corpse - * 4 = does corpse petrify - * 8 = stone resistance + * st_gloves wearing gloves? + * st_corpse is it a corpse obj? + * st_petrifies does the corpse petrify on touch? + * st_resists does hero have stoning resistance? + * st_all st_gloves | st_corpse | st_petrifies | st_resists */ boolean u_safe_from_fatal_corpse(struct obj *obj, int tests) { - if (((tests & 1) && uarmg) - || ((tests & 2) && obj->otyp != CORPSE) - || ((tests & 4) && !touch_petrifies(&mons[obj->corpsenm])) - || ((tests & 8) && Stone_resistance)) + if (((tests & st_gloves) && uarmg) + || ((tests & st_corpse) && obj->otyp != CORPSE) + || ((tests & st_petrifies) && !touch_petrifies(&mons[obj->corpsenm])) + || ((tests & st_resists) && Stone_resistance)) return TRUE; return FALSE; } @@ -283,7 +284,7 @@ u_safe_from_fatal_corpse(struct obj *obj, int tests) staticfn boolean fatal_corpse_mistake(struct obj *obj, boolean remotely) { - if (u_safe_from_fatal_corpse(obj, 0xF) || remotely) + if (u_safe_from_fatal_corpse(obj, st_all) || remotely) return FALSE; if (poly_when_stoned(gy.youmonst.data) && polymon(PM_STONE_GOLEM)) { diff --git a/src/zap.c b/src/zap.c index b25b80681..2748acd77 100644 --- a/src/zap.c +++ b/src/zap.c @@ -6189,7 +6189,7 @@ makewish(void) /* TODO? maybe generate a second event describing what was received since these just echo player's request rather than show actual result */ - if (otmp->otyp == CORPSE && !u_safe_from_fatal_corpse(otmp, 0xF)) + if (otmp->otyp == CORPSE && !u_safe_from_fatal_corpse(otmp, st_all)) otmp->wishedfor = 1; const char *verb = ((Is_airlevel(&u.uz) || u.uinwater)