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

Function pick_obj

src/pickup.c:1896–1942  ·  view source on GitHub ↗

* Do the actual work of picking otmp from the floor or monster's interior * and putting it in the hero's inventory. Take care of billing. Return a * pointer to the object where otmp ends up. This may be different * from otmp because of merging. */

Source from the content-addressed store, hash-verified

1894 * from otmp because of merging.
1895 */
1896struct obj *
1897pick_obj(struct obj *otmp)
1898{
1899 struct obj *result;
1900 coordxy ox, oy;
1901 boolean robshop, fromfloor = otmp->where == OBJ_FLOOR;
1902
1903 /* otmp is either on the floor or in an engulfer's inventory; for the
1904 latter, its <ox,oy> probably won't be set */
1905 (void) get_obj_location(otmp, &ox, &oy, 0);
1906
1907 robshop = (!u.uswallow && otmp != uball && costly_spot(ox, oy));
1908 obj_extract_self(otmp);
1909 if (fromfloor)
1910 newsym(ox, oy);
1911
1912 /* for shop items, addinv() needs to be after addtobill() (so that
1913 object merger can take otmp->unpaid into account) but before
1914 remote_robbery() (which calls rob_shop() which calls setpaid()
1915 after moving costs of unpaid items to shop debt; setpaid()
1916 calls clear_unpaid() for lots of object chains, but 'otmp' isn't
1917 on any of those between obj_extract_self() and addinv(); for
1918 3.6.0, 'otmp' remained flagged as an unpaid item in inventory
1919 and triggered impossible() every time inventory was examined) */
1920 if (robshop) {
1921 char saveushops[5], fakeshop[2];
1922
1923 /* addtobill cares about your location rather than the object's;
1924 usually they'll be the same, but not when using telekinesis
1925 (if ever implemented) or a grappling hook */
1926 Strcpy(saveushops, u.ushops);
1927 fakeshop[0] = *in_rooms(ox, oy, SHOPBASE);
1928 fakeshop[1] = '\0';
1929 Strcpy(u.ushops, fakeshop);
1930 /* sets obj->unpaid if necessary */
1931 addtobill(otmp, TRUE, FALSE, FALSE);
1932 Strcpy(u.ushops, saveushops);
1933 robshop = otmp->unpaid && !strchr(u.ushops, *fakeshop);
1934 }
1935
1936 result = addinv(otmp);
1937 /* if you're taking a shop item from outside the shop, make shk notice */
1938 if (robshop)
1939 remote_burglary(ox, oy);
1940
1941 return result;
1942}
1943
1944/* pickup_object()/out_container() helper;
1945 print an added-to-invent message for current object, limiting feedback

Callers 1

pickup_objectFunction · 0.85

Calls 8

get_obj_locationFunction · 0.85
costly_spotFunction · 0.85
obj_extract_selfFunction · 0.85
newsymFunction · 0.85
in_roomsFunction · 0.85
addtobillFunction · 0.85
addinvFunction · 0.85
remote_burglaryFunction · 0.85

Tested by

no test coverage detected