OSDN Git Service

Merge pull request #2946 from backwardsEric/sprintf-refactor-tombstone-generation
[hengbandforosx/hengbandosx.git] / src / inventory / item-getter.cpp
1 #include "inventory/item-getter.h"
2 #include "core/stuff-handler.h"
3 #include "core/window-redrawer.h"
4 #include "game-option/input-options.h"
5 #include "game-option/option-flags.h"
6 #include "game-option/text-display-options.h"
7 #include "inventory/floor-item-getter.h"
8 #include "inventory/inventory-slot-types.h"
9 #include "inventory/inventory-util.h"
10 #include "inventory/item-selection-util.h"
11 #include "io/command-repeater.h"
12 #include "io/input-key-acceptor.h"
13 #include "io/input-key-requester.h"
14 #include "main/sound-of-music.h"
15 #include "object/item-tester-hooker.h"
16 #include "object/item-use-flags.h"
17 #include "object/object-info.h"
18 #include "object/object-mark-types.h"
19 #include "player/player-status-flags.h"
20 #include "system/floor-type-definition.h"
21 #include "system/grid-type-definition.h"
22 #include "system/item-entity.h"
23 #include "system/player-type-definition.h"
24 #include "term/gameterm.h"
25 #include "term/screen-processor.h"
26 #include "term/z-form.h"
27 #include "util/int-char-converter.h"
28 #include "util/string-processor.h"
29 #include "view/display-inventory.h"
30 #include "view/display-messages.h"
31 #include "window/display-sub-windows.h"
32
33 /*!
34  * @brief オブジェクト選択のモード設定
35  * @param item_selection_ptr アイテム選択への参照ポインタ
36  */
37 static void check_item_selection_mode(item_selection_type *item_selection_ptr)
38 {
39     if (item_selection_ptr->mode & USE_EQUIP) {
40         item_selection_ptr->equip = true;
41     }
42
43     if (item_selection_ptr->mode & USE_INVEN) {
44         item_selection_ptr->inven = true;
45     }
46
47     if (item_selection_ptr->mode & USE_FLOOR) {
48         item_selection_ptr->floor = true;
49     }
50 }
51
52 /*!
53  * @brief アイテムへにタグ付けがされているかの調査処理 (のはず)
54  * @param player_ptr プレイヤーへの参照ポインタ
55  * @param item_selection_ptr アイテムへの参照ポインタ
56  * @return プレイヤーによりアイテムが選択されたならTRUEを返す
57  * @todo 適切な関数名をどうしても付けられなかったので暫定でauxとした
58  */
59 static bool check_item_tag_aux(PlayerType *player_ptr, item_selection_type *item_selection_ptr, const ItemTester &item_tester)
60 {
61     if (!item_selection_ptr->floor || (*item_selection_ptr->cp >= 0)) {
62         return false;
63     }
64
65     ItemEntity *o_ptr;
66     item_selection_ptr->k = 0 - (*item_selection_ptr->cp);
67     o_ptr = &player_ptr->current_floor_ptr->o_list[item_selection_ptr->k];
68     if (!item_tester.okay(o_ptr) && ((item_selection_ptr->mode & USE_FULL) == 0)) {
69         return false;
70     }
71
72     command_cmd = 0;
73     return true;
74 }
75
76 /*!
77  * @brief インベントリのアイテムにタグ付けがされているかの調査処理 (のはず)
78  * @param player_ptr プレイヤーへの参照ポインタ
79  * @param fis_ptr 床上アイテムへの参照ポインタ
80  * @param prev_tag 前回選択したアイテムのタグ (のはず)
81  * @return プレイヤーによりアイテムが選択されたならTRUEを返す
82  */
83 static bool check_item_tag_inventory(PlayerType *player_ptr, item_selection_type *item_selection_ptr, char *prev_tag, const ItemTester &item_tester)
84 {
85     if ((!item_selection_ptr->inven || (*item_selection_ptr->cp < 0) || (*item_selection_ptr->cp >= INVEN_PACK)) && (!item_selection_ptr->equip || (*item_selection_ptr->cp < INVEN_MAIN_HAND) || (*item_selection_ptr->cp >= INVEN_TOTAL))) {
86         return false;
87     }
88
89     if (*prev_tag && command_cmd) {
90
91         bool flag = false;
92         item_use_flag use_flag = (*item_selection_ptr->cp >= INVEN_MAIN_HAND) ? USE_EQUIP : USE_INVEN;
93
94         flag |= !get_tag(player_ptr, &item_selection_ptr->k, *prev_tag, use_flag, item_tester);
95         flag |= !get_item_okay(player_ptr, item_selection_ptr->k, item_tester);
96
97         if (item_selection_ptr->k < INVEN_MAIN_HAND) {
98             flag |= !item_selection_ptr->inven;
99         } else {
100             flag |= !item_selection_ptr->equip;
101         }
102
103         if (flag) {
104             *prev_tag = '\0';
105             return false;
106         }
107
108         *item_selection_ptr->cp = item_selection_ptr->k;
109         command_cmd = 0;
110         return true;
111     }
112
113     if (!get_item_okay(player_ptr, *item_selection_ptr->cp, item_tester)) {
114         return false;
115     }
116
117     command_cmd = 0;
118     return true;
119 }
120
121 /*!
122  * @brief アイテムにタグ付けがされているかの調査処理 (のはず)
123  * @param player_ptr プレイヤーへの参照ポインタ
124  * @param item_selection_ptr アイテムへの参照ポインタ
125  * @param prev_tag 前回選択したアイテムのタグ (のはず)
126  * @return プレイヤーによりアイテムが選択されたならTRUEを返す
127  */
128 static bool check_item_tag(PlayerType *player_ptr, item_selection_type *item_selection_ptr, char *prev_tag, const ItemTester &item_tester)
129 {
130     if (!repeat_pull(item_selection_ptr->cp)) {
131         return false;
132     }
133
134     if (item_selection_ptr->mode & USE_FORCE && (*item_selection_ptr->cp == INVEN_FORCE)) {
135         command_cmd = 0;
136         return true;
137     }
138
139     if (check_item_tag_aux(player_ptr, item_selection_ptr, item_tester)) {
140         return true;
141     }
142
143     return check_item_tag_inventory(player_ptr, item_selection_ptr, prev_tag, item_tester);
144 }
145
146 /*!
147  * @brief インベントリ内のアイテムが妥当かを判定する
148  * @param player_ptr プレイヤーへの参照ポインタ
149  * @param fis_ptr アイテム選択への参照ポインタ
150  */
151 static void test_inventory(PlayerType *player_ptr, item_selection_type *item_selection_ptr, const ItemTester &item_tester)
152 {
153     if (!item_selection_ptr->inven) {
154         item_selection_ptr->i2 = -1;
155         return;
156     }
157
158     if (!use_menu) {
159         return;
160     }
161
162     for (int j = 0; j < INVEN_PACK; j++) {
163         if (item_tester.okay(&player_ptr->inventory_list[j]) || (item_selection_ptr->mode & USE_FULL)) {
164             item_selection_ptr->max_inven++;
165         }
166     }
167 }
168
169 /*!
170  * @brief 装備品が妥当かを判定する
171  * @param player_ptr プレイヤーへの参照ポインタ
172  * @param fis_ptr アイテム選択への参照ポインタ
173  */
174 static void test_equipment(PlayerType *player_ptr, item_selection_type *item_selection_ptr, const ItemTester &item_tester)
175 {
176     if (!item_selection_ptr->equip) {
177         item_selection_ptr->e2 = -1;
178         return;
179     }
180
181     if (!use_menu) {
182         return;
183     }
184
185     for (int j = INVEN_MAIN_HAND; j < INVEN_TOTAL; j++) {
186         if (player_ptr->select_ring_slot ? is_ring_slot(j)
187                                          : item_tester.okay(&player_ptr->inventory_list[j]) || (item_selection_ptr->mode & USE_FULL)) {
188             item_selection_ptr->max_equip++;
189         }
190     }
191
192     if (has_two_handed_weapons(player_ptr) && !(item_selection_ptr->mode & IGNORE_BOTHHAND_SLOT)) {
193         item_selection_ptr->max_equip++;
194     }
195 }
196
197 /*!
198  * @brief オブジェクト選択の汎用関数 / General function for the selection of item
199  * Let the user select an item, save its "index"
200  * @param player_ptr プレイヤーへの参照ポインタ
201  * @param cp 選択したオブジェクトのID
202  * @param pmt 選択目的のメッセージ
203  * @param str 選択できるオブジェクトがない場合のキャンセルメッセージ
204  * @param mode オプションフラグ
205  * @return プレイヤーによりアイテムが選択されたならTRUEを返す
206  * Return TRUE only if an acceptable item was chosen by the user
207  */
208 bool get_item(PlayerType *player_ptr, OBJECT_IDX *cp, concptr pmt, concptr str, BIT_FLAGS mode, const ItemTester &item_tester)
209 {
210     static char prev_tag = '\0';
211     if (easy_floor || use_menu) {
212         return get_item_floor(player_ptr, cp, pmt, str, mode, item_tester);
213     }
214
215     item_selection_type tmp_selection;
216     item_selection_type *item_selection_ptr = initialize_item_selection_type(&tmp_selection, cp, mode);
217     check_item_selection_mode(item_selection_ptr);
218     if (check_item_tag(player_ptr, item_selection_ptr, &prev_tag, item_tester)) {
219         return true;
220     }
221
222     msg_print(nullptr);
223     item_selection_ptr->done = false;
224     item_selection_ptr->item = false;
225     item_selection_ptr->i1 = 0;
226     item_selection_ptr->i2 = INVEN_PACK - 1;
227     test_inventory(player_ptr, item_selection_ptr, item_tester);
228     while ((item_selection_ptr->i1 <= item_selection_ptr->i2) && (!get_item_okay(player_ptr, item_selection_ptr->i1, item_tester))) {
229         item_selection_ptr->i1++;
230     }
231
232     while ((item_selection_ptr->i1 <= item_selection_ptr->i2) && (!get_item_okay(player_ptr, item_selection_ptr->i2, item_tester))) {
233         item_selection_ptr->i2--;
234     }
235
236     item_selection_ptr->e1 = INVEN_MAIN_HAND;
237     item_selection_ptr->e2 = INVEN_TOTAL - 1;
238     test_equipment(player_ptr, item_selection_ptr, item_tester);
239     while ((item_selection_ptr->e1 <= item_selection_ptr->e2) && (!get_item_okay(player_ptr, item_selection_ptr->e1, item_tester))) {
240         item_selection_ptr->e1++;
241     }
242
243     while ((item_selection_ptr->e1 <= item_selection_ptr->e2) && (!get_item_okay(player_ptr, item_selection_ptr->e2, item_tester))) {
244         item_selection_ptr->e2--;
245     }
246
247     if (item_selection_ptr->equip && has_two_handed_weapons(player_ptr) && !(item_selection_ptr->mode & IGNORE_BOTHHAND_SLOT)) {
248         if (can_attack_with_main_hand(player_ptr)) {
249             if (item_selection_ptr->e2 < INVEN_SUB_HAND) {
250                 item_selection_ptr->e2 = INVEN_SUB_HAND;
251             }
252         } else if (can_attack_with_sub_hand(player_ptr)) {
253             item_selection_ptr->e1 = INVEN_MAIN_HAND;
254         }
255     }
256
257     if (item_selection_ptr->floor) {
258         for (const auto this_o_idx : player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].o_idx_list) {
259             ItemEntity *o_ptr;
260             o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx];
261             if ((item_tester.okay(o_ptr) || (item_selection_ptr->mode & USE_FULL)) && o_ptr->marked.has(OmType::FOUND)) {
262                 item_selection_ptr->allow_floor = true;
263             }
264         }
265     }
266
267     if (!item_selection_ptr->allow_floor && (item_selection_ptr->i1 > item_selection_ptr->i2) && (item_selection_ptr->e1 > item_selection_ptr->e2)) {
268         command_see = false;
269         item_selection_ptr->oops = true;
270         item_selection_ptr->done = true;
271
272         if (item_selection_ptr->mode & USE_FORCE) {
273             *item_selection_ptr->cp = INVEN_FORCE;
274             item_selection_ptr->item = true;
275         }
276     } else {
277         if (command_see && command_wrk && item_selection_ptr->equip) {
278             command_wrk = true;
279         } else if (item_selection_ptr->inven) {
280             command_wrk = false;
281         } else if (item_selection_ptr->equip) {
282             command_wrk = true;
283         } else {
284             command_wrk = false;
285         }
286     }
287
288     /* 追加オプション(always_show_list)が設定されている場合は常に一覧を表示する */
289     if (always_show_list || use_menu) {
290         command_see = true;
291     }
292
293     if (command_see) {
294         screen_save();
295     }
296
297     while (!item_selection_ptr->done) {
298         COMMAND_CODE get_item_label = 0;
299         int ni = 0;
300         int ne = 0;
301         for (auto i = 0U; i < angband_terms.size(); ++i) {
302             if (!angband_terms[i]) {
303                 continue;
304             }
305
306             if (window_flag[i] & (PW_INVEN)) {
307                 ni++;
308             }
309
310             if (window_flag[i] & (PW_EQUIP)) {
311                 ne++;
312             }
313         }
314
315         if ((command_wrk && ni && !ne) || (!command_wrk && !ni && ne)) {
316             toggle_inventory_equipment(player_ptr);
317             item_selection_ptr->toggle = !item_selection_ptr->toggle;
318         }
319
320         player_ptr->window_flags |= (PW_INVEN | PW_EQUIP);
321         handle_stuff(player_ptr);
322
323         if (!command_wrk) {
324             if (command_see) {
325                 get_item_label = show_inventory(player_ptr, item_selection_ptr->menu_line, item_selection_ptr->mode, item_tester);
326             }
327         } else {
328             if (command_see) {
329                 get_item_label = show_equipment(player_ptr, item_selection_ptr->menu_line, item_selection_ptr->mode, item_tester);
330             }
331         }
332
333         if (!command_wrk) {
334             angband_strcpy(item_selection_ptr->out_val, _("持ち物:", "Inven:"), sizeof(item_selection_ptr->out_val));
335             if ((item_selection_ptr->i1 <= item_selection_ptr->i2) && !use_menu) {
336                 char tmp_val[80];
337                 strnfmt(tmp_val, sizeof(tmp_val), _("%c-%c,'(',')',", " %c-%c,'(',')',"), index_to_label(item_selection_ptr->i1), index_to_label(item_selection_ptr->i2));
338                 angband_strcat(item_selection_ptr->out_val, tmp_val, sizeof(item_selection_ptr->out_val));
339             }
340
341             if (!command_see && !use_menu) {
342                 angband_strcat(item_selection_ptr->out_val, _(" '*'一覧,", " * to see,"), sizeof(item_selection_ptr->out_val));
343             }
344
345             if (item_selection_ptr->equip) {
346                 char tmp_val[80];
347                 strnfmt(tmp_val, sizeof(tmp_val), _(" %s 装備品,", " %s for Equip,"), use_menu ? _("'4'or'6'", "4 or 6") : _("'/'", "/"));
348                 angband_strcat(item_selection_ptr->out_val, tmp_val, sizeof(item_selection_ptr->out_val));
349             }
350         } else {
351             angband_strcpy(item_selection_ptr->out_val, _("装備品:", "Equip:"), sizeof(item_selection_ptr->out_val));
352             if ((item_selection_ptr->e1 <= item_selection_ptr->e2) && !use_menu) {
353                 char tmp_val[80];
354                 strnfmt(tmp_val, sizeof(tmp_val), _("%c-%c,'(',')',", " %c-%c,'(',')',"), index_to_label(item_selection_ptr->e1), index_to_label(item_selection_ptr->e2));
355                 angband_strcat(item_selection_ptr->out_val, tmp_val, sizeof(item_selection_ptr->out_val));
356             }
357
358             if (!command_see && !use_menu) {
359                 angband_strcat(item_selection_ptr->out_val, _(" '*'一覧,", " * to see,"), sizeof(item_selection_ptr->out_val));
360             }
361
362             if (item_selection_ptr->inven) {
363                 char tmp_val[80];
364                 strnfmt(tmp_val, sizeof(tmp_val), _(" %s 持ち物,", " %s for Inven,"), use_menu ? _("'4'or'6'", "4 or 6") : _("'/'", "'/'"));
365                 angband_strcat(item_selection_ptr->out_val, tmp_val, sizeof(item_selection_ptr->out_val));
366             }
367         }
368
369         if (item_selection_ptr->allow_floor) {
370             angband_strcat(item_selection_ptr->out_val, _(" '-'床上,", " - for floor,"), sizeof(item_selection_ptr->out_val));
371         }
372
373         if (item_selection_ptr->mode & USE_FORCE) {
374             angband_strcat(item_selection_ptr->out_val, _(" 'w'練気術,", " w for the Force,"), sizeof(item_selection_ptr->out_val));
375         }
376
377         angband_strcat(item_selection_ptr->out_val, " ESC", sizeof(item_selection_ptr->out_val));
378         strnfmt(item_selection_ptr->tmp_val, sizeof(item_selection_ptr->tmp_val), "(%s) %s", item_selection_ptr->out_val, pmt);
379         prt(item_selection_ptr->tmp_val, 0, 0);
380         item_selection_ptr->which = inkey();
381         if (use_menu) {
382             int max_line = (command_wrk ? item_selection_ptr->max_equip : item_selection_ptr->max_inven);
383             switch (item_selection_ptr->which) {
384             case ESCAPE:
385             case 'z':
386             case 'Z':
387             case '0': {
388                 item_selection_ptr->done = true;
389                 break;
390             }
391
392             case '8':
393             case 'k':
394             case 'K': {
395                 item_selection_ptr->menu_line += (max_line - 1);
396                 break;
397             }
398
399             case '2':
400             case 'j':
401             case 'J': {
402                 item_selection_ptr->menu_line++;
403                 break;
404             }
405
406             case '4':
407             case '6':
408             case 'h':
409             case 'H':
410             case 'l':
411             case 'L': {
412                 if (!item_selection_ptr->inven || !item_selection_ptr->equip) {
413                     bell();
414                     break;
415                 }
416
417                 if (command_see) {
418                     screen_load();
419                     screen_save();
420                 }
421
422                 command_wrk = !command_wrk;
423                 max_line = (command_wrk ? item_selection_ptr->max_equip : item_selection_ptr->max_inven);
424                 if (item_selection_ptr->menu_line > max_line) {
425                     item_selection_ptr->menu_line = max_line;
426                 }
427
428                 break;
429             }
430
431             case 'x':
432             case 'X':
433             case '\r':
434             case '\n': {
435                 if (command_wrk == USE_FLOOR) {
436                     *item_selection_ptr->cp = -get_item_label;
437                 } else {
438                     if (!get_item_okay(player_ptr, get_item_label, item_tester)) {
439                         bell();
440                         break;
441                     }
442
443                     if (!get_item_allow(player_ptr, get_item_label)) {
444                         item_selection_ptr->done = true;
445                         break;
446                     }
447
448                     *item_selection_ptr->cp = get_item_label;
449                 }
450
451                 item_selection_ptr->item = true;
452                 item_selection_ptr->done = true;
453                 break;
454             }
455             case 'w': {
456                 if (item_selection_ptr->mode & USE_FORCE) {
457                     *item_selection_ptr->cp = INVEN_FORCE;
458                     item_selection_ptr->item = true;
459                     item_selection_ptr->done = true;
460                     break;
461                 }
462             }
463             }
464
465             if (item_selection_ptr->menu_line > max_line) {
466                 item_selection_ptr->menu_line -= max_line;
467             }
468
469             continue;
470         }
471
472         switch (item_selection_ptr->which) {
473         case ESCAPE: {
474             item_selection_ptr->done = true;
475             break;
476         }
477         case '*':
478         case '?':
479         case ' ': {
480             if (command_see) {
481                 command_see = false;
482                 screen_load();
483             } else {
484                 screen_save();
485                 command_see = true;
486             }
487
488             break;
489         }
490         case '/': {
491             if (!item_selection_ptr->inven || !item_selection_ptr->equip) {
492                 bell();
493                 break;
494             }
495
496             if (command_see) {
497                 screen_load();
498                 screen_save();
499             }
500
501             command_wrk = !command_wrk;
502             break;
503         }
504         case '-': {
505             if (item_selection_ptr->allow_floor) {
506                 for (const auto this_o_idx : player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].o_idx_list) {
507                     ItemEntity *o_ptr;
508                     o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx];
509                     if (!item_tester.okay(o_ptr) && !(item_selection_ptr->mode & USE_FULL)) {
510                         continue;
511                     }
512
513                     item_selection_ptr->k = 0 - this_o_idx;
514                     if ((other_query_flag && !verify(player_ptr, _("本当に", "Try"), item_selection_ptr->k)) || !get_item_allow(player_ptr, item_selection_ptr->k)) {
515                         continue;
516                     }
517
518                     *item_selection_ptr->cp = item_selection_ptr->k;
519                     item_selection_ptr->item = true;
520                     item_selection_ptr->done = true;
521                     break;
522                 }
523
524                 if (item_selection_ptr->done) {
525                     break;
526                 }
527             }
528
529             bell();
530             break;
531         }
532         case '0':
533         case '1':
534         case '2':
535         case '3':
536         case '4':
537         case '5':
538         case '6':
539         case '7':
540         case '8':
541         case '9': {
542             if (!get_tag(player_ptr, &item_selection_ptr->k, item_selection_ptr->which, command_wrk ? USE_EQUIP : USE_INVEN, item_tester)) {
543                 bell();
544                 break;
545             }
546
547             if ((item_selection_ptr->k < INVEN_MAIN_HAND) ? !item_selection_ptr->inven : !item_selection_ptr->equip) {
548                 bell();
549                 break;
550             }
551
552             if (!get_item_okay(player_ptr, item_selection_ptr->k, item_tester)) {
553                 bell();
554                 break;
555             }
556
557             if (!get_item_allow(player_ptr, item_selection_ptr->k)) {
558                 item_selection_ptr->done = true;
559                 break;
560             }
561
562             *item_selection_ptr->cp = item_selection_ptr->k;
563             item_selection_ptr->item = true;
564             item_selection_ptr->done = true;
565             item_selection_ptr->cur_tag = item_selection_ptr->which;
566             break;
567         }
568         case 'w': {
569             if (item_selection_ptr->mode & USE_FORCE) {
570                 *item_selection_ptr->cp = INVEN_FORCE;
571                 item_selection_ptr->item = true;
572                 item_selection_ptr->done = true;
573                 break;
574             }
575         }
576             [[fallthrough]];
577         default: {
578             bool tag_not_found = false;
579
580             if (!get_tag(player_ptr, &item_selection_ptr->k, item_selection_ptr->which, command_wrk ? USE_EQUIP : USE_INVEN, item_tester)) {
581                 tag_not_found = true;
582             } else if ((item_selection_ptr->k < INVEN_MAIN_HAND) ? !item_selection_ptr->inven : !item_selection_ptr->equip) {
583                 tag_not_found = true;
584             }
585
586             if (!tag_not_found) {
587                 item_selection_ptr->cur_tag = item_selection_ptr->which;
588             } else {
589                 auto which = (char)tolower(item_selection_ptr->which);
590
591                 if (!command_wrk) {
592                     if (which == '(') {
593                         item_selection_ptr->k = item_selection_ptr->i1;
594                     } else if (which == ')') {
595                         item_selection_ptr->k = item_selection_ptr->i2;
596                     } else {
597                         item_selection_ptr->k = label_to_inventory(player_ptr, which);
598                     }
599                 } else {
600                     if (which == '(') {
601                         item_selection_ptr->k = item_selection_ptr->e1;
602                     } else if (which == ')') {
603                         item_selection_ptr->k = item_selection_ptr->e2;
604                     } else {
605                         item_selection_ptr->k = label_to_equipment(player_ptr, which);
606                     }
607                 }
608             }
609
610             if (!get_item_okay(player_ptr, item_selection_ptr->k, item_tester)) {
611                 bell();
612                 break;
613             }
614
615             auto ver = tag_not_found && isupper(item_selection_ptr->which);
616             if (ver && !verify(player_ptr, _("本当に", "Try"), item_selection_ptr->k)) {
617                 item_selection_ptr->done = true;
618                 break;
619             }
620
621             if (!get_item_allow(player_ptr, item_selection_ptr->k)) {
622                 item_selection_ptr->done = true;
623                 break;
624             }
625
626             *item_selection_ptr->cp = item_selection_ptr->k;
627             item_selection_ptr->item = true;
628             item_selection_ptr->done = true;
629             break;
630         }
631         }
632     }
633
634     if (command_see) {
635         screen_load();
636         command_see = false;
637     }
638
639     if (item_selection_ptr->toggle) {
640         toggle_inventory_equipment(player_ptr);
641     }
642
643     player_ptr->window_flags |= (PW_INVEN | PW_EQUIP);
644     handle_stuff(player_ptr);
645     prt("", 0, 0);
646     if (item_selection_ptr->oops && str) {
647         msg_print(str);
648     }
649
650     if (item_selection_ptr->item) {
651         repeat_push(*item_selection_ptr->cp);
652         if (command_cmd) {
653             prev_tag = item_selection_ptr->cur_tag;
654         }
655         command_cmd = 0;
656     }
657
658     return item_selection_ptr->item;
659 }