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

Function lift_object

src/pickup.c:1704–1795  ·  view source on GitHub ↗

determine whether character is able and player is willing to carry `obj' */

Source from the content-addressed store, hash-verified

1702
1703/* determine whether character is able and player is willing to carry `obj' */
1704staticfn int
1705lift_object(
1706 struct obj *obj, /* object to pick up... */
1707 struct obj *container, /* ...bag it's coming out of */
1708 long *cnt_p,
1709 boolean telekinesis)
1710{
1711 int result, old_wt, new_wt, prev_encumbr, next_encumbr;
1712
1713 if (obj->otyp == BOULDER && Sokoban) {
1714 You("cannot get your %s around this %s.", body_part(HAND),
1715 xname(obj));
1716 return -1;
1717 }
1718 /* override weight consideration for loadstone picked up by anybody
1719 and for boulder picked up by hero poly'd into a giant; override
1720 availability of open inventory slot iff not already carrying one */
1721 if (obj->otyp == LOADSTONE
1722 || (obj->otyp == BOULDER && throws_rocks(gy.youmonst.data))) {
1723 if (inv_cnt(FALSE) < invlet_basic || !carrying(obj->otyp)
1724 || merge_choice(gi.invent, obj))
1725 return 1; /* lift regardless of current situation */
1726 /* if we reach here, we're out of slots and already have at least
1727 one of these, so treat this one more like a normal item
1728 [this was using simpleonames(obj) for shortest description, but
1729 that's suboptimal for loadstones because it omits user-assigned
1730 type name which is something of interest for gray stones] */
1731 You("are carrying too much stuff to pick up %s %s.",
1732 (obj->quan == 1L) ? "another" : "more", xname(obj));
1733 return -1;
1734 }
1735
1736 *cnt_p = carry_count(obj, container, *cnt_p, telekinesis,
1737 &old_wt, &new_wt);
1738 if (*cnt_p < 1L) {
1739 result = -1; /* nothing lifted */
1740 } else if (obj->oclass != COIN_CLASS
1741 /* [exception for gold coins will have to change
1742 if silver/copper ones ever get implemented] */
1743 && inv_cnt(FALSE) >= invlet_basic
1744 && !merge_choice(gi.invent, obj)) {
1745 /* if there is some gold here (and we haven't already skipped it),
1746 we aren't limited by the 52 item limit for it, but caller and
1747 "grandcaller" aren't prepared to skip stuff and then pickup
1748 just gold, so the best we can do here is vary the message */
1749 Your("knapsack cannot accommodate any more items%s.",
1750 /* floor follows by nexthere, otherwise container so by nobj */
1751 nxtobj(obj, GOLD_PIECE, (boolean) (obj->where == OBJ_FLOOR))
1752 ? " (except gold)" : "");
1753 result = -1; /* nothing lifted */
1754 } else {
1755 result = 1;
1756 prev_encumbr = near_capacity();
1757 if (prev_encumbr < flags.pickup_burden)
1758 prev_encumbr = flags.pickup_burden;
1759 next_encumbr = calc_capacity(new_wt - old_wt);
1760 if (next_encumbr > prev_encumbr) {
1761 if (telekinesis) {

Callers 2

pickup_objectFunction · 0.85
out_containerFunction · 0.85

Calls 12

YouFunction · 0.85
body_partFunction · 0.85
xnameFunction · 0.85
inv_cntFunction · 0.85
carryingFunction · 0.85
merge_choiceFunction · 0.85
carry_countFunction · 0.85
YourFunction · 0.85
nxtobjFunction · 0.85
near_capacityFunction · 0.85
calc_capacityFunction · 0.85
safe_qbufFunction · 0.85

Tested by

no test coverage detected