From 0acaa9bc1b741451deeaa8d1d375f06edc9b9087 Mon Sep 17 00:00:00 2001 From: "nethack.rankin" Date: Sun, 28 Aug 2011 20:47:56 +0000 Subject: [PATCH] wishing tweak: detect X vs X detection (trunk only) Allow wishing for a "potion of detect objects" to generate a "potion of object detection", or for a "spellbook of monster detection" to generate a "spellbook of detect monsters". To get a spellbook you'll need to explicitly specify "spellbook" even when using a name that's unique to books: asking for "detect food" will yield a "scroll of food detection" rather than "spellbook of detect food" because it finds potions and scrolls first. [That's nothing new for the case where a spellbook and potion or scroll have the same name, only new behavior for "detect X" vs "X detection" matches.] Wishing for "detect food" used to yield a random food item rather than a "spellbook of detect food". That's fixed now, although as mentioned above it will actually produce a "scroll of food detection". --- doc/fixes35.0 | 1 + src/objnam.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/doc/fixes35.0 b/doc/fixes35.0 index 655a643fc..a38bbbeaa 100644 --- a/doc/fixes35.0 +++ b/doc/fixes35.0 @@ -519,6 +519,7 @@ adopt/adapt/improve the Paranoid_Quit patch; default is paranoid_confirm:pray paranoid_confirm:attack yes vs y to attack a peaceful monster paranoid_confirm:pray y to confirm #pray; supersedes prayconfirm paranoid_confirm:Remove always pick from inventory for 'R' and 'T' +flexibility for specifying "detect " vs " detection" when wishing Platform- and/or Interface-Specific New Features diff --git a/src/objnam.c b/src/objnam.c index c18946e33..17ad4a719 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -2082,12 +2082,15 @@ const char *u_str; /* from user, so might be variant spelling */ const char *o_str; /* from objects[], so is in canonical form */ boolean retry_inverted; /* optional extra "of" handling */ { + static NEARDATA const char + detect_SP[] = "detect ", SP_detection[] = " detection"; + char *p, buf[BUFSZ]; + /* ignore spaces & hyphens and upper/lower case when comparing */ if (fuzzymatch(u_str, o_str, " -", TRUE)) return TRUE; if (retry_inverted) { const char *u_of, *o_of; - char *p, buf[BUFSZ]; /* when just one of the strings is in the form "foo of bar", convert it into "bar foo" and perform another comparison */ @@ -2119,6 +2122,29 @@ boolean retry_inverted; /* optional extra "of" handling */ return fuzzymatch(u_str + 7, o_str + 6, " -", TRUE); else if (!strncmpi(u_str, "elfin ", 6)) return fuzzymatch(u_str + 6, o_str + 6, " -", TRUE); + } else if (!strncmp(o_str, detect_SP, sizeof detect_SP - 1)) { + /* check for "detect " vs " detection" */ + if ((p = strstri(u_str, SP_detection)) != 0 && + !*(p + sizeof SP_detection - 1)) { + /* convert " detection" into "detect " */ + *p = '\0'; + Strcat(strcpy(buf, detect_SP), u_str); + /* "detect monster" -> "detect monsters" */ + if (!strcmpi(u_str, "monster")) Strcat(buf, "s"); + *p = ' '; + return fuzzymatch(buf, o_str, " -", TRUE); + } + } else if (strstri(o_str, SP_detection)) { + /* and the inverse, " detection" vs "detect " */ + if (!strncmpi(u_str, detect_SP, sizeof detect_SP - 1)) { + /* convert "detect s" into " detection" */ + p = makesingular(u_str + sizeof detect_SP - 1); + Strcat(strcpy(buf, p), SP_detection); + /* caller may be looping through objects[], so avoid + churning through all the obufs */ + releaseobuf(p); + return fuzzymatch(buf, o_str, " -", TRUE); + } } else if (!strcmp(o_str, "aluminum")) { /* this special case doesn't really fit anywhere else... */ /* (note that " wand" will have been stripped off by now) */ @@ -2591,6 +2617,7 @@ struct obj *no_wish; /* false hits on, e.g., rings for "ring mail". */ if(strncmpi(bp, "enchant ", 8) && strncmpi(bp, "destroy ", 8) && + strncmpi(bp, "detect food", 11) && strncmpi(bp, "food detection", 14) && strncmpi(bp, "ring mail", 9) && strncmpi(bp, "studded leather armor", 21) &&