OSDN Git Service

Merge pull request #716 from sikabane-works/release/3.0.0Alpha16
[hengbandforosx/hengbandosx.git] / src / view / display-map.cpp
1 #include "view/display-map.h"
2 #include "autopick/autopick-finder.h"
3 #include "autopick/autopick-methods-table.h"
4 #include "floor/cave.h"
5 #include "game-option/map-screen-options.h"
6 #include "game-option/special-options.h"
7 #include "grid/feature.h"
8 #include "grid/grid.h"
9 #include "monster-race/monster-race.h"
10 #include "monster-race/race-flags1.h"
11 #include "monster-race/race-flags2.h"
12 #include "object/object-info.h"
13 #include "object/object-kind.h"
14 #include "object/object-mark-types.h"
15 #include "system/floor-type-definition.h"
16 #include "term/term-color-types.h"
17 #include "util/bit-flags-calculator.h"
18 #include "window/main-window-util.h"
19 #include "world/world.h"
20
21 byte display_autopick; /*!< 自動拾い状態の設定フラグ */
22
23 /* 一般的にオブジェクトシンボルとして扱われる記号を定義する(幻覚処理向け) /  Hack -- Legal object codes */
24 char image_object_hack[MAX_IMAGE_OBJECT_HACK] = "?/|\\\"!$()_-=[]{},~";
25
26 /* 一般的にモンスターシンボルとして扱われる記号を定義する(幻覚処理向け) / Hack -- Legal monster codes */
27 char image_monster_hack[MAX_IMAGE_MONSTER_HACK] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
28
29 /*!
30  * @brief オブジェクトの表示を幻覚状態に差し替える / Hallucinatory object
31  * @param ap 本来の色
32  * @param cp 本来のシンボル
33  * @return なし
34  */
35 static void image_object(TERM_COLOR *ap, SYMBOL_CODE *cp)
36 {
37     if (use_graphics) {
38         object_kind *k_ptr = &k_info[randint1(max_k_idx - 1)];
39         *cp = k_ptr->x_char;
40         *ap = k_ptr->x_attr;
41         return;
42     }
43
44     size_t n = sizeof(image_object_hack) - 1;
45     *cp = image_object_hack[randint0(n)];
46     *ap = randint1(15);
47 }
48
49 /*!
50  * @brief モンスターの表示を幻覚状態に差し替える / Mega-Hack -- Hallucinatory monster
51  * @param ap 本来の色
52  * @param cp 本来のシンボル
53  * @return なし
54  */
55 static void image_monster(TERM_COLOR *ap, SYMBOL_CODE *cp)
56 {
57     if (use_graphics) {
58         monster_race *r_ptr = &r_info[randint1(max_r_idx - 1)];
59         *cp = r_ptr->x_char;
60         *ap = r_ptr->x_attr;
61         return;
62     }
63
64     *cp = (one_in_(25) ? image_object_hack[randint0(sizeof(image_object_hack) - 1)] : image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
65     *ap = randint1(15);
66 }
67
68 /*!
69  * @brief オブジェクト&モンスターの表示を幻覚状態に差し替える / Hack -- Random hallucination
70  * @param ap 本来の色
71  * @param cp 本来のシンボル
72  * @return なし
73  */
74 static void image_random(TERM_COLOR *ap, SYMBOL_CODE *cp)
75 {
76     if (randint0(100) < 75) {
77         image_monster(ap, cp);
78     } else {
79         image_object(ap, cp);
80     }
81 }
82
83 static bool is_revealed_wall(floor_type *floor_ptr, feature_type *f_ptr, POSITION y, POSITION x)
84 {
85     if (view_hidden_walls)
86         return TRUE;
87
88     if (!has_flag(f_ptr->flags, FF_WALL) || has_flag(f_ptr->flags, FF_HAS_GOLD))
89         return TRUE;
90
91     if (in_bounds(floor_ptr, y, x) && has_flag(f_ptr->flags, FF_PERMANENT))
92         return TRUE;
93
94     int n = 0;
95     for (int i = 0; i < 8; i++) {
96         int dy = y + ddy_cdd[i];
97         int dx = x + ddx_cdd[i];
98         if (!in_bounds(floor_ptr, dy, dx)) {
99             n++;
100             continue;
101         }
102
103         FEAT_IDX f_idx = floor_ptr->grid_array[dy][dx].feat;
104         feature_type *n_ptr = &f_info[f_idx];
105         if (has_flag(n_ptr->flags, FF_WALL))
106             n++;
107     }
108
109     return (n != 8);
110 }
111
112 /*!
113  * @brief 指定した座標の地形の表示属性を取得する / Extract the attr/char to display at the given (legal) map location
114  * @param player_ptr プレイヤー情報への参照ポインタ
115  * @param y 階の中のy座標
116  * @param x 階の中のy座標
117  * @param ap 文字色属性
118  * @param cp 文字種属性
119  * @param tap 文字色属性(タイル)
120  * @param tcp 文字種属性(タイル)
121  * @return なし
122  */
123 void map_info(player_type *player_ptr, POSITION y, POSITION x, TERM_COLOR *ap, SYMBOL_CODE *cp, TERM_COLOR *tap, SYMBOL_CODE *tcp)
124 {
125     floor_type *floor_ptr = player_ptr->current_floor_ptr;
126     grid_type *g_ptr = &floor_ptr->grid_array[y][x];
127     OBJECT_IDX this_o_idx, next_o_idx = 0;
128     FEAT_IDX feat = get_feat_mimic(g_ptr);
129     feature_type *f_ptr = &f_info[feat];
130     TERM_COLOR a;
131     SYMBOL_CODE c;
132     if (!has_flag(f_ptr->flags, FF_REMEMBER)) {
133         if (!player_ptr->blind
134             && ((g_ptr->info & (CAVE_MARK | CAVE_LITE | CAVE_MNLT))
135                 || ((g_ptr->info & CAVE_VIEW) && (((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) || player_ptr->see_nocto)))) {
136             a = f_ptr->x_attr[F_LIT_STANDARD];
137             c = f_ptr->x_char[F_LIT_STANDARD];
138             if (player_ptr->wild_mode) {
139                 if (view_special_lite && !is_daytime()) {
140                     a = f_ptr->x_attr[F_LIT_DARK];
141                     c = f_ptr->x_char[F_LIT_DARK];
142                 }
143             } else if (darkened_grid(player_ptr, g_ptr)) {
144                 feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
145                 f_ptr = &f_info[feat];
146                 a = f_ptr->x_attr[F_LIT_STANDARD];
147                 c = f_ptr->x_char[F_LIT_STANDARD];
148             } else if (view_special_lite) {
149                 if (g_ptr->info & (CAVE_LITE | CAVE_MNLT)) {
150                     if (view_yellow_lite) {
151                         a = f_ptr->x_attr[F_LIT_LITE];
152                         c = f_ptr->x_char[F_LIT_LITE];
153                     }
154                 } else if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) {
155                     a = f_ptr->x_attr[F_LIT_DARK];
156                     c = f_ptr->x_char[F_LIT_DARK];
157                 } else if (!(g_ptr->info & CAVE_VIEW)) {
158                     if (view_bright_lite) {
159                         a = f_ptr->x_attr[F_LIT_DARK];
160                         c = f_ptr->x_char[F_LIT_DARK];
161                     }
162                 }
163             }
164         } else {
165             feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
166             f_ptr = &f_info[feat];
167             a = f_ptr->x_attr[F_LIT_STANDARD];
168             c = f_ptr->x_char[F_LIT_STANDARD];
169         }
170     } else {
171         if (g_ptr->info & CAVE_MARK && is_revealed_wall(floor_ptr, f_ptr, y, x)) {
172             a = f_ptr->x_attr[F_LIT_STANDARD];
173             c = f_ptr->x_char[F_LIT_STANDARD];
174             if (player_ptr->wild_mode) {
175                 if (view_granite_lite && (player_ptr->blind || !is_daytime())) {
176                     a = f_ptr->x_attr[F_LIT_DARK];
177                     c = f_ptr->x_char[F_LIT_DARK];
178                 }
179             } else if (darkened_grid(player_ptr, g_ptr) && !player_ptr->blind) {
180                 if (has_flag(f_ptr->flags, FF_LOS) && has_flag(f_ptr->flags, FF_PROJECT)) {
181                     feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
182                     f_ptr = &f_info[feat];
183                     a = f_ptr->x_attr[F_LIT_STANDARD];
184                     c = f_ptr->x_char[F_LIT_STANDARD];
185                 } else if (view_granite_lite && view_bright_lite) {
186                     a = f_ptr->x_attr[F_LIT_DARK];
187                     c = f_ptr->x_char[F_LIT_DARK];
188                 }
189             } else if (view_granite_lite) {
190                 if (player_ptr->blind) {
191                     a = f_ptr->x_attr[F_LIT_DARK];
192                     c = f_ptr->x_char[F_LIT_DARK];
193                 } else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT)) {
194                     if (view_yellow_lite) {
195                         a = f_ptr->x_attr[F_LIT_LITE];
196                         c = f_ptr->x_char[F_LIT_LITE];
197                     }
198                 } else if (view_bright_lite) {
199                     if (!(g_ptr->info & CAVE_VIEW)) {
200                         a = f_ptr->x_attr[F_LIT_DARK];
201                         c = f_ptr->x_char[F_LIT_DARK];
202                     } else if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) {
203                         a = f_ptr->x_attr[F_LIT_DARK];
204                         c = f_ptr->x_char[F_LIT_DARK];
205                     } else if (!has_flag(f_ptr->flags, FF_LOS) && !check_local_illumination(player_ptr, y, x)) {
206                         a = f_ptr->x_attr[F_LIT_DARK];
207                         c = f_ptr->x_char[F_LIT_DARK];
208                     }
209                 }
210             }
211         } else {
212             feat = (view_unsafe_grids && (g_ptr->info & CAVE_UNSAFE)) ? feat_undetected : feat_none;
213             f_ptr = &f_info[feat];
214             a = f_ptr->x_attr[F_LIT_STANDARD];
215             c = f_ptr->x_char[F_LIT_STANDARD];
216         }
217     }
218
219     if (feat_priority == -1)
220         feat_priority = f_ptr->priority;
221
222     (*tap) = a;
223     (*tcp) = c;
224     (*ap) = a;
225     (*cp) = c;
226
227     if (player_ptr->image && one_in_(256))
228         image_random(ap, cp);
229
230     for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
231         object_type *o_ptr;
232         o_ptr = &floor_ptr->o_list[this_o_idx];
233         next_o_idx = o_ptr->next_o_idx;
234         if (!(o_ptr->marked & OM_FOUND))
235             continue;
236
237         if (display_autopick) {
238             byte act;
239
240             match_autopick = find_autopick_list(player_ptr, o_ptr);
241             if (match_autopick == -1)
242                 continue;
243
244             act = autopick_list[match_autopick].action;
245
246             if ((act & DO_DISPLAY) && (act & display_autopick)) {
247                 autopick_obj = o_ptr;
248             } else {
249                 match_autopick = -1;
250                 continue;
251             }
252         }
253
254         (*cp) = object_char(o_ptr);
255         (*ap) = object_attr(o_ptr);
256         feat_priority = 20;
257         if (player_ptr->image)
258             image_object(ap, cp);
259
260         break;
261     }
262
263     if (g_ptr->m_idx && display_autopick != 0) {
264         set_term_color(player_ptr, y, x, ap, cp);
265         return;
266     }
267
268     monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
269     if (!m_ptr->ml) {
270         set_term_color(player_ptr, y, x, ap, cp);
271         return;
272     }
273
274     monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
275     feat_priority = 30;
276     if (player_ptr->image) {
277         if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) {
278             /* Do nothing */
279         } else {
280             image_monster(ap, cp);
281         }
282
283         set_term_color(player_ptr, y, x, ap, cp);
284         return;
285     }
286
287     a = r_ptr->x_attr;
288     c = r_ptr->x_char;
289     if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_SHAPECHANGER | RF1_ATTR_CLEAR | RF1_ATTR_MULTI | RF1_ATTR_SEMIRAND))) {
290         *ap = a;
291         *cp = c;
292         set_term_color(player_ptr, y, x, ap, cp);
293         return;
294     }
295
296     if ((r_ptr->flags1 & (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) == (RF1_CHAR_CLEAR | RF1_ATTR_CLEAR)) {
297         set_term_color(player_ptr, y, x, ap, cp);
298         return;
299     }
300
301     if ((r_ptr->flags1 & RF1_ATTR_CLEAR) && (*ap != TERM_DARK) && !use_graphics) {
302         /* Do nothing */
303     } else if ((r_ptr->flags1 & RF1_ATTR_MULTI) && !use_graphics) {
304         if (r_ptr->flags2 & RF2_ATTR_ANY)
305             *ap = randint1(15);
306         else
307             switch (randint1(7)) {
308             case 1:
309                 *ap = TERM_RED;
310                 break;
311             case 2:
312                 *ap = TERM_L_RED;
313                 break;
314             case 3:
315                 *ap = TERM_WHITE;
316                 break;
317             case 4:
318                 *ap = TERM_L_GREEN;
319                 break;
320             case 5:
321                 *ap = TERM_BLUE;
322                 break;
323             case 6:
324                 *ap = TERM_L_DARK;
325                 break;
326             case 7:
327                 *ap = TERM_GREEN;
328                 break;
329             }
330     } else if ((r_ptr->flags1 & RF1_ATTR_SEMIRAND) && !use_graphics) {
331         *ap = g_ptr->m_idx % 15 + 1;
332     } else {
333         *ap = a;
334     }
335
336     if ((r_ptr->flags1 & RF1_CHAR_CLEAR) && (*cp != ' ') && !use_graphics) {
337         set_term_color(player_ptr, y, x, ap, cp);
338         return;
339     }
340
341     if (r_ptr->flags1 & RF1_SHAPECHANGER) {
342         if (use_graphics) {
343             monster_race *tmp_r_ptr = &r_info[randint1(max_r_idx - 1)];
344             *cp = tmp_r_ptr->x_char;
345             *ap = tmp_r_ptr->x_attr;
346         } else {
347             *cp = (one_in_(25) ? image_object_hack[randint0(sizeof(image_object_hack) - 1)] : image_monster_hack[randint0(sizeof(image_monster_hack) - 1)]);
348         }
349
350         set_term_color(player_ptr, y, x, ap, cp);
351         return;
352     }
353
354     *cp = c;
355     set_term_color(player_ptr, y, x, ap, cp);
356 }