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

Function query_objlist

src/pickup.c:1024–1216  ·  view source on GitHub ↗

* Put up a menu using the given object list. Only those objects on the * list that meet the approval of the allow function are displayed. Return * a count of the number of items selected, as well as an allocated array of * menu_items, containing pointers to the objects selected and counts. The * returned counts are guaranteed to be in bounds and non-zero. * * Query flags: * BY_NEXTH

Source from the content-addressed store, hash-verified

1022 * FEEL_COCKATRICE - touch corpse.
1023 */
1024int
1025query_objlist(const char *qstr, /* query string */
1026 struct obj **olist_p, /* the list to pick from */
1027 int qflags, /* options to control the query */
1028 menu_item **pick_list, /* return list of items picked */
1029 int how, /* type of query */
1030 boolean (*allow)(OBJ_P)) /* allow function */
1031{
1032 int i, n, tmpglyph;
1033 winid win;
1034 struct obj *curr, *last, fake_hero_object, *olist = *olist_p;
1035 char *pack, packbuf[MAXOCLASSES + 1];
1036 anything any;
1037 boolean printed_type_name, first,
1038 sorted = (qflags & INVORDER_SORT) != 0,
1039 engulfer = (qflags & INCLUDE_HERO) != 0,
1040 engulfer_minvent;
1041 unsigned sortflags;
1042 glyph_info tmpglyphinfo = nul_glyphinfo;
1043 Loot *sortedolist, *srtoli;
1044 int clr = NO_COLOR;
1045
1046 *pick_list = (menu_item *) 0;
1047 if (!olist && !engulfer)
1048 return 0;
1049
1050 /* count the number of items allowed */
1051 for (n = 0, last = 0, curr = olist; curr; curr = FOLLOW(curr, qflags))
1052 if ((*allow)(curr)) {
1053 last = curr;
1054 n++;
1055 }
1056 /* can't depend upon 'engulfer' because that's used to indicate whether
1057 hero should be shown as an extra, fake item */
1058 engulfer_minvent = (olist && olist->where == OBJ_MINVENT
1059 && engulfing_u(olist->ocarry));
1060 if (engulfer_minvent && n == 1 && olist->owornmask != 0L) {
1061 qflags &= ~AUTOSELECT_SINGLE;
1062 }
1063 if (engulfer) {
1064 ++n;
1065 /* don't autoselect swallowed hero if it's the only choice */
1066 qflags &= ~AUTOSELECT_SINGLE;
1067 }
1068
1069 if (n == 0) /* nothing to pick here */
1070 return (qflags & SIGNAL_NOMENU) ? -1 : 0;
1071
1072 if (n == 1 && (qflags & AUTOSELECT_SINGLE)) {
1073 *pick_list = (menu_item *) alloc(sizeof (menu_item));
1074 (*pick_list)->item.a_obj = last;
1075 (*pick_list)->count = last->quan;
1076 return 1;
1077 }
1078
1079 sortflags = (((flags.sortloot == 'f'
1080 || (flags.sortloot == 'l' && !(qflags & USE_INVLET)))
1081 ? SORTLOOT_LOOT

Callers 9

menu_remarmFunction · 0.85
menu_dropFunction · 0.85
menu_identifyFunction · 0.85
dotypeinvFunction · 0.85
display_minventoryFunction · 0.85
display_cinventoryFunction · 0.85
display_binventoryFunction · 0.85
pickupFunction · 0.85
menu_lootFunction · 0.85

Calls 15

sortlootFunction · 0.85
add_menu_strFunction · 0.85
strkittenFunction · 0.85
will_feel_cockatriceFunction · 0.85
look_hereFunction · 0.85
unsortlootFunction · 0.85
add_menu_headingFunction · 0.85
let_to_nameFunction · 0.85
map_glyphinfoFunction · 0.85
add_menuFunction · 0.85
doname_with_priceFunction · 0.85
anFunction · 0.85

Tested by

no test coverage detected