From 097d2259944d956a035369c8752fdcb3292da529 Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 8 Sep 2022 08:53:02 -0700 Subject: [PATCH] secret door detection feedback When zapping a wand of secret door detection or casting spell of detect unseem instead of displaying |You reveal secret doors. |You reveal a secret corridor. |You reveal traps. |You reveal a hidden monster. show |You reveal 2 secret doors, a secret corridor, 3 traps, and a hidden monster. as a single message. Detecting invisible monsters is still a separate message; those get re-mapped as "remembered, unseen monster" but not actually revealed. --- src/detect.c | 122 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 83 insertions(+), 39 deletions(-) diff --git a/src/detect.c b/src/detect.c index 33896260b..7f43e13e0 100644 --- a/src/detect.c +++ b/src/detect.c @@ -43,6 +43,7 @@ struct found_things { uchar num_mons; uchar num_invis; uchar num_cleared_invis; + uchar num_kept_invis; }; /* wildcard class for clear_stale_map - this used to be used as a getobj() @@ -1554,8 +1555,9 @@ cvt_sdoor_to_door(struct rm *lev) static void findone(coordxy zx, coordxy zy, genericptr_t whatfound) { - register struct trap *ttmp; - register struct monst *mtmp; + struct trap *ttmp; + struct monst *mtmp; + struct found_things *found_p = (struct found_things *) whatfound; /* * This used to use if/else-if/else-if/else/end-if but that only @@ -1568,13 +1570,13 @@ findone(coordxy zx, coordxy zy, genericptr_t whatfound) cvt_sdoor_to_door(&levl[zx][zy]); /* .typ = DOOR */ magic_map_background(zx, zy, 0); newsym(zx, zy); - ((struct found_things *) whatfound)->num_sdoors++; + found_p->num_sdoors++; } else if (levl[zx][zy].typ == SCORR) { levl[zx][zy].typ = CORR; unblock_point(zx, zy); magic_map_background(zx, zy, 0); newsym(zx, zy); - ((struct found_things *) whatfound)->num_scorrs++; + found_p->num_scorrs++; } if ((ttmp = t_at(zx, zy)) != 0 && !ttmp->tseen @@ -1582,7 +1584,7 @@ findone(coordxy zx, coordxy zy, genericptr_t whatfound) && ttmp->ttyp != STATUE_TRAP) { ttmp->tseen = 1; newsym(zx, zy); - ((struct found_things *) whatfound)->num_traps++; + found_p->num_traps++; } if ((mtmp = m_at(zx, zy)) != 0 @@ -1590,20 +1592,24 @@ findone(coordxy zx, coordxy zy, genericptr_t whatfound) && (!canspotmon(mtmp) || mtmp->mundetected || M_AP_TYPE(mtmp))) { if (M_AP_TYPE(mtmp)) { seemimic(mtmp); - ((struct found_things *) whatfound)->num_mons++; + found_p->num_mons++; } else if (mtmp->mundetected && (is_hider(mtmp->data) || hides_under(mtmp->data) || mtmp->data->mlet == S_EEL)) { mtmp->mundetected = 0; newsym(zx, zy); - ((struct found_things *) whatfound)->num_mons++; + found_p->num_mons++; } - if (!canspotmon(mtmp) && !glyph_is_invisible(levl[zx][zy].glyph)) { - map_invisible(zx, zy); - ((struct found_things *) whatfound)->num_invis++; + if (!glyph_is_invisible(levl[zx][zy].glyph)) { + if (!canspotmon(mtmp)) { + map_invisible(zx, zy); + found_p->num_invis++; + } + } else { + found_p->num_kept_invis++; } } else if (unmap_invisible(zx, zy)) { - ((struct found_things *) whatfound)->num_cleared_invis++; + found_p->num_cleared_invis++; } } @@ -1673,41 +1679,79 @@ openone(coordxy zx, coordxy zy, genericptr_t num) int findit(void) { - int num = 0; - struct found_things found = {0}; + int num = 0, k; + char buf[BUFSZ]; + struct found_things found; if (u.uswallow) return 0; + + (void) memset((genericptr_t) &found, 0, sizeof found); do_clear_area(u.ux, u.uy, BOLT_LIM, findone, (genericptr_t) &found); + /* count that controls "reveal" punctuation; 0..4 */ + k = !!found.num_sdoors + !!found.num_scorrs + !!found.num_traps + + !!found.num_mons; - if (found.num_sdoors) - You("reveal %ssecret door%s!", found.num_sdoors == 1 ? "a " : "", - found.num_sdoors == 1 ? "" : "s"); - num += found.num_sdoors; + buf[0] = '\0'; + if (found.num_sdoors) { + if (found.num_sdoors > 1) + Sprintf(eos(buf), "%d secret doors", found.num_sdoors); + else + Strcat(buf, "a secret door"); + num += found.num_sdoors; + } + /* note: non-\0 *buf implies that at least one previous type is present */ + if (found.num_scorrs) { + if (*buf) /* "doors and corrs" or "doors, coors ..." */ + Strcat(buf, (k == 2) ? " and " : ", "); + if (found.num_scorrs > 1) + Sprintf(eos(buf), "%d secret corridors", found.num_scorrs); + else + Strcat(buf, "a secret corridor"); + num += found.num_scorrs; + } + if (found.num_traps) { + if (*buf) /* "doors, corrs, and traps" or "{doors|coors} and traps" + * or "..., traps ..." */ + Strcat(buf, (k == 3 && !found.num_mons) ? ", and " + : (k == 2) ? " and " : ", "); + if (found.num_traps > 1) + Sprintf(eos(buf), "%d traps", found.num_traps); + else + Strcat(buf, "a trap"); + num += found.num_traps; + } + if (found.num_mons) { + if (*buf) + Strcat(buf, (k > 2) ? ", and " : " and "); + if (found.num_mons > 1) + Sprintf(eos(buf), "%d hidden monsters", found.num_mons); + else + Strcat(buf, "a hidden monster"); + num += found.num_mons; + } + if (*buf) + You("reveal %s!", buf); - if (found.num_scorrs) - You("reveal %ssecret corridor%s!", found.num_scorrs == 1 ? "a " : "", - found.num_scorrs == 1 ? "" : "s"); - num += found.num_scorrs; + if (found.num_invis) { + if (found.num_invis > 1) + Sprintf(buf, "%d%s invisible monsters", found.num_invis, + found.num_kept_invis ? " other" : ""); + else + Sprintf(buf, "%s invisible monster", + found.num_kept_invis ? "another" : "an"); + You("detect %s!", buf); + num += found.num_invis; + } - if (found.num_traps) - You("reveal %strap%s!", found.num_traps == 1 ? "a " : "", - found.num_traps == 1 ? "" : "s"); - num += found.num_traps; - - if (found.num_mons) - You("reveal %shidden monster%s!", found.num_mons == 1 ? "a " : "", - found.num_mons == 1 ? "" : "s"); - num += found.num_mons; - - if (found.num_invis) - You("detect %sinvisible monster%s!", found.num_invis == 1 ? "an " : "", - found.num_invis == 1 ? "" : "s"); - num += found.num_invis; - - if (!num && found.num_cleared_invis) - You_feel("less paranoid."); - num += found.num_cleared_invis; + if (found.num_cleared_invis) { + /* at least 1 "remembered, unseen monster" marker has been removed */ + if (!num) + You_feel("%sless paranoid.", + found.num_kept_invis ? "somewhat " : ""); + num += found.num_cleared_invis; + } + /* note: num_kept_invis is not included in the final result */ return num; }