| 369 | } |
| 370 | |
| 371 | struct obj * |
| 372 | oname( |
| 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 | |
| 428 | boolean |
no test coverage detected