MCPcopy Index your code
hub / github.com/NetHack/NetHack / dozap

Function dozap

src/zap.c:2626–2683  ·  view source on GitHub ↗

#zap command, 'z' (or 'y' if numbed_pad==-1) */

Source from the content-addressed store, hash-verified

2624
2625/* #zap command, 'z' (or 'y' if numbed_pad==-1) */
2626int
2627dozap(void)
2628{
2629 struct obj *obj;
2630 int damage, need_dir;
2631
2632 if (nohands(gy.youmonst.data)) {
2633 You("aren't able to zap anything in your current form.");
2634 return ECMD_OK;
2635 }
2636 if (check_capacity((char *) 0))
2637 return ECMD_OK;
2638 obj = getobj("zap", zap_ok, GETOBJ_NOFLAGS);
2639 if (!obj)
2640 return ECMD_CANCEL;
2641
2642 check_unpaid(obj);
2643
2644 need_dir = objects[obj->otyp].oc_dir != NODIR;
2645 if (!zappable(obj)) {
2646 pline1(nothing_happens);
2647 } else if (obj->cursed && !rn2(WAND_BACKFIRE_CHANCE)) {
2648 backfire(obj); /* the wand blows up in your face! */
2649 exercise(A_STR, FALSE);
2650 /* 'obj' is gone; skip update_inventory() because
2651 backfire() -> useupall() -> freeinv() did it */
2652 return ECMD_TIME;
2653 } else if (need_dir && !getdir((char *) 0)) {
2654 if (!Blind)
2655 pline("%s glows and fades.", The(xname(obj)));
2656 /* make him pay for knowing !NODIR */
2657 } else if (need_dir && !u.dx && !u.dy && !u.dz) {
2658 if ((damage = zapyourself(obj, TRUE)) != 0) {
2659 char buf[BUFSZ];
2660
2661 Sprintf(buf, "zapped %sself with %s",
2662 uhim(), killer_xname(obj));
2663 losehp(Maybe_Half_Phys(damage), buf, NO_KILLER_PREFIX);
2664 }
2665 } else {
2666 /* Are we having fun yet?
2667 * weffects -> buzz(obj->otyp) -> zhitm (temple priest) ->
2668 * attack -> hitum -> known_hitum -> ghod_hitsu ->
2669 * buzz(AD_ELEC) -> destroy_items(AD_ELEC) ->
2670 * useup -> obfree -> dealloc_obj -> free(obj)
2671 */
2672 gc.current_wand = obj;
2673 weffects(obj);
2674 obj = gc.current_wand;
2675 gc.current_wand = 0;
2676 }
2677 if (obj && obj->spe < 0) {
2678 pline("%s to dust.", Tobjnam(obj, "turn"));
2679 useupall(obj); /* calls freeinv() -> update_inventory() */
2680 } else
2681 update_inventory(); /* maybe used a charge */
2682 return ECMD_TIME;
2683}

Callers

nothing calls this directly

Calls 15

YouFunction · 0.85
check_capacityFunction · 0.85
getobjFunction · 0.85
check_unpaidFunction · 0.85
zappableFunction · 0.85
rn2Function · 0.85
backfireFunction · 0.85
exerciseFunction · 0.85
getdirFunction · 0.85
TheFunction · 0.85
xnameFunction · 0.85
zapyourselfFunction · 0.85

Tested by

no test coverage detected