MCPcopy Create free account
hub / github.com/NetHack/NetHack / alreadynamed

Function alreadynamed

src/do_name.c:157–195  ·  view source on GitHub ↗

check whether user-supplied name matches or nearly matches an unnameable monster's name, or is an attempt to delete the monster's name; if so, give alternate reject message for do_mgivenname() */

Source from the content-addressed store, hash-verified

155 monster's name, or is an attempt to delete the monster's name; if so, give
156 alternate reject message for do_mgivenname() */
157staticfn boolean
158alreadynamed(struct monst *mtmp, char *monnambuf, char *usrbuf)
159{
160 char pronounbuf[10], *p;
161
162 if (!*usrbuf) { /* attempt to erase existing name */
163 boolean name_not_title = (has_mgivenname(mtmp)
164 || type_is_pname(mtmp->data)
165 || mtmp->isshk);
166 pline("%s would rather keep %s existing %s.", upstart(monnambuf),
167 is_rider(mtmp->data) ? "its" : mhis(mtmp),
168 name_not_title ? "name" : "title");
169 return TRUE;
170 } else if (fuzzymatch(usrbuf, monnambuf, " -_", TRUE)
171 /* catch trying to name "the Oracle" as "Oracle" */
172 || (!strncmpi(monnambuf, "the ", 4)
173 && fuzzymatch(usrbuf, monnambuf + 4, " -_", TRUE))
174 /* catch trying to name "invisible Orcus" as "Orcus" */
175 || ((p = strstri(monnambuf, "invisible ")) != 0
176 && fuzzymatch(usrbuf, p + 10, " -_", TRUE))
177 /* catch trying to name "the priest of Crom" as "Crom" */
178 || ((p = strstri(monnambuf, " of ")) != 0
179 && fuzzymatch(usrbuf, p + 4, " -_", TRUE))) {
180 if (is_rider(mtmp->data)) {
181 /* avoid gendered pronoun for riders */
182 pline("%s is already called that.", upstart(monnambuf));
183 } else {
184 pline("%s is already called %s.",
185 upstart(strcpy(pronounbuf, mhe(mtmp))), monnambuf);
186 }
187 return TRUE;
188 } else if (mtmp->data == &mons[PM_JUIBLEX]
189 && strstri(monnambuf, "Juiblex")
190 && !strcmpi(usrbuf, "Jubilex")) {
191 pline("%s doesn't like being called %s.", upstart(monnambuf), usrbuf);
192 return TRUE;
193 }
194 return FALSE;
195}
196
197/* allow player to assign a name to some chosen monster */
198staticfn void

Callers 1

do_mgivennameFunction · 0.85

Calls 5

upstartFunction · 0.85
fuzzymatchFunction · 0.85
strstriFunction · 0.85
plineFunction · 0.70
strncmpiFunction · 0.70

Tested by

no test coverage detected