From 3c979cb0a5748538e02e63fe42eaa670b68e5195 Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 19 Jun 2018 18:39:08 -0700 Subject: [PATCH] more glob wishing Wishing for " glob of black pudding" worked, and wishing for "black pudding glob" worked, but wishing for " black pudding glob" didn't work. Fix that. Also, remove a bit of spaghetti introduced by the previous patch. And once we know we're wishing for a glob, we can skip a big chunk of wish parsing and special case handling. --- src/objnam.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/objnam.c b/src/objnam.c index ec6861e64..5fa0ddd42 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -2721,9 +2721,9 @@ char oclass; if (!name) return STRANGE_OBJECT; - memset((genericptr_t) validobjs, 0, sizeof(validobjs)); + memset((genericptr_t) validobjs, 0, sizeof validobjs); - for (i = oclass ? bases[(int)oclass] : STRANGE_OBJECT + 1; + for (i = oclass ? bases[(int) oclass] : STRANGE_OBJECT + 1; i < NUM_OBJECTS && (!oclass || objects[i].oc_class == oclass); ++i) { /* don't match extra descriptions (w/o real name) */ @@ -2921,8 +2921,11 @@ struct obj *no_wish; contents = EMPTY; } else if (!strncmpi(bp, "small ", l = 6)) { /* glob sizes */ /* "small" might be part of monster name (mimic, if wishing - for its corpse) rather than prefix for glob size */ - if (strncmpi(bp + l, "glob", 4)) + for its corpse) rather than prefix for glob size; when + used for globs, it might be either "small glob of " or + "small glob" and user might add 's' even though plural + doesn't accomplish anything because globs don't stack */ + if (strncmpi(bp + l, "glob", 4) && !strstri(bp + l, " glob")) break; gsize = 1; } else if (!strncmpi(bp, "medium ", l = 7)) { @@ -2934,7 +2937,7 @@ struct obj *no_wish; /* "large" might be part of monster name (dog, cat, koboold, mimic) or object name (box, round shield) rather than prefix for glob size */ - if (strncmpi(bp + l, "glob", 4)) + if (strncmpi(bp + l, "glob", 4) && !strstri(bp + l, " glob")) break; /* "very large " had "very " peeled off on previous iteration */ gsize = (very != 1) ? 3 : 4; @@ -3067,30 +3070,27 @@ struct obj *no_wish; * also don't let player wish for multiple globs. */ i = (int) strlen(bp); + p = (char *) 0; + /* check for "glob", " glob", and "glob of " */ if (!strcmpi(bp, "glob") || !BSTRCMPI(bp, bp + i - 5, " glob") - || !strcmpi(bp, "globs") || !BSTRCMPI(bp, bp + i - 6, " globs")) { - /* string ends in "glob"; accept "black pudding glob" variation */ - if ((mntmp = name_to_mon(bp)) == NON_PM) - /* "[size] glob" without "of "; pick random */ + || !strcmpi(bp, "globs") || !BSTRCMPI(bp, bp + i - 6, " globs") + || (p = strstri(bp, "glob of ")) != 0 + || (p = strstri(bp, "globs of ")) != 0) { + mntmp = name_to_mon(!p ? bp : (strstri(p, " of ") + 4)); + /* if we didn't recognize monster type, pick a valid one at random */ + if (mntmp == NON_PM) mntmp = rn1(PM_BLACK_PUDDING - PM_GRAY_OOZE, PM_GRAY_OOZE); - replaceglob: + /* construct canonical spelling in case name_to_mon() recognized a + variant (grey ooze) or player used inverted syntax ( glob); + if player has given a valid monster type but not valid glob type, + object name lookup won't find it and wish attempt will fail */ Sprintf(globbuf, "glob of %s", mons[mntmp].mname); bp = globbuf; mntmp = NON_PM; /* not useful for "glob of " object lookup */ cnt = 0; /* globs don't stack */ - } else if ((p = strstri(bp, "glob of ")) != 0 - || (p = strstri(bp, "globs of ")) != 0) { - int globoffset = (*(p + 4) == 's') ? 9 : 8; - - if ((mntmp = name_to_mon(p + globoffset)) == PM_GRAY_OOZE) { - /* name_to_mon() recognizes "grey ooze" as variant spelling - but doesn't change input string to fix it; force canonical - spelling so that object name lookup always finds it */ - goto replaceglob; - } else if (mntmp > PM_GRAY_OOZE && mntmp <= PM_BLACK_PUDDING) { - mntmp = NON_PM; /* lie to ourselves */ - cnt = 0; /* force only one */ - } + oclass = FOOD_CLASS; + actualn = bp, dn = 0; + goto srch; } else { /* * Find corpse type using "of" (figurine of an orc, tin of orc meat)