loot current_container (take things out or put things in), using a menu */
| 3262 | |
| 3263 | /* loot current_container (take things out or put things in), using a menu */ |
| 3264 | staticfn int |
| 3265 | menu_loot(int retry, boolean put_in) |
| 3266 | { |
| 3267 | int n, i, n_looted = 0; |
| 3268 | boolean all_categories = TRUE, loot_everything = FALSE, autopick = FALSE; |
| 3269 | char buf[BUFSZ]; |
| 3270 | boolean loot_justpicked = FALSE; |
| 3271 | const char *action = put_in ? "Put in" : "Take out"; |
| 3272 | struct obj *otmp, *otmp2; |
| 3273 | menu_item *pick_list; |
| 3274 | int mflags, res; |
| 3275 | long count = 0; |
| 3276 | |
| 3277 | gp.pickup_encumbrance = 0; /* used by out_container(); no harm in |
| 3278 | * zeroing it if about to use in_container() */ |
| 3279 | if (retry) { |
| 3280 | all_categories = (retry == -2); |
| 3281 | } else if (flags.menu_style == MENU_FULL) { |
| 3282 | all_categories = FALSE; |
| 3283 | Sprintf(buf, "%s what type of objects?", action); |
| 3284 | mflags = (ALL_TYPES | UNPAID_TYPES | BUCX_TYPES | CHOOSE_ALL |
| 3285 | | JUSTPICKED ); |
| 3286 | n = query_category(buf, |
| 3287 | put_in ? gi.invent : gc.current_container->cobj, |
| 3288 | mflags, &pick_list, PICK_ANY); |
| 3289 | /* when paranoid_confirm:A is set, 'A' by itself implies |
| 3290 | 'A'+'a' which will be followed by a confirmation prompt; |
| 3291 | when that option isn't set, 'A' by itself is rejected |
| 3292 | by query_categorry() and result here will be n==0 */ |
| 3293 | if (!n) |
| 3294 | return ECMD_OK; /* no non-autopick category filters specified */ |
| 3295 | |
| 3296 | for (i = 0; i < n; i++) { |
| 3297 | if (pick_list[i].item.a_int == 'A') { |
| 3298 | loot_everything = autopick = TRUE; |
| 3299 | } else if (put_in && pick_list[i].item.a_int == 'P') { |
| 3300 | loot_justpicked = TRUE; |
| 3301 | count = max(0, pick_list[i].count); |
| 3302 | add_valid_menu_class(pick_list[i].item.a_int); |
| 3303 | loot_everything = FALSE; |
| 3304 | } else if (pick_list[i].item.a_int == ALL_TYPES_SELECTED) { |
| 3305 | all_categories = TRUE; |
| 3306 | } else { |
| 3307 | add_valid_menu_class(pick_list[i].item.a_int); |
| 3308 | loot_everything = FALSE; |
| 3309 | } |
| 3310 | } |
| 3311 | free((genericptr_t) pick_list); |
| 3312 | } |
| 3313 | |
| 3314 | if (autopick) { |
| 3315 | int (*inout_func)(struct obj *); /* in_container or out_container */ |
| 3316 | struct obj *firstobj; |
| 3317 | |
| 3318 | if (!put_in) { |
| 3319 | gc.current_container->cknown = 1; |
| 3320 | inout_func = out_container; |
| 3321 | firstobj = gc.current_container->cobj; |
no test coverage detected