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"
23 #include "view/display-sub-windows.h"
26 * @brief オブジェクト選択の汎用関数 /
27 * Let the user select an item, save its "index"
28 * @param owner_ptr プレーヤーへの参照ポインタ
29 * @param cp 選択したオブジェクトのIDを返す。
30 * @param pmt 選択目的のメッセージ
31 * @param str 選択できるオブジェクトがない場合のキャンセルメッセージ
32 * @param mode オプションフラグ
33 * @return プレイヤーによりアイテムが選択されたならTRUEを返す。/
34 * Return TRUE only if an acceptable item was chosen by the user.\n
36 bool get_item(player_type *owner_ptr, OBJECT_IDX *cp, concptr pmt, concptr str, BIT_FLAGS mode, tval_type tval)
38 OBJECT_IDX this_o_idx, next_o_idx = 0;
49 bool allow_floor = FALSE;
53 int menu_line = (use_menu ? 1 : 0);
56 static char prev_tag = '\0';
58 if (easy_floor || use_menu)
59 return get_item_floor(owner_ptr, cp, pmt, str, mode, tval);
70 if (repeat_pull(cp)) {
71 if (mode & USE_FORCE && (*cp == INVEN_FORCE)) {
73 item_tester_hook = NULL;
76 } else if (floor && (*cp < 0)) {
79 o_ptr = &owner_ptr->current_floor_ptr->o_list[k];
80 if (item_tester_okay(owner_ptr, o_ptr, tval) || (mode & USE_FULL)) {
82 item_tester_hook = NULL;
86 } else if ((inven && (*cp >= 0) && (*cp < INVEN_PACK)) || (equip && (*cp >= INVEN_RARM) && (*cp < INVEN_TOTAL))) {
87 if (prev_tag && command_cmd) {
88 if (!get_tag(owner_ptr, &k, prev_tag, (*cp >= INVEN_RARM) ? USE_EQUIP : USE_INVEN, tval)) /* Reject */
90 else if ((k < INVEN_RARM) ? !inven : !equip) /* Reject */
92 else if (!get_item_okay(owner_ptr, k, tval)) /* Reject */
97 item_tester_hook = NULL;
103 } else if (get_item_okay(owner_ptr, *cp, tval)) {
105 item_tester_hook = NULL;
120 for (j = 0; j < INVEN_PACK; j++)
121 if (item_tester_okay(owner_ptr, &owner_ptr->inventory_list[j], tval) || (mode & USE_FULL))
124 while ((i1 <= i2) && (!get_item_okay(owner_ptr, i1, tval)))
127 while ((i1 <= i2) && (!get_item_okay(owner_ptr, i2, tval)))
131 e2 = INVEN_TOTAL - 1;
135 for (j = INVEN_RARM; j < INVEN_TOTAL; j++)
136 if (select_ring_slot ? is_ring_slot(j) : item_tester_okay(owner_ptr, &owner_ptr->inventory_list[j], tval) || (mode & USE_FULL))
139 if (owner_ptr->ryoute && !(mode & IGNORE_BOTHHAND_SLOT))
143 while ((e1 <= e2) && (!get_item_okay(owner_ptr, e1, tval)))
146 while ((e1 <= e2) && (!get_item_okay(owner_ptr, e2, tval)))
149 if (equip && owner_ptr->ryoute && !(mode & IGNORE_BOTHHAND_SLOT)) {
150 if (owner_ptr->migite) {
153 } else if (owner_ptr->hidarite)
158 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) {
160 o_ptr = &owner_ptr->current_floor_ptr->o_list[this_o_idx];
161 next_o_idx = o_ptr->next_o_idx;
162 if ((item_tester_okay(owner_ptr, o_ptr, tval) || (mode & USE_FULL)) && (o_ptr->marked & OM_FOUND))
167 if (!allow_floor && (i1 > i2) && (e1 > e2)) {
172 if (mode & USE_FORCE) {
177 if (command_see && command_wrk && equip)
187 /* 追加オプション(always_show_list)が設定されている場合は常に一覧を表示する */
188 if ((always_show_list == TRUE) || use_menu)
195 COMMAND_CODE get_item_label = 0;
198 for (j = 0; j < 8; j++) {
199 if (!angband_term[j])
202 if (window_flag[j] & (PW_INVEN))
205 if (window_flag[j] & (PW_EQUIP))
209 if ((command_wrk && ni && !ne) || (!command_wrk && !ni && ne)) {
210 toggle_inventory_equipment(owner_ptr);
214 owner_ptr->window |= (PW_INVEN | PW_EQUIP);
215 handle_stuff(owner_ptr);
219 get_item_label = show_inventory(owner_ptr, menu_line, mode, tval);
222 get_item_label = show_equipment(owner_ptr, menu_line, mode, tval);
226 sprintf(out_val, _("持ち物:", "Inven:"));
227 if ((i1 <= i2) && !use_menu) {
228 sprintf(tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"), index_to_label(i1), index_to_label(i2));
229 strcat(out_val, tmp_val);
232 if (!command_see && !use_menu)
233 strcat(out_val, _(" '*'一覧,", " * to see,"));
236 strcat(out_val, format(_(" %s 装備品,", " %s for Equip,"), use_menu ? _("'4'or'6'", "4 or 6") : _("'/'", "/")));
238 sprintf(out_val, _("装備品:", "Equip:"));
239 if ((e1 <= e2) && !use_menu) {
240 sprintf(tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"), index_to_label(e1), index_to_label(e2));
241 strcat(out_val, tmp_val);
244 if (!command_see && !use_menu)
245 strcat(out_val, _(" '*'一覧,", " * to see,"));
248 strcat(out_val, format(_(" %s 持ち物,", " %s for Inven,"), use_menu ? _("'4'or'6'", "4 or 6") : _("'/'", "'/'")));
252 strcat(out_val, _(" '-'床上,", " - for floor,"));
254 if (mode & USE_FORCE)
255 strcat(out_val, _(" 'w'練気術,", " w for the Force,"));
257 strcat(out_val, " ESC");
258 sprintf(tmp_val, "(%s) %s", out_val, pmt);
262 int max_line = (command_wrk ? max_equip : max_inven);
275 menu_line += (max_line - 1);
292 if (!inven || !equip) {
302 command_wrk = !command_wrk;
303 max_line = (command_wrk ? max_equip : max_inven);
304 if (menu_line > max_line)
305 menu_line = max_line;
314 if (command_wrk == USE_FLOOR) {
315 (*cp) = -get_item_label;
317 if (!get_item_okay(owner_ptr, get_item_label, tval)) {
322 if (!get_item_allow(owner_ptr, get_item_label)) {
327 (*cp) = get_item_label;
335 if (mode & USE_FORCE) {
344 if (menu_line > max_line)
345 menu_line -= max_line;
369 if (!inven || !equip) {
379 command_wrk = !command_wrk;
384 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) {
386 o_ptr = &owner_ptr->current_floor_ptr->o_list[this_o_idx];
387 next_o_idx = o_ptr->next_o_idx;
388 if (!item_tester_okay(owner_ptr, o_ptr, tval) && !(mode & USE_FULL))
392 if (other_query_flag && !verify(owner_ptr, _("本当に", "Try"), k) || !get_item_allow(owner_ptr, k))
418 if (!get_tag(owner_ptr, &k, which, command_wrk ? USE_EQUIP : USE_INVEN, tval)) {
423 if ((k < INVEN_RARM) ? !inven : !equip) {
428 if (!get_item_okay(owner_ptr, k, tval)) {
433 if (!get_item_allow(owner_ptr, k)) {
445 if (mode & USE_FORCE) {
455 bool not_found = FALSE;
456 if (!get_tag(owner_ptr, &k, which, command_wrk ? USE_EQUIP : USE_INVEN, tval)) {
458 } else if ((k < INVEN_RARM) ? !inven : !equip) {
460 } else if (!get_item_okay(owner_ptr, k, tval)) {
472 ver = isupper(which);
473 which = (char)tolower(which);
477 else if (which == ')')
480 k = label_to_inventory(owner_ptr, which);
484 else if (which == ')')
487 k = label_to_equipment(owner_ptr, which);
490 if (!get_item_okay(owner_ptr, k, tval)) {
495 if (ver && !verify(owner_ptr, _("本当に", "Try"), k)) {
500 if (!get_item_allow(owner_ptr, k)) {
519 item_tester_hook = NULL;
521 toggle_inventory_equipment(owner_ptr);
523 owner_ptr->window |= (PW_INVEN | PW_EQUIP);
524 handle_stuff(owner_ptr);