OSDN Git Service

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