* 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
| 1022 | * FEEL_COCKATRICE - touch corpse. |
| 1023 | */ |
| 1024 | int |
| 1025 | query_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 |
no test coverage detected