more glob wishing

Wishing for "<size> glob of black pudding" worked, and wishing for
"black pudding glob" worked, but wishing for "<size> 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.
This commit is contained in:
PatR
2018-06-19 18:39:08 -07:00
parent 9415797c65
commit 3c979cb0a5

View File

@@ -2721,9 +2721,9 @@ char oclass;
if (!name) if (!name)
return STRANGE_OBJECT; 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 < NUM_OBJECTS && (!oclass || objects[i].oc_class == oclass);
++i) { ++i) {
/* don't match extra descriptions (w/o real name) */ /* don't match extra descriptions (w/o real name) */
@@ -2921,8 +2921,11 @@ struct obj *no_wish;
contents = EMPTY; contents = EMPTY;
} else if (!strncmpi(bp, "small ", l = 6)) { /* glob sizes */ } else if (!strncmpi(bp, "small ", l = 6)) { /* glob sizes */
/* "small" might be part of monster name (mimic, if wishing /* "small" might be part of monster name (mimic, if wishing
for its corpse) rather than prefix for glob size */ for its corpse) rather than prefix for glob size; when
if (strncmpi(bp + l, "glob", 4)) used for globs, it might be either "small glob of <foo>" or
"small <foo> 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; break;
gsize = 1; gsize = 1;
} else if (!strncmpi(bp, "medium ", l = 7)) { } 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, /* "large" might be part of monster name (dog, cat, koboold,
mimic) or object name (box, round shield) rather than mimic) or object name (box, round shield) rather than
prefix for glob size */ prefix for glob size */
if (strncmpi(bp + l, "glob", 4)) if (strncmpi(bp + l, "glob", 4) && !strstri(bp + l, " glob"))
break; break;
/* "very large " had "very " peeled off on previous iteration */ /* "very large " had "very " peeled off on previous iteration */
gsize = (very != 1) ? 3 : 4; gsize = (very != 1) ? 3 : 4;
@@ -3067,30 +3070,27 @@ struct obj *no_wish;
* also don't let player wish for multiple globs. * also don't let player wish for multiple globs.
*/ */
i = (int) strlen(bp); i = (int) strlen(bp);
p = (char *) 0;
/* check for "glob", "<foo> glob", and "glob of <foo>" */
if (!strcmpi(bp, "glob") || !BSTRCMPI(bp, bp + i - 5, " glob") if (!strcmpi(bp, "glob") || !BSTRCMPI(bp, bp + i - 5, " glob")
|| !strcmpi(bp, "globs") || !BSTRCMPI(bp, bp + i - 6, " globs")) { || !strcmpi(bp, "globs") || !BSTRCMPI(bp, bp + i - 6, " globs")
/* string ends in "glob"; accept "black pudding glob" variation */ || (p = strstri(bp, "glob of ")) != 0
if ((mntmp = name_to_mon(bp)) == NON_PM) || (p = strstri(bp, "globs of ")) != 0) {
/* "[size] glob" without "of <foo>"; pick random <foo> */ 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); 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 (<foo> 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); Sprintf(globbuf, "glob of %s", mons[mntmp].mname);
bp = globbuf; bp = globbuf;
mntmp = NON_PM; /* not useful for "glob of <foo>" object lookup */ mntmp = NON_PM; /* not useful for "glob of <foo>" object lookup */
cnt = 0; /* globs don't stack */ cnt = 0; /* globs don't stack */
} else if ((p = strstri(bp, "glob of ")) != 0 oclass = FOOD_CLASS;
|| (p = strstri(bp, "globs of ")) != 0) { actualn = bp, dn = 0;
int globoffset = (*(p + 4) == 's') ? 9 : 8; goto srch;
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 */
}
} else { } else {
/* /*
* Find corpse type using "of" (figurine of an orc, tin of orc meat) * Find corpse type using "of" (figurine of an orc, tin of orc meat)