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

Function untouchable

src/artifact.c:2597–2636  ·  view source on GitHub ↗

hero has changed form or alignment; an item which is worn/wielded or an artifact which conveys something via being carried or which has an #invoke effect currently in operation undergoes a touch test; if it fails, it will be unworn/unwielded and maybe dropped */

Source from the content-addressed store, hash-verified

2595 has an #invoke effect currently in operation undergoes a touch test;
2596 if it fails, it will be unworn/unwielded and maybe dropped */
2597staticfn boolean
2598untouchable(
2599 struct obj *obj, /* object to test; in invent or is steed's saddle */
2600 boolean drop_untouchable) /* whether to drop it if it can't be touched */
2601{
2602 struct artifact *art;
2603 boolean beingworn, carryeffect, invoked;
2604 long wearmask = ~(W_QUIVER | (u.twoweap ? 0L : W_SWAPWEP) | W_BALL);
2605
2606 beingworn = (obj /* never Null; this pacifies static analysis when
2607 * the get_artifact() macro tests 'obj' for Null */
2608 && ((obj->owornmask & wearmask) != 0L
2609 /* some items in use don't have any wornmask setting */
2610 || (obj->oclass == TOOL_CLASS
2611 && (obj->lamplit
2612 || (obj->otyp == LEASH && obj->leashmon)
2613 || (Is_container(obj) && Has_contents(obj))))));
2614
2615 if ((art = get_artifact(obj)) != &artilist[ART_NONARTIFACT]) {
2616 carryeffect = (art->cary.adtyp || art->cspfx);
2617 invoked = (art->inv_prop > 0 && art->inv_prop <= LAST_PROP
2618 && (u.uprops[art->inv_prop].extrinsic & W_ARTI) != 0L);
2619 } else {
2620 carryeffect = invoked = FALSE;
2621 }
2622
2623 if (beingworn || carryeffect || invoked) {
2624 if (!retouch_object(&obj, drop_untouchable)) {
2625 /* "<artifact> is beyond your control" or "you can't handle
2626 <object>" has been given and it is now unworn/unwielded
2627 and possibly dropped (depending upon caller); if dropped,
2628 carried effect was turned off, else we leave that alone;
2629 we turn off invocation property here if still carried */
2630 if (invoked && obj)
2631 (void) arti_invoke(obj); /* reverse #invoke */
2632 return TRUE;
2633 }
2634 }
2635 return FALSE;
2636}
2637
2638/* check all items currently in use (mostly worn) for touchability */
2639void

Callers 1

retouch_equipmentFunction · 0.85

Calls 3

get_artifactFunction · 0.85
retouch_objectFunction · 0.85
arti_invokeFunction · 0.85

Tested by

no test coverage detected