| 2653 | } |
| 2654 | |
| 2655 | staticfn int |
| 2656 | throw_gold(struct obj *obj) |
| 2657 | { |
| 2658 | int range, odx, ody; |
| 2659 | struct monst *mon; |
| 2660 | |
| 2661 | if (!u.dx && !u.dy && !u.dz) { |
| 2662 | You("cannot throw gold at yourself."); |
| 2663 | /* If we tried to throw part of a stack, force it to merge back |
| 2664 | together (same as in throw_obj). Essential for gold. */ |
| 2665 | if (obj->o_id == svc.context.objsplit.parent_oid |
| 2666 | || obj->o_id == svc.context.objsplit.child_oid) |
| 2667 | (void) unsplitobj(obj); |
| 2668 | return ECMD_CANCEL; |
| 2669 | } |
| 2670 | freeinv(obj); |
| 2671 | if (u.uswallow) { |
| 2672 | const char *swallower = mon_nam(u.ustuck); |
| 2673 | |
| 2674 | if (digests(u.ustuck->data)) |
| 2675 | /* note: s_suffix() returns a modifiable buffer */ |
| 2676 | swallower = strcat(s_suffix(swallower), " entrails"); |
| 2677 | pline_The("gold disappears into %s.", swallower); |
| 2678 | add_to_minv(u.ustuck, obj); |
| 2679 | return ECMD_TIME; |
| 2680 | } |
| 2681 | |
| 2682 | if (u.dz) { |
| 2683 | if (u.dz < 0 && !Is_airlevel(&u.uz) && !Underwater |
| 2684 | && !Is_waterlevel(&u.uz)) { |
| 2685 | pline_The("gold hits the %s, then falls back on top of your %s.", |
| 2686 | ceiling(u.ux, u.uy), body_part(HEAD)); |
| 2687 | /* some self damage? */ |
| 2688 | if (uarmh) |
| 2689 | pline("Fortunately, you are wearing %s!", |
| 2690 | an(helm_simple_name(uarmh))); |
| 2691 | } |
| 2692 | gb.bhitpos.x = u.ux; |
| 2693 | gb.bhitpos.y = u.uy; |
| 2694 | } else { |
| 2695 | /* consistent with range for normal objects */ |
| 2696 | range = (int) ((ACURRSTR) / 2 - obj->owt / 40); |
| 2697 | |
| 2698 | /* see if the gold has a place to move into */ |
| 2699 | odx = u.ux + u.dx; |
| 2700 | ody = u.uy + u.dy; |
| 2701 | if (!isok(odx, ody) |
| 2702 | || !ZAP_POS(levl[odx][ody].typ) || closed_door(odx, ody)) { |
| 2703 | gb.bhitpos.x = u.ux; |
| 2704 | gb.bhitpos.y = u.uy; |
| 2705 | } else { |
| 2706 | mon = bhit(u.dx, u.dy, range, THROWN_WEAPON, |
| 2707 | (int (*)(MONST_P, OBJ_P)) 0, |
| 2708 | (int (*)(OBJ_P, OBJ_P)) 0, &obj); |
| 2709 | if (!obj) |
| 2710 | return ECMD_TIME; /* object is gone */ |
| 2711 | if (mon) { |
| 2712 | if (ghitm(mon, obj)) /* was it caught? */ |
no test coverage detected