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

Function mloot_container

src/muse.c:2263–2378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2261}
2262
2263staticfn int
2264mloot_container(
2265 struct monst *mon,
2266 struct obj *container,
2267 boolean vismon)
2268{
2269 char contnr_nam[BUFSZ], mpronounbuf[20];
2270 boolean nearby;
2271 int takeout_indx, takeout_count, howfar, res = 0;
2272
2273 if (!container || !Has_contents(container) || container->olocked)
2274 return res; /* 0 */
2275 /* FIXME: handle cursed bag of holding */
2276 if (Is_mbag(container) && container->cursed)
2277 return res; /* 0 */
2278 if (SchroedingersBox(container))
2279 return res;
2280
2281 switch (rn2(10)) {
2282 default: /* case 0, 1, 2, 3: */
2283 takeout_count = 1;
2284 break;
2285 case 4: case 5: case 6:
2286 takeout_count = 2;
2287 break;
2288 case 7: case 8:
2289 takeout_count = 3;
2290 break;
2291 case 9:
2292 takeout_count = 4;
2293 break;
2294 }
2295 howfar = mdistu(mon);
2296 nearby = (howfar <= 7 * 7);
2297 contnr_nam[0] = mpronounbuf[0] = '\0';
2298 if (vismon) {
2299 /* do this once so that when hallucinating it won't change
2300 from one item to the next */
2301 Strcpy(mpronounbuf, mhe(mon));
2302 }
2303
2304 for (takeout_indx = 0; takeout_indx < takeout_count; ++takeout_indx) {
2305 struct obj *xobj;
2306 int nitems;
2307
2308 if (!Has_contents(container)) /* might have removed all items */
2309 break;
2310 /* TODO?
2311 * Monster ought to prioritize on something it wants to use.
2312 */
2313 nitems = 0;
2314 for (xobj = container->cobj; xobj != 0; xobj = xobj->nobj)
2315 ++nitems;
2316 /* nitems is always greater than 0 due to Has_contents() check;
2317 throttle item removal as the container becomes less filled */
2318 if (!rn2(nitems + 1))
2319 break;
2320 nitems = rn2(nitems);

Callers 1

use_miscFunction · 0.85

Calls 15

rn2Function · 0.85
anFunction · 0.85
xnameFunction · 0.85
distant_nameFunction · 0.85
obj_extract_selfFunction · 0.85
can_carryFunction · 0.85
NorepFunction · 0.85
MonnamFunction · 0.85
pline_monFunction · 0.85
donameFunction · 0.85
upstartFunction · 0.85
removed_from_iceboxFunction · 0.85

Tested by

no test coverage detected