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

Function display_minventory

src/invent.c:5340–5386  ·  view source on GitHub ↗

* Display a monster's inventory. * Returns a pointer to the object from the monster's inventory selected * or NULL if nothing was selected. * * By default, only worn and wielded items are displayed. The caller * can pick one. Modifier flags are: * * PICK_NONE, PICK_ONE - standard menu control * PICK_ANY - allowed, but we only return a single object * MINV_NOLET

Source from the content-addressed store, hash-verified

5338 * MINV_ALL - display all inventory
5339 */
5340struct obj *
5341display_minventory(
5342 struct monst *mon, /* monster whose minvent we're showing */
5343 int dflags, /* control over what to display */
5344 char *title) /* menu title */
5345{
5346 struct obj *ret;
5347 char tmp[QBUFSZ];
5348 int n;
5349 menu_item *selected = 0;
5350 int do_all = (dflags & MINV_ALL) != 0,
5351 incl_hero = (do_all && engulfing_u(mon)),
5352 have_inv = (mon->minvent != 0),
5353 have_any = (have_inv || incl_hero),
5354 pickings = (dflags & MINV_PICKMASK);
5355
5356 Sprintf(tmp, "%s %s:", s_suffix(noit_Monnam(mon)),
5357 do_all ? "possessions" : "armament");
5358
5359 if (do_all ? have_any : (mon->misc_worn_check || MON_WEP(mon))) {
5360 /* Fool the 'weapon in hand' routine into
5361 * displaying 'weapon in claw', etc. properly.
5362 */
5363 gy.youmonst.data = mon->data;
5364 /* in case inside a shop, don't append "for sale" prices */
5365 iflags.suppress_price++;
5366
5367 n = query_objlist(title ? title : tmp, &(mon->minvent),
5368 (INVORDER_SORT | (incl_hero ? INCLUDE_HERO : 0)),
5369 &selected, pickings,
5370 do_all ? allow_all : worn_wield_only);
5371
5372 iflags.suppress_price--;
5373 /* was 'set_uasmon();' but that potentially has side-effects */
5374 gy.youmonst.data = &mons[u.umonnum]; /* basic part of set_uasmon() */
5375 } else {
5376 invdisp_nothing(title ? title : tmp, "(none)");
5377 n = 0;
5378 }
5379
5380 if (n > 0) {
5381 ret = selected[0].item.a_obj;
5382 free((genericptr_t) selected);
5383 } else
5384 ret = (struct obj *) 0;
5385 return ret;
5386}
5387
5388/* format a container name for cinventory_display(), inserting "trapped"
5389 if that's appropriate */

Callers 2

look_hereFunction · 0.85
probe_monsterFunction · 0.85

Calls 4

s_suffixFunction · 0.85
noit_MonnamFunction · 0.85
query_objlistFunction · 0.85
invdisp_nothingFunction · 0.85

Tested by

no test coverage detected