* Have the hero pick things from the ground * or a monster's inventory if swallowed. * * Arg what: * >0 autopickup * =0 interactive * <0 pickup count of something * * Returns 1 if tried to pick something up, whether * or not it succeeded. */
| 669 | * or not it succeeded. |
| 670 | */ |
| 671 | int |
| 672 | pickup(int what) /* should be a long */ |
| 673 | { |
| 674 | int i, n, res, count, n_tried = 0, n_picked = 0; |
| 675 | menu_item *pick_list = (menu_item *) 0; |
| 676 | boolean autopickup = what > 0; |
| 677 | struct obj **objchain_p; |
| 678 | int traverse_how; |
| 679 | |
| 680 | /* we might have arrived here while fainted or sleeping, via |
| 681 | random teleport or levitation timeout; if so, skip check_here |
| 682 | and read_engr_at in addition to bypassing autopickup itself |
| 683 | [probably ought to check whether hero is using a cockatrice |
| 684 | corpse for a pillow here... (also at initial faint/sleep)] */ |
| 685 | if (autopickup && gm.multi < 0 && unconscious()) { |
| 686 | iflags.prev_decor = STONE; |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | /* used by pickup_object() for encumbrance feedback */ |
| 691 | gp.pickup_encumbrance = 0; |
| 692 | |
| 693 | if (what < 0) /* pick N of something */ |
| 694 | count = -what; |
| 695 | else /* pick anything */ |
| 696 | count = 0; |
| 697 | |
| 698 | if (!u.uswallow) { |
| 699 | struct trap *t; |
| 700 | |
| 701 | /* no auto-pick if no-pick move, nothing there, or in a pool */ |
| 702 | if (autopickup && (svc.context.nopick || !OBJ_AT(u.ux, u.uy) |
| 703 | || (is_pool(u.ux, u.uy) && !Underwater) |
| 704 | || is_lava(u.ux, u.uy))) { |
| 705 | if (flags.mention_decor) |
| 706 | (void) describe_decor(); |
| 707 | read_engr_at(u.ux, u.uy); |
| 708 | return 0; |
| 709 | } |
| 710 | /* no pickup if levitating & not on air or water level */ |
| 711 | t = t_at(u.ux, u.uy); |
| 712 | if (!can_reach_floor(t && is_pit(t->ttyp))) { |
| 713 | (void) describe_decor(); /* even when !flags.mention_decor */ |
| 714 | if ((gm.multi && !svc.context.run) |
| 715 | || (autopickup && !flags.pickup) |
| 716 | || (t && (uteetering_at_seen_pit(t) || uescaped_shaft(t)))) |
| 717 | read_engr_at(u.ux, u.uy); |
| 718 | return 0; |
| 719 | } |
| 720 | /* multi && !svc.context.run means they are in the middle of some |
| 721 | * other action, or possibly paralyzed, sleeping, etc.... and they |
| 722 | * just teleported onto the object. They shouldn't pick it up. |
| 723 | */ |
| 724 | if ((gm.multi && !svc.context.run) |
| 725 | || (autopickup && !flags.pickup) |
| 726 | || notake(gy.youmonst.data)) { |
| 727 | check_here(FALSE); |
| 728 | if (notake(gy.youmonst.data) && OBJ_AT(u.ux, u.uy) |
no test coverage detected