7 #include "knowledge/knowledge-features.h"
8 #include "core/show-file.h"
9 #include "game-option/special-options.h"
10 #include "grid/feature.h"
11 #include "io-dump/dump-util.h"
12 #include "io/input-key-acceptor.h"
13 #include "knowledge/lighting-level-table.h"
14 #include "monster-race/monster-race.h"
15 #include "system/dungeon-info.h"
16 #include "system/monster-race-info.h"
17 #include "system/player-type-definition.h"
18 #include "system/terrain-type-definition.h"
19 #include "term/screen-processor.h"
20 #include "term/term-color-types.h"
21 #include "util/angband-files.h"
22 #include "util/int-char-converter.h"
23 #include "world/world.h"
26 * Build a list of feature indexes in the given group. Return the number
27 * of features in the group.
29 * mode & 0x01 : check for non-empty group
31 static FEAT_IDX collect_features(FEAT_IDX *feat_idx, BIT_FLAGS8 mode)
33 FEAT_IDX feat_cnt = 0;
34 for (const auto &f_ref : terrains_info) {
35 if (f_ref.name.empty()) {
38 if (f_ref.mimic != f_ref.idx) {
42 feat_idx[feat_cnt++] = f_ref.idx;
48 feat_idx[feat_cnt] = -1;
53 * Display the features in a group.
55 static void display_feature_list(int col, int row, int per_page, FEAT_IDX *feat_idx, FEAT_IDX feat_cur, FEAT_IDX feat_top, bool visual_only, int lighting_level)
57 int lit_col[F_LIT_MAX], i;
58 int f_idx_col = use_bigtile ? 62 : 64;
60 lit_col[F_LIT_STANDARD] = use_bigtile ? (71 - F_LIT_MAX) : 71;
61 for (i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) {
62 lit_col[i] = lit_col[F_LIT_STANDARD] + 2 + (i - F_LIT_NS_BEGIN) * 2 + (use_bigtile ? i : 0);
65 for (i = 0; i < per_page && (feat_idx[feat_top + i] >= 0); i++) {
67 FEAT_IDX f_idx = feat_idx[feat_top + i];
68 auto *f_ptr = &terrains_info[f_idx];
70 attr = ((i + feat_top == feat_cur) ? TERM_L_BLUE : TERM_WHITE);
71 c_prt(attr, f_ptr->name.data(), row_i, col);
73 c_prt(attr, format("(%s)", lighting_level_str[lighting_level]), row_i, col + 1 + f_ptr->name.size());
74 c_prt(attr, format("%02x/%02x", f_ptr->x_attr[lighting_level], (unsigned char)f_ptr->x_char[lighting_level]), row_i,
75 f_idx_col - ((w_ptr->wizard || visual_only) ? 6 : 2));
77 if (w_ptr->wizard || visual_only) {
78 c_prt(attr, format("%d", f_idx), row_i, f_idx_col);
81 term_queue_bigchar(lit_col[F_LIT_STANDARD], row_i, f_ptr->x_attr[F_LIT_STANDARD], f_ptr->x_char[F_LIT_STANDARD], 0, 0);
82 term_putch(lit_col[F_LIT_NS_BEGIN], row_i, TERM_SLATE, '(');
83 for (int j = F_LIT_NS_BEGIN + 1; j < F_LIT_MAX; j++) {
84 term_putch(lit_col[j], row_i, TERM_SLATE, '/');
87 term_putch(lit_col[F_LIT_MAX - 1] + (use_bigtile ? 3 : 2), row_i, TERM_SLATE, ')');
88 for (int j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++) {
89 term_queue_bigchar(lit_col[j] + 1, row_i, f_ptr->x_attr[j], f_ptr->x_char[j], 0, 0);
93 for (; i < per_page; i++) {
94 term_erase(col, row + i, 255);
99 * Interact with feature visuals.
101 void do_cmd_knowledge_features(bool *need_redraw, bool visual_only, IDX direct_f_idx, IDX *lighting_level)
103 TERM_COLOR attr_old[F_LIT_MAX] = {};
104 char char_old[F_LIT_MAX] = {};
107 term_get_size(&wid, &hgt);
109 std::vector<FEAT_IDX> feat_idx(terrains_info.size());
111 concptr feature_group_text[] = { "terrains", nullptr };
116 FEAT_IDX grp_idx[100];
117 TERM_COLOR attr_top = 0;
118 bool visual_list = false;
120 TERM_LEN browser_rows = hgt - 8;
121 if (direct_f_idx < 0) {
122 for (FEAT_IDX i = 0; feature_group_text[i] != nullptr; i++) {
123 len = strlen(feature_group_text[i]);
128 if (collect_features(feat_idx.data(), 0x01)) {
129 grp_idx[grp_cnt++] = i;
135 auto *f_ptr = &terrains_info[direct_f_idx];
137 feat_idx[0] = direct_f_idx;
141 (void)visual_mode_command('v', &visual_list, browser_rows - 1, wid - (max + 3), &attr_top, &char_left, &f_ptr->x_attr[*lighting_level],
142 &f_ptr->x_char[*lighting_level], need_redraw);
144 for (FEAT_IDX i = 0; i < F_LIT_MAX; i++) {
145 attr_old[i] = f_ptr->x_attr[i];
146 char_old[i] = f_ptr->x_char[i];
150 grp_idx[grp_cnt] = -1;
152 FEAT_IDX old_grp_cur = -1;
153 FEAT_IDX grp_cur = 0;
154 FEAT_IDX grp_top = 0;
155 FEAT_IDX feat_cur = 0;
156 FEAT_IDX feat_top = 0;
160 TERM_COLOR *cur_attr_ptr;
169 prt(_("表示 - 地形", "Visuals - features"), 2, 0);
170 if (direct_f_idx < 0) {
171 prt(_("グループ", "Group"), 4, 0);
173 prt(_("名前", "Name"), 4, max + 3);
175 if (w_ptr->wizard || visual_only) {
178 prt(_("文字 ( l/ d)", "Sym ( l/ d)"), 4, 66);
180 if (w_ptr->wizard || visual_only) {
183 prt(_("文字 (l/d)", "Sym (l/d)"), 4, 68);
186 for (FEAT_IDX i = 0; i < 78; i++) {
187 term_putch(i, 5, TERM_WHITE, '=');
190 if (direct_f_idx < 0) {
191 for (FEAT_IDX i = 0; i < browser_rows; i++) {
192 term_putch(max + 1, 6 + i, TERM_WHITE, '|');
199 if (direct_f_idx < 0) {
200 if (grp_cur < grp_top) {
203 if (grp_cur >= grp_top + browser_rows) {
204 grp_top = grp_cur - browser_rows + 1;
207 display_group_list(0, 6, max, browser_rows, grp_idx, feature_group_text, grp_cur, grp_top);
208 if (old_grp_cur != grp_cur) {
209 old_grp_cur = grp_cur;
210 feat_cnt = collect_features(feat_idx.data(), 0x00);
213 while (feat_cur < feat_top) {
214 feat_top = std::max<short>(0, feat_top - browser_rows / 2);
216 while (feat_cur >= feat_top + browser_rows) {
217 feat_top = std::min<short>(feat_cnt - browser_rows, feat_top + browser_rows / 2);
222 display_feature_list(max + 3, 6, browser_rows, feat_idx.data(), feat_cur, feat_top, visual_only, F_LIT_STANDARD);
225 display_feature_list(max + 3, 6, 1, feat_idx.data(), feat_cur, feat_top, visual_only, *lighting_level);
226 display_visual_list(max + 3, 7, browser_rows - 1, wid - (max + 3), attr_top, char_left);
229 prt(format(_("<方向>%s, 'd'で標準光源効果%s, ESC", "<dir>%s, 'd' for default lighting%s, ESC"),
230 visual_list ? _(", ENTERで決定, 'a'で対象明度変更", ", ENTER to accept, 'a' for lighting level")
231 : _(", 'v'でシンボル変更", ", 'v' for visuals"),
232 (attr_idx || char_idx) ? _(", 'c', 'p'でペースト", ", 'c', 'p' to paste") : _(", 'c'でコピー", ", 'c' to copy")),
235 f_ptr = &terrains_info[feat_idx[feat_cur]];
236 cur_attr_ptr = &f_ptr->x_attr[*lighting_level];
237 cur_char_ptr = &f_ptr->x_char[*lighting_level];
240 place_visual_list_cursor(max + 3, 7, *cur_attr_ptr, *cur_char_ptr, attr_top, char_left);
241 } else if (!column) {
242 term_gotoxy(0, 6 + (grp_cur - grp_top));
244 term_gotoxy(max + 3, 6 + (feat_cur - feat_top));
248 if (visual_list && ((ch == 'A') || (ch == 'a'))) {
249 int prev_lighting_level = *lighting_level;
252 if (*lighting_level <= 0) {
253 *lighting_level = F_LIT_MAX - 1;
258 if (*lighting_level >= F_LIT_MAX - 1) {
265 if (f_ptr->x_attr[prev_lighting_level] != f_ptr->x_attr[*lighting_level]) {
266 attr_top = std::max<byte>(0, (f_ptr->x_attr[*lighting_level] & 0x7f) - 5);
269 if (f_ptr->x_char[prev_lighting_level] != f_ptr->x_char[*lighting_level]) {
270 char_left = std::max<byte>(0, f_ptr->x_char[*lighting_level] - 10);
274 } else if ((ch == 'D') || (ch == 'd')) {
275 TERM_COLOR prev_x_attr = f_ptr->x_attr[*lighting_level];
276 byte prev_x_char = f_ptr->x_char[*lighting_level];
278 apply_default_feat_lighting(f_ptr->x_attr, f_ptr->x_char);
281 if (prev_x_attr != f_ptr->x_attr[*lighting_level]) {
282 attr_top = std::max<byte>(0, (f_ptr->x_attr[*lighting_level] & 0x7f) - 5);
285 if (prev_x_char != f_ptr->x_char[*lighting_level]) {
286 char_left = std::max<byte>(0, f_ptr->x_char[*lighting_level] - 10);
293 } else if (visual_mode_command(ch, &visual_list, browser_rows - 1, wid - (max + 3), &attr_top, &char_left, cur_attr_ptr, cur_char_ptr, need_redraw)) {
296 for (FEAT_IDX i = 0; i < F_LIT_MAX; i++) {
297 f_ptr->x_attr[i] = attr_old[i];
298 f_ptr->x_char[i] = char_old[i];
304 if (direct_f_idx >= 0) {
307 *lighting_level = F_LIT_STANDARD;
312 for (FEAT_IDX i = 0; i < F_LIT_MAX; i++) {
313 attr_old[i] = f_ptr->x_attr[i];
314 char_old[i] = f_ptr->x_char[i];
316 *lighting_level = F_LIT_STANDARD;
322 for (FEAT_IDX i = 0; i < F_LIT_MAX; i++) {
323 attr_idx_feat[i] = f_ptr->x_attr[i];
324 char_idx_feat[i] = f_ptr->x_char[i];
332 for (FEAT_IDX i = F_LIT_NS_BEGIN; i < F_LIT_MAX; i++) {
333 if (attr_idx_feat[i] || (!(char_idx_feat[i] & 0x80) && char_idx_feat[i])) {
334 f_ptr->x_attr[i] = attr_idx_feat[i];
336 if (char_idx_feat[i]) {
337 f_ptr->x_char[i] = char_idx_feat[i];
353 browser_cursor(ch, &column, &grp_cur, grp_cnt, &feat_cur, feat_cnt);
363 void do_cmd_knowledge_dungeon(PlayerType *player_ptr)
366 GAME_TEXT file_name[FILE_NAME_SIZE];
367 if (!open_temporary_file(&fff, file_name)) {
371 for (const auto &d_ref : dungeons_info) {
374 if (d_ref.idx == 0 || !d_ref.maxdepth) {
377 if (!max_dlv[d_ref.idx]) {
380 if (MonsterRace(d_ref.final_guardian).is_valid()) {
381 if (!monraces_info[d_ref.final_guardian].max_num) {
384 } else if (max_dlv[d_ref.idx] == d_ref.maxdepth) {
388 fprintf(fff, _("%c%-12s : %3d 階\n", "%c%-16s : level %3d\n"), seiha ? '!' : ' ', d_ref.name.data(), (int)max_dlv[d_ref.idx]);
392 (void)show_file(player_ptr, true, file_name, _("今までに入ったダンジョン", "Dungeon"), 0, 0);