monster picks up one item stack from the map location they are at */
| 1844 | |
| 1845 | /* monster picks up one item stack from the map location they are at */ |
| 1846 | boolean |
| 1847 | mpickstuff(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 */ |
no test coverage detected