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

Function mpickstuff

src/mon.c:1846–1910  ·  view source on GitHub ↗

monster picks up one item stack from the map location they are at */

Source from the content-addressed store, hash-verified

1844
1845/* monster picks up one item stack from the map location they are at */
1846boolean
1847mpickstuff(struct monst *mtmp)
1848{
1849 struct obj *otmp, *otmp2, *otmp3;
1850 int carryamt = 0;
1851
1852 /* prevent shopkeepers from leaving the door of their shop */
1853 if (mtmp->isshk && inhishop(mtmp))
1854 return FALSE;
1855
1856 /* non-tame monsters normally don't go shopping */
1857 if (!mtmp->mtame && *in_rooms(mtmp->mx, mtmp->my, SHOPBASE) && rn2(25))
1858 return FALSE;
1859
1860 /* item in a pool, but monster can't swim */
1861 if (!could_reach_item(mtmp, mtmp->mx, mtmp->my))
1862 return FALSE;
1863
1864 for (otmp = svl.level.objects[mtmp->mx][mtmp->my]; otmp; otmp = otmp2) {
1865 otmp2 = otmp->nexthere;
1866
1867 /* avoid special items; once hero picks them up, they'll cease
1868 being special, becoming eligible for normal pickup */
1869 if (is_mines_prize(otmp) || is_soko_prize(otmp))
1870 continue;
1871
1872 /* Nymphs take everything. Most monsters don't pick up corpses. */
1873 if (mon_would_take_item(mtmp, otmp)) {
1874
1875 if (otmp->otyp == CORPSE && mtmp->data->mlet != S_NYMPH
1876 /* let a handful of corpse types thru to can_carry() */
1877 && !touch_petrifies(&mons[otmp->corpsenm])
1878 && otmp->corpsenm != PM_LIZARD
1879 && !acidic(&mons[otmp->corpsenm]))
1880 continue;
1881 if (!can_touch_safely(mtmp, otmp))
1882 continue;
1883 carryamt = can_carry(mtmp, otmp);
1884 if (carryamt == 0)
1885 continue;
1886 /* handle cases where the critter can only get some */
1887 otmp3 = otmp;
1888 if (carryamt != otmp->quan) {
1889 otmp3 = splitobj(otmp, carryamt);
1890 }
1891 if (cansee(mtmp->mx, mtmp->my)) {
1892 /* call distant_name() for its possible side-effects even
1893 if the result won't be printed; do it before the extract
1894 from floor and subsequent pickup by mtmp */
1895 char *otmpname = distant_name(otmp, doname);
1896
1897 if (flags.verbose)
1898 pline_mon(mtmp, "%s picks up %s.",
1899 Monnam(mtmp), otmpname);
1900 }
1901 obj_extract_self(otmp3); /* remove from floor */
1902 (void) mpickobj(mtmp, otmp3); /* may merge and free otmp3 */
1903 /* let them try to equip it on the next turn */

Callers 1

monmove.cFile · 0.85

Calls 15

inhishopFunction · 0.85
in_roomsFunction · 0.85
rn2Function · 0.85
could_reach_itemFunction · 0.85
mon_would_take_itemFunction · 0.85
can_touch_safelyFunction · 0.85
can_carryFunction · 0.85
splitobjFunction · 0.85
distant_nameFunction · 0.85
pline_monFunction · 0.85
MonnamFunction · 0.85
obj_extract_selfFunction · 0.85

Tested by

no test coverage detected