1 #include "inventory/item-getter.h"
2 #include "core/stuff-handler.h"
3 #include "floor/floor.h"
4 #include "game-option/input-options.h"
5 #include "game-option/option-flags.h"
6 #include "game-option/text-display-options.h"
8 #include "inventory/floor-item-getter.h"
9 #include "inventory/inventory-util.h"
10 #include "inventory/player-inventory.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 "term/gameterm.h"
20 #include "term/screen-processor.h"
21 #include "util/int-char-converter.h"
22 #include "view/display-messages.h"
25 * @brief オブジェクト選択の汎用関数 /
26 * Let the user select an item, save its "index"
27 * @param owner_ptr プレーヤーへの参照ポインタ
28 * @param cp 選択したオブジェクトのIDを返す。
29 * @param pmt 選択目的のメッセージ
30 * @param str 選択できるオブジェクトがない場合のキャンセルメッセージ
31 * @param mode オプションフラグ
32 * @return プレイヤーによりアイテムが選択されたならTRUEを返す。/
33 * Return TRUE only if an acceptable item was chosen by the user.\n
35 bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str, BIT_FLAGS mode, tval_type tval)
37 OBJECT_IDX this_o_idx, next_o_idx = 0;
48 bool allow_floor = FALSE;
52 int menu_line = (use_menu ? 1 : 0);
55 static char prev_tag = '\0';
57 if (easy_floor || use_menu)
58 return get_item_floor(owner_ptr, cp, pmt, str, mode, tval);
69 if (repeat_pull(cp)) {
70 if (mode & USE_FORCE && (*cp == INVEN_FORCE)) {
72 item_tester_hook = NULL;
75 } else if (floor && (*cp < 0)) {
78 o_ptr = &owner_ptr->current_floor_ptr->o_list[k];
79 if (item_tester_okay(owner_ptr, o_ptr, tval) || (mode & USE_FULL)) {
81 item_tester_hook = NULL;
85 } else if ((inven && (*cp >= 0) && (*cp < INVEN_PACK)) || (equip && (*cp >= INVEN_RARM) && (*cp < INVEN_TOTAL))) {
86 if (prev_tag && command_cmd) {
87 if (!get_tag(owner_ptr, &k, prev_tag, (*cp >= INVEN_RARM) ? USE_EQUIP : USE_INVEN, tval)) /* Reject */
89 else if ((k < INVEN_RARM) ? !inven : !equip) /* Reject */
91 else if (!get_item_okay(owner_ptr, k, tval)) /* Reject */
96 item_tester_hook = NULL;
102 } else if (get_item_okay(owner_ptr, *cp, tval)) {
104 item_tester_hook = NULL;
119 for (j = 0; j < INVEN_PACK; j++)
120 if (item_tester_okay(owner_ptr, &owner_ptr->inventory_list[j], tval) || (mode & USE_FULL))
123 while ((i1 <= i2) && (!get_item_okay(owner_ptr, i1, tval)))
126 while ((i1 <= i2) && (!get_item_okay(owner_ptr, i2, tval)))
130 e2 = INVEN_TOTAL - 1;
134 for (j = INVEN_RARM; j < INVEN_TOTAL; j++)
135 if (select_ring_slot ? is_ring_slot(j) : item_tester_okay(owner_ptr, &owner_ptr->inventory_list[j], tval) || (mode & USE_FULL))
138 if (owner_ptr->ryoute && !(mode & IGNORE_BOTHHAND_SLOT))
142 while ((e1 <= e2) && (!get_item_okay(owner_ptr, e1, tval)))
145 while ((e1 <= e2) && (!get_item_okay(owner_ptr, e2, tval)))
148 if (equip && owner_ptr->ryoute && !(mode & IGNORE_BOTHHAND_SLOT)) {
149 if (owner_ptr->migite) {
152 } else if (owner_ptr->hidarite)
157 for (this_o_idx = owner_ptr->current_floor_ptr->grid_array[owner_ptr->y][owner_ptr->x].o_idx; this_o_idx; this_o_idx = next_o_idx) {
159 o_ptr = &owner_ptr->current_floor_ptr->o_list[this_o_idx];
160 next_o_idx = o_ptr->next_o_idx;
161 if ((item_tester_okay(owner_ptr, o_ptr, tval) || (mode & USE_FULL)) && (o_ptr->marked & OM_FOUND))
166 if (!allow_floor && (i1 > i2) && (e1 > e2)) {
171 if (mode & USE_FORCE) {
176 if (command_see && command_wrk && equip)
186 /* 追加オプション(always_show_list)が設定されている場合は常に一覧を表示する */
187 if ((always_show_list == TRUE) || use_menu)
194 COMMAND_CODE get_item_label = 0;
197 for (j = 0; j < 8; j++) {
198 if (!angband_term[j])
201 if (window_flag[j] & (PW_INVEN))
204 if (window_flag[j] & (PW_EQUIP))
208 if ((command_wrk && ni && !ne) || (!command_wrk && !ni && ne)) {
209 toggle_inventory_equipment(owner_ptr);
213 owner_ptr->window |= (PW_INVEN | PW_EQUIP);
214 handle_stuff(owner_ptr);
218 get_item_label = show_inventory(owner_ptr, menu_line, mode, tval);
221 get_item_label = show_equipment(owner_ptr, menu_line, mode, tval);
225 sprintf(out_val, _("持ち物:", "Inven:"));
226 if ((i1 <= i2) && !use_menu) {
227 sprintf(tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"), index_to_label(i1), index_to_label(i2));
228 strcat(out_val, tmp_val);
231 if (!command_see && !use_menu)
232 strcat(out_val, _(" '*'一覧,", " * to see,"));
235 strcat(out_val, format(_(" %s 装備品,", " %s for Equip,"), use_menu ? _("'4'or'6'", "4 or 6") : _("'/'", "/")));
237 sprintf(out_val, _("装備品:", "Equip:"));
238 if ((e1 <= e2) && !use_menu) {
239 sprintf(tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"), index_to_label(e1), index_to_label(e2));
240 strcat(out_val, tmp_val);
243 if (!command_see && !use_menu)
244 strcat(out_val, _(" '*'一覧,", " * to see,"));
247 strcat(out_val, format(_(" %s 持ち物,", " %s for Inven,"), use_menu ? _("'4'or'6'", "4 or 6") : _("'/'", "'/'")));
251 strcat(out_val, _(" '-'床上,", " - for floor,"));
253 if (mode & USE_FORCE)
254 strcat(out_val, _(" 'w'練気術,", " w for the Force,"));
256 strcat(out_val, " ESC");
257 sprintf(tmp_val, "(%s) %s", out_val, pmt);
261 int max_line = (command_wrk ? max_equip : max_inven);
274 menu_line += (max_line - 1);
291 if (!inven || !equip) {
301 command_wrk = !command_wrk;
302 max_line = (command_wrk ? max_equip : max_inven);
303 if (menu_line > max_line)
304 menu_line = max_line;
313 if (command_wrk == USE_FLOOR) {
314 (*cp) = -get_item_label;
316 if (!get_item_okay(owner_ptr, get_item_label, tval)) {
321 if (!get_item_allow(owner_ptr, get_item_label)) {
326 (*cp) = get_item_label;
334 if (mode & USE_FORCE) {
343 if (menu_line > max_line)
344 menu_line -= max_line;
368 if (!inven || !equip) {
378 command_wrk = !command_wrk;
383 for (this_o_idx = owner_ptr->current_floor_ptr->grid_array[owner_ptr->y][owner_ptr->x].o_idx; this_o_idx; this_o_idx = next_o_idx) {
385 o_ptr = &owner_ptr->current_floor_ptr->o_list[this_o_idx];
386 next_o_idx = o_ptr->next_o_idx;
387 if (!item_tester_okay(owner_ptr, o_ptr, tval) && !(mode & USE_FULL))
391 if (other_query_flag && !verify(owner_ptr, _("本当に", "Try"), k) || !get_item_allow(owner_ptr, k))
417 if (!get_tag(owner_ptr, &k, which, command_wrk ? USE_EQUIP : USE_INVEN, tval)) {
422 if ((k < INVEN_RARM) ? !inven : !equip) {
427 if (!get_item_okay(owner_ptr, k, tval)) {
432 if (!get_item_allow(owner_ptr, k)) {
444 if (mode & USE_FORCE) {
454 bool not_found = FALSE;
455 if (!get_tag(owner_ptr, &k, which, command_wrk ? USE_EQUIP : USE_INVEN, tval)) {
457 } else if ((k < INVEN_RARM) ? !inven : !equip) {
459 } else if (!get_item_okay(owner_ptr, k, tval)) {
471 ver = isupper(which);
472 which = (char)tolower(which);
476 else if (which == ')')
479 k = label_to_inventory(owner_ptr, which);
483 else if (which == ')')
486 k = label_to_equipment(owner_ptr, which);
489 if (!get_item_okay(owner_ptr, k, tval)) {
494 if (ver && !verify(owner_ptr, _("本当に", "Try"), k)) {
499 if (!get_item_allow(owner_ptr, k)) {
518 item_tester_hook = NULL;
520 toggle_inventory_equipment(owner_ptr);
522 owner_ptr->window |= (PW_INVEN | PW_EQUIP);
523 handle_stuff(owner_ptr);