OSDN Git Service

[Refactor] #38997 disterb() に player_type * 引数を追加. / Add player_type * argument to...
[hengband/hengband.git] / src / player-inventory.c
1 #include "angband.h"
2 #include "core.h"
3 #include "util.h"
4 #include "player-inventory.h"
5
6 #include "term.h"
7 #include "object.h"
8 #include "objectkind.h"
9 #include "object-flavor.h"
10 #include "object-hook.h"
11 #include "floor.h"
12 #include "player-move.h"
13
14 #include "view-mainwindow.h"
15
16 bool select_ring_slot;
17
18 /*!
19  * @brief プレイヤーの所持/装備オブジェクトIDが指輪枠かを返す /
20  * @param i プレイヤーの所持/装備オブジェクトID
21  * @return 指輪枠ならばTRUEを返す。
22  */
23 bool is_ring_slot(int i)
24 {
25         return (i == INVEN_RIGHT) || (i == INVEN_LEFT);
26 }
27
28
29 /*!
30  * @brief 選択アルファベットラベルからプレイヤーの装備オブジェクトIDを返す /
31  * Convert a label into the index of a item in the "equip"
32  * @return 対応するID。該当スロットにオブジェクトが存在しなかった場合-1を返す / Return "-1" if the label does not indicate a real item
33  */
34 static INVENTORY_IDX label_to_equip(int c)
35 {
36         INVENTORY_IDX i;
37
38         /* Convert */
39         i = (INVENTORY_IDX)(islower(c) ? A2I(c) : -1) + INVEN_RARM;
40
41         /* Verify the index */
42         if ((i < INVEN_RARM) || (i >= INVEN_TOTAL)) return (-1);
43
44         if (select_ring_slot) return is_ring_slot(i) ? i : -1;
45
46         /* Empty slots can never be chosen */
47         if (!p_ptr->inventory_list[i].k_idx) return (-1);
48
49         /* Return the index */
50         return (i);
51 }
52
53 /*!
54  * @brief 選択アルファベットラベルからプレイヤーの所持オブジェクトIDを返す /
55  * Convert a label into the index of an item in the "inven"
56  * @return 対応するID。該当スロットにオブジェクトが存在しなかった場合-1を返す / Return "-1" if the label does not indicate a real item
57  * @details Note that the label does NOT distinguish inven/equip.
58  */
59 static INVENTORY_IDX label_to_inven(int c)
60 {
61         INVENTORY_IDX i;
62
63         /* Convert */
64         i = (INVENTORY_IDX)(islower(c) ? A2I(c) : -1);
65
66         /* Verify the index */
67         if ((i < 0) || (i > INVEN_PACK)) return (-1);
68
69         /* Empty slots can never be chosen */
70         if (!p_ptr->inventory_list[i].k_idx) return (-1);
71
72         /* Return the index */
73         return (i);
74 }
75
76
77 /*!
78  * @brief 所持/装備オブジェクトIDの部位表現を返す /
79  * Return a string mentioning how a given item is carried
80  * @param i 部位表現を求めるプレイヤーの所持/装備オブジェクトID
81  * @return 部位表現の文字列ポインタ
82  */
83 static concptr mention_use(player_type *creature_ptr, int i)
84 {
85         concptr p;
86
87         /* Examine the location */
88         switch (i)
89         {
90 #ifdef JP
91         case INVEN_RARM:  p = creature_ptr->heavy_wield[0] ? "運搬中" : ((creature_ptr->ryoute && creature_ptr->migite) ? " 両手" : (left_hander ? " 左手" : " 右手")); break;
92 #else
93         case INVEN_RARM:  p = creature_ptr->heavy_wield[0] ? "Just lifting" : (creature_ptr->migite ? "Wielding" : "On arm"); break;
94 #endif
95
96 #ifdef JP
97         case INVEN_LARM:  p = creature_ptr->heavy_wield[1] ? "運搬中" : ((creature_ptr->ryoute && creature_ptr->hidarite) ? " 両手" : (left_hander ? " 右手" : " 左手")); break;
98 #else
99         case INVEN_LARM:  p = creature_ptr->heavy_wield[1] ? "Just lifting" : (creature_ptr->hidarite ? "Wielding" : "On arm"); break;
100 #endif
101
102         case INVEN_BOW:   p = (adj_str_hold[creature_ptr->stat_ind[A_STR]] < creature_ptr->inventory_list[i].weight / 10) ? _("運搬中", "Just holding") : _("射撃用", "Shooting"); break;
103         case INVEN_RIGHT: p = (left_hander ? _("左手指", "On left hand") : _("右手指", "On right hand")); break;
104         case INVEN_LEFT:  p = (left_hander ? _("右手指", "On right hand") : _("左手指", "On left hand")); break;
105         case INVEN_NECK:  p = _("  首", "Around neck"); break;
106         case INVEN_LITE:  p = _(" 光源", "Light source"); break;
107         case INVEN_BODY:  p = _("  体", "On body"); break;
108         case INVEN_OUTER: p = _("体の上", "About body"); break;
109         case INVEN_HEAD:  p = _("  頭", "On head"); break;
110         case INVEN_HANDS: p = _("  手", "On hands"); break;
111         case INVEN_FEET:  p = _("  足", "On feet"); break;
112         default:          p = _("ザック", "In pack"); break;
113         }
114
115         /* Return the result */
116         return p;
117 }
118
119 /*!
120  * @brief 装備アイテム一覧を表示する /
121  * Choice window "shadow" of the "show_equip()" function
122  * @return なし
123  */
124 void display_equip(OBJECT_TYPE_VALUE tval)
125 {
126         register int i, n;
127         object_type *o_ptr;
128         TERM_COLOR attr = TERM_WHITE;
129         char tmp_val[80];
130         GAME_TEXT o_name[MAX_NLEN];
131         TERM_LEN wid, hgt;
132
133         Term_get_size(&wid, &hgt);
134
135         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
136         {
137                 o_ptr = &p_ptr->inventory_list[i];
138                 tmp_val[0] = tmp_val[1] = tmp_val[2] = ' ';
139                 if (select_ring_slot ? is_ring_slot(i) : item_tester_okay(o_ptr, tval))
140                 {
141                         tmp_val[0] = index_to_label(i);
142                         tmp_val[1] = ')';
143                 }
144
145                 Term_putstr(0, i - INVEN_RARM, 3, TERM_WHITE, tmp_val);
146                 if ((((i == INVEN_RARM) && p_ptr->hidarite) || ((i == INVEN_LARM) && p_ptr->migite)) && p_ptr->ryoute)
147                 {
148                         strcpy(o_name, _("(武器を両手持ち)", "(wielding with two-hands)"));
149                         attr = TERM_WHITE;
150                 }
151                 else
152                 {
153                         object_desc(o_name, o_ptr, 0);
154                         attr = tval_to_attr[o_ptr->tval % 128];
155                 }
156
157                 n = strlen(o_name);
158                 if (o_ptr->timeout)
159                 {
160                         attr = TERM_L_DARK;
161                 }
162                 Term_putstr(3, i - INVEN_RARM, n, attr, o_name);
163
164                 Term_erase(3 + n, i - INVEN_RARM, 255);
165
166                 if (show_weights)
167                 {
168                         int wgt = o_ptr->weight * o_ptr->number;
169 #ifdef JP
170                         sprintf(tmp_val, "%3d.%1d kg", lbtokg1(wgt), lbtokg2(wgt));
171 #else
172                         sprintf(tmp_val, "%3d.%1d lb", wgt / 10, wgt % 10);
173 #endif
174
175                         prt(tmp_val, i - INVEN_RARM, wid - (show_labels ? 28 : 9));
176                 }
177
178                 if (show_labels)
179                 {
180                         Term_putstr(wid - 20, i - INVEN_RARM, -1, TERM_WHITE, " <-- ");
181                         prt(mention_use(p_ptr, i), i - INVEN_RARM, wid - 15);
182                 }
183         }
184
185         for (i = INVEN_TOTAL - INVEN_RARM; i < hgt; i++)
186         {
187                 Term_erase(0, i, 255);
188         }
189 }
190
191 /*!
192  * @brief サブウィンドウに所持品、装備品リストの表示を行う /
193  * Flip "inven" and "equip" in any sub-windows
194  * @return なし
195  */
196 void toggle_inven_equip(player_type *creature_ptr)
197 {
198         int j;
199
200         /* Scan windows */
201         for (j = 0; j < 8; j++)
202         {
203                 /* Unused */
204                 if (!angband_term[j]) continue;
205
206                 /* Flip inven to equip */
207                 if (window_flag[j] & (PW_INVEN))
208                 {
209                         /* Flip flags */
210                         window_flag[j] &= ~(PW_INVEN);
211                         window_flag[j] |= (PW_EQUIP);
212
213                         creature_ptr->window |= (PW_EQUIP);
214                 }
215
216                 /* Flip inven to equip */
217                 else if (window_flag[j] & (PW_EQUIP))
218                 {
219                         /* Flip flags */
220                         window_flag[j] &= ~(PW_EQUIP);
221                         window_flag[j] |= (PW_INVEN);
222
223                         creature_ptr->window |= (PW_INVEN);
224                 }
225         }
226 }
227
228
229 /*!
230  * @brief プレイヤーの所持/装備オブジェクトが正規のものかを返す /
231  * Auxiliary function for "get_item()" -- test an index
232  * @param i 選択アイテムID
233  * @return 正規のIDならばTRUEを返す。
234  */
235 bool get_item_okay(OBJECT_IDX i)
236 {
237         /* Illegal items */
238         if ((i < 0) || (i >= INVEN_TOTAL)) return (FALSE);
239
240         if (select_ring_slot) return is_ring_slot(i);
241
242         /* Verify the item */
243         if (!item_tester_okay(&p_ptr->inventory_list[i], item_tester_tval)) return (FALSE);
244
245         /* Assume okay */
246         return (TRUE);
247 }
248
249 /*!
250  * @brief 規定の処理にできるアイテムがプレイヤーの利用可能範囲内にあるかどうかを返す /
251  * Determine whether get_item() can get some item or not
252  * @return アイテムを拾えるならばTRUEを返す。
253  * @details assuming mode = (USE_EQUIP | USE_INVEN | USE_FLOOR).
254  */
255 bool can_get_item(OBJECT_TYPE_VALUE tval)
256 {
257         int j;
258         OBJECT_IDX floor_list[23];
259         ITEM_NUMBER floor_num = 0;
260
261         for (j = 0; j < INVEN_TOTAL; j++)
262                 if (item_tester_okay(&p_ptr->inventory_list[j], tval))
263                         return TRUE;
264
265         floor_num = scan_floor(floor_list, p_ptr->y, p_ptr->x, 0x03);
266         if (floor_num)
267                 return TRUE;
268
269         return FALSE;
270 }
271
272
273 /*!
274  * @brief 床オブジェクトに選択タグを与える/タグに該当するオブジェクトがあるかを返す /
275  * Find the "first" p_ptr->inventory_list object with the given "tag".
276  * @param cp 対応するタグIDを与える参照ポインタ
277  * @param tag 該当するオブジェクトがあるかを調べたいタグ
278  * @param floor_list 床上アイテムの配列
279  * @param floor_num  床上アイテムの配列ID
280  * @return タグに該当するオブジェクトがあるならTRUEを返す
281  * @details
282  * A "tag" is a numeral "n" appearing as "@n" anywhere in the\n
283  * inscription of an object.  Alphabetical characters don't work as a\n
284  * tag in this form.\n
285  *\n
286  * Also, the tag "@xn" will work as well, where "n" is a any tag-char,\n
287  * and "x" is the "current" command_cmd code.\n
288  */
289 static bool get_tag_floor(COMMAND_CODE *cp, char tag, FLOOR_IDX floor_list[], ITEM_NUMBER floor_num)
290 {
291         COMMAND_CODE i;
292         concptr s;
293
294         /**** Find a tag in the form of {@x#} (allow alphabet tag) ***/
295
296         /* Check every object in the grid */
297         for (i = 0; i < floor_num && i < 23; i++)
298         {
299                 object_type *o_ptr = &current_floor_ptr->o_list[floor_list[i]];
300
301                 /* Skip empty inscriptions */
302                 if (!o_ptr->inscription) continue;
303
304                 /* Find a '@' */
305                 s = my_strchr(quark_str(o_ptr->inscription), '@');
306
307                 /* Process all tags */
308                 while (s)
309                 {
310                         /* Check the special tags */
311                         if ((s[1] == command_cmd) && (s[2] == tag))
312                         {
313                                 /* Save the actual floor object ID */
314                                 *cp = i;
315
316                                 /* Success */
317                                 return (TRUE);
318                         }
319
320                         /* Find another '@' */
321                         s = my_strchr(s + 1, '@');
322                 }
323         }
324
325
326         /**** Find a tag in the form of {@#} (allows only numerals)  ***/
327
328         /* Don't allow {@#} with '#' being alphabet */
329         if (tag < '0' || '9' < tag)
330         {
331                 /* No such tag */
332                 return FALSE;
333         }
334
335         /* Check every object in the grid */
336         for (i = 0; i < floor_num && i < 23; i++)
337         {
338                 object_type *o_ptr = &current_floor_ptr->o_list[floor_list[i]];
339
340                 /* Skip empty inscriptions */
341                 if (!o_ptr->inscription) continue;
342
343                 /* Find a '@' */
344                 s = my_strchr(quark_str(o_ptr->inscription), '@');
345
346                 /* Process all tags */
347                 while (s)
348                 {
349                         /* Check the normal tags */
350                         if (s[1] == tag)
351                         {
352                                 /* Save the floor object ID */
353                                 *cp = i;
354
355                                 /* Success */
356                                 return (TRUE);
357                         }
358
359                         /* Find another '@' */
360                         s = my_strchr(s + 1, '@');
361                 }
362         }
363
364         /* No such tag */
365         return (FALSE);
366 }
367
368
369 /*!
370  * @brief 所持/装備オブジェクトに選択タグを与える/タグに該当するオブジェクトがあるかを返す /
371  * Find the "first" p_ptr->inventory_list object with the given "tag".
372  * @param cp 対応するタグIDを与える参照ポインタ
373  * @param tag 該当するオブジェクトがあるかを調べたいタグ
374  * @param mode 所持、装備の切り替え
375  * @return タグに該当するオブジェクトがあるならTRUEを返す
376  * @details
377  * A "tag" is a numeral "n" appearing as "@n" anywhere in the\n
378  * inscription of an object.  Alphabetical characters don't work as a\n
379  * tag in this form.\n
380  *\n
381  * Also, the tag "@xn" will work as well, where "n" is a any tag-char,\n
382  * and "x" is the "current" command_cmd code.\n
383  */
384 static bool get_tag(COMMAND_CODE *cp, char tag, BIT_FLAGS mode, OBJECT_TYPE_VALUE tval)
385 {
386         COMMAND_CODE i;
387         COMMAND_CODE start, end;
388         concptr s;
389
390         /* Extract index from mode */
391         switch (mode)
392         {
393         case USE_EQUIP:
394                 start = INVEN_RARM;
395                 end = INVEN_TOTAL - 1;
396                 break;
397
398         case USE_INVEN:
399                 start = 0;
400                 end = INVEN_PACK - 1;
401                 break;
402
403         default:
404                 return FALSE;
405         }
406
407         /**** Find a tag in the form of {@x#} (allow alphabet tag) ***/
408
409         /* Check every p_ptr->inventory_list object */
410         for (i = start; i <= end; i++)
411         {
412                 object_type *o_ptr = &p_ptr->inventory_list[i];
413                 if (!o_ptr->k_idx) continue;
414
415                 /* Skip empty inscriptions */
416                 if (!o_ptr->inscription) continue;
417
418                 /* Skip non-choice */
419                 if (!item_tester_okay(o_ptr, tval) && !(mode & USE_FULL)) continue;
420
421                 /* Find a '@' */
422                 s = my_strchr(quark_str(o_ptr->inscription), '@');
423
424                 /* Process all tags */
425                 while (s)
426                 {
427                         /* Check the special tags */
428                         if ((s[1] == command_cmd) && (s[2] == tag))
429                         {
430                                 /* Save the actual p_ptr->inventory_list ID */
431                                 *cp = i;
432
433                                 /* Success */
434                                 return (TRUE);
435                         }
436
437                         /* Find another '@' */
438                         s = my_strchr(s + 1, '@');
439                 }
440         }
441
442
443         /**** Find a tag in the form of {@#} (allows only numerals)  ***/
444
445         /* Don't allow {@#} with '#' being alphabet */
446         if (tag < '0' || '9' < tag)
447         {
448                 /* No such tag */
449                 return FALSE;
450         }
451
452         /* Check every object */
453         for (i = start; i <= end; i++)
454         {
455                 object_type *o_ptr = &p_ptr->inventory_list[i];
456                 if (!o_ptr->k_idx) continue;
457
458                 /* Skip empty inscriptions */
459                 if (!o_ptr->inscription) continue;
460
461                 /* Skip non-choice */
462                 if (!item_tester_okay(o_ptr, tval) && !(mode & USE_FULL)) continue;
463
464                 /* Find a '@' */
465                 s = my_strchr(quark_str(o_ptr->inscription), '@');
466
467                 /* Process all tags */
468                 while (s)
469                 {
470                         /* Check the normal tags */
471                         if (s[1] == tag)
472                         {
473                                 /* Save the actual p_ptr->inventory_list ID */
474                                 *cp = i;
475
476                                 /* Success */
477                                 return (TRUE);
478                         }
479
480                         /* Find another '@' */
481                         s = my_strchr(s + 1, '@');
482                 }
483         }
484
485         /* No such tag */
486         return (FALSE);
487 }
488
489 /*!
490  * @brief タグIDにあわせてタグアルファベットのリストを返す /
491  * Move around label characters with correspond tags
492  * @param label ラベルリストを取得する文字列参照ポインタ
493  * @param mode 所持品リストか装備品リストかの切り替え
494  * @return なし
495  */
496 void prepare_label_string(char *label, BIT_FLAGS mode, OBJECT_TYPE_VALUE tval)
497 {
498         concptr alphabet_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
499         int  offset = (mode == USE_EQUIP) ? INVEN_RARM : 0;
500         int  i;
501
502         /* Prepare normal labels */
503         strcpy(label, alphabet_chars);
504
505         /* Move each label */
506         for (i = 0; i < 52; i++)
507         {
508                 COMMAND_CODE index;
509                 SYMBOL_CODE c = alphabet_chars[i];
510
511                 /* Find a tag with this label */
512                 if (get_tag(&index, c, mode, tval))
513                 {
514                         /* Delete the overwritten label */
515                         if (label[i] == c) label[i] = ' ';
516
517                         /* Move the label to the place of corresponding tag */
518                         label[index - offset] = c;
519                 }
520         }
521 }
522
523
524 /*!
525  * @brief タグIDにあわせてタグアルファベットのリストを返す(床上アイテム用) /
526  * Move around label characters with correspond tags (floor version)
527  * @param label ラベルリストを取得する文字列参照ポインタ
528  * @param floor_list 床上アイテムの配列
529  * @param floor_num  床上アイテムの配列ID
530  * @return なし
531  */
532  /*
533   */
534 static void prepare_label_string_floor(char *label, FLOOR_IDX floor_list[], ITEM_NUMBER floor_num)
535 {
536         concptr alphabet_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
537         int  i;
538
539         /* Prepare normal labels */
540         strcpy(label, alphabet_chars);
541
542         /* Move each label */
543         for (i = 0; i < 52; i++)
544         {
545                 COMMAND_CODE index;
546                 SYMBOL_CODE c = alphabet_chars[i];
547
548                 /* Find a tag with this label */
549                 if (get_tag_floor(&index, c, floor_list, floor_num))
550                 {
551                         /* Delete the overwritten label */
552                         if (label[i] == c) label[i] = ' ';
553
554                         /* Move the label to the place of corresponding tag */
555                         label[index] = c;
556                 }
557         }
558 }
559
560 /*!
561  * @brief 所持アイテムの表示を行う /
562  * Display the p_ptr->inventory_list.
563  * @param target_item アイテムの選択処理を行うか否か。
564  * @return 選択したアイテムのタグ
565  * @details
566  * Hack -- do not display "trailing" empty slots
567  */
568 COMMAND_CODE show_inven(int target_item, BIT_FLAGS mode, OBJECT_TYPE_VALUE tval)
569 {
570         COMMAND_CODE i;
571         int j, k, l, z = 0;
572         int             col, cur_col, len;
573         object_type *o_ptr;
574         GAME_TEXT o_name[MAX_NLEN];
575         char            tmp_val[80];
576         COMMAND_CODE    out_index[23];
577         TERM_COLOR      out_color[23];
578         char            out_desc[23][MAX_NLEN];
579         COMMAND_CODE target_item_label = 0;
580         TERM_LEN wid, hgt;
581         char inven_label[52 + 1];
582
583         /* Starting column */
584         col = command_gap;
585
586         Term_get_size(&wid, &hgt);
587
588         /* Default "max-length" */
589         len = wid - col - 1;
590
591
592         /* Find the "final" slot */
593         for (i = 0; i < INVEN_PACK; i++)
594         {
595                 o_ptr = &p_ptr->inventory_list[i];
596                 if (!o_ptr->k_idx) continue;
597
598                 /* Track */
599                 z = i + 1;
600         }
601
602         prepare_label_string(inven_label, USE_INVEN, tval);
603
604         /* Display the p_ptr->inventory_list */
605         for (k = 0, i = 0; i < z; i++)
606         {
607                 o_ptr = &p_ptr->inventory_list[i];
608
609                 /* Is this item acceptable? */
610                 if (!item_tester_okay(o_ptr, tval) && !(mode & USE_FULL)) continue;
611
612                 object_desc(o_name, o_ptr, 0);
613
614                 /* Save the object index, color, and description */
615                 out_index[k] = i;
616                 out_color[k] = tval_to_attr[o_ptr->tval % 128];
617
618                 /* Grey out charging items */
619                 if (o_ptr->timeout)
620                 {
621                         out_color[k] = TERM_L_DARK;
622                 }
623
624                 (void)strcpy(out_desc[k], o_name);
625
626                 /* Find the predicted "line length" */
627                 l = strlen(out_desc[k]) + 5;
628
629                 /* Be sure to account for the weight */
630                 if (show_weights) l += 9;
631
632                 /* Account for icon if displayed */
633                 if (show_item_graph)
634                 {
635                         l += 2;
636                         if (use_bigtile) l++;
637                 }
638
639                 /* Maintain the maximum length */
640                 if (l > len) len = l;
641
642                 /* Advance to next "line" */
643                 k++;
644         }
645
646         /* Find the column to start in */
647         col = (len > wid - 4) ? 0 : (wid - len - 1);
648
649         /* Output each entry */
650         for (j = 0; j < k; j++)
651         {
652                 i = out_index[j];
653                 o_ptr = &p_ptr->inventory_list[i];
654
655                 /* Clear the line */
656                 prt("", j + 1, col ? col - 2 : col);
657
658                 if (use_menu && target_item)
659                 {
660                         if (j == (target_item - 1))
661                         {
662                                 strcpy(tmp_val, _("》", "> "));
663                                 target_item_label = i;
664                         }
665                         else strcpy(tmp_val, "  ");
666                 }
667                 else if (i <= INVEN_PACK)
668                 {
669                         /* Prepare an index --(-- */
670                         sprintf(tmp_val, "%c)", inven_label[i]);
671                 }
672                 else
673                 {
674                         /* Prepare an index --(-- */
675                         sprintf(tmp_val, "%c)", index_to_label(i));
676                 }
677
678                 /* Clear the line with the (possibly indented) index */
679                 put_str(tmp_val, j + 1, col);
680
681                 cur_col = col + 3;
682
683                 /* Display graphics for object, if desired */
684                 if (show_item_graph)
685                 {
686                         TERM_COLOR a = object_attr(o_ptr);
687                         SYMBOL_CODE c = object_char(o_ptr);
688                         Term_queue_bigchar(cur_col, j + 1, a, c, 0, 0);
689                         if (use_bigtile) cur_col++;
690
691                         cur_col += 2;
692                 }
693
694
695                 /* Display the entry itself */
696                 c_put_str(out_color[j], out_desc[j], j + 1, cur_col);
697
698                 /* Display the weight if needed */
699                 if (show_weights)
700                 {
701                         int wgt = o_ptr->weight * o_ptr->number;
702 #ifdef JP
703                         (void)sprintf(tmp_val, "%3d.%1d kg", lbtokg1(wgt), lbtokg2(wgt));
704 #else
705                         (void)sprintf(tmp_val, "%3d.%1d lb", wgt / 10, wgt % 10);
706 #endif
707
708                         prt(tmp_val, j + 1, wid - 9);
709                 }
710         }
711
712         /* Make a "shadow" below the list (only if needed) */
713         if (j && (j < 23)) prt("", j + 1, col ? col - 2 : col);
714
715         /* Save the new column */
716         command_gap = col;
717
718         return target_item_label;
719 }
720
721
722 /*!
723  * @brief 選択したアイテムの確認処理の補助 /
724  * Verify the choice of an item.
725  * @param prompt メッセージ表示の一部
726  * @param item 選択アイテムID
727  * @return 確認がYesならTRUEを返す。
728  * @details The item can be negative to mean "item on floor".
729  */
730 static bool verify(concptr prompt, INVENTORY_IDX item)
731 {
732         GAME_TEXT o_name[MAX_NLEN];
733         char        out_val[MAX_NLEN + 20];
734         object_type *o_ptr;
735
736
737         /* Inventory */
738         if (item >= 0)
739         {
740                 o_ptr = &p_ptr->inventory_list[item];
741         }
742
743         /* Floor */
744         else
745         {
746                 o_ptr = &current_floor_ptr->o_list[0 - item];
747         }
748         object_desc(o_name, o_ptr, 0);
749
750         /* Prompt */
751         (void)sprintf(out_val, _("%s%sですか? ", "%s %s? "), prompt, o_name);
752
753         /* Query */
754         return (get_check(out_val));
755 }
756
757
758 /*!
759  * @brief 選択したアイテムの確認処理のメインルーチン /
760  * @param item 選択アイテムID
761  * @return 確認がYesならTRUEを返す。
762  * @details The item can be negative to mean "item on floor".
763  * Hack -- allow user to "prevent" certain choices
764  */
765 static bool get_item_allow(INVENTORY_IDX item)
766 {
767         concptr s;
768         object_type *o_ptr;
769         if (!command_cmd) return TRUE; /* command_cmd is no longer effective */
770
771         /* Inventory */
772         if (item >= 0)
773         {
774                 o_ptr = &p_ptr->inventory_list[item];
775         }
776
777         /* Floor */
778         else
779         {
780                 o_ptr = &current_floor_ptr->o_list[0 - item];
781         }
782
783         /* No inscription */
784         if (!o_ptr->inscription) return (TRUE);
785
786         /* Find a '!' */
787         s = my_strchr(quark_str(o_ptr->inscription), '!');
788
789         /* Process preventions */
790         while (s)
791         {
792                 /* Check the "restriction" */
793                 if ((s[1] == command_cmd) || (s[1] == '*'))
794                 {
795                         /* Verify the choice */
796                         if (!verify(_("本当に", "Really try"), item)) return (FALSE);
797                 }
798
799                 /* Find another '!' */
800                 s = my_strchr(s + 1, '!');
801         }
802
803         /* Allow it */
804         return (TRUE);
805 }
806
807
808 /*!
809  * @brief オブジェクト選択の汎用関数 /
810  * Let the user select an item, save its "index"
811  * @param cp 選択したオブジェクトのIDを返す。
812  * @param pmt 選択目的のメッセージ
813  * @param str 選択できるオブジェクトがない場合のキャンセルメッセージ
814  * @param mode オプションフラグ
815  * @return プレイヤーによりアイテムが選択されたならTRUEを返す。/
816  * Return TRUE only if an acceptable item was chosen by the user.\n
817  * @details
818  * The selected item must satisfy the "item_tester_hook()" function,\n
819  * if that hook is set, and the "item_tester_tval", if that value is set.\n
820  *\n
821  * All "item_tester" restrictions are cleared before this function returns.\n
822  *\n
823  * The user is allowed to choose acceptable items from the equipment,\n
824  * p_ptr->inventory_list, or floor, respectively, if the proper flag was given,\n
825  * and there are any acceptable items in that location.\n
826  *\n
827  * The equipment or p_ptr->inventory_list are displayed (even if no acceptable\n
828  * items are in that location) if the proper flag was given.\n
829  *\n
830  * If there are no acceptable items available anywhere, and "str" is\n
831  * not NULL, then it will be used as the text of a warning message\n
832  * before the function returns.\n
833  *\n
834  * Note that the user must press "-" to specify the item on the floor,\n
835  * and there is no way to "examine" the item on the floor, while the\n
836  * use of "capital" letters will "examine" an p_ptr->inventory_list/equipment item,\n
837  * and prompt for its use.\n
838  *\n
839  * If a legal item is selected from the p_ptr->inventory_list, we save it in "cp"\n
840  * directly (0 to 35), and return TRUE.\n
841  *\n
842  * If a legal item is selected from the floor, we save it in "cp" as\n
843  * a negative (-1 to -511), and return TRUE.\n
844  *\n
845  * If no item is available, we do nothing to "cp", and we display a\n
846  * warning message, using "str" if available, and return FALSE.\n
847  *\n
848  * If no item is selected, we do nothing to "cp", and return FALSE.\n
849  *\n
850  * Global "p_ptr->command_new" is used when viewing the p_ptr->inventory_list or equipment\n
851  * to allow the user to enter a command while viewing those screens, and\n
852  * also to induce "auto-enter" of stores, and other such stuff.\n
853  *\n
854  * Global "p_ptr->command_see" may be set before calling this function to start\n
855  * out in "browse" mode.  It is cleared before this function returns.\n
856  *\n
857  * Global "p_ptr->command_wrk" is used to choose between equip/inven listings.\n
858  * If it is TRUE then we are viewing p_ptr->inventory_list, else equipment.\n
859  *\n
860  * We always erase the prompt when we are done, leaving a blank line,\n
861  * or a warning message, if appropriate, if no items are available.\n
862  */
863 bool get_item(OBJECT_IDX *cp, concptr pmt, concptr str, BIT_FLAGS mode, OBJECT_TYPE_VALUE tval)
864 {
865         OBJECT_IDX this_o_idx, next_o_idx = 0;
866
867         char which = ' ';
868
869         int j;
870         OBJECT_IDX k;
871         OBJECT_IDX i1, i2;
872         OBJECT_IDX e1, e2;
873
874         bool done, item;
875
876         bool oops = FALSE;
877
878         bool equip = FALSE;
879         bool inven = FALSE;
880         bool floor = FALSE;
881
882         bool allow_floor = FALSE;
883
884         bool toggle = FALSE;
885
886         char tmp_val[160];
887         char out_val[160];
888
889         int menu_line = (use_menu ? 1 : 0);
890         int max_inven = 0;
891         int max_equip = 0;
892
893         static char prev_tag = '\0';
894         char cur_tag = '\0';
895
896         if (easy_floor || use_menu) return get_item_floor(cp, pmt, str, mode, tval);
897
898         /* Extract args */
899         if (mode & USE_EQUIP) equip = TRUE;
900         if (mode & USE_INVEN) inven = TRUE;
901         if (mode & USE_FLOOR) floor = TRUE;
902
903         /* Get the item index */
904         if (repeat_pull(cp))
905         {
906                 /* the_force */
907                 if (mode & USE_FORCE && (*cp == INVEN_FORCE))
908                 {
909                         tval = 0;
910                         item_tester_hook = NULL;
911                         command_cmd = 0; /* Hack -- command_cmd is no longer effective */
912                         return (TRUE);
913                 }
914
915                 /* Floor item? */
916                 else if (floor && (*cp < 0))
917                 {
918                         object_type *o_ptr;
919
920                         /* Special index */
921                         k = 0 - (*cp);
922                         o_ptr = &current_floor_ptr->o_list[k];
923
924                         /* Validate the item */
925                         if (item_tester_okay(o_ptr, tval) || (mode & USE_FULL))
926                         {
927                                 /* Forget restrictions */
928                                 tval = 0;
929                                 item_tester_hook = NULL;
930                                 command_cmd = 0; /* Hack -- command_cmd is no longer effective */
931
932                                 /* Success */
933                                 return TRUE;
934                         }
935                 }
936
937                 else if ((inven && (*cp >= 0) && (*cp < INVEN_PACK)) ||
938                         (equip && (*cp >= INVEN_RARM) && (*cp < INVEN_TOTAL)))
939                 {
940                         if (prev_tag && command_cmd)
941                         {
942                                 /* Look up the tag and validate the item */
943                                 if (!get_tag(&k, prev_tag, (*cp >= INVEN_RARM) ? USE_EQUIP : USE_INVEN, tval)) /* Reject */;
944                                 else if ((k < INVEN_RARM) ? !inven : !equip) /* Reject */;
945                                 else if (!get_item_okay(k)) /* Reject */;
946                                 else
947                                 {
948                                         /* Accept that choice */
949                                         (*cp) = k;
950
951                                         /* Forget restrictions */
952                                         tval = 0;
953                                         item_tester_hook = NULL;
954                                         command_cmd = 0; /* Hack -- command_cmd is no longer effective */
955
956                                         /* Success */
957                                         return TRUE;
958                                 }
959
960                                 prev_tag = '\0'; /* prev_tag is no longer effective */
961                         }
962
963                         /* Verify the item */
964                         else if (get_item_okay(*cp))
965                         {
966                                 /* Forget restrictions */
967                                 tval = 0;
968                                 item_tester_hook = NULL;
969                                 command_cmd = 0; /* Hack -- command_cmd is no longer effective */
970
971                                 /* Success */
972                                 return TRUE;
973                         }
974                 }
975         }
976         msg_print(NULL);
977
978         /* Not done */
979         done = FALSE;
980
981         /* No item selected */
982         item = FALSE;
983
984
985         /* Full p_ptr->inventory_list */
986         i1 = 0;
987         i2 = INVEN_PACK - 1;
988
989         /* Forbid p_ptr->inventory_list */
990         if (!inven) i2 = -1;
991         else if (use_menu)
992         {
993                 for (j = 0; j < INVEN_PACK; j++)
994                         if (item_tester_okay(&p_ptr->inventory_list[j], tval) || (mode & USE_FULL)) max_inven++;
995         }
996
997         /* Restrict p_ptr->inventory_list indexes */
998         while ((i1 <= i2) && (!get_item_okay(i1))) i1++;
999         while ((i1 <= i2) && (!get_item_okay(i2))) i2--;
1000
1001
1002         /* Full equipment */
1003         e1 = INVEN_RARM;
1004         e2 = INVEN_TOTAL - 1;
1005
1006         /* Forbid equipment */
1007         if (!equip) e2 = -1;
1008         else if (use_menu)
1009         {
1010                 for (j = INVEN_RARM; j < INVEN_TOTAL; j++)
1011                         if (select_ring_slot ? is_ring_slot(j) : item_tester_okay(&p_ptr->inventory_list[j], tval) || (mode & USE_FULL)) max_equip++;
1012                 if (p_ptr->ryoute && !(mode & IGNORE_BOTHHAND_SLOT)) max_equip++;
1013         }
1014
1015         /* Restrict equipment indexes */
1016         while ((e1 <= e2) && (!get_item_okay(e1))) e1++;
1017         while ((e1 <= e2) && (!get_item_okay(e2))) e2--;
1018
1019         if (equip && p_ptr->ryoute && !(mode & IGNORE_BOTHHAND_SLOT))
1020         {
1021                 if (p_ptr->migite)
1022                 {
1023                         if (e2 < INVEN_LARM) e2 = INVEN_LARM;
1024                 }
1025                 else if (p_ptr->hidarite) e1 = INVEN_RARM;
1026         }
1027
1028
1029         /* Restrict floor usage */
1030         if (floor)
1031         {
1032                 /* Scan all objects in the grid */
1033                 for (this_o_idx = current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].o_idx; this_o_idx; this_o_idx = next_o_idx)
1034                 {
1035                         object_type *o_ptr;
1036                         o_ptr = &current_floor_ptr->o_list[this_o_idx];
1037                         next_o_idx = o_ptr->next_o_idx;
1038
1039                         /* Accept the item on the floor if legal */
1040                         if ((item_tester_okay(o_ptr, tval) || (mode & USE_FULL)) && (o_ptr->marked & OM_FOUND)) allow_floor = TRUE;
1041                 }
1042         }
1043
1044         /* Require at least one legal choice */
1045         if (!allow_floor && (i1 > i2) && (e1 > e2))
1046         {
1047                 /* Cancel p_ptr->command_see */
1048                 command_see = FALSE;
1049                 oops = TRUE;
1050                 done = TRUE;
1051
1052                 if (mode & USE_FORCE) {
1053                         *cp = INVEN_FORCE;
1054                         item = TRUE;
1055                 }
1056         }
1057
1058         /* Analyze choices */
1059         else
1060         {
1061                 /* Hack -- Start on equipment if requested */
1062                 if (command_see && command_wrk && equip)
1063                 {
1064                         command_wrk = TRUE;
1065                 }
1066
1067                 /* Use p_ptr->inventory_list if allowed */
1068                 else if (inven)
1069                 {
1070                         command_wrk = FALSE;
1071                 }
1072
1073                 /* Use equipment if allowed */
1074                 else if (equip)
1075                 {
1076                         command_wrk = TRUE;
1077                 }
1078
1079                 /* Use p_ptr->inventory_list for floor */
1080                 else
1081                 {
1082                         command_wrk = FALSE;
1083                 }
1084         }
1085
1086
1087         /*
1088          * 追加オプション(always_show_list)が設定されている場合は常に一覧を表示する
1089          */
1090         if ((always_show_list == TRUE) || use_menu) command_see = TRUE;
1091
1092         /* Hack -- start out in "display" mode */
1093         if (command_see)
1094         {
1095                 screen_save();
1096         }
1097
1098
1099         /* Repeat until done */
1100         while (!done)
1101         {
1102                 COMMAND_CODE get_item_label = 0;
1103
1104                 /* Show choices */
1105                 int ni = 0;
1106                 int ne = 0;
1107
1108                 /* Scan windows */
1109                 for (j = 0; j < 8; j++)
1110                 {
1111                         /* Unused */
1112                         if (!angband_term[j]) continue;
1113
1114                         /* Count windows displaying inven */
1115                         if (window_flag[j] & (PW_INVEN)) ni++;
1116
1117                         /* Count windows displaying equip */
1118                         if (window_flag[j] & (PW_EQUIP)) ne++;
1119                 }
1120
1121                 if ((command_wrk && ni && !ne) || (!command_wrk && !ni && ne))
1122                 {
1123                         toggle_inven_equip(p_ptr);
1124                         toggle = !toggle;
1125                 }
1126
1127                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
1128                 handle_stuff();
1129
1130                 /* Inventory screen */
1131                 if (!command_wrk)
1132                 {
1133                         /* Redraw if needed */
1134                         if (command_see) get_item_label = show_inven(menu_line, mode, tval);
1135                 }
1136
1137                 /* Equipment screen */
1138                 else
1139                 {
1140                         /* Redraw if needed */
1141                         if (command_see) get_item_label = show_equip(menu_line, mode, tval);
1142                 }
1143
1144                 /* Viewing p_ptr->inventory_list */
1145                 if (!command_wrk)
1146                 {
1147                         /* Begin the prompt */
1148                         sprintf(out_val, _("持ち物:", "Inven:"));
1149
1150                         /* Some legal items */
1151                         if ((i1 <= i2) && !use_menu)
1152                         {
1153                                 /* Build the prompt */
1154                                 sprintf(tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"),
1155                                         index_to_label(i1), index_to_label(i2));
1156
1157                                 /* Append */
1158                                 strcat(out_val, tmp_val);
1159                         }
1160
1161                         /* Indicate ability to "view" */
1162                         if (!command_see && !use_menu) strcat(out_val, _(" '*'一覧,", " * to see,"));
1163
1164                         /* Append */
1165                         if (equip) strcat(out_val, format(_(" %s 装備品,", " %s for Equip,"), use_menu ? _("'4'or'6'", "4 or 6") : _("'/'", "/")));
1166                 }
1167
1168                 /* Viewing equipment */
1169                 else
1170                 {
1171                         /* Begin the prompt */
1172                         sprintf(out_val, _("装備品:", "Equip:"));
1173
1174                         /* Some legal items */
1175                         if ((e1 <= e2) && !use_menu)
1176                         {
1177                                 /* Build the prompt */
1178                                 sprintf(tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"),
1179                                         index_to_label(e1), index_to_label(e2));
1180
1181                                 /* Append */
1182                                 strcat(out_val, tmp_val);
1183                         }
1184
1185                         /* Indicate ability to "view" */
1186                         if (!command_see && !use_menu) strcat(out_val, _(" '*'一覧,", " * to see,"));
1187
1188                         /* Append */
1189                         if (inven) strcat(out_val, format(_(" %s 持ち物,", " %s for Inven,"), use_menu ? _("'4'or'6'", "4 or 6") : _("'/'", "'/'")));
1190                 }
1191
1192                 /* Indicate legality of the "floor" item */
1193                 if (allow_floor) strcat(out_val, _(" '-'床上,", " - for floor,"));
1194                 if (mode & USE_FORCE) strcat(out_val, _(" 'w'練気術,", " w for the Force,"));
1195
1196                 /* Finish the prompt */
1197                 strcat(out_val, " ESC");
1198
1199                 /* Build the prompt */
1200                 sprintf(tmp_val, "(%s) %s", out_val, pmt);
1201
1202                 /* Show the prompt */
1203                 prt(tmp_val, 0, 0);
1204
1205                 /* Get a key */
1206                 which = inkey();
1207
1208                 if (use_menu)
1209                 {
1210                         int max_line = (command_wrk ? max_equip : max_inven);
1211                         switch (which)
1212                         {
1213                         case ESCAPE:
1214                         case 'z':
1215                         case 'Z':
1216                         case '0':
1217                         {
1218                                 done = TRUE;
1219                                 break;
1220                         }
1221
1222                         case '8':
1223                         case 'k':
1224                         case 'K':
1225                         {
1226                                 menu_line += (max_line - 1);
1227                                 break;
1228                         }
1229
1230                         case '2':
1231                         case 'j':
1232                         case 'J':
1233                         {
1234                                 menu_line++;
1235                                 break;
1236                         }
1237
1238                         case '4':
1239                         case '6':
1240                         case 'h':
1241                         case 'H':
1242                         case 'l':
1243                         case 'L':
1244                         {
1245                                 /* Verify legality */
1246                                 if (!inven || !equip)
1247                                 {
1248                                         bell();
1249                                         break;
1250                                 }
1251
1252                                 /* Hack -- Fix screen */
1253                                 if (command_see)
1254                                 {
1255                                         screen_load();
1256                                         screen_save();
1257                                 }
1258
1259                                 /* Switch inven/equip */
1260                                 command_wrk = !command_wrk;
1261                                 max_line = (command_wrk ? max_equip : max_inven);
1262                                 if (menu_line > max_line) menu_line = max_line;
1263
1264                                 /* Need to redraw */
1265                                 break;
1266                         }
1267
1268                         case 'x':
1269                         case 'X':
1270                         case '\r':
1271                         case '\n':
1272                         {
1273                                 if (command_wrk == USE_FLOOR)
1274                                 {
1275                                         /* Special index */
1276                                         (*cp) = -get_item_label;
1277                                 }
1278                                 else
1279                                 {
1280                                         /* Validate the item */
1281                                         if (!get_item_okay(get_item_label))
1282                                         {
1283                                                 bell();
1284                                                 break;
1285                                         }
1286
1287                                         /* Allow player to "refuse" certain actions */
1288                                         if (!get_item_allow(get_item_label))
1289                                         {
1290                                                 done = TRUE;
1291                                                 break;
1292                                         }
1293
1294                                         /* Accept that choice */
1295                                         (*cp) = get_item_label;
1296                                 }
1297
1298                                 item = TRUE;
1299                                 done = TRUE;
1300                                 break;
1301                         }
1302                         case 'w':
1303                         {
1304                                 if (mode & USE_FORCE) {
1305                                         *cp = INVEN_FORCE;
1306                                         item = TRUE;
1307                                         done = TRUE;
1308                                         break;
1309                                 }
1310                         }
1311                         }
1312                         if (menu_line > max_line) menu_line -= max_line;
1313                 }
1314                 else
1315                 {
1316                         /* Parse it */
1317                         switch (which)
1318                         {
1319                         case ESCAPE:
1320                         {
1321                                 done = TRUE;
1322                                 break;
1323                         }
1324
1325                         case '*':
1326                         case '?':
1327                         case ' ':
1328                         {
1329                                 /* Hide the list */
1330                                 if (command_see)
1331                                 {
1332                                         /* Flip flag */
1333                                         command_see = FALSE;
1334                                         screen_load();
1335                                 }
1336
1337                                 /* Show the list */
1338                                 else
1339                                 {
1340                                         screen_save();
1341
1342                                         /* Flip flag */
1343                                         command_see = TRUE;
1344                                 }
1345                                 break;
1346                         }
1347
1348                         case '/':
1349                         {
1350                                 /* Verify legality */
1351                                 if (!inven || !equip)
1352                                 {
1353                                         bell();
1354                                         break;
1355                                 }
1356
1357                                 /* Hack -- Fix screen */
1358                                 if (command_see)
1359                                 {
1360                                         screen_load();
1361                                         screen_save();
1362                                 }
1363
1364                                 /* Switch inven/equip */
1365                                 command_wrk = !command_wrk;
1366
1367                                 /* Need to redraw */
1368                                 break;
1369                         }
1370
1371                         case '-':
1372                         {
1373                                 /* Use floor item */
1374                                 if (allow_floor)
1375                                 {
1376                                         /* Scan all objects in the grid */
1377                                         for (this_o_idx = current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].o_idx; this_o_idx; this_o_idx = next_o_idx)
1378                                         {
1379                                                 object_type *o_ptr;
1380                                                 o_ptr = &current_floor_ptr->o_list[this_o_idx];
1381                                                 next_o_idx = o_ptr->next_o_idx;
1382
1383                                                 /* Validate the item */
1384                                                 if (!item_tester_okay(o_ptr, tval) && !(mode & USE_FULL)) continue;
1385
1386                                                 /* Special index */
1387                                                 k = 0 - this_o_idx;
1388
1389                                                 /* Verify the item (if required) */
1390                                                 if (other_query_flag && !verify(_("本当に", "Try"), k)) continue;
1391
1392                                                 /* Allow player to "refuse" certain actions */
1393                                                 if (!get_item_allow(k)) continue;
1394
1395                                                 /* Accept that choice */
1396                                                 (*cp) = k;
1397                                                 item = TRUE;
1398                                                 done = TRUE;
1399                                                 break;
1400                                         }
1401
1402                                         /* Outer break */
1403                                         if (done) break;
1404                                 }
1405
1406                                 bell();
1407                                 break;
1408                         }
1409
1410                         case '0':
1411                         case '1': case '2': case '3':
1412                         case '4': case '5': case '6':
1413                         case '7': case '8': case '9':
1414                         {
1415                                 /* Look up the tag */
1416                                 if (!get_tag(&k, which, command_wrk ? USE_EQUIP : USE_INVEN, tval))
1417                                 {
1418                                         bell();
1419                                         break;
1420                                 }
1421
1422                                 /* Hack -- Validate the item */
1423                                 if ((k < INVEN_RARM) ? !inven : !equip)
1424                                 {
1425                                         bell();
1426                                         break;
1427                                 }
1428
1429                                 /* Validate the item */
1430                                 if (!get_item_okay(k))
1431                                 {
1432                                         bell();
1433                                         break;
1434                                 }
1435
1436                                 /* Allow player to "refuse" certain actions */
1437                                 if (!get_item_allow(k))
1438                                 {
1439                                         done = TRUE;
1440                                         break;
1441                                 }
1442
1443                                 /* Accept that choice */
1444                                 (*cp) = k;
1445                                 item = TRUE;
1446                                 done = TRUE;
1447                                 cur_tag = which;
1448                                 break;
1449                         }
1450
1451 #if 0
1452                         case '\n':
1453                         case '\r':
1454                         {
1455                                 /* Choose "default" p_ptr->inventory_list item */
1456                                 if (!command_wrk)
1457                                 {
1458                                         k = ((i1 == i2) ? i1 : -1);
1459                                 }
1460
1461                                 /* Choose "default" equipment item */
1462                                 else
1463                                 {
1464                                         k = ((e1 == e2) ? e1 : -1);
1465                                 }
1466
1467                                 /* Validate the item */
1468                                 if (!get_item_okay(k))
1469                                 {
1470                                         bell();
1471                                         break;
1472                                 }
1473
1474                                 /* Allow player to "refuse" certain actions */
1475                                 if (!get_item_allow(k))
1476                                 {
1477                                         done = TRUE;
1478                                         break;
1479                                 }
1480
1481                                 /* Accept that choice */
1482                                 (*cp) = k;
1483                                 item = TRUE;
1484                                 done = TRUE;
1485                                 break;
1486                         }
1487 #endif
1488
1489                         case 'w':
1490                         {
1491                                 if (mode & USE_FORCE) {
1492                                         *cp = INVEN_FORCE;
1493                                         item = TRUE;
1494                                         done = TRUE;
1495                                         break;
1496                                 }
1497
1498                                 /* Fall through */
1499                         }
1500
1501                         default:
1502                         {
1503                                 int ver;
1504                                 bool not_found = FALSE;
1505
1506                                 /* Look up the alphabetical tag */
1507                                 if (!get_tag(&k, which, command_wrk ? USE_EQUIP : USE_INVEN, tval))
1508                                 {
1509                                         not_found = TRUE;
1510                                 }
1511
1512                                 /* Hack -- Validate the item */
1513                                 else if ((k < INVEN_RARM) ? !inven : !equip)
1514                                 {
1515                                         not_found = TRUE;
1516                                 }
1517
1518                                 /* Validate the item */
1519                                 else if (!get_item_okay(k))
1520                                 {
1521                                         not_found = TRUE;
1522                                 }
1523
1524                                 if (!not_found)
1525                                 {
1526                                         /* Accept that choice */
1527                                         (*cp) = k;
1528                                         item = TRUE;
1529                                         done = TRUE;
1530                                         cur_tag = which;
1531                                         break;
1532                                 }
1533
1534                                 /* Extract "query" setting */
1535                                 ver = isupper(which);
1536                                 which = (char)tolower(which);
1537
1538                                 /* Convert letter to p_ptr->inventory_list index */
1539                                 if (!command_wrk)
1540                                 {
1541                                         if (which == '(') k = i1;
1542                                         else if (which == ')') k = i2;
1543                                         else k = label_to_inven(which);
1544                                 }
1545
1546                                 /* Convert letter to equipment index */
1547                                 else
1548                                 {
1549                                         if (which == '(') k = e1;
1550                                         else if (which == ')') k = e2;
1551                                         else k = label_to_equip(which);
1552                                 }
1553
1554                                 /* Validate the item */
1555                                 if (!get_item_okay(k))
1556                                 {
1557                                         bell();
1558                                         break;
1559                                 }
1560
1561                                 /* Verify the item */
1562                                 if (ver && !verify(_("本当に", "Try"), k))
1563                                 {
1564                                         done = TRUE;
1565                                         break;
1566                                 }
1567
1568                                 /* Allow player to "refuse" certain actions */
1569                                 if (!get_item_allow(k))
1570                                 {
1571                                         done = TRUE;
1572                                         break;
1573                                 }
1574
1575                                 /* Accept that choice */
1576                                 (*cp) = k;
1577                                 item = TRUE;
1578                                 done = TRUE;
1579                                 break;
1580                         }
1581                         }
1582                 }
1583         }
1584
1585
1586         /* Fix the screen if necessary */
1587         if (command_see)
1588         {
1589                 screen_load();
1590
1591                 /* Hack -- Cancel "display" */
1592                 command_see = FALSE;
1593         }
1594
1595
1596         /* Forget the tval restriction */
1597         tval = 0;
1598
1599         /* Forget the item_tester_hook restriction */
1600         item_tester_hook = NULL;
1601
1602
1603         /* Clean up  'show choices' */
1604         if (toggle) toggle_inven_equip(p_ptr);
1605
1606         p_ptr->window |= (PW_INVEN | PW_EQUIP);
1607         handle_stuff();
1608
1609         /* Clear the prompt line */
1610         prt("", 0, 0);
1611
1612         /* Warning if needed */
1613         if (oops && str) msg_print(str);
1614
1615         if (item)
1616         {
1617                 repeat_push(*cp);
1618                 if (command_cmd) prev_tag = cur_tag;
1619                 command_cmd = 0; /* Hack -- command_cmd is no longer effective */
1620         }
1621         return (item);
1622 }
1623
1624 /*
1625  * Choose an item and get auto-picker entry from it.
1626  */
1627 object_type *choose_object(player_type *creature_ptr, OBJECT_IDX *idx, concptr q, concptr s, BIT_FLAGS option, OBJECT_TYPE_VALUE tval)
1628 {
1629         OBJECT_IDX item;
1630         if (!get_item(&item, q, s, option, tval)) return NULL;
1631         if (idx) *idx = item;
1632         if (item == INVEN_FORCE) return NULL;
1633         return REF_ITEM(creature_ptr, current_floor_ptr, item);
1634 }
1635
1636
1637 /*!
1638  * @brief 床下に落ちているオブジェクトの数を返す / scan_floor
1639  * @param items オブジェクトのIDリストを返すための配列参照ポインタ
1640  * @param y 走査するフロアのY座標
1641  * @param x 走査するフロアのX座標
1642  * @param mode オプションフラグ
1643  * @return 対象のマスに落ちているアイテム数
1644  * @details
1645  * Return a list of o_list[] indexes of items at the given current_floor_ptr->grid_array
1646  * location. Valid flags are:
1647  *
1648  *              mode & 0x01 -- Item tester
1649  *              mode & 0x02 -- Marked items only
1650  *              mode & 0x04 -- Stop after first
1651  */
1652 ITEM_NUMBER scan_floor(OBJECT_IDX *items, POSITION y, POSITION x, BIT_FLAGS mode)
1653 {
1654         OBJECT_IDX this_o_idx, next_o_idx;
1655
1656         ITEM_NUMBER num = 0;
1657
1658         /* Sanity */
1659         if (!in_bounds(y, x)) return 0;
1660
1661         /* Scan all objects in the grid */
1662         for (this_o_idx = current_floor_ptr->grid_array[y][x].o_idx; this_o_idx; this_o_idx = next_o_idx)
1663         {
1664                 object_type *o_ptr;
1665                 o_ptr = &current_floor_ptr->o_list[this_o_idx];
1666                 next_o_idx = o_ptr->next_o_idx;
1667
1668                 /* Item tester */
1669                 if ((mode & 0x01) && !item_tester_okay(o_ptr, item_tester_tval)) continue;
1670
1671                 /* Marked */
1672                 if ((mode & 0x02) && !(o_ptr->marked & OM_FOUND)) continue;
1673
1674                 /* Accept this item */
1675                 /* XXX Hack -- Enforce limit */
1676                 if (num < 23)
1677                         items[num] = this_o_idx;
1678
1679                 num++;
1680
1681                 /* Only one */
1682                 if (mode & 0x04) break;
1683         }
1684         return num;
1685 }
1686
1687
1688 /*!
1689  * @brief 床下に落ちているアイテムの一覧を返す / Display a list of the items on the floor at the given location.
1690  * @param target_item カーソルの初期値
1691  * @param y 走査するフロアのY座標
1692  * @param x 走査するフロアのX座標
1693  * @param min_width 表示の長さ
1694  * @return 選択したアイテムの添え字
1695  * @details
1696  */
1697 COMMAND_CODE show_floor(int target_item, POSITION y, POSITION x, TERM_LEN *min_width)
1698 {
1699         COMMAND_CODE i, m;
1700         int j, k, l;
1701         int col, len;
1702
1703         object_type *o_ptr;
1704
1705         GAME_TEXT o_name[MAX_NLEN];
1706         char tmp_val[80];
1707
1708         COMMAND_CODE out_index[23];
1709         TERM_COLOR out_color[23];
1710         char out_desc[23][MAX_NLEN];
1711         COMMAND_CODE target_item_label = 0;
1712
1713         OBJECT_IDX floor_list[23];
1714         ITEM_NUMBER floor_num;
1715         TERM_LEN wid, hgt;
1716         char floor_label[52 + 1];
1717
1718         bool dont_need_to_show_weights = TRUE;
1719
1720         Term_get_size(&wid, &hgt);
1721
1722         /* Default length */
1723         len = MAX((*min_width), 20);
1724
1725         /* Scan for objects in the grid, using item_tester_okay() */
1726         floor_num = scan_floor(floor_list, y, x, 0x03);
1727
1728         /* Display the floor objects */
1729         for (k = 0, i = 0; i < floor_num && i < 23; i++)
1730         {
1731                 o_ptr = &current_floor_ptr->o_list[floor_list[i]];
1732
1733                 object_desc(o_name, o_ptr, 0);
1734
1735                 /* Save the index */
1736                 out_index[k] = i;
1737
1738                 /* Acquire p_ptr->inventory_list color */
1739                 out_color[k] = tval_to_attr[o_ptr->tval & 0x7F];
1740
1741                 /* Save the object description */
1742                 strcpy(out_desc[k], o_name);
1743
1744                 /* Find the predicted "line length" */
1745                 l = strlen(out_desc[k]) + 5;
1746
1747                 /* Be sure to account for the weight */
1748                 if (show_weights) l += 9;
1749
1750                 if (o_ptr->tval != TV_GOLD) dont_need_to_show_weights = FALSE;
1751
1752                 /* Maintain the maximum length */
1753                 if (l > len) len = l;
1754
1755                 /* Advance to next "line" */
1756                 k++;
1757         }
1758
1759         if (show_weights && dont_need_to_show_weights) len -= 9;
1760
1761         /* Save width */
1762         *min_width = len;
1763
1764         /* Find the column to start in */
1765         col = (len > wid - 4) ? 0 : (wid - len - 1);
1766
1767         prepare_label_string_floor(floor_label, floor_list, floor_num);
1768
1769         /* Output each entry */
1770         for (j = 0; j < k; j++)
1771         {
1772                 m = floor_list[out_index[j]];
1773                 o_ptr = &current_floor_ptr->o_list[m];
1774
1775                 /* Clear the line */
1776                 prt("", j + 1, col ? col - 2 : col);
1777
1778                 if (use_menu && target_item)
1779                 {
1780                         if (j == (target_item - 1))
1781                         {
1782                                 strcpy(tmp_val, _("》", "> "));
1783                                 target_item_label = m;
1784                         }
1785                         else strcpy(tmp_val, "   ");
1786                 }
1787                 else
1788                 {
1789                         /* Prepare an index --(-- */
1790                         sprintf(tmp_val, "%c)", floor_label[j]);
1791                 }
1792
1793                 /* Clear the line with the (possibly indented) index */
1794                 put_str(tmp_val, j + 1, col);
1795
1796                 /* Display the entry itself */
1797                 c_put_str(out_color[j], out_desc[j], j + 1, col + 3);
1798
1799                 /* Display the weight if needed */
1800                 if (show_weights && (o_ptr->tval != TV_GOLD))
1801                 {
1802                         int wgt = o_ptr->weight * o_ptr->number;
1803 #ifdef JP
1804                         sprintf(tmp_val, "%3d.%1d kg", lbtokg1(wgt), lbtokg2(wgt));
1805 #else
1806                         sprintf(tmp_val, "%3d.%1d lb", wgt / 10, wgt % 10);
1807 #endif
1808
1809                         prt(tmp_val, j + 1, wid - 9);
1810                 }
1811         }
1812
1813         /* Make a "shadow" below the list (only if needed) */
1814         if (j && (j < 23)) prt("", j + 1, col ? col - 2 : col);
1815
1816         return target_item_label;
1817 }
1818
1819 /*!
1820  * @brief オブジェクト選択の汎用関数(床上アイテム用) /
1821  * Let the user select an item, save its "index"
1822  * @param cp 選択したオブジェクトのIDを返す。
1823  * @param pmt 選択目的のメッセージ
1824  * @param str 選択できるオブジェクトがない場合のキャンセルメッセージ
1825  * @param mode オプションフラグ
1826  * @return プレイヤーによりアイテムが選択されたならTRUEを返す。/
1827  */
1828 bool get_item_floor(COMMAND_CODE *cp, concptr pmt, concptr str, BIT_FLAGS mode, OBJECT_TYPE_VALUE tval)
1829 {
1830         char n1 = ' ', n2 = ' ', which = ' ';
1831
1832         int j;
1833         COMMAND_CODE i1, i2;
1834         COMMAND_CODE e1, e2;
1835         COMMAND_CODE k;
1836
1837         bool done, item;
1838
1839         bool oops = FALSE;
1840
1841         /* Extract args */
1842         bool equip = (mode & USE_EQUIP) ? TRUE : FALSE;
1843         bool inven = (mode & USE_INVEN) ? TRUE : FALSE;
1844         bool floor = (mode & USE_FLOOR) ? TRUE : FALSE;
1845         bool force = (mode & USE_FORCE) ? TRUE : FALSE;
1846
1847         bool allow_equip = FALSE;
1848         bool allow_inven = FALSE;
1849         bool allow_floor = FALSE;
1850
1851         bool toggle = FALSE;
1852
1853         char tmp_val[160];
1854         char out_val[160];
1855
1856         ITEM_NUMBER floor_num;
1857         OBJECT_IDX floor_list[23];
1858         int floor_top = 0;
1859         TERM_LEN min_width = 0;
1860
1861         int menu_line = (use_menu ? 1 : 0);
1862         int max_inven = 0;
1863         int max_equip = 0;
1864
1865         static char prev_tag = '\0';
1866         char cur_tag = '\0';
1867
1868         /* Get the item index */
1869         if (repeat_pull(cp))
1870         {
1871                 /* the_force */
1872                 if (force && (*cp == INVEN_FORCE))
1873                 {
1874                         tval = 0;
1875                         item_tester_hook = NULL;
1876                         command_cmd = 0; /* Hack -- command_cmd is no longer effective */
1877                         return (TRUE);
1878                 }
1879
1880                 /* Floor item? */
1881                 else if (floor && (*cp < 0))
1882                 {
1883                         if (prev_tag && command_cmd)
1884                         {
1885                                 /* Scan all objects in the grid */
1886                                 floor_num = scan_floor(floor_list, p_ptr->y, p_ptr->x, 0x03);
1887
1888                                 /* Look up the tag */
1889                                 if (get_tag_floor(&k, prev_tag, floor_list, floor_num))
1890                                 {
1891                                         /* Accept that choice */
1892                                         (*cp) = 0 - floor_list[k];
1893
1894                                         /* Forget restrictions */
1895                                         tval = 0;
1896                                         item_tester_hook = NULL;
1897                                         command_cmd = 0; /* Hack -- command_cmd is no longer effective */
1898
1899                                         /* Success */
1900                                         return TRUE;
1901                                 }
1902
1903                                 prev_tag = '\0'; /* prev_tag is no longer effective */
1904                         }
1905
1906                         /* Validate the item */
1907                         else if (item_tester_okay(&current_floor_ptr->o_list[0 - (*cp)], tval) || (mode & USE_FULL))
1908                         {
1909                                 /* Forget restrictions */
1910                                 tval = 0;
1911                                 item_tester_hook = NULL;
1912                                 command_cmd = 0; /* Hack -- command_cmd is no longer effective */
1913
1914                                 /* Success */
1915                                 return TRUE;
1916                         }
1917                 }
1918
1919                 else if ((inven && (*cp >= 0) && (*cp < INVEN_PACK)) ||
1920                         (equip && (*cp >= INVEN_RARM) && (*cp < INVEN_TOTAL)))
1921                 {
1922                         if (prev_tag && command_cmd)
1923                         {
1924                                 /* Look up the tag and validate the item */
1925                                 if (!get_tag(&k, prev_tag, (*cp >= INVEN_RARM) ? USE_EQUIP : USE_INVEN, tval)) /* Reject */;
1926                                 else if ((k < INVEN_RARM) ? !inven : !equip) /* Reject */;
1927                                 else if (!get_item_okay(k)) /* Reject */;
1928                                 else
1929                                 {
1930                                         /* Accept that choice */
1931                                         (*cp) = k;
1932
1933                                         /* Forget restrictions */
1934                                         tval = 0;
1935                                         item_tester_hook = NULL;
1936                                         command_cmd = 0; /* Hack -- command_cmd is no longer effective */
1937
1938                                         /* Success */
1939                                         return TRUE;
1940                                 }
1941
1942                                 prev_tag = '\0'; /* prev_tag is no longer effective */
1943                         }
1944
1945                         /* Verify the item */
1946                         else if (get_item_okay(*cp))
1947                         {
1948                                 /* Forget restrictions */
1949                                 tval = 0;
1950                                 item_tester_hook = NULL;
1951                                 command_cmd = 0; /* Hack -- command_cmd is no longer effective */
1952
1953                                 /* Success */
1954                                 return TRUE;
1955                         }
1956                 }
1957         }
1958
1959         msg_print(NULL);
1960
1961
1962         /* Not done */
1963         done = FALSE;
1964
1965         /* No item selected */
1966         item = FALSE;
1967
1968
1969         /* Full p_ptr->inventory_list */
1970         i1 = 0;
1971         i2 = INVEN_PACK - 1;
1972
1973         /* Forbid p_ptr->inventory_list */
1974         if (!inven) i2 = -1;
1975         else if (use_menu)
1976         {
1977                 for (j = 0; j < INVEN_PACK; j++)
1978                         if (item_tester_okay(&p_ptr->inventory_list[j], tval) || (mode & USE_FULL)) max_inven++;
1979         }
1980
1981         /* Restrict p_ptr->inventory_list indexes */
1982         while ((i1 <= i2) && (!get_item_okay(i1))) i1++;
1983         while ((i1 <= i2) && (!get_item_okay(i2))) i2--;
1984
1985
1986         /* Full equipment */
1987         e1 = INVEN_RARM;
1988         e2 = INVEN_TOTAL - 1;
1989
1990         /* Forbid equipment */
1991         if (!equip) e2 = -1;
1992         else if (use_menu)
1993         {
1994                 for (j = INVEN_RARM; j < INVEN_TOTAL; j++)
1995                         if (select_ring_slot ? is_ring_slot(j) : item_tester_okay(&p_ptr->inventory_list[j], tval) || (mode & USE_FULL)) max_equip++;
1996                 if (p_ptr->ryoute && !(mode & IGNORE_BOTHHAND_SLOT)) max_equip++;
1997         }
1998
1999         /* Restrict equipment indexes */
2000         while ((e1 <= e2) && (!get_item_okay(e1))) e1++;
2001         while ((e1 <= e2) && (!get_item_okay(e2))) e2--;
2002
2003         if (equip && p_ptr->ryoute && !(mode & IGNORE_BOTHHAND_SLOT))
2004         {
2005                 if (p_ptr->migite)
2006                 {
2007                         if (e2 < INVEN_LARM) e2 = INVEN_LARM;
2008                 }
2009                 else if (p_ptr->hidarite) e1 = INVEN_RARM;
2010         }
2011
2012
2013         /* Count "okay" floor items */
2014         floor_num = 0;
2015
2016         /* Restrict floor usage */
2017         if (floor)
2018         {
2019                 /* Scan all objects in the grid */
2020                 floor_num = scan_floor(floor_list, p_ptr->y, p_ptr->x, 0x03);
2021         }
2022
2023         /* Accept p_ptr->inventory_list */
2024         if (i1 <= i2) allow_inven = TRUE;
2025
2026         /* Accept equipment */
2027         if (e1 <= e2) allow_equip = TRUE;
2028
2029         /* Accept floor */
2030         if (floor_num) allow_floor = TRUE;
2031
2032         /* Require at least one legal choice */
2033         if (!allow_inven && !allow_equip && !allow_floor)
2034         {
2035                 /* Cancel p_ptr->command_see */
2036                 command_see = FALSE;
2037                 oops = TRUE;
2038                 done = TRUE;
2039
2040                 if (force) {
2041                         *cp = INVEN_FORCE;
2042                         item = TRUE;
2043                 }
2044         }
2045
2046         /* Analyze choices */
2047         else
2048         {
2049                 /* Hack -- Start on equipment if requested */
2050                 if (command_see && (command_wrk == (USE_EQUIP))
2051                         && allow_equip)
2052                 {
2053                         command_wrk = (USE_EQUIP);
2054                 }
2055
2056                 /* Use p_ptr->inventory_list if allowed */
2057                 else if (allow_inven)
2058                 {
2059                         command_wrk = (USE_INVEN);
2060                 }
2061
2062                 /* Use equipment if allowed */
2063                 else if (allow_equip)
2064                 {
2065                         command_wrk = (USE_EQUIP);
2066                 }
2067
2068                 /* Use floor if allowed */
2069                 else if (allow_floor)
2070                 {
2071                         command_wrk = (USE_FLOOR);
2072                 }
2073         }
2074
2075         /*
2076          * 追加オプション(always_show_list)が設定されている場合は常に一覧を表示する
2077          */
2078         if ((always_show_list == TRUE) || use_menu) command_see = TRUE;
2079
2080         /* Hack -- start out in "display" mode */
2081         if (command_see)
2082         {
2083                 screen_save();
2084         }
2085
2086         /* Repeat until done */
2087         while (!done)
2088         {
2089                 COMMAND_CODE get_item_label = 0;
2090
2091                 /* Show choices */
2092                 int ni = 0;
2093                 int ne = 0;
2094
2095                 /* Scan windows */
2096                 for (j = 0; j < 8; j++)
2097                 {
2098                         /* Unused */
2099                         if (!angband_term[j]) continue;
2100
2101                         /* Count windows displaying inven */
2102                         if (window_flag[j] & (PW_INVEN)) ni++;
2103
2104                         /* Count windows displaying equip */
2105                         if (window_flag[j] & (PW_EQUIP)) ne++;
2106                 }
2107
2108                 /* Toggle if needed */
2109                 if ((command_wrk == (USE_EQUIP) && ni && !ne) ||
2110                         (command_wrk == (USE_INVEN) && !ni && ne))
2111                 {
2112                         toggle_inven_equip(p_ptr);
2113                         toggle = !toggle;
2114                 }
2115
2116                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
2117                 handle_stuff();
2118
2119                 /* Inventory screen */
2120                 if (command_wrk == (USE_INVEN))
2121                 {
2122                         /* Extract the legal requests */
2123                         n1 = I2A(i1);
2124                         n2 = I2A(i2);
2125
2126                         /* Redraw if needed */
2127                         if (command_see) get_item_label = show_inven(menu_line, mode, tval);
2128                 }
2129
2130                 /* Equipment screen */
2131                 else if (command_wrk == (USE_EQUIP))
2132                 {
2133                         /* Extract the legal requests */
2134                         n1 = I2A(e1 - INVEN_RARM);
2135                         n2 = I2A(e2 - INVEN_RARM);
2136
2137                         /* Redraw if needed */
2138                         if (command_see) get_item_label = show_equip(menu_line, mode, tval);
2139                 }
2140
2141                 /* Floor screen */
2142                 else if (command_wrk == (USE_FLOOR))
2143                 {
2144                         j = floor_top;
2145                         k = MIN(floor_top + 23, floor_num) - 1;
2146
2147                         /* Extract the legal requests */
2148                         n1 = I2A(j - floor_top);
2149                         n2 = I2A(k - floor_top);
2150
2151                         /* Redraw if needed */
2152                         if (command_see) get_item_label = show_floor(menu_line, p_ptr->y, p_ptr->x, &min_width);
2153                 }
2154
2155                 /* Viewing p_ptr->inventory_list */
2156                 if (command_wrk == (USE_INVEN))
2157                 {
2158                         /* Begin the prompt */
2159                         sprintf(out_val, _("持ち物:", "Inven:"));
2160
2161                         if (!use_menu)
2162                         {
2163                                 /* Build the prompt */
2164                                 sprintf(tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"),
2165                                         index_to_label(i1), index_to_label(i2));
2166
2167                                 /* Append */
2168                                 strcat(out_val, tmp_val);
2169                         }
2170
2171                         /* Indicate ability to "view" */
2172                         if (!command_see && !use_menu) strcat(out_val, _(" '*'一覧,", " * to see,"));
2173
2174                         /* Append */
2175                         if (allow_equip)
2176                         {
2177                                 if (!use_menu)
2178                                         strcat(out_val, _(" '/' 装備品,", " / for Equip,"));
2179                                 else if (allow_floor)
2180                                         strcat(out_val, _(" '6' 装備品,", " 6 for Equip,"));
2181                                 else
2182                                         strcat(out_val, _(" '4'or'6' 装備品,", " 4 or 6 for Equip,"));
2183                         }
2184
2185                         /* Append */
2186                         if (allow_floor)
2187                         {
2188                                 if (!use_menu)
2189                                         strcat(out_val, _(" '-'床上,", " - for floor,"));
2190                                 else if (allow_equip)
2191                                         strcat(out_val, _(" '4' 床上,", " 4 for floor,"));
2192                                 else
2193                                         strcat(out_val, _(" '4'or'6' 床上,", " 4 or 6 for floor,"));
2194                         }
2195                 }
2196
2197                 /* Viewing equipment */
2198                 else if (command_wrk == (USE_EQUIP))
2199                 {
2200                         /* Begin the prompt */
2201                         sprintf(out_val, _("装備品:", "Equip:"));
2202
2203                         if (!use_menu)
2204                         {
2205                                 /* Build the prompt */
2206                                 sprintf(tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"),
2207                                         index_to_label(e1), index_to_label(e2));
2208
2209                                 /* Append */
2210                                 strcat(out_val, tmp_val);
2211                         }
2212
2213                         /* Indicate ability to "view" */
2214                         if (!command_see && !use_menu) strcat(out_val, _(" '*'一覧,", " * to see,"));
2215
2216                         /* Append */
2217                         if (allow_inven)
2218                         {
2219                                 if (!use_menu)
2220                                         strcat(out_val, _(" '/' 持ち物,", " / for Inven,"));
2221                                 else if (allow_floor)
2222                                         strcat(out_val, _(" '4' 持ち物,", " 4 for Inven,"));
2223                                 else
2224                                         strcat(out_val, _(" '4'or'6' 持ち物,", " 4 or 6 for Inven,"));
2225                         }
2226
2227                         /* Append */
2228                         if (allow_floor)
2229                         {
2230                                 if (!use_menu)
2231                                         strcat(out_val, _(" '-'床上,", " - for floor,"));
2232                                 else if (allow_inven)
2233                                         strcat(out_val, _(" '6' 床上,", " 6 for floor,"));
2234                                 else
2235                                         strcat(out_val, _(" '4'or'6' 床上,", " 4 or 6 for floor,"));
2236                         }
2237                 }
2238
2239                 /* Viewing floor */
2240                 else if (command_wrk == (USE_FLOOR))
2241                 {
2242                         /* Begin the prompt */
2243                         sprintf(out_val, _("床上:", "Floor:"));
2244
2245                         if (!use_menu)
2246                         {
2247                                 /* Build the prompt */
2248                                 sprintf(tmp_val, _("%c-%c,'(',')',", " %c-%c,'(',')',"), n1, n2);
2249
2250                                 /* Append */
2251                                 strcat(out_val, tmp_val);
2252                         }
2253
2254                         /* Indicate ability to "view" */
2255                         if (!command_see && !use_menu) strcat(out_val, _(" '*'一覧,", " * to see,"));
2256
2257                         if (use_menu)
2258                         {
2259                                 if (allow_inven && allow_equip)
2260                                 {
2261                                         strcat(out_val, _(" '4' 装備品, '6' 持ち物,", " 4 for Equip, 6 for Inven,"));
2262                                 }
2263                                 else if (allow_inven)
2264                                 {
2265                                         strcat(out_val, _(" '4'or'6' 持ち物,", " 4 or 6 for Inven,"));
2266                                 }
2267                                 else if (allow_equip)
2268                                 {
2269                                         strcat(out_val, _(" '4'or'6' 装備品,", " 4 or 6 for Equip,"));
2270                                 }
2271                         }
2272                         /* Append */
2273                         else if (allow_inven)
2274                         {
2275                                 strcat(out_val, _(" '/' 持ち物,", " / for Inven,"));
2276                         }
2277                         else if (allow_equip)
2278                         {
2279                                 strcat(out_val, _(" '/'装備品,", " / for Equip,"));
2280                         }
2281
2282                         /* Append */
2283                         if (command_see && !use_menu)
2284                         {
2285                                 strcat(out_val, _(" Enter 次,", " Enter for scroll down,"));
2286                         }
2287                 }
2288
2289                 /* Append */
2290                 if (force) strcat(out_val, _(" 'w'練気術,", " w for the Force,"));
2291
2292                 /* Finish the prompt */
2293                 strcat(out_val, " ESC");
2294
2295                 /* Build the prompt */
2296                 sprintf(tmp_val, "(%s) %s", out_val, pmt);
2297
2298                 /* Show the prompt */
2299                 prt(tmp_val, 0, 0);
2300
2301                 /* Get a key */
2302                 which = inkey();
2303
2304                 if (use_menu)
2305                 {
2306                         int max_line = 1;
2307                         if (command_wrk == USE_INVEN) max_line = max_inven;
2308                         else if (command_wrk == USE_EQUIP) max_line = max_equip;
2309                         else if (command_wrk == USE_FLOOR) max_line = MIN(23, floor_num);
2310                         switch (which)
2311                         {
2312                         case ESCAPE:
2313                         case 'z':
2314                         case 'Z':
2315                         case '0':
2316                         {
2317                                 done = TRUE;
2318                                 break;
2319                         }
2320
2321                         case '8':
2322                         case 'k':
2323                         case 'K':
2324                         {
2325                                 menu_line += (max_line - 1);
2326                                 break;
2327                         }
2328
2329                         case '2':
2330                         case 'j':
2331                         case 'J':
2332                         {
2333                                 menu_line++;
2334                                 break;
2335                         }
2336
2337                         case '4':
2338                         case 'h':
2339                         case 'H':
2340                         {
2341                                 /* Verify legality */
2342                                 if (command_wrk == (USE_INVEN))
2343                                 {
2344                                         if (allow_floor) command_wrk = USE_FLOOR;
2345                                         else if (allow_equip) command_wrk = USE_EQUIP;
2346                                         else
2347                                         {
2348                                                 bell();
2349                                                 break;
2350                                         }
2351                                 }
2352                                 else if (command_wrk == (USE_EQUIP))
2353                                 {
2354                                         if (allow_inven) command_wrk = USE_INVEN;
2355                                         else if (allow_floor) command_wrk = USE_FLOOR;
2356                                         else
2357                                         {
2358                                                 bell();
2359                                                 break;
2360                                         }
2361                                 }
2362                                 else if (command_wrk == (USE_FLOOR))
2363                                 {
2364                                         if (allow_equip) command_wrk = USE_EQUIP;
2365                                         else if (allow_inven) command_wrk = USE_INVEN;
2366                                         else
2367                                         {
2368                                                 bell();
2369                                                 break;
2370                                         }
2371                                 }
2372                                 else
2373                                 {
2374                                         bell();
2375                                         break;
2376                                 }
2377
2378                                 /* Hack -- Fix screen */
2379                                 if (command_see)
2380                                 {
2381                                         screen_load();
2382                                         screen_save();
2383                                 }
2384
2385                                 /* Switch inven/equip */
2386                                 if (command_wrk == USE_INVEN) max_line = max_inven;
2387                                 else if (command_wrk == USE_EQUIP) max_line = max_equip;
2388                                 else if (command_wrk == USE_FLOOR) max_line = MIN(23, floor_num);
2389                                 if (menu_line > max_line) menu_line = max_line;
2390
2391                                 /* Need to redraw */
2392                                 break;
2393                         }
2394
2395                         case '6':
2396                         case 'l':
2397                         case 'L':
2398                         {
2399                                 /* Verify legality */
2400                                 if (command_wrk == (USE_INVEN))
2401                                 {
2402                                         if (allow_equip) command_wrk = USE_EQUIP;
2403                                         else if (allow_floor) command_wrk = USE_FLOOR;
2404                                         else
2405                                         {
2406                                                 bell();
2407                                                 break;
2408                                         }
2409                                 }
2410                                 else if (command_wrk == (USE_EQUIP))
2411                                 {
2412                                         if (allow_floor) command_wrk = USE_FLOOR;
2413                                         else if (allow_inven) command_wrk = USE_INVEN;
2414                                         else
2415                                         {
2416                                                 bell();
2417                                                 break;
2418                                         }
2419                                 }
2420                                 else if (command_wrk == (USE_FLOOR))
2421                                 {
2422                                         if (allow_inven) command_wrk = USE_INVEN;
2423                                         else if (allow_equip) command_wrk = USE_EQUIP;
2424                                         else
2425                                         {
2426                                                 bell();
2427                                                 break;
2428                                         }
2429                                 }
2430                                 else
2431                                 {
2432                                         bell();
2433                                         break;
2434                                 }
2435
2436                                 /* Hack -- Fix screen */
2437                                 if (command_see)
2438                                 {
2439                                         screen_load();
2440                                         screen_save();
2441                                 }
2442
2443                                 /* Switch inven/equip */
2444                                 if (command_wrk == USE_INVEN) max_line = max_inven;
2445                                 else if (command_wrk == USE_EQUIP) max_line = max_equip;
2446                                 else if (command_wrk == USE_FLOOR) max_line = MIN(23, floor_num);
2447                                 if (menu_line > max_line) menu_line = max_line;
2448
2449                                 /* Need to redraw */
2450                                 break;
2451                         }
2452
2453                         case 'x':
2454                         case 'X':
2455                         case '\r':
2456                         case '\n':
2457                         {
2458                                 if (command_wrk == USE_FLOOR)
2459                                 {
2460                                         /* Special index */
2461                                         (*cp) = -get_item_label;
2462                                 }
2463                                 else
2464                                 {
2465                                         /* Validate the item */
2466                                         if (!get_item_okay(get_item_label))
2467                                         {
2468                                                 bell();
2469                                                 break;
2470                                         }
2471
2472                                         /* Allow player to "refuse" certain actions */
2473                                         if (!get_item_allow(get_item_label))
2474                                         {
2475                                                 done = TRUE;
2476                                                 break;
2477                                         }
2478
2479                                         /* Accept that choice */
2480                                         (*cp) = get_item_label;
2481                                 }
2482
2483                                 item = TRUE;
2484                                 done = TRUE;
2485                                 break;
2486                         }
2487                         case 'w':
2488                         {
2489                                 if (force) {
2490                                         *cp = INVEN_FORCE;
2491                                         item = TRUE;
2492                                         done = TRUE;
2493                                         break;
2494                                 }
2495                         }
2496                         }
2497                         if (menu_line > max_line) menu_line -= max_line;
2498                 }
2499                 else
2500                 {
2501                         /* Parse it */
2502                         switch (which)
2503                         {
2504                         case ESCAPE:
2505                         {
2506                                 done = TRUE;
2507                                 break;
2508                         }
2509
2510                         case '*':
2511                         case '?':
2512                         case ' ':
2513                         {
2514                                 /* Hide the list */
2515                                 if (command_see)
2516                                 {
2517                                         /* Flip flag */
2518                                         command_see = FALSE;
2519                                         screen_load();
2520                                 }
2521
2522                                 /* Show the list */
2523                                 else
2524                                 {
2525                                         screen_save();
2526
2527                                         /* Flip flag */
2528                                         command_see = TRUE;
2529                                 }
2530                                 break;
2531                         }
2532
2533                         case '\n':
2534                         case '\r':
2535                         case '+':
2536                         {
2537                                 int i;
2538                                 OBJECT_IDX o_idx;
2539                                 grid_type *g_ptr = &current_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
2540
2541                                 if (command_wrk != (USE_FLOOR)) break;
2542
2543                                 /* Get the object being moved. */
2544                                 o_idx = g_ptr->o_idx;
2545
2546                                 /* Only rotate a pile of two or more objects. */
2547                                 if (!(o_idx && current_floor_ptr->o_list[o_idx].next_o_idx)) break;
2548
2549                                 /* Remove the first object from the list. */
2550                                 excise_object_idx(o_idx);
2551
2552                                 /* Find end of the list. */
2553                                 i = g_ptr->o_idx;
2554                                 while (current_floor_ptr->o_list[i].next_o_idx)
2555                                         i = current_floor_ptr->o_list[i].next_o_idx;
2556
2557                                 /* Add after the last object. */
2558                                 current_floor_ptr->o_list[i].next_o_idx = o_idx;
2559
2560                                 /* Re-scan floor list */
2561                                 floor_num = scan_floor(floor_list, p_ptr->y, p_ptr->x, 0x03);
2562
2563                                 /* Hack -- Fix screen */
2564                                 if (command_see)
2565                                 {
2566                                         screen_load();
2567                                         screen_save();
2568                                 }
2569
2570                                 break;
2571                         }
2572
2573                         case '/':
2574                         {
2575                                 if (command_wrk == (USE_INVEN))
2576                                 {
2577                                         if (!allow_equip)
2578                                         {
2579                                                 bell();
2580                                                 break;
2581                                         }
2582                                         command_wrk = (USE_EQUIP);
2583                                 }
2584                                 else if (command_wrk == (USE_EQUIP))
2585                                 {
2586                                         if (!allow_inven)
2587                                         {
2588                                                 bell();
2589                                                 break;
2590                                         }
2591                                         command_wrk = (USE_INVEN);
2592                                 }
2593                                 else if (command_wrk == (USE_FLOOR))
2594                                 {
2595                                         if (allow_inven)
2596                                         {
2597                                                 command_wrk = (USE_INVEN);
2598                                         }
2599                                         else if (allow_equip)
2600                                         {
2601                                                 command_wrk = (USE_EQUIP);
2602                                         }
2603                                         else
2604                                         {
2605                                                 bell();
2606                                                 break;
2607                                         }
2608                                 }
2609
2610                                 /* Hack -- Fix screen */
2611                                 if (command_see)
2612                                 {
2613                                         screen_load();
2614                                         screen_save();
2615                                 }
2616
2617                                 /* Need to redraw */
2618                                 break;
2619                         }
2620
2621                         case '-':
2622                         {
2623                                 if (!allow_floor)
2624                                 {
2625                                         bell();
2626                                         break;
2627                                 }
2628
2629                                 /*
2630                                  * If we are already examining the floor, and there
2631                                  * is only one item, we will always select it.
2632                                  * If we aren't examining the floor and there is only
2633                                  * one item, we will select it if floor_query_flag
2634                                  * is FALSE.
2635                                  */
2636                                 if (floor_num == 1)
2637                                 {
2638                                         if ((command_wrk == (USE_FLOOR)) || (!carry_query_flag))
2639                                         {
2640                                                 /* Special index */
2641                                                 k = 0 - floor_list[0];
2642
2643                                                 /* Allow player to "refuse" certain actions */
2644                                                 if (!get_item_allow(k))
2645                                                 {
2646                                                         done = TRUE;
2647                                                         break;
2648                                                 }
2649
2650                                                 /* Accept that choice */
2651                                                 (*cp) = k;
2652                                                 item = TRUE;
2653                                                 done = TRUE;
2654
2655                                                 break;
2656                                         }
2657                                 }
2658
2659                                 /* Hack -- Fix screen */
2660                                 if (command_see)
2661                                 {
2662                                         screen_load();
2663                                         screen_save();
2664                                 }
2665
2666                                 command_wrk = (USE_FLOOR);
2667
2668                                 break;
2669                         }
2670
2671                         case '0':
2672                         case '1': case '2': case '3':
2673                         case '4': case '5': case '6':
2674                         case '7': case '8': case '9':
2675                         {
2676                                 if (command_wrk != USE_FLOOR)
2677                                 {
2678                                         /* Look up the tag */
2679                                         if (!get_tag(&k, which, command_wrk, tval))
2680                                         {
2681                                                 bell();
2682                                                 break;
2683                                         }
2684
2685                                         /* Hack -- Validate the item */
2686                                         if ((k < INVEN_RARM) ? !inven : !equip)
2687                                         {
2688                                                 bell();
2689                                                 break;
2690                                         }
2691
2692                                         /* Validate the item */
2693                                         if (!get_item_okay(k))
2694                                         {
2695                                                 bell();
2696                                                 break;
2697                                         }
2698                                 }
2699                                 else
2700                                 {
2701                                         /* Look up the alphabetical tag */
2702                                         if (get_tag_floor(&k, which, floor_list, floor_num))
2703                                         {
2704                                                 /* Special index */
2705                                                 k = 0 - floor_list[k];
2706                                         }
2707                                         else
2708                                         {
2709                                                 bell();
2710                                                 break;
2711                                         }
2712                                 }
2713
2714                                 /* Allow player to "refuse" certain actions */
2715                                 if (!get_item_allow(k))
2716                                 {
2717                                         done = TRUE;
2718                                         break;
2719                                 }
2720
2721                                 /* Accept that choice */
2722                                 (*cp) = k;
2723                                 item = TRUE;
2724                                 done = TRUE;
2725                                 cur_tag = which;
2726                                 break;
2727                         }
2728
2729 #if 0
2730                         case '\n':
2731                         case '\r':
2732                         {
2733                                 /* Choose "default" p_ptr->inventory_list item */
2734                                 if (command_wrk == (USE_INVEN))
2735                                 {
2736                                         k = ((i1 == i2) ? i1 : -1);
2737                                 }
2738
2739                                 /* Choose "default" equipment item */
2740                                 else if (command_wrk == (USE_EQUIP))
2741                                 {
2742                                         k = ((e1 == e2) ? e1 : -1);
2743                                 }
2744
2745                                 /* Choose "default" floor item */
2746                                 else if (command_wrk == (USE_FLOOR))
2747                                 {
2748                                         if (floor_num == 1)
2749                                         {
2750                                                 /* Special index */
2751                                                 k = 0 - floor_list[0];
2752
2753                                                 /* Allow player to "refuse" certain actions */
2754                                                 if (!get_item_allow(k))
2755                                                 {
2756                                                         done = TRUE;
2757                                                         break;
2758                                                 }
2759
2760                                                 /* Accept that choice */
2761                                                 (*cp) = k;
2762                                                 item = TRUE;
2763                                                 done = TRUE;
2764                                         }
2765                                         break;
2766                                 }
2767
2768                                 /* Validate the item */
2769                                 if (!get_item_okay(k))
2770                                 {
2771                                         bell();
2772                                         break;
2773                                 }
2774
2775                                 /* Allow player to "refuse" certain actions */
2776                                 if (!get_item_allow(k))
2777                                 {
2778                                         done = TRUE;
2779                                         break;
2780                                 }
2781
2782                                 /* Accept that choice */
2783                                 (*cp) = k;
2784                                 item = TRUE;
2785                                 done = TRUE;
2786                                 break;
2787                         }
2788 #endif
2789
2790                         case 'w':
2791                         {
2792                                 if (force) {
2793                                         *cp = INVEN_FORCE;
2794                                         item = TRUE;
2795                                         done = TRUE;
2796                                         break;
2797                                 }
2798
2799                                 /* Fall through */
2800                         }
2801
2802                         default:
2803                         {
2804                                 int ver;
2805
2806                                 if (command_wrk != USE_FLOOR)
2807                                 {
2808                                         bool not_found = FALSE;
2809
2810                                         /* Look up the alphabetical tag */
2811                                         if (!get_tag(&k, which, command_wrk, tval))
2812                                         {
2813                                                 not_found = TRUE;
2814                                         }
2815
2816                                         /* Hack -- Validate the item */
2817                                         else if ((k < INVEN_RARM) ? !inven : !equip)
2818                                         {
2819                                                 not_found = TRUE;
2820                                         }
2821
2822                                         /* Validate the item */
2823                                         else if (!get_item_okay(k))
2824                                         {
2825                                                 not_found = TRUE;
2826                                         }
2827
2828                                         if (!not_found)
2829                                         {
2830                                                 /* Accept that choice */
2831                                                 (*cp) = k;
2832                                                 item = TRUE;
2833                                                 done = TRUE;
2834                                                 cur_tag = which;
2835                                                 break;
2836                                         }
2837                                 }
2838                                 else
2839                                 {
2840                                         /* Look up the alphabetical tag */
2841                                         if (get_tag_floor(&k, which, floor_list, floor_num))
2842                                         {
2843                                                 /* Special index */
2844                                                 k = 0 - floor_list[k];
2845
2846                                                 /* Accept that choice */
2847                                                 (*cp) = k;
2848                                                 item = TRUE;
2849                                                 done = TRUE;
2850                                                 cur_tag = which;
2851                                                 break;
2852                                         }
2853                                 }
2854
2855                                 /* Extract "query" setting */
2856                                 ver = isupper(which);
2857                                 which = (char)tolower(which);
2858
2859                                 /* Convert letter to p_ptr->inventory_list index */
2860                                 if (command_wrk == (USE_INVEN))
2861                                 {
2862                                         if (which == '(') k = i1;
2863                                         else if (which == ')') k = i2;
2864                                         else k = label_to_inven(which);
2865                                 }
2866
2867                                 /* Convert letter to equipment index */
2868                                 else if (command_wrk == (USE_EQUIP))
2869                                 {
2870                                         if (which == '(') k = e1;
2871                                         else if (which == ')') k = e2;
2872                                         else k = label_to_equip(which);
2873                                 }
2874
2875                                 /* Convert letter to floor index */
2876                                 else if (command_wrk == USE_FLOOR)
2877                                 {
2878                                         if (which == '(') k = 0;
2879                                         else if (which == ')') k = floor_num - 1;
2880                                         else k = islower(which) ? A2I(which) : -1;
2881                                         if (k < 0 || k >= floor_num || k >= 23)
2882                                         {
2883                                                 bell();
2884                                                 break;
2885                                         }
2886
2887                                         /* Special index */
2888                                         k = 0 - floor_list[k];
2889                                 }
2890
2891                                 /* Validate the item */
2892                                 if ((command_wrk != USE_FLOOR) && !get_item_okay(k))
2893                                 {
2894                                         bell();
2895                                         break;
2896                                 }
2897
2898                                 /* Verify the item */
2899                                 if (ver && !verify(_("本当に", "Try"), k))
2900                                 {
2901                                         done = TRUE;
2902                                         break;
2903                                 }
2904
2905                                 /* Allow player to "refuse" certain actions */
2906                                 if (!get_item_allow(k))
2907                                 {
2908                                         done = TRUE;
2909                                         break;
2910                                 }
2911
2912                                 /* Accept that choice */
2913                                 (*cp) = k;
2914                                 item = TRUE;
2915                                 done = TRUE;
2916                                 break;
2917                         }
2918                         }
2919                 }
2920         }
2921
2922         /* Fix the screen if necessary */
2923         if (command_see)
2924         {
2925                 screen_load();
2926
2927                 /* Hack -- Cancel "display" */
2928                 command_see = FALSE;
2929         }
2930
2931
2932         /* Forget the tval restriction */
2933         tval = 0;
2934
2935         /* Forget the item_tester_hook restriction */
2936         item_tester_hook = NULL;
2937
2938
2939         /* Clean up  'show choices' */
2940         if (toggle) toggle_inven_equip(p_ptr);
2941
2942         p_ptr->window |= (PW_INVEN | PW_EQUIP);
2943         handle_stuff();
2944
2945         /* Clear the prompt line */
2946         prt("", 0, 0);
2947
2948         /* Warning if needed */
2949         if (oops && str) msg_print(str);
2950
2951         if (item)
2952         {
2953                 repeat_push(*cp);
2954                 if (command_cmd) prev_tag = cur_tag;
2955                 command_cmd = 0; /* Hack -- command_cmd is no longer effective */
2956         }
2957         return (item);
2958 }
2959
2960 /*!
2961  * @brief 床上のアイテムを拾う選択用サブルーチン
2962  * @return プレイヤーによりアイテムが選択されたならTRUEを返す。
2963  */
2964 static bool py_pickup_floor_aux(void)
2965 {
2966         OBJECT_IDX this_o_idx;
2967         concptr q, s;
2968         OBJECT_IDX item;
2969
2970         /* Restrict the choices */
2971         item_tester_hook = inven_carry_okay;
2972
2973         /* Get an object */
2974         q = _("どれを拾いますか?", "Get which item? ");
2975         s = _("もうザックには床にあるどのアイテムも入らない。", "You no longer have any room for the objects on the floor.");
2976
2977         if (choose_object(p_ptr, &item, q, s, (USE_FLOOR), 0))
2978         {
2979                 this_o_idx = 0 - item;
2980         }
2981         else
2982         {
2983                 return (FALSE);
2984         }
2985
2986         /* Pick up the object */
2987         py_pickup_aux(this_o_idx);
2988
2989         return (TRUE);
2990 }
2991
2992 /*!
2993  * @brief 床上のアイテムを拾うメイン処理
2994  * @param pickup FALSEなら金銭の自動拾いのみを行う/ FALSE then only gold will be picked up
2995  * @return なし
2996  * @details
2997  * This is called by py_pickup() when easy_floor is TRUE.
2998  */
2999 void py_pickup_floor(bool pickup)
3000 {
3001         OBJECT_IDX this_o_idx, next_o_idx = 0;
3002
3003         GAME_TEXT o_name[MAX_NLEN];
3004         object_type *o_ptr;
3005
3006         int floor_num = 0;
3007         OBJECT_IDX floor_o_idx = 0;
3008
3009         int can_pickup = 0;
3010
3011         /* Scan the pile of objects */
3012         for (this_o_idx = current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].o_idx; this_o_idx; this_o_idx = next_o_idx)
3013         {
3014                 /* Access the object */
3015                 o_ptr = &current_floor_ptr->o_list[this_o_idx];
3016
3017                 object_desc(o_name, o_ptr, 0);
3018
3019                 /* Access the next object */
3020                 next_o_idx = o_ptr->next_o_idx;
3021
3022                 disturb(p_ptr, FALSE, FALSE);
3023
3024                 /* Pick up gold */
3025                 if (o_ptr->tval == TV_GOLD)
3026                 {
3027 #ifdef JP
3028                         msg_format(" $%ld の価値がある%sを見つけた。",
3029                                 (long)o_ptr->pval, o_name);
3030 #else
3031                         msg_format("You have found %ld gold pieces worth of %s.",
3032                                 (long)o_ptr->pval, o_name);
3033 #endif
3034
3035                         /* Collect the gold */
3036                         p_ptr->au += o_ptr->pval;
3037
3038                         /* Redraw gold */
3039                         p_ptr->redraw |= (PR_GOLD);
3040
3041                         p_ptr->window |= (PW_PLAYER);
3042
3043                         /* Delete the gold */
3044                         delete_object_idx(this_o_idx);
3045
3046                         /* Check the next object */
3047                         continue;
3048                 }
3049                 else if (o_ptr->marked & OM_NOMSG)
3050                 {
3051                         /* If 0 or 1 non-NOMSG items are in the pile, the NOMSG ones are
3052                          * ignored. Otherwise, they are included in the prompt. */
3053                         o_ptr->marked &= ~(OM_NOMSG);
3054                         continue;
3055                 }
3056
3057                 /* Count non-gold objects that can be picked up. */
3058                 if (inven_carry_okay(o_ptr))
3059                 {
3060                         can_pickup++;
3061                 }
3062
3063                 /* Count non-gold objects */
3064                 floor_num++;
3065
3066                 /* Remember this index */
3067                 floor_o_idx = this_o_idx;
3068         }
3069
3070         /* There are no non-gold objects */
3071         if (!floor_num)
3072                 return;
3073
3074         /* Mention the number of objects */
3075         if (!pickup)
3076         {
3077                 /* One object */
3078                 if (floor_num == 1)
3079                 {
3080                         /* Access the object */
3081                         o_ptr = &current_floor_ptr->o_list[floor_o_idx];
3082
3083 #ifdef ALLOW_EASY_SENSE
3084
3085                         /* Option: Make object sensing easy */
3086                         if (easy_sense)
3087                         {
3088                                 /* Sense the object */
3089                                 (void)sense_object(o_ptr);
3090                         }
3091
3092 #endif /* ALLOW_EASY_SENSE */
3093
3094                         object_desc(o_name, o_ptr, 0);
3095
3096                         msg_format(_("%sがある。", "You see %s."), o_name);
3097                 }
3098
3099                 /* Multiple objects */
3100                 else
3101                 {
3102                         msg_format(_("%d 個のアイテムの山がある。", "You see a pile of %d items."), floor_num);
3103                 }
3104
3105                 return;
3106         }
3107
3108         /* The player has no room for anything on the floor. */
3109         if (!can_pickup)
3110         {
3111                 /* One object */
3112                 if (floor_num == 1)
3113                 {
3114                         /* Access the object */
3115                         o_ptr = &current_floor_ptr->o_list[floor_o_idx];
3116
3117 #ifdef ALLOW_EASY_SENSE
3118
3119                         /* Option: Make object sensing easy */
3120                         if (easy_sense)
3121                         {
3122                                 /* Sense the object */
3123                                 (void)sense_object(o_ptr);
3124                         }
3125
3126 #endif /* ALLOW_EASY_SENSE */
3127
3128                         object_desc(o_name, o_ptr, 0);
3129
3130                         msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
3131                 }
3132
3133                 /* Multiple objects */
3134                 else
3135                 {
3136                         msg_print(_("ザックには床にあるどのアイテムも入らない。", "You have no room for any of the objects on the floor."));
3137
3138                 }
3139
3140                 return;
3141         }
3142
3143         /* One object */
3144         if (floor_num == 1)
3145         {
3146                 /* Hack -- query every object */
3147                 if (carry_query_flag)
3148                 {
3149                         char out_val[MAX_NLEN + 20];
3150
3151                         /* Access the object */
3152                         o_ptr = &current_floor_ptr->o_list[floor_o_idx];
3153
3154 #ifdef ALLOW_EASY_SENSE
3155
3156                         /* Option: Make object sensing easy */
3157                         if (easy_sense)
3158                         {
3159                                 /* Sense the object */
3160                                 (void)sense_object(o_ptr);
3161                         }
3162
3163 #endif /* ALLOW_EASY_SENSE */
3164
3165                         object_desc(o_name, o_ptr, 0);
3166
3167                         (void)sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
3168
3169                         /* Ask the user to confirm */
3170                         if (!get_check(out_val))
3171                         {
3172                                 return;
3173                         }
3174                 }
3175
3176                 /* Access the object */
3177                 o_ptr = &current_floor_ptr->o_list[floor_o_idx];
3178
3179 #ifdef ALLOW_EASY_SENSE
3180
3181                 /* Option: Make object sensing easy */
3182                 if (easy_sense)
3183                 {
3184                         /* Sense the object */
3185                         (void)sense_object(o_ptr);
3186                 }
3187
3188 #endif /* ALLOW_EASY_SENSE */
3189
3190                 /* Pick up the object */
3191                 py_pickup_aux(floor_o_idx);
3192         }
3193
3194         /* Allow the user to choose an object */
3195         else
3196         {
3197                 while (can_pickup--)
3198                 {
3199                         if (!py_pickup_floor_aux()) break;
3200                 }
3201         }
3202 }
3203
3204
3205
3206 /*!
3207  * @brief 所持アイテム一覧を表示する /
3208  * Choice window "shadow" of the "show_inven()" function
3209  * @return なし
3210  */
3211 void display_inven(OBJECT_TYPE_VALUE tval)
3212 {
3213         register int i, n, z = 0;
3214         object_type *o_ptr;
3215         TERM_COLOR attr = TERM_WHITE;
3216         char tmp_val[80];
3217         GAME_TEXT o_name[MAX_NLEN];
3218         TERM_LEN wid, hgt;
3219
3220         Term_get_size(&wid, &hgt);
3221
3222         for (i = 0; i < INVEN_PACK; i++)
3223         {
3224                 o_ptr = &p_ptr->inventory_list[i];
3225                 if (!o_ptr->k_idx) continue;
3226                 z = i + 1;
3227         }
3228
3229         for (i = 0; i < z; i++)
3230         {
3231                 o_ptr = &p_ptr->inventory_list[i];
3232                 tmp_val[0] = tmp_val[1] = tmp_val[2] = ' ';
3233                 if (item_tester_okay(o_ptr, tval))
3234                 {
3235                         tmp_val[0] = index_to_label(i);
3236                         tmp_val[1] = ')';
3237                 }
3238
3239                 Term_putstr(0, i, 3, TERM_WHITE, tmp_val);
3240                 object_desc(o_name, o_ptr, 0);
3241                 n = strlen(o_name);
3242                 attr = tval_to_attr[o_ptr->tval % 128];
3243                 if (o_ptr->timeout)
3244                 {
3245                         attr = TERM_L_DARK;
3246                 }
3247
3248                 Term_putstr(3, i, n, attr, o_name);
3249                 Term_erase(3 + n, i, 255);
3250
3251                 if (show_weights)
3252                 {
3253                         int wgt = o_ptr->weight * o_ptr->number;
3254 #ifdef JP
3255                         sprintf(tmp_val, "%3d.%1d kg", lbtokg1(wgt), lbtokg2(wgt));
3256 #else
3257                         sprintf(tmp_val, "%3d.%1d lb", wgt / 10, wgt % 10);
3258 #endif
3259                         prt(tmp_val, i, wid - 9);
3260                 }
3261         }
3262
3263         for (i = z; i < hgt; i++)
3264         {
3265                 Term_erase(0, i, 255);
3266         }
3267 }
3268
3269
3270 /*!
3271  * @brief 装備アイテムの表示を行う /
3272  * Display the equipment.
3273  * @param target_item アイテムの選択処理を行うか否か。
3274  * @return 選択したアイテムのタグ
3275  */
3276 COMMAND_CODE show_equip(int target_item, BIT_FLAGS mode, OBJECT_TYPE_VALUE tval)
3277 {
3278         COMMAND_CODE i;
3279         int j, k, l;
3280         int             col, cur_col, len;
3281         object_type *o_ptr;
3282         char            tmp_val[80];
3283         GAME_TEXT o_name[MAX_NLEN];
3284         COMMAND_CODE    out_index[23];
3285         TERM_COLOR      out_color[23];
3286         char            out_desc[23][MAX_NLEN];
3287         COMMAND_CODE target_item_label = 0;
3288         TERM_LEN wid, hgt;
3289         char            equip_label[52 + 1];
3290
3291         /* Starting column */
3292         col = command_gap;
3293
3294         Term_get_size(&wid, &hgt);
3295
3296         /* Maximal length */
3297         len = wid - col - 1;
3298
3299
3300         /* Scan the equipment list */
3301         for (k = 0, i = INVEN_RARM; i < INVEN_TOTAL; i++)
3302         {
3303                 o_ptr = &p_ptr->inventory_list[i];
3304
3305                 /* Is this item acceptable? */
3306                 if (!(select_ring_slot ? is_ring_slot(i) : item_tester_okay(o_ptr, tval) || (mode & USE_FULL)) &&
3307                         (!((((i == INVEN_RARM) && p_ptr->hidarite) || ((i == INVEN_LARM) && p_ptr->migite)) && p_ptr->ryoute) ||
3308                         (mode & IGNORE_BOTHHAND_SLOT))) continue;
3309
3310                 object_desc(o_name, o_ptr, 0);
3311
3312                 if ((((i == INVEN_RARM) && p_ptr->hidarite) || ((i == INVEN_LARM) && p_ptr->migite)) && p_ptr->ryoute)
3313                 {
3314                         (void)strcpy(out_desc[k], _("(武器を両手持ち)", "(wielding with two-hands)"));
3315                         out_color[k] = TERM_WHITE;
3316                 }
3317                 else
3318                 {
3319                         (void)strcpy(out_desc[k], o_name);
3320                         out_color[k] = tval_to_attr[o_ptr->tval % 128];
3321                 }
3322
3323                 out_index[k] = i;
3324                 /* Grey out charging items */
3325                 if (o_ptr->timeout)
3326                 {
3327                         out_color[k] = TERM_L_DARK;
3328                 }
3329
3330                 /* Extract the maximal length (see below) */
3331 #ifdef JP
3332                 l = strlen(out_desc[k]) + (2 + 1);
3333 #else
3334                 l = strlen(out_desc[k]) + (2 + 3);
3335 #endif
3336
3337
3338                 /* Increase length for labels (if needed) */
3339 #ifdef JP
3340                 if (show_labels) l += (7 + 2);
3341 #else
3342                 if (show_labels) l += (14 + 2);
3343 #endif
3344
3345
3346                 /* Increase length for weight (if needed) */
3347                 if (show_weights) l += 9;
3348
3349                 if (show_item_graph) l += 2;
3350
3351                 /* Maintain the max-length */
3352                 if (l > len) len = l;
3353
3354                 /* Advance the entry */
3355                 k++;
3356         }
3357
3358         /* Hack -- Find a column to start in */
3359 #ifdef JP
3360         col = (len > wid - 6) ? 0 : (wid - len - 1);
3361 #else
3362         col = (len > wid - 4) ? 0 : (wid - len - 1);
3363 #endif
3364
3365         prepare_label_string(equip_label, USE_EQUIP, tval);
3366
3367         /* Output each entry */
3368         for (j = 0; j < k; j++)
3369         {
3370                 i = out_index[j];
3371                 o_ptr = &p_ptr->inventory_list[i];
3372
3373                 /* Clear the line */
3374                 prt("", j + 1, col ? col - 2 : col);
3375
3376                 if (use_menu && target_item)
3377                 {
3378                         if (j == (target_item - 1))
3379                         {
3380                                 strcpy(tmp_val, _("》", "> "));
3381                                 target_item_label = i;
3382                         }
3383                         else strcpy(tmp_val, "  ");
3384                 }
3385                 else if (i >= INVEN_RARM)
3386                 {
3387                         /* Prepare an index --(-- */
3388                         sprintf(tmp_val, "%c)", equip_label[i - INVEN_RARM]);
3389                 }
3390                 else
3391                 {
3392                         /* Prepare an index --(-- */
3393                         sprintf(tmp_val, "%c)", index_to_label(i));
3394                 }
3395
3396                 /* Clear the line with the (possibly indented) index */
3397                 put_str(tmp_val, j + 1, col);
3398
3399                 cur_col = col + 3;
3400
3401                 /* Display graphics for object, if desired */
3402                 if (show_item_graph)
3403                 {
3404                         TERM_COLOR a = object_attr(o_ptr);
3405                         SYMBOL_CODE c = object_char(o_ptr);
3406                         Term_queue_bigchar(cur_col, j + 1, a, c, 0, 0);
3407                         if (use_bigtile) cur_col++;
3408
3409                         cur_col += 2;
3410                 }
3411
3412                 /* Use labels */
3413                 if (show_labels)
3414                 {
3415                         /* Mention the use */
3416                         (void)sprintf(tmp_val, _("%-7s: ", "%-14s: "), mention_use(p_ptr, i));
3417
3418                         put_str(tmp_val, j + 1, cur_col);
3419
3420                         /* Display the entry itself */
3421                         c_put_str(out_color[j], out_desc[j], j + 1, _(cur_col + 9, cur_col + 16));
3422                 }
3423
3424                 /* No labels */
3425                 else
3426                 {
3427                         /* Display the entry itself */
3428                         c_put_str(out_color[j], out_desc[j], j + 1, cur_col);
3429                 }
3430
3431                 /* Display the weight if needed */
3432                 if (show_weights)
3433                 {
3434                         int wgt = o_ptr->weight * o_ptr->number;
3435 #ifdef JP
3436                         (void)sprintf(tmp_val, "%3d.%1d kg", lbtokg1(wgt), lbtokg2(wgt));
3437 #else
3438                         (void)sprintf(tmp_val, "%3d.%d lb", wgt / 10, wgt % 10);
3439 #endif
3440
3441                         prt(tmp_val, j + 1, wid - 9);
3442                 }
3443         }
3444
3445         /* Make a "shadow" below the list (only if needed) */
3446         if (j && (j < 23)) prt("", j + 1, col ? col - 2 : col);
3447
3448         /* Save the new column */
3449         command_gap = col;
3450
3451         return target_item_label;
3452 }
3453
3454
3455 /*!
3456  * @brief 所持/装備オブジェクトIDの現在の扱い方の状態表現を返す /
3457  * Return a string describing how a given item is being worn.
3458  * @param i 状態表現を求めるプレイヤーの所持/装備オブジェクトID
3459  * @return 状態表現内容の文字列ポインタ
3460  * @details
3461  * Currently, only used for items in the equipment, not p_ptr->inventory_list.
3462  */
3463 concptr describe_use(int i)
3464 {
3465         concptr p;
3466
3467         switch (i)
3468         {
3469 #ifdef JP
3470         case INVEN_RARM:  p = p_ptr->heavy_wield[0] ? "運搬中の" : ((p_ptr->ryoute && p_ptr->migite) ? "両手に装備している" : (left_hander ? "左手に装備している" : "右手に装備している")); break;
3471 #else
3472         case INVEN_RARM:  p = p_ptr->heavy_wield[0] ? "just lifting" : (p_ptr->migite ? "attacking monsters with" : "wearing on your arm"); break;
3473 #endif
3474
3475 #ifdef JP
3476         case INVEN_LARM:  p = p_ptr->heavy_wield[1] ? "運搬中の" : ((p_ptr->ryoute && p_ptr->hidarite) ? "両手に装備している" : (left_hander ? "右手に装備している" : "左手に装備している")); break;
3477 #else
3478         case INVEN_LARM:  p = p_ptr->heavy_wield[1] ? "just lifting" : (p_ptr->hidarite ? "attacking monsters with" : "wearing on your arm"); break;
3479 #endif
3480
3481         case INVEN_BOW:   p = (adj_str_hold[p_ptr->stat_ind[A_STR]] < p_ptr->inventory_list[i].weight / 10) ? _("持つだけで精一杯の", "just holding") : _("射撃用に装備している", "shooting missiles with"); break;
3482         case INVEN_RIGHT: p = (left_hander ? _("左手の指にはめている", "wearing on your left hand") : _("右手の指にはめている", "wearing on your right hand")); break;
3483         case INVEN_LEFT:  p = (left_hander ? _("右手の指にはめている", "wearing on your right hand") : _("左手の指にはめている", "wearing on your left hand")); break;
3484         case INVEN_NECK:  p = _("首にかけている", "wearing around your neck"); break;
3485         case INVEN_LITE:  p = _("光源にしている", "using to light the way"); break;
3486         case INVEN_BODY:  p = _("体に着ている", "wearing on your body"); break;
3487         case INVEN_OUTER: p = _("身にまとっている", "wearing on your back"); break;
3488         case INVEN_HEAD:  p = _("頭にかぶっている", "wearing on your head"); break;
3489         case INVEN_HANDS: p = _("手につけている", "wearing on your hands"); break;
3490         case INVEN_FEET:  p = _("足にはいている", "wearing on your feet"); break;
3491         default:          p = _("ザックに入っている", "carrying in your pack"); break;
3492         }
3493
3494         /* Return the result */
3495         return p;
3496 }
3497