OSDN Git Service

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