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

Function retouch_object

src/artifact.c:2507–2591  ·  view source on GitHub ↗

called when hero is wielding/applying/invoking a carried item, or after undergoing a transformation (alignment change, lycanthropy, polymorph) which might affect item access */

Source from the content-addressed store, hash-verified

2505 after undergoing a transformation (alignment change, lycanthropy,
2506 polymorph) which might affect item access */
2507int
2508retouch_object(
2509 struct obj **objp, /* might be destroyed or unintentionally dropped */
2510 boolean loseit) /* whether to drop it if hero can longer touch it */
2511{
2512 struct obj *obj = *objp;
2513
2514 /* allow hero in silver-hating form to try to perform invocation ritual */
2515 if (obj->otyp == BELL_OF_OPENING
2516 && invocation_pos(u.ux, u.uy) && !On_stairs(u.ux, u.uy)) {
2517 return 1;
2518 }
2519
2520 if (touch_artifact(obj, &gy.youmonst)) {
2521 char buf[BUFSZ];
2522 int dmg = 0, tmp;
2523 boolean ag = (objects[obj->otyp].oc_material == SILVER && Hate_silver),
2524 bane = bane_applies(get_artifact(obj), &gy.youmonst);
2525
2526 /* nothing else to do if hero can successfully handle this object */
2527 if (!ag && !bane)
2528 return 1;
2529
2530 /* hero can't handle this object, but didn't get touch_artifact()'s
2531 "<obj> evades your grasp|control" message; give an alternate one */
2532 You_cant("handle %s%s!", yname(obj),
2533 obj->owornmask ? " anymore" : "");
2534 /* also inflict damage unless touch_artifact() already did so */
2535 if (!touch_blasted) {
2536 const char *what = killer_xname(obj);
2537
2538 if (ag && !obj->oartifact && !bane) {
2539 /* 'obj' is silver; for rings and wands it ended up that
2540 way due to randomization at start of game; showing this
2541 game's silver item without stating that it is silver
2542 potentially leads to confusion about cause of death */
2543 if (obj->oclass == RING_CLASS)
2544 what = "a silver ring";
2545 else if (obj->oclass == WAND_CLASS)
2546 what = "a silver wand";
2547 /* for anything else, stick with killer_xname() */
2548 }
2549 /* damage is somewhat arbitrary; half the usual 1d20 physical
2550 for silver, 1d10 magical for <foo>bane, potentially both */
2551 if (ag)
2552 tmp = rnd(10), dmg += Maybe_Half_Phys(tmp);
2553 if (bane)
2554 dmg += rnd(10);
2555 Sprintf(buf, "handling %s", what);
2556 losehp(dmg, buf, KILLED_BY);
2557 exercise(A_CON, FALSE);
2558 }
2559 }
2560
2561 /* removing a worn item might result in loss of levitation,
2562 dropping the hero onto a polymorph trap or into water or
2563 lava and potentially dropping or destroying the item */
2564 if (obj->owornmask) {

Callers 6

ready_weaponFunction · 0.85
accessory_or_armor_onFunction · 0.85
doinvokeFunction · 0.85
untouchableFunction · 0.85
doeatFunction · 0.85
doapplyFunction · 0.85

Calls 15

invocation_posFunction · 0.85
On_stairsFunction · 0.85
touch_artifactFunction · 0.85
bane_appliesFunction · 0.85
get_artifactFunction · 0.85
You_cantFunction · 0.85
ynameFunction · 0.85
killer_xnameFunction · 0.85
rndFunction · 0.85
losehpFunction · 0.85
exerciseFunction · 0.85
remove_worn_itemFunction · 0.85

Tested by

no test coverage detected