OSDN Git Service

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