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

Function pickup_object

src/pickup.c:1802–1888  ·  view source on GitHub ↗

* Pick up of obj from the ground and add it to the hero's inventory. * Returns -1 if caller should break out of its loop, 0 if nothing picked * up, 1 if otherwise. */

Source from the content-addressed store, hash-verified

1800 * up, 1 if otherwise.
1801 */
1802int
1803pickup_object(
1804 struct obj *obj,
1805 long count, /* if non-zero, pick up a subset of this amount */
1806 boolean telekinesis) /* not picking it up directly by hand */
1807{
1808 int res;
1809
1810 if (obj->quan < count) {
1811 impossible("pickup_object: count %ld > quan %ld?", count, obj->quan);
1812 return 0;
1813 }
1814
1815 /* In case of auto-pickup, where we haven't had a chance
1816 to look at it yet; affects docall(SCR_SCARE_MONSTER). */
1817 if (!Blind)
1818 observe_object(obj);
1819
1820 if (obj == uchain) { /* do not pick up attached chain */
1821 return 0;
1822 } else if (obj->where == OBJ_MINVENT && obj->owornmask != 0L
1823 && engulfing_u(obj->ocarry)) {
1824 You_cant("pick %s up.", ysimple_name(obj));
1825 return 0;
1826 } else if (obj->oartifact && !touch_artifact(obj, &gy.youmonst)) {
1827 return 0;
1828 } else if (obj->otyp == CORPSE) {
1829 if (fatal_corpse_mistake(obj, telekinesis)
1830 || rider_corpse_revival(obj, telekinesis))
1831 return -1;
1832 } else if (obj->otyp == SCR_SCARE_MONSTER) {
1833 int old_wt, new_wt;
1834
1835 /* process a count before altering/deleting scrolls;
1836 tricky because being unable to lift full stack imposes an
1837 implicit count; unliftable ones should be treated as if
1838 the count excluded them so that they don't change state */
1839 if ((count = carry_count(obj, (struct obj *) 0,
1840 count ? count : obj->quan,
1841 FALSE, &old_wt, &new_wt)) < 1L)
1842 return -1; /* couldn't even pick up 1, so effectively untouched */
1843 /* all current callers handle a new object sanely when traversing
1844 a list; other half of a split will be left as-is and whatever
1845 already follows 'obj' will still be processed next */
1846 if (count > 0L && count < obj->quan)
1847 obj = splitobj(obj, count);
1848
1849 if (obj->blessed) {
1850 unbless(obj);
1851 } else if (!obj->spe && !obj->cursed) {
1852 obj->spe = 1;
1853 } else {
1854 pline_The("scroll%s %s to dust as you %s %s up.", plur(obj->quan),
1855 otense(obj, "turn"), telekinesis ? "raise" : "pick",
1856 (obj->quan == 1L) ? "it" : "them");
1857 trycall(obj);
1858 useupf(obj, obj->quan);
1859 return 1; /* tried to pick something up and failed, but

Callers 3

pickupFunction · 0.85
use_whipFunction · 0.85
use_grappleFunction · 0.85

Calls 15

observe_objectFunction · 0.85
You_cantFunction · 0.85
ysimple_nameFunction · 0.85
touch_artifactFunction · 0.85
fatal_corpse_mistakeFunction · 0.85
rider_corpse_revivalFunction · 0.85
carry_countFunction · 0.85
splitobjFunction · 0.85
unblessFunction · 0.85
pline_TheFunction · 0.85
otenseFunction · 0.85
trycallFunction · 0.85

Tested by

no test coverage detected