OSDN Git Service

Merge branch 'master' of git.osdn.net:/gitroot/hengband/hengband
[hengband/hengband.git] / src / floor / object-scanner.c
1 #include "floor/object-scanner.h"
2 #include "floor/cave.h"
3 #include "flavor/flavor-describer.h"
4 #include "game-option/text-display-options.h"
5 #include "grid/grid.h"
6 #include "inventory/inventory-util.h"
7 #include "io/input-key-requester.h"
8 #include "object/item-tester-hooker.h"
9 #include "object/object-mark-types.h"
10 #include "system/floor-type-definition.h"
11 #include "system/object-type-definition.h"
12 #include "term/gameterm.h"
13 #include "term/screen-processor.h"
14
15 /*!
16  * @brief 床に落ちているオブジェクトの数を返す / scan floor items
17  * @param items オブジェクトのIDリストを返すための配列参照ポインタ
18  * @param y 走査するフロアのY座標
19  * @param x 走査するフロアのX座標
20  * @param mode オプションフラグ
21  * @return 対象のマスに落ちているアイテム数
22  * @details
23  * Return a list of o_list[] indexes of items at the given floor
24  * location. Valid flags are:
25  *
26  *              mode & 0x01 -- Item tester
27  *              mode & 0x02 -- Marked items only
28  *              mode & 0x04 -- Stop after first
29  */
30 ITEM_NUMBER scan_floor_items(player_type *owner_ptr, OBJECT_IDX *items, POSITION y, POSITION x, BIT_FLAGS mode, tval_type item_tester_tval)
31 {
32     floor_type *floor_ptr = owner_ptr->current_floor_ptr;
33     if (!in_bounds(floor_ptr, y, x))
34         return 0;
35
36     OBJECT_IDX this_o_idx, next_o_idx;
37     ITEM_NUMBER num = 0;
38     for (this_o_idx = floor_ptr->grid_array[y][x].o_idx; this_o_idx; this_o_idx = next_o_idx) {
39         object_type *o_ptr;
40         o_ptr = &floor_ptr->o_list[this_o_idx];
41         next_o_idx = o_ptr->next_o_idx;
42         if ((mode & 0x01) && !item_tester_okay(owner_ptr, o_ptr, item_tester_tval))
43             continue;
44
45         if ((mode & 0x02) && !(o_ptr->marked & OM_FOUND))
46             continue;
47
48         if (num < 23)
49             items[num] = this_o_idx;
50
51         num++;
52         if (mode & 0x04)
53             break;
54     }
55
56     return num;
57 }
58
59 /*!
60  * @brief タグIDにあわせてタグアルファベットのリストを返す(床上アイテム用) /
61  * Move around label characters with correspond tags (floor version)
62  * @param label ラベルリストを取得する文字列参照ポインタ
63  * @param floor_list 床上アイテムの配列
64  * @param floor_num  床上アイテムの配列ID
65  * @return なし
66  */
67 /*
68  */
69 static void prepare_label_string_floor(floor_type *floor_ptr, char *label, FLOOR_IDX floor_list[], ITEM_NUMBER floor_num)
70 {
71     concptr alphabet_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
72     strcpy(label, alphabet_chars);
73     for (int i = 0; i < 52; i++) {
74         COMMAND_CODE index;
75         SYMBOL_CODE c = alphabet_chars[i];
76         if (!get_tag_floor(floor_ptr, &index, c, floor_list, floor_num))
77             continue;
78
79         if (label[i] == c)
80             label[i] = ' ';
81
82         label[index] = c;
83     }
84 }
85
86 /*!
87  * @brief 床下に落ちているアイテムの一覧を返す / Display a list of the items on the floor at the given location.
88  * @param target_item カーソルの初期値
89  * @param y 走査するフロアのY座標
90  * @param x 走査するフロアのX座標
91  * @param min_width 表示の長さ
92  * @return 選択したアイテムの添え字
93  * @details
94  */
95 COMMAND_CODE show_floor_items(player_type *owner_ptr, int target_item, POSITION y, POSITION x, TERM_LEN *min_width, tval_type item_tester_tval)
96 {
97     COMMAND_CODE i, m;
98     int j, k, l;
99     object_type *o_ptr;
100     GAME_TEXT o_name[MAX_NLEN];
101     char tmp_val[80];
102     COMMAND_CODE out_index[23];
103     TERM_COLOR out_color[23];
104     char out_desc[23][MAX_NLEN];
105     COMMAND_CODE target_item_label = 0;
106     OBJECT_IDX floor_list[23];
107     ITEM_NUMBER floor_num;
108     TERM_LEN wid, hgt;
109     char floor_label[52 + 1];
110     bool dont_need_to_show_weights = TRUE;
111     term_get_size(&wid, &hgt);
112     int len = MAX((*min_width), 20);
113     floor_num = scan_floor_items(owner_ptr, floor_list, y, x, 0x03, item_tester_tval);
114     floor_type *floor_ptr = owner_ptr->current_floor_ptr;
115     for (k = 0, i = 0; i < floor_num && i < 23; i++) {
116         o_ptr = &floor_ptr->o_list[floor_list[i]];
117         describe_flavor(owner_ptr, o_name, o_ptr, 0);
118         out_index[k] = i;
119         out_color[k] = tval_to_attr[o_ptr->tval & 0x7F];
120         strcpy(out_desc[k], o_name);
121         l = strlen(out_desc[k]) + 5;
122         if (show_weights)
123             l += 9;
124
125         if (o_ptr->tval != TV_GOLD)
126             dont_need_to_show_weights = FALSE;
127
128         if (l > len)
129             len = l;
130
131         k++;
132     }
133
134     if (show_weights && dont_need_to_show_weights)
135         len -= 9;
136
137     *min_width = len;
138     int col = (len > wid - 4) ? 0 : (wid - len - 1);
139     prepare_label_string_floor(floor_ptr, floor_label, floor_list, floor_num);
140     for (j = 0; j < k; j++) {
141         m = floor_list[out_index[j]];
142         o_ptr = &floor_ptr->o_list[m];
143         prt("", j + 1, col ? col - 2 : col);
144         if (use_menu && target_item) {
145             if (j == (target_item - 1)) {
146                 strcpy(tmp_val, _("》", "> "));
147                 target_item_label = m;
148             } else
149                 strcpy(tmp_val, "   ");
150         } else {
151             sprintf(tmp_val, "%c)", floor_label[j]);
152         }
153
154         put_str(tmp_val, j + 1, col);
155         c_put_str(out_color[j], out_desc[j], j + 1, col + 3);
156         if (show_weights && (o_ptr->tval != TV_GOLD)) {
157             int wgt = o_ptr->weight * o_ptr->number;
158             sprintf(tmp_val, _("%3d.%1d kg", "%3d.%1d lb"), _(lbtokg1(wgt), wgt / 10), _(lbtokg2(wgt), wgt % 10));
159             prt(tmp_val, j + 1, wid - 9);
160         }
161     }
162
163     if (j && (j < 23))
164         prt("", j + 1, col ? col - 2 : col);
165
166     return target_item_label;
167 }