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

Function oname

src/do_name.c:371–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

369}
370
371struct obj *
372oname(
373 struct obj *obj, /* item to assign name to */
374 const char *name, /* name to assign */
375 unsigned oflgs) /* flags, mostly for artifact creation */
376{
377 int lth;
378 char buf[PL_PSIZ];
379 boolean via_naming = (oflgs & ONAME_VIA_NAMING) != 0,
380 skip_inv_update = (oflgs & ONAME_SKIP_INVUPD) != 0;
381
382 lth = *name ? (int) (strlen(name) + 1) : 0;
383 if (lth > PL_PSIZ) {
384 lth = PL_PSIZ;
385 name = strncpy(buf, name, PL_PSIZ - 1);
386 buf[PL_PSIZ - 1] = '\0';
387 }
388 /* If named artifact exists in the game, do not create another.
389 Also trying to create an artifact shouldn't de-artifact
390 it (e.g. Excalibur from prayer). In this case the object
391 will retain its current name. */
392 if (obj->oartifact || (lth && exist_artifact(obj->otyp, name)))
393 return obj;
394
395 new_oname(obj, lth); /* removes old name if one is present */
396 if (lth)
397 Strcpy(ONAME(obj), name);
398
399 if (lth)
400 artifact_exists(obj, name, TRUE, oflgs);
401 if (obj->oartifact) {
402 /* can't dual-wield with artifact as secondary weapon */
403 if (obj == uswapwep)
404 untwoweapon();
405 /* activate warning if you've just named your weapon "Sting" */
406 if (obj == uwep)
407 set_artifact_intrinsic(obj, TRUE, W_WEP);
408 /* if obj is owned by a shop, increase your bill */
409 if (obj->unpaid)
410 alter_cost(obj, 0L);
411 if (via_naming) {
412 /* violate illiteracy conduct since successfully wrote arti-name */
413 if (!u.uconduct.literate++)
414 livelog_printf(LL_CONDUCT | LL_ARTIFACT,
415 "became literate by naming %s",
416 bare_artifactname(obj));
417 else
418 livelog_printf(LL_ARTIFACT,
419 "chose %s to be named \"%s\"",
420 ansimpleoname(obj), bare_artifactname(obj));
421 }
422 }
423 if (carried(obj) && !skip_inv_update)
424 update_inventory();
425 return obj;
426}
427
428boolean

Callers 15

do_onameFunction · 0.85
readobjnamFunction · 0.85
mk_artifactFunction · 0.85
tt_onameFunction · 0.85
newmailFunction · 0.85
gcrownuFunction · 0.85
mergedFunction · 0.85
observe_quantum_catFunction · 0.85
make_corpseFunction · 0.85
monstoneFunction · 0.85
copy_oextraFunction · 0.85
mksobjFunction · 0.85

Calls 10

exist_artifactFunction · 0.85
artifact_existsFunction · 0.85
untwoweaponFunction · 0.85
set_artifact_intrinsicFunction · 0.85
alter_costFunction · 0.85
livelog_printfFunction · 0.85
bare_artifactnameFunction · 0.85
ansimpleonameFunction · 0.85
update_inventoryFunction · 0.85
new_onameFunction · 0.70

Tested by

no test coverage detected