wishing fix

name_to_mon() has a bunch of alternate monster names, such as
"gray-elf" to match "grey-elf" and "ki rin" to match "ki-rin".  Those
worked as intended when they occurred at the end of a wish, but only
worked in the middle if their length was the same or one character
less than the canonical name in mons[].mname.

djinni figurine     -> h - a figurine of a djinni
genie figurine      -> i - a figurine of a djinni
figurine of mumak   -> j - a figurine of a mumak
mumak figurine      -> k - a figurine of a mumak
figurine of mumakil -> l - a figurine of a mumak
mumakil figurine    -> nothing fitting that description exists

(The one-less case worked because its following space ended up being
implicitly removed when skipping ahead by the length of mons[].mname;
subsequent explicit removal didn't find a space so was a no-op.)
This commit is contained in:
PatR
2020-04-19 04:58:18 -07:00
parent 37ef5a2561
commit 05403182eb
5 changed files with 52 additions and 12 deletions
+30 -4
View File
@@ -678,10 +678,23 @@ struct alt_spl {
short pm_val;
};
/* figure out what type of monster a user-supplied string is specifying */
/* figure out what type of monster a user-supplied string is specifying;
ingore anything past the monster name */
int
name_to_mon(in_str)
const char *in_str;
{
return name_to_monplus(in_str, (const char **) 0);
}
/* figure out what type of monster a user-supplied string is specifying;
return a pointer to whatever is past the monster name--necessary if
caller wants to strip off the name and it matches one of the alternate
names rather the canonical mons[].mname */
int
name_to_monplus(in_str, remainder_p)
const char *in_str;
const char **remainder_p;
{
/* Be careful. We must check the entire string in case it was
* something such as "ettin zombie corpse". The calling routine
@@ -701,6 +714,9 @@ const char *in_str;
char buf[BUFSZ];
int len, slen;
if (remainder_p)
*remainder_p = (const char *) 0;
str = strcpy(buf, in_str);
if (!strncmp(str, "a ", 2))
@@ -767,6 +783,7 @@ const char *in_str;
{ "elf lord", PM_ELF_LORD },
{ "olog hai", PM_OLOG_HAI },
{ "arch lich", PM_ARCH_LICH },
{ "archlich", PM_ARCH_LICH },
/* Some irregular plurals */
{ "incubi", PM_INCUBUS },
{ "succubi", PM_SUCCUBUS },
@@ -785,9 +802,16 @@ const char *in_str;
};
register const struct alt_spl *namep;
for (namep = names; namep->name; namep++)
if (!strncmpi(str, namep->name, (int) strlen(namep->name)))
for (namep = names; namep->name; namep++) {
len = (int) strlen(namep->name);
if (!strncmpi(str, namep->name, len)
/* force full word (which could conceivably be possessive) */
&& (!str[len] || str[len] == ' ' || str[len] == '\'')) {
if (remainder_p)
*remainder_p = in_str + (&str[len] - buf);
return namep->pm_val;
}
}
}
for (len = 0, i = LOW_PM; i < NUMMONS; i++) {
@@ -813,7 +837,9 @@ const char *in_str;
}
}
if (mntmp == NON_PM)
mntmp = title_to_mon(str, (int *) 0, (int *) 0);
mntmp = title_to_mon(str, (int *) 0, &len);
if (len && remainder_p)
*remainder_p = in_str + (&str[len] - buf);
return mntmp;
}