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

Function do_oname

src/do_name.c:289–369  ·  view source on GitHub ↗

* This routine used to change the address of 'obj' so be unsafe if not * used with extreme care. Applying a name to an object no longer * allocates a replacement object, so that old risk is gone. */

Source from the content-addressed store, hash-verified

287 * allocates a replacement object, so that old risk is gone.
288 */
289staticfn void
290do_oname(struct obj *obj)
291{
292 char *bufp, buf[BUFSZ], bufcpy[BUFSZ], qbuf[QBUFSZ];
293 const char *aname;
294 short objtyp = STRANGE_OBJECT;
295
296 /* Do this now because there's no point in even asking for a name */
297 if (obj->otyp == SPE_NOVEL) {
298 pline("%s already has a published name.", Ysimple_name2(obj));
299 return;
300 }
301
302 Sprintf(qbuf, "What do you want to name %s ",
303 is_plural(obj) ? "these" : "this");
304 (void) safe_qbuf(qbuf, qbuf, "?", obj, xname, simpleonames, "item");
305 /* use getlin() to get a name string from the player */
306 if (!name_from_player(buf, qbuf, safe_oname(obj)))
307 return;
308
309 /*
310 * We don't violate illiteracy conduct here, although it is
311 * arguable that we should for anything other than "X". Doing so
312 * would make attaching player's notes to hero's inventory have an
313 * in-game effect, which may or may not be the correct thing to do.
314 *
315 * We do violate illiteracy in oname() if player creates Sting or
316 * Orcrist, clearly being literate (no pun intended...).
317 */
318
319 if (obj->oartifact) {
320 /* this used to give "The artifact seems to resist the attempt."
321 but resisting is definite, no "seems to" about it */
322 pline("%s resists the attempt.",
323 /* any artifact should always pass the has_oname() test
324 but be careful just in case */
325 has_oname(obj) ? ONAME(obj) : "The artifact");
326 return;
327 }
328
329 /* relax restrictions over proper capitalization for artifacts */
330 if ((aname = artifact_name(buf, &objtyp, TRUE)) != 0
331 && (restrict_name(obj, aname) || exist_artifact(obj->otyp, aname))) {
332 /* substitute canonical spelling before slippage */
333 Strcpy(buf, aname);
334 /* this used to change one letter, substituting a value
335 of 'a' through 'y' (due to an off by one error, 'z'
336 would never be selected) and then force that to
337 upper case if such was the case of the input;
338 now, the hand slip scuffs one or two letters as if
339 the text had been trodden upon, sometimes picking
340 punctuation instead of an arbitrary letter;
341 unfortunately, we have to cover the possibility of
342 it targeting spaces so failing to make any change
343 (we know that it must eventually target a nonspace
344 because buf[] matches a valid artifact name) */
345 Strcpy(bufcpy, buf);
346 /* for "the Foo of Bar", only scuff "Foo of Bar" part */

Callers 1

docallcmdFunction · 0.85

Calls 14

Ysimple_name2Function · 0.85
safe_qbufFunction · 0.85
name_from_playerFunction · 0.85
safe_onameFunction · 0.85
artifact_nameFunction · 0.85
restrict_nameFunction · 0.85
exist_artifactFunction · 0.85
wipeout_textFunction · 0.85
rnd_on_display_rngFunction · 0.85
body_partFunction · 0.85
YouFunction · 0.85
onameFunction · 0.85

Tested by

no test coverage detected