OSDN Git Service

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