OSDN Git Service

[Refactor] #2523 PlayerType::blind をPlayerBlindnessの呼び出しに差し替えた
[hengbandforosx/hengbandosx.git] / src / grid / grid.cpp
1 /*!
2  * @brief グリッドの実装 / low level dungeon routines -BEN-
3  * @date 2013/12/30
4  * @author
5  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
6  *\n
7  * This software may be copied and distributed for educational, research,\n
8  * and not for profit purposes provided that this copyright and statement\n
9  * are included in all such copies.  Other copyrights may also apply.\n
10  * \n
11  * Support for Adam Bolt's tileset, lighting and transparency effects\n
12  * by Robert Ruehlmann (rr9@angband.org)\n
13  * \n
14  * 2013 Deskull Doxygen向けのコメント整理\n
15  */
16
17 #include "grid/grid.h"
18 #include "core/window-redrawer.h"
19 #include "dungeon/dungeon-flag-types.h"
20 #include "dungeon/dungeon.h"
21 #include "dungeon/quest.h"
22 #include "effect/attribute-types.h"
23 #include "effect/effect-characteristics.h"
24 #include "effect/effect-processor.h"
25 #include "floor/cave.h"
26 #include "floor/floor-generator.h"
27 #include "floor/geometry.h"
28 #include "game-option/game-play-options.h"
29 #include "game-option/map-screen-options.h"
30 #include "game-option/special-options.h"
31 #include "grid/feature-action-flags.h"
32 #include "grid/feature.h"
33 #include "grid/object-placer.h"
34 #include "grid/trap.h"
35 #include "io/screen-util.h"
36 #include "monster-floor/monster-remover.h"
37 #include "monster-race/monster-race.h"
38 #include "monster-race/race-flags2.h"
39 #include "monster-race/race-flags7.h"
40 #include "monster/monster-info.h"
41 #include "monster/monster-status.h"
42 #include "monster/monster-update.h"
43 #include "object/item-tester-hooker.h"
44 #include "object/object-mark-types.h"
45 #include "player-info/class-info.h"
46 #include "player/player-status-flags.h"
47 #include "player/player-status.h"
48 #include "room/rooms-builder.h"
49 #include "system/floor-type-definition.h"
50 #include "system/grid-type-definition.h"
51 #include "system/monster-race-definition.h"
52 #include "system/monster-type-definition.h"
53 #include "system/object-type-definition.h"
54 #include "system/player-type-definition.h"
55 #include "term/gameterm.h"
56 #include "term/term-color-types.h"
57 #include "timed-effect/player-blindness.h"
58 #include "timed-effect/timed-effects.h"
59 #include "util/bit-flags-calculator.h"
60 #include "util/enum-converter.h"
61 #include "util/point-2d.h"
62 #include "view/display-map.h"
63 #include "view/display-messages.h"
64 #include "window/main-window-util.h"
65 #include "world/world.h"
66 #include <queue>
67
68 #define MONSTER_FLOW_DEPTH \
69     32 /*!< 敵のプレイヤーに対する移動道のりの最大値(この値以上は処理を打ち切る) / OPTION: Maximum flow depth when using "MONSTER_FLOW" */
70
71 /*!
72  * @brief 新規フロアに入りたてのプレイヤーをランダムな場所に配置する / Returns random co-ordinates for player/monster/object
73  * @param player_ptr プレイヤーへの参照ポインタ
74  * @return 配置に成功したらTRUEを返す
75  */
76 bool new_player_spot(PlayerType *player_ptr)
77 {
78     POSITION y = 0, x = 0;
79     int max_attempts = 10000;
80
81     grid_type *g_ptr;
82     feature_type *f_ptr;
83
84     while (max_attempts--) {
85         /* Pick a legal spot */
86         y = (POSITION)rand_range(1, player_ptr->current_floor_ptr->height - 2);
87         x = (POSITION)rand_range(1, player_ptr->current_floor_ptr->width - 2);
88
89         g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
90
91         /* Must be a "naked" floor grid */
92         if (g_ptr->m_idx) {
93             continue;
94         }
95         if (is_in_dungeon(player_ptr)) {
96             f_ptr = &f_info[g_ptr->feat];
97
98             if (max_attempts > 5000) /* Rule 1 */
99             {
100                 if (f_ptr->flags.has_not(FloorFeatureType::FLOOR)) {
101                     continue;
102                 }
103             } else /* Rule 2 */
104             {
105                 if (f_ptr->flags.has_not(FloorFeatureType::MOVE)) {
106                     continue;
107                 }
108                 if (f_ptr->flags.has(FloorFeatureType::HIT_TRAP)) {
109                     continue;
110                 }
111             }
112
113             /* Refuse to start on anti-teleport grids in dungeon */
114             if (f_ptr->flags.has_not(FloorFeatureType::TELEPORTABLE)) {
115                 continue;
116             }
117         }
118         if (!player_can_enter(player_ptr, g_ptr->feat, 0)) {
119             continue;
120         }
121         if (!in_bounds(player_ptr->current_floor_ptr, y, x)) {
122             continue;
123         }
124
125         /* Refuse to start on anti-teleport grids */
126         if (g_ptr->is_icky()) {
127             continue;
128         }
129
130         break;
131     }
132
133     if (max_attempts < 1) { /* Should be -1, actually if we failed... */
134         return false;
135     }
136
137     /* Save the new player grid */
138     player_ptr->y = y;
139     player_ptr->x = x;
140
141     return true;
142 }
143
144 /*!
145  * @brief マスに隠されたドアがあるかの判定を行う。 / Return TRUE if the given grid is a hidden closed door
146  * @param player_ptr プレイヤーへの参照ポインタ
147  * @param g_ptr マス構造体の参照ポインタ
148  * @return 隠されたドアがあるならTRUEを返す。
149  */
150 bool is_hidden_door(PlayerType *player_ptr, grid_type *g_ptr)
151 {
152     if ((g_ptr->mimic || g_ptr->cave_has_flag(FloorFeatureType::SECRET)) && is_closed_door(player_ptr, g_ptr->feat)) {
153         return true;
154     } else {
155         return false;
156     }
157 }
158
159 /*!
160  * @brief 指定された座標のマスが現在照らされているかを返す。 / Check for "local" illumination
161  * @param y y座標
162  * @param x x座標
163  * @return 指定された座標に照明がかかっているならTRUEを返す。。
164  */
165 bool check_local_illumination(PlayerType *player_ptr, POSITION y, POSITION x)
166 {
167     /* Hack -- move towards player */
168     POSITION yy = (y < player_ptr->y) ? (y + 1) : (y > player_ptr->y) ? (y - 1)
169                                                                       : y;
170     POSITION xx = (x < player_ptr->x) ? (x + 1) : (x > player_ptr->x) ? (x - 1)
171                                                                       : x;
172
173     /* Check for "local" illumination */
174
175     /* Check for "complex" illumination */
176     auto *floor_ptr = player_ptr->current_floor_ptr;
177     if ((feat_supports_los(floor_ptr->grid_array[yy][xx].get_feat_mimic()) && (floor_ptr->grid_array[yy][xx].info & CAVE_GLOW)) || (feat_supports_los(floor_ptr->grid_array[y][xx].get_feat_mimic()) && (floor_ptr->grid_array[y][xx].info & CAVE_GLOW)) || (feat_supports_los(floor_ptr->grid_array[yy][x].get_feat_mimic()) && (floor_ptr->grid_array[yy][x].info & CAVE_GLOW))) {
178         return true;
179     } else {
180         return false;
181     }
182 }
183
184 /*! 対象座標のマスの照明状態を更新する際の補助処理マクロ */
185 #define update_local_illumination_aux(C, Y, X)                                                  \
186     {                                                                                           \
187         if (player_has_los_bold((C), (Y), (X))) {                                               \
188             /* Update the monster */                                                            \
189             if ((C)->current_floor_ptr->grid_array[(Y)][(X)].m_idx)                             \
190                 update_monster((C), (C)->current_floor_ptr->grid_array[(Y)][(X)].m_idx, false); \
191                                                                                                 \
192             /* Notice and redraw */                                                             \
193             note_spot((C), (Y), (X));                                                           \
194             lite_spot((C), (Y), (X));                                                           \
195         }                                                                                       \
196     }
197
198 /*!
199  * @brief 指定された座標の照明状態を更新する / Update "local" illumination
200  * @param player_ptr プレイヤーへの参照ポインタ
201  * @param y 視界先y座標
202  * @param x 視界先x座標
203  */
204 void update_local_illumination(PlayerType *player_ptr, POSITION y, POSITION x)
205 {
206     int i;
207     POSITION yy, xx;
208
209     if (!in_bounds(player_ptr->current_floor_ptr, y, x)) {
210         return;
211     }
212
213     if ((y != player_ptr->y) && (x != player_ptr->x)) {
214         yy = (y < player_ptr->y) ? (y - 1) : (y + 1);
215         xx = (x < player_ptr->x) ? (x - 1) : (x + 1);
216         update_local_illumination_aux(player_ptr, yy, xx);
217         update_local_illumination_aux(player_ptr, y, xx);
218         update_local_illumination_aux(player_ptr, yy, x);
219     } else if (x != player_ptr->x) /* y == player_ptr->y */
220     {
221         xx = (x < player_ptr->x) ? (x - 1) : (x + 1);
222         for (i = -1; i <= 1; i++) {
223             yy = y + i;
224             update_local_illumination_aux(player_ptr, yy, xx);
225         }
226         yy = y - 1;
227         update_local_illumination_aux(player_ptr, yy, x);
228         yy = y + 1;
229         update_local_illumination_aux(player_ptr, yy, x);
230     } else if (y != player_ptr->y) /* x == player_ptr->x */
231     {
232         yy = (y < player_ptr->y) ? (y - 1) : (y + 1);
233         for (i = -1; i <= 1; i++) {
234             xx = x + i;
235             update_local_illumination_aux(player_ptr, yy, xx);
236         }
237         xx = x - 1;
238         update_local_illumination_aux(player_ptr, y, xx);
239         xx = x + 1;
240         update_local_illumination_aux(player_ptr, y, xx);
241     } else /* Player's grid */
242     {
243         for (i = 0; i < 8; i++) {
244             yy = y + ddy_cdd[i];
245             xx = x + ddx_cdd[i];
246             update_local_illumination_aux(player_ptr, yy, xx);
247         }
248     }
249 }
250
251 /*!
252  * @brief 指定された座標をプレイヤー収められていない状態かどうか / Returns true if the player's grid is dark
253  * @return 視覚に収められていないならTRUEを返す
254  * @details player_can_see_bold()関数の返り値の否定を返している。
255  */
256 bool no_lite(PlayerType *player_ptr)
257 {
258     return !player_can_see_bold(player_ptr, player_ptr->y, player_ptr->x);
259 }
260
261 /*
262  * Place an attr/char pair at the given map coordinate, if legal.
263  */
264 void print_rel(PlayerType *player_ptr, char c, TERM_COLOR a, POSITION y, POSITION x)
265 {
266     /* Only do "legal" locations */
267     if (panel_contains(y, x)) {
268         /* Hack -- fake monochrome */
269         if (!use_graphics) {
270             if (w_ptr->timewalk_m_idx) {
271                 a = TERM_DARK;
272             } else if (is_invuln(player_ptr) || player_ptr->timewalk) {
273                 a = TERM_WHITE;
274             } else if (player_ptr->wraith_form) {
275                 a = TERM_L_DARK;
276             }
277         }
278
279         /* Draw the char using the attr */
280         term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, 0, 0);
281     }
282 }
283
284 void print_bolt_pict(PlayerType *player_ptr, POSITION y, POSITION x, POSITION ny, POSITION nx, AttributeType typ)
285 {
286     const auto [a, c] = bolt_pict(y, x, ny, nx, typ);
287     print_rel(player_ptr, c, a, ny, nx);
288 }
289
290 /*!
291  * Memorize interesting viewable object/features in the given grid
292  *
293  * This function should only be called on "legal" grids.
294  *
295  * This function will memorize the object and/or feature in the given
296  * grid, if they are (1) viewable and (2) interesting.  Note that all
297  * objects are interesting, all terrain features except floors (and
298  * invisible traps) are interesting, and floors (and invisible traps)
299  * are interesting sometimes (depending on various options involving
300  * the illumination of floor grids).
301  *
302  * The automatic memorization of all objects and non-floor terrain
303  * features as soon as they are displayed allows incredible amounts
304  * of optimization in various places, especially "map_info()".
305  *
306  * Note that the memorization of objects is completely separate from
307  * the memorization of terrain features, preventing annoying floor
308  * memorization when a detected object is picked up from a dark floor,
309  * and object memorization when an object is dropped into a floor grid
310  * which is memorized but out-of-sight.
311  *
312  * This function should be called every time the "memorization" of
313  * a grid (or the object in a grid) is called into question, such
314  * as when an object is created in a grid, when a terrain feature
315  * "changes" from "floor" to "non-floor", when any grid becomes
316  * "illuminated" or "viewable", and when a "floor" grid becomes
317  * "torch-lit".
318  *
319  * Note the relatively efficient use of this function by the various
320  * "update_view()" and "update_lite()" calls, to allow objects and
321  * terrain features to be memorized (and drawn) whenever they become
322  * viewable or illuminated in any way, but not when they "maintain"
323  * or "lose" their previous viewability or illumination.
324  *
325  * Note the butchered "internal" version of "player_can_see_bold()",
326  * optimized primarily for the most common cases, that is, for the
327  * non-marked floor grids.
328  */
329 void note_spot(PlayerType *player_ptr, POSITION y, POSITION x)
330 {
331     auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
332
333     /* Blind players see nothing */
334     if (player_ptr->effects()->blindness()->is_blind()) {
335         return;
336     }
337
338     /* Analyze non-torch-lit grids */
339     if (!(g_ptr->info & (CAVE_LITE | CAVE_MNLT))) {
340         /* Require line of sight to the grid */
341         if (!(g_ptr->info & (CAVE_VIEW))) {
342             return;
343         }
344
345         /* Require "perma-lite" of the grid */
346         if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW) {
347             /* Not Ninja */
348             if (!player_ptr->see_nocto) {
349                 return;
350             }
351         }
352     }
353
354     /* Hack -- memorize objects */
355     for (const auto this_o_idx : g_ptr->o_idx_list) {
356         auto *o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx];
357
358         /* Memorize objects */
359         o_ptr->marked |= OM_FOUND;
360     }
361
362     /* Hack -- memorize grids */
363     if (!g_ptr->is_mark()) {
364         /* Feature code (applying "mimic" field) */
365         auto *f_ptr = &f_info[g_ptr->get_feat_mimic()];
366
367         /* Memorize some "boring" grids */
368         if (f_ptr->flags.has_not(FloorFeatureType::REMEMBER)) {
369             /* Option -- memorize all torch-lit floors */
370             if (view_torch_grids && ((g_ptr->info & (CAVE_LITE | CAVE_MNLT)) || player_ptr->see_nocto)) {
371                 g_ptr->info |= (CAVE_MARK);
372             }
373
374             /* Option -- memorize all perma-lit floors */
375             else if (view_perma_grids && ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)) {
376                 g_ptr->info |= (CAVE_MARK);
377             }
378         }
379
380         /* Memorize normal grids */
381         else if (f_ptr->flags.has(FloorFeatureType::LOS)) {
382             g_ptr->info |= (CAVE_MARK);
383         }
384
385         /* Memorize torch-lit walls */
386         else if (g_ptr->info & (CAVE_LITE | CAVE_MNLT)) {
387             g_ptr->info |= (CAVE_MARK);
388         }
389
390         /* Memorize walls seen by noctovision of Ninja */
391         else if (player_ptr->see_nocto) {
392             g_ptr->info |= (CAVE_MARK);
393         }
394
395         /* Memorize certain non-torch-lit wall grids */
396         else if (check_local_illumination(player_ptr, y, x)) {
397             g_ptr->info |= (CAVE_MARK);
398         }
399     }
400
401     /* Memorize terrain of the grid */
402     g_ptr->info |= (CAVE_KNOWN);
403 }
404
405 /*
406  * Redraw (on the screen) a given MAP location
407  *
408  * This function should only be called on "legal" grids
409  */
410 void lite_spot(PlayerType *player_ptr, POSITION y, POSITION x)
411 {
412     /* Redraw if on screen */
413     if (panel_contains(y, x) && in_bounds2(player_ptr->current_floor_ptr, y, x)) {
414         TERM_COLOR a;
415         char c;
416         TERM_COLOR ta;
417         char tc;
418
419         map_info(player_ptr, y, x, &a, &c, &ta, &tc);
420
421         /* Hack -- fake monochrome */
422         if (!use_graphics) {
423             if (w_ptr->timewalk_m_idx) {
424                 a = TERM_DARK;
425             } else if (is_invuln(player_ptr) || player_ptr->timewalk) {
426                 a = TERM_WHITE;
427             } else if (player_ptr->wraith_form) {
428                 a = TERM_L_DARK;
429             }
430         }
431
432         /* Hack -- Queue it */
433         term_queue_bigchar(panel_col_of(x), y - panel_row_prt, a, c, ta, tc);
434
435         /* Update sub-windows */
436         player_ptr->window_flags |= (PW_OVERHEAD | PW_DUNGEON);
437     }
438 }
439
440 /*
441  * Some comments on the grid flags.  -BEN-
442  *
443  *
444  * One of the major bottlenecks in previous versions of Angband was in
445  * the calculation of "line of sight" from the player to various grids,
446  * such as monsters.  This was such a nasty bottleneck that a lot of
447  * silly things were done to reduce the dependancy on "line of sight",
448  * for example, you could not "see" any grids in a lit room until you
449  * actually entered the room, and there were all kinds of bizarre grid
450  * flags to enable this behavior.  This is also why the "call light"
451  * spells always lit an entire room.
452  *
453  * The code below provides functions to calculate the "field of view"
454  * for the player, which, once calculated, provides extremely fast
455  * calculation of "line of sight from the player", and to calculate
456  * the "field of torch lite", which, again, once calculated, provides
457  * extremely fast calculation of "which grids are lit by the player's
458  * lite source".  In addition to marking grids as "GRID_VIEW" and/or
459  * "GRID_LITE", as appropriate, these functions maintain an array for
460  * each of these two flags, each array containing the locations of all
461  * of the grids marked with the appropriate flag, which can be used to
462  * very quickly scan through all of the grids in a given set.
463  *
464  * To allow more "semantically valid" field of view semantics, whenever
465  * the field of view (or the set of torch lit grids) changes, all of the
466  * grids in the field of view (or the set of torch lit grids) are "drawn"
467  * so that changes in the world will become apparent as soon as possible.
468  * This has been optimized so that only grids which actually "change" are
469  * redrawn, using the "temp" array and the "GRID_TEMP" flag to keep track
470  * of the grids which are entering or leaving the relevent set of grids.
471  *
472  * These new methods are so efficient that the old nasty code was removed.
473  *
474  * Note that there is no reason to "update" the "viewable space" unless
475  * the player "moves", or walls/doors are created/destroyed, and there
476  * is no reason to "update" the "torch lit grids" unless the field of
477  * view changes, or the "light radius" changes.  This means that when
478  * the player is resting, or digging, or doing anything that does not
479  * involve movement or changing the state of the dungeon, there is no
480  * need to update the "view" or the "lite" regions, which is nice.
481  *
482  * Note that the calls to the nasty "los()" function have been reduced
483  * to a bare minimum by the use of the new "field of view" calculations.
484  *
485  * I wouldn't be surprised if slight modifications to the "update_view()"
486  * function would allow us to determine "reverse line-of-sight" as well
487  * as "normal line-of-sight", which would allow monsters to use a more
488  * "correct" calculation to determine if they can "see" the player.  For
489  * now, monsters simply "cheat" somewhat and assume that if the player
490  * has "line of sight" to the monster, then the monster can "pretend"
491  * that it has "line of sight" to the player.
492  *
493  *
494  * The "update_lite()" function maintains the "CAVE_LITE" flag for each
495  * grid and maintains an array of all "CAVE_LITE" grids.
496  *
497  * This set of grids is the complete set of all grids which are lit by
498  * the players light source, which allows the "player_can_see_bold()"
499  * function to work very quickly.
500  *
501  * Note that every "CAVE_LITE" grid is also a "CAVE_VIEW" grid, and in
502  * fact, the player (unless blind) can always "see" all grids which are
503  * marked as "CAVE_LITE", unless they are "off screen".
504  *
505  *
506  * The "update_view()" function maintains the "CAVE_VIEW" flag for each
507  * grid and maintains an array of all "CAVE_VIEW" grids.
508  *
509  * This set of grids is the complete set of all grids within line of sight
510  * of the player, allowing the "player_has_los_bold()" macro to work very
511  * quickly.
512  *
513  *
514  * The current "update_view()" algorithm uses the "CAVE_XTRA" flag as a
515  * temporary internal flag to mark those grids which are not only in view,
516  * but which are also "easily" in line of sight of the player.  This flag
517  * is always cleared when we are done.
518  *
519  *
520  * The current "update_lite()" and "update_view()" algorithms use the
521  * "CAVE_TEMP" flag, and the array of grids which are marked as "CAVE_TEMP",
522  * to keep track of which grids were previously marked as "CAVE_LITE" or
523  * "CAVE_VIEW", which allows us to optimize the "screen updates".
524  *
525  * The "CAVE_TEMP" flag, and the array of "CAVE_TEMP" grids, is also used
526  * for various other purposes, such as spreading lite or darkness during
527  * "lite_room()" / "unlite_room()", and for calculating monster flow.
528  *
529  *
530  * Any grid can be marked as "CAVE_GLOW" which means that the grid itself is
531  * in some way permanently lit.  However, for the player to "see" anything
532  * in the grid, as determined by "player_can_see()", the player must not be
533  * blind, the grid must be marked as "CAVE_VIEW", and, in addition, "wall"
534  * grids, even if marked as "perma lit", are only illuminated if they touch
535  * a grid which is not a wall and is marked both "CAVE_GLOW" and "CAVE_VIEW".
536  *
537  *
538  * To simplify various things, a grid may be marked as "CAVE_MARK", meaning
539  * that even if the player cannot "see" the grid, he "knows" the terrain in
540  * that grid.  This is used to "remember" walls/doors/stairs/floors when they
541  * are "seen" or "detected", and also to "memorize" floors, after "wiz_lite()",
542  * or when one of the "memorize floor grids" options induces memorization.
543  *
544  * Objects are "memorized" in a different way, using a special "marked" flag
545  * on the object itself, which is set when an object is observed or detected.
546  *
547  *
548  * A grid may be marked as "CAVE_ROOM" which means that it is part of a "room",
549  * and should be illuminated by "lite room" and "darkness" spells.
550  *
551  *
552  * A grid may be marked as "CAVE_ICKY" which means it is part of a "vault",
553  * and should be unavailable for "teleportation" destinations.
554  *
555  *
556  * The "view_perma_grids" allows the player to "memorize" every perma-lit grid
557  * which is observed, and the "view_torch_grids" allows the player to memorize
558  * every torch-lit grid.  The player will always memorize important walls,
559  * doors, stairs, and other terrain features, as well as any "detected" grids.
560  *
561  * Note that the new "update_view()" method allows, among other things, a room
562  * to be "partially" seen as the player approaches it, with a growing cone of
563  * floor appearing as the player gets closer to the door.  Also, by not turning
564  * on the "memorize perma-lit grids" option, the player will only "see" those
565  * floor grids which are actually in line of sight.
566  *
567  * And my favorite "plus" is that you can now use a special option to draw the
568  * "floors" in the "viewable region" brightly (actually, to draw the *other*
569  * grids dimly), providing a "pretty" effect as the player runs around, and
570  * to efficiently display the "torch lite" in a special color.
571  *
572  *
573  * Some comments on the "update_view()" algorithm...
574  *
575  * The algorithm is very fast, since it spreads "obvious" grids very quickly,
576  * and only has to call "los()" on the borderline cases.  The major axes/diags
577  * even terminate early when they hit walls.  I need to find a quick way
578  * to "terminate" the other scans.
579  *
580  * Note that in the worst case (a big empty area with say 5% scattered walls),
581  * each of the 1500 or so nearby grids is checked once, most of them getting
582  * an "instant" rating, and only a small portion requiring a call to "los()".
583  *
584  * The only time that the algorithm appears to be "noticeably" too slow is
585  * when running, and this is usually only important in town, since the town
586  * provides about the worst scenario possible, with large open regions and
587  * a few scattered obstructions.  There is a special "efficiency" option to
588  * allow the player to reduce his field of view in town, if needed.
589  *
590  * In the "best" case (say, a normal stretch of corridor), the algorithm
591  * makes one check for each viewable grid, and makes no calls to "los()".
592  * So running in corridors is very fast, and if a lot of monsters are
593  * nearby, it is much faster than the old methods.
594  *
595  * Note that resting, most normal commands, and several forms of running,
596  * plus all commands executed near large groups of monsters, are strictly
597  * more efficient with "update_view()" that with the old "compute los() on
598  * demand" method, primarily because once the "field of view" has been
599  * calculated, it does not have to be recalculated until the player moves
600  * (or a wall or door is created or destroyed).
601  *
602  * Note that we no longer have to do as many "los()" checks, since once the
603  * "view" region has been built, very few things cause it to be "changed"
604  * (player movement, and the opening/closing of doors, changes in wall status).
605  * Note that door/wall changes are only relevant when the door/wall itself is
606  * in the "view" region.
607  *
608  * The algorithm seems to only call "los()" from zero to ten times, usually
609  * only when coming down a corridor into a room, or standing in a room, just
610  * misaligned with a corridor.  So if, say, there are five "nearby" monsters,
611  * we will be reducing the calls to "los()".
612  *
613  * I am thinking in terms of an algorithm that "walks" from the central point
614  * out to the maximal "distance", at each point, determining the "view" code
615  * (above).  For each grid not on a major axis or diagonal, the "view" code
616  * depends on the "cave_los_bold()" and "view" of exactly two other grids
617  * (the one along the nearest diagonal, and the one next to that one, see
618  * "update_view_aux()"...).
619  *
620  * We "memorize" the viewable space array, so that at the cost of under 3000
621  * bytes, we reduce the time taken by "forget_view()" to one assignment for
622  * each grid actually in the "viewable space".  And for another 3000 bytes,
623  * we prevent "erase + redraw" ineffiencies via the "seen" set.  These bytes
624  * are also used by other routines, thus reducing the cost to almost nothing.
625  *
626  * A similar thing is done for "forget_lite()" in which case the savings are
627  * much less, but save us from doing bizarre maintenance checking.
628  *
629  * In the worst "normal" case (in the middle of the town), the reachable space
630  * actually reaches to more than half of the largest possible "circle" of view,
631  * or about 800 grids, and in the worse case (in the middle of a dungeon level
632  * where all the walls have been removed), the reachable space actually reaches
633  * the theoretical maximum size of just under 1500 grids.
634  *
635  * Each grid G examines the "state" of two (?) other (adjacent) grids, G1 & G2.
636  * If G1 is lite, G is lite.  Else if G2 is lite, G is half.  Else if G1 and G2
637  * are both half, G is half.  Else G is dark.  It only takes 2 (or 4) bits to
638  * "name" a grid, so (for MAX_RAD of 20) we could use 1600 bytes, and scan the
639  * entire possible space (including initialization) in one step per grid.  If
640  * we do the "clearing" as a separate step (and use an array of "view" grids),
641  * then the clearing will take as many steps as grids that were viewed, and the
642  * algorithm will be able to "stop" scanning at various points.
643  * Oh, and outside of the "torch radius", only "lite" grids need to be scanned.
644  */
645
646 /*
647  * Hack - speed up the update_flow algorithm by only doing
648  * it everytime the player moves out of LOS of the last
649  * "way-point".
650  */
651 static POSITION flow_x = 0;
652 static POSITION flow_y = 0;
653
654 /*
655  * Hack -- fill in the "cost" field of every grid that the player
656  * can "reach" with the number of steps needed to reach that grid.
657  * This also yields the "distance" of the player from every grid.
658  *
659  * In addition, mark the "when" of the grids that can reach
660  * the player with the incremented value of "flow_n".
661  *
662  * Hack -- use the "seen" array as a "circular queue".
663  *
664  * We do not need a priority queue because the cost from grid
665  * to grid is always "one" and we process them in order.
666  */
667 void update_flow(PlayerType *player_ptr)
668 {
669     POSITION x, y;
670     DIRECTION d;
671     floor_type *f_ptr = player_ptr->current_floor_ptr;
672
673     /* The last way-point is on the map */
674     if (player_ptr->running && in_bounds(f_ptr, flow_y, flow_x)) {
675         /* The way point is in sight - do not update.  (Speedup) */
676         if (f_ptr->grid_array[flow_y][flow_x].info & CAVE_VIEW) {
677             return;
678         }
679     }
680
681     /* Erase all of the current flow information */
682     for (y = 0; y < f_ptr->height; y++) {
683         for (x = 0; x < f_ptr->width; x++) {
684             memset(&f_ptr->grid_array[y][x].costs, 0, sizeof(f_ptr->grid_array[y][x].costs));
685             memset(&f_ptr->grid_array[y][x].dists, 0, sizeof(f_ptr->grid_array[y][x].dists));
686         }
687     }
688
689     /* Save player position */
690     flow_y = player_ptr->y;
691     flow_x = player_ptr->x;
692
693     for (int i = 0; i < FLOW_MAX; i++) {
694         // 幅優先探索用のキュー。
695         std::queue<Pos2D> que;
696         que.emplace(player_ptr->y, player_ptr->x);
697
698         /* Now process the queue */
699         while (!que.empty()) {
700             /* Extract the next entry */
701             const auto [ty, tx] = que.front();
702             que.pop();
703
704             /* Add the "children" */
705             for (d = 0; d < 8; d++) {
706                 byte m = player_ptr->current_floor_ptr->grid_array[ty][tx].costs[i] + 1;
707                 byte n = player_ptr->current_floor_ptr->grid_array[ty][tx].dists[i] + 1;
708
709                 /* Child location */
710                 y = ty + ddy_ddd[d];
711                 x = tx + ddx_ddd[d];
712
713                 /* Ignore player's grid */
714                 if (player_bold(player_ptr, y, x)) {
715                     continue;
716                 }
717
718                 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
719
720                 if (is_closed_door(player_ptr, g_ptr->feat)) {
721                     m += 3;
722                 }
723
724                 /* Ignore "pre-stamped" entries */
725                 if (g_ptr->dists[i] != 0 && g_ptr->dists[i] <= n && g_ptr->costs[i] <= m) {
726                     continue;
727                 }
728
729                 /* Ignore "walls", "holes" and "rubble" */
730                 bool can_move = false;
731                 switch (i) {
732                 case FLOW_CAN_FLY:
733                     can_move = g_ptr->cave_has_flag(FloorFeatureType::MOVE) || g_ptr->cave_has_flag(FloorFeatureType::CAN_FLY);
734                     break;
735                 default:
736                     can_move = g_ptr->cave_has_flag(FloorFeatureType::MOVE);
737                     break;
738                 }
739
740                 if (!can_move && !is_closed_door(player_ptr, g_ptr->feat)) {
741                     continue;
742                 }
743
744                 /* Save the flow cost */
745                 if (g_ptr->costs[i] == 0 || g_ptr->costs[i] > m) {
746                     g_ptr->costs[i] = m;
747                 }
748                 if (g_ptr->dists[i] == 0 || g_ptr->dists[i] > n) {
749                     g_ptr->dists[i] = n;
750                 }
751
752                 /* Hack -- limit flow depth */
753                 if (n == MONSTER_FLOW_DEPTH) {
754                     continue;
755                 }
756
757                 /* Enqueue that entry */
758                 que.emplace(y, x);
759             }
760         }
761     }
762 }
763
764 /*
765  * Take a feature, determine what that feature becomes
766  * through applying the given action.
767  */
768 FEAT_IDX feat_state(floor_type *floor_ptr, FEAT_IDX feat, FloorFeatureType action)
769 {
770     auto *f_ptr = &f_info[feat];
771     int i;
772
773     /* Get the new feature */
774     for (i = 0; i < MAX_FEAT_STATES; i++) {
775         if (f_ptr->state[i].action == action) {
776             return conv_dungeon_feat(floor_ptr, f_ptr->state[i].result);
777         }
778     }
779
780     if (f_ptr->flags.has(FloorFeatureType::PERMANENT)) {
781         return feat;
782     }
783
784     return (feature_action_flags[enum2i(action)] & FAF_DESTROY) ? conv_dungeon_feat(floor_ptr, f_ptr->destroyed) : feat;
785 }
786
787 /*
788  * Takes a location and action and changes the feature at that
789  * location through applying the given action.
790  */
791 void cave_alter_feat(PlayerType *player_ptr, POSITION y, POSITION x, FloorFeatureType action)
792 {
793     /* Set old feature */
794     auto *floor_ptr = player_ptr->current_floor_ptr;
795     FEAT_IDX oldfeat = floor_ptr->grid_array[y][x].feat;
796
797     /* Get the new feat */
798     FEAT_IDX newfeat = feat_state(player_ptr->current_floor_ptr, oldfeat, action);
799
800     /* No change */
801     if (newfeat == oldfeat) {
802         return;
803     }
804
805     /* Set the new feature */
806     cave_set_feat(player_ptr, y, x, newfeat);
807
808     if (!(feature_action_flags[enum2i(action)] & FAF_NO_DROP)) {
809         feature_type *old_f_ptr = &f_info[oldfeat];
810         auto *f_ptr = &f_info[newfeat];
811         bool found = false;
812
813         /* Handle gold */
814         if (old_f_ptr->flags.has(FloorFeatureType::HAS_GOLD) && f_ptr->flags.has_not(FloorFeatureType::HAS_GOLD)) {
815             /* Place some gold */
816             place_gold(player_ptr, y, x);
817             found = true;
818         }
819
820         /* Handle item */
821         if (old_f_ptr->flags.has(FloorFeatureType::HAS_ITEM) && f_ptr->flags.has_not(FloorFeatureType::HAS_ITEM) && (randint0(100) < (15 - floor_ptr->dun_level / 2))) {
822             /* Place object */
823             place_object(player_ptr, y, x, 0L);
824             found = true;
825         }
826
827         if (found && w_ptr->character_dungeon && player_can_see_bold(player_ptr, y, x)) {
828             msg_print(_("何かを発見した!", "You have found something!"));
829         }
830     }
831
832     if (feature_action_flags[enum2i(action)] & FAF_CRASH_GLASS) {
833         feature_type *old_f_ptr = &f_info[oldfeat];
834
835         if (old_f_ptr->flags.has(FloorFeatureType::GLASS) && w_ptr->character_dungeon) {
836             project(player_ptr, PROJECT_WHO_GLASS_SHARDS, 1, y, x, std::min(floor_ptr->dun_level, 100) / 4, AttributeType::SHARDS,
837                 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_HIDE | PROJECT_JUMP | PROJECT_NO_HANGEKI));
838         }
839     }
840 }
841
842 /*!
843  * @brief 指定されたマスがモンスターのテレポート可能先かどうかを判定する。
844  * @param player_ptr プレイヤーへの参照ポインタ
845  * @param m_idx モンスターID
846  * @param y 移動先Y座標
847  * @param x 移動先X座標
848  * @param mode オプション
849  * @return テレポート先として妥当ならばtrue
850  */
851 bool cave_monster_teleportable_bold(PlayerType *player_ptr, MONSTER_IDX m_idx, POSITION y, POSITION x, teleport_flags mode)
852 {
853     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
854     auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
855     auto *f_ptr = &f_info[g_ptr->feat];
856
857     /* Require "teleportable" space */
858     if (f_ptr->flags.has_not(FloorFeatureType::TELEPORTABLE)) {
859         return false;
860     }
861
862     if (g_ptr->m_idx && (g_ptr->m_idx != m_idx)) {
863         return false;
864     }
865     if (player_bold(player_ptr, y, x)) {
866         return false;
867     }
868
869     /* Hack -- no teleport onto rune of protection */
870     if (g_ptr->is_rune_protection()) {
871         return false;
872     }
873     if (g_ptr->is_rune_explosion()) {
874         return false;
875     }
876
877     if (!(mode & TELEPORT_PASSIVE)) {
878         if (!monster_can_cross_terrain(player_ptr, g_ptr->feat, &r_info[m_ptr->r_idx], 0)) {
879             return false;
880         }
881     }
882
883     return true;
884 }
885
886 /*!
887  * @brief 指定されたマスにプレイヤーがテレポート可能かどうかを判定する。
888  * @param player_ptr プレイヤーへの参照ポインタ
889  * @param y 移動先Y座標
890  * @param x 移動先X座標
891  * @param mode オプション
892  * @return テレポート先として妥当ならばtrue
893  */
894 bool cave_player_teleportable_bold(PlayerType *player_ptr, POSITION y, POSITION x, teleport_flags mode)
895 {
896     auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
897     auto *f_ptr = &f_info[g_ptr->feat];
898
899     /* Require "teleportable" space */
900     if (f_ptr->flags.has_not(FloorFeatureType::TELEPORTABLE)) {
901         return false;
902     }
903
904     /* No magical teleporting into vaults and such */
905     if (!(mode & TELEPORT_NONMAGICAL) && g_ptr->is_icky()) {
906         return false;
907     }
908
909     if (g_ptr->m_idx && (g_ptr->m_idx != player_ptr->riding)) {
910         return false;
911     }
912
913     /* don't teleport on a trap. */
914     if (f_ptr->flags.has(FloorFeatureType::HIT_TRAP)) {
915         return false;
916     }
917
918     if (!(mode & TELEPORT_PASSIVE)) {
919         if (!player_can_enter(player_ptr, g_ptr->feat, 0)) {
920             return false;
921         }
922
923         if (f_ptr->flags.has_all_of({ FloorFeatureType::WATER, FloorFeatureType::DEEP })) {
924             if (!player_ptr->levitation && !player_ptr->can_swim) {
925                 return false;
926             }
927         }
928
929         if (f_ptr->flags.has(FloorFeatureType::LAVA) && !has_immune_fire(player_ptr) && !is_invuln(player_ptr)) {
930             /* Always forbid deep lava */
931             if (f_ptr->flags.has(FloorFeatureType::DEEP)) {
932                 return false;
933             }
934
935             /* Forbid shallow lava when the player don't have levitation */
936             if (!player_ptr->levitation) {
937                 return false;
938             }
939         }
940     }
941
942     return true;
943 }
944
945 /*!
946  * @brief 地形は開くものであって、かつ開かれているかを返す /
947  * Attempt to open the given chest at the given location
948  * @param feat 地形ID
949  * @return 開いた地形である場合TRUEを返す /  Return TRUE if the given feature is an open door
950  */
951 bool is_open(PlayerType *player_ptr, FEAT_IDX feat)
952 {
953     return f_info[feat].flags.has(FloorFeatureType::CLOSE) && (feat != feat_state(player_ptr->current_floor_ptr, feat, FloorFeatureType::CLOSE));
954 }
955
956 /*!
957  * @brief プレイヤーが地形踏破可能かを返す
958  * @param feature 判定したい地形ID
959  * @param mode 移動に関するオプションフラグ
960  * @return 移動可能ならばTRUEを返す
961  */
962 bool player_can_enter(PlayerType *player_ptr, FEAT_IDX feature, BIT_FLAGS16 mode)
963 {
964     auto *f_ptr = &f_info[feature];
965
966     if (player_ptr->riding) {
967         return monster_can_cross_terrain(
968             player_ptr, feature, &r_info[player_ptr->current_floor_ptr->m_list[player_ptr->riding].r_idx], mode | CEM_RIDING);
969     }
970
971     if (f_ptr->flags.has(FloorFeatureType::PATTERN)) {
972         if (!(mode & CEM_P_CAN_ENTER_PATTERN)) {
973             return false;
974         }
975     }
976
977     if (f_ptr->flags.has(FloorFeatureType::CAN_FLY) && player_ptr->levitation) {
978         return true;
979     }
980     if (f_ptr->flags.has(FloorFeatureType::CAN_SWIM) && player_ptr->can_swim) {
981         return true;
982     }
983     if (f_ptr->flags.has(FloorFeatureType::CAN_PASS) && has_pass_wall(player_ptr)) {
984         return true;
985     }
986
987     if (f_ptr->flags.has_not(FloorFeatureType::MOVE)) {
988         return false;
989     }
990
991     return true;
992 }
993
994 void place_grid(PlayerType *player_ptr, grid_type *g_ptr, grid_bold_type gb_type)
995 {
996     switch (gb_type) {
997     case GB_FLOOR: {
998         g_ptr->feat = feat_ground_type[randint0(100)];
999         g_ptr->info &= ~(CAVE_MASK);
1000         g_ptr->info |= CAVE_FLOOR;
1001         break;
1002     }
1003     case GB_EXTRA: {
1004         g_ptr->feat = feat_wall_type[randint0(100)];
1005         g_ptr->info &= ~(CAVE_MASK);
1006         g_ptr->info |= CAVE_EXTRA;
1007         break;
1008     }
1009     case GB_EXTRA_PERM: {
1010         g_ptr->feat = feat_permanent;
1011         g_ptr->info &= ~(CAVE_MASK);
1012         g_ptr->info |= CAVE_EXTRA;
1013         break;
1014     }
1015     case GB_INNER: {
1016         g_ptr->feat = feat_wall_inner;
1017         g_ptr->info &= ~(CAVE_MASK);
1018         g_ptr->info |= CAVE_INNER;
1019         break;
1020     }
1021     case GB_INNER_PERM: {
1022         g_ptr->feat = feat_permanent;
1023         g_ptr->info &= ~(CAVE_MASK);
1024         g_ptr->info |= CAVE_INNER;
1025         break;
1026     }
1027     case GB_OUTER: {
1028         g_ptr->feat = feat_wall_outer;
1029         g_ptr->info &= ~(CAVE_MASK);
1030         g_ptr->info |= CAVE_OUTER;
1031         break;
1032     }
1033     case GB_OUTER_NOPERM: {
1034         auto *f_ptr = &f_info[feat_wall_outer];
1035         if (permanent_wall(f_ptr)) {
1036             g_ptr->feat = (int16_t)feat_state(player_ptr->current_floor_ptr, feat_wall_outer, FloorFeatureType::UNPERM);
1037         } else {
1038             g_ptr->feat = feat_wall_outer;
1039         }
1040
1041         g_ptr->info &= ~(CAVE_MASK);
1042         g_ptr->info |= (CAVE_OUTER | CAVE_VAULT);
1043         break;
1044     }
1045     case GB_SOLID: {
1046         g_ptr->feat = feat_wall_solid;
1047         g_ptr->info &= ~(CAVE_MASK);
1048         g_ptr->info |= CAVE_SOLID;
1049         break;
1050     }
1051     case GB_SOLID_PERM: {
1052         g_ptr->feat = feat_permanent;
1053         g_ptr->info &= ~(CAVE_MASK);
1054         g_ptr->info |= CAVE_SOLID;
1055         break;
1056     }
1057     case GB_SOLID_NOPERM: {
1058         auto *f_ptr = &f_info[feat_wall_solid];
1059         if ((g_ptr->info & CAVE_VAULT) && permanent_wall(f_ptr)) {
1060             g_ptr->feat = (int16_t)feat_state(player_ptr->current_floor_ptr, feat_wall_solid, FloorFeatureType::UNPERM);
1061         } else {
1062             g_ptr->feat = feat_wall_solid;
1063         }
1064         g_ptr->info &= ~(CAVE_MASK);
1065         g_ptr->info |= CAVE_SOLID;
1066         break;
1067     }
1068     default:
1069         // 未知の値が渡されたら何もしない。
1070         return;
1071     }
1072
1073     if (g_ptr->m_idx > 0) {
1074         delete_monster_idx(player_ptr, g_ptr->m_idx);
1075     }
1076 }
1077
1078 /*!
1079  * モンスターにより照明が消されている地形か否かを判定する。 / Is this grid "darkened" by monster?
1080  * @param player_ptr プレイヤーへの参照ポインタ
1081  * @param g_ptr グリッドへの参照ポインタ
1082  * @return 照明が消されている地形ならばTRUE
1083  */
1084 bool darkened_grid(PlayerType *player_ptr, grid_type *g_ptr)
1085 {
1086     return ((g_ptr->info & (CAVE_VIEW | CAVE_LITE | CAVE_MNLT | CAVE_MNDK)) == (CAVE_VIEW | CAVE_MNDK)) && !player_ptr->see_nocto;
1087 }
1088
1089 void place_bold(PlayerType *player_ptr, POSITION y, POSITION x, grid_bold_type gb_type)
1090 {
1091     grid_type *const g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
1092     place_grid(player_ptr, g_ptr, gb_type);
1093 }
1094
1095 void set_cave_feat(floor_type *floor_ptr, POSITION y, POSITION x, FEAT_IDX feature_idx)
1096 {
1097     floor_ptr->grid_array[y][x].feat = feature_idx;
1098 }
1099
1100 /*!
1101  * @brief プレイヤーの周辺9マスに該当する地形がいくつあるかを返す /
1102  * Attempt to open the given chest at the given location
1103  * @param y 該当する地形の中から1つのY座標を返す参照ポインタ
1104  * @param x 該当する地形の中から1つのX座標を返す参照ポインタ
1105  * @param test 地形条件を判定するための関数ポインタ
1106  * @param under TRUEならばプレイヤーの直下の座標も走査対象にする
1107  * @return 該当する地形の数
1108  * @details Return the number of features around (or under) the character.
1109  * Usually look for doors and floor traps.
1110  */
1111 int count_dt(PlayerType *player_ptr, POSITION *y, POSITION *x, bool (*test)(PlayerType *, FEAT_IDX), bool under)
1112 {
1113     int count = 0;
1114     for (DIRECTION d = 0; d < 9; d++) {
1115         grid_type *g_ptr;
1116         FEAT_IDX feat;
1117         if ((d == 8) && !under) {
1118             continue;
1119         }
1120
1121         POSITION yy = player_ptr->y + ddy_ddd[d];
1122         POSITION xx = player_ptr->x + ddx_ddd[d];
1123         g_ptr = &player_ptr->current_floor_ptr->grid_array[yy][xx];
1124         if (!g_ptr->is_mark()) {
1125             continue;
1126         }
1127
1128         feat = g_ptr->get_feat_mimic();
1129         if (!((*test)(player_ptr, feat))) {
1130             continue;
1131         }
1132
1133         ++count;
1134         *y = yy;
1135         *x = xx;
1136     }
1137
1138     return count;
1139 }
1140
1141 /*!
1142  * @brief マス構造体のspecial要素を利用する地形かどうかを判定する.
1143  */
1144 bool feat_uses_special(FEAT_IDX f_idx)
1145 {
1146     return f_info[(f_idx)].flags.has(FloorFeatureType::SPECIAL);
1147 }
1148
1149 /*
1150  * This function allows us to efficiently add a grid to the "lite" array,
1151  * note that we are never called for illegal grids, or for grids which
1152  * have already been placed into the "lite" array, and we are never
1153  * called when the "lite" array is full.
1154  */
1155 void cave_lite_hack(floor_type *floor_ptr, POSITION y, POSITION x)
1156 {
1157     auto *g_ptr = &floor_ptr->grid_array[y][x];
1158     if (g_ptr->is_lite()) {
1159         return;
1160     }
1161
1162     g_ptr->info |= CAVE_LITE;
1163     floor_ptr->lite_y[floor_ptr->lite_n] = y;
1164     floor_ptr->lite_x[floor_ptr->lite_n++] = x;
1165 }
1166
1167 /*
1168  * For delayed visual update
1169  */
1170 void cave_redraw_later(floor_type *floor_ptr, POSITION y, POSITION x)
1171 {
1172     auto *g_ptr = &floor_ptr->grid_array[y][x];
1173     if (g_ptr->is_redraw()) {
1174         return;
1175     }
1176
1177     g_ptr->info |= CAVE_REDRAW;
1178     floor_ptr->redraw_y[floor_ptr->redraw_n] = y;
1179     floor_ptr->redraw_x[floor_ptr->redraw_n++] = x;
1180 }
1181
1182 /*
1183  * For delayed visual update
1184  */
1185 void cave_note_and_redraw_later(floor_type *floor_ptr, POSITION y, POSITION x)
1186 {
1187     floor_ptr->grid_array[y][x].info |= CAVE_NOTE;
1188     cave_redraw_later(floor_ptr, y, x);
1189 }
1190
1191 void cave_view_hack(floor_type *floor_ptr, POSITION y, POSITION x)
1192 {
1193     auto *g_ptr = &floor_ptr->grid_array[y][x];
1194     if (g_ptr->is_view()) {
1195         return;
1196     }
1197
1198     g_ptr->info |= CAVE_VIEW;
1199     floor_ptr->view_y[floor_ptr->view_n] = y;
1200     floor_ptr->view_x[floor_ptr->view_n] = x;
1201     floor_ptr->view_n++;
1202 }